File Coverage

inc/matrixssl-3-9-3-open/crypto/layer/matrix.c
Criterion Covered Total %
statement 16 21 76.1
branch 4 8 50.0
condition n/a
subroutine n/a
pod n/a
total 20 29 68.9


line stmt bran cond sub pod time code
1             /**
2             * @file matrix.c
3             * @version 950bba4 (HEAD -> master)
4             *
5             * Matrix Crypto Initialization and utility layer.
6             */
7             /*
8             * Copyright (c) 2013-2017 INSIDE Secure Corporation
9             * Copyright (c) PeerSec Networks, 2002-2011
10             * All Rights Reserved
11             *
12             * The latest version of this code is available at http://www.matrixssl.org
13             *
14             * This software is open source; you can redistribute it and/or modify
15             * it under the terms of the GNU General Public License as published by
16             * the Free Software Foundation; either version 2 of the License, or
17             * (at your option) any later version.
18             *
19             * This General Public License does NOT permit incorporating this software
20             * into proprietary programs. If you are unable to comply with the GPL, a
21             * commercial license for this software may be purchased from INSIDE at
22             * http://www.insidesecure.com/
23             *
24             * This program is distributed in WITHOUT ANY WARRANTY; without even the
25             * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
26             * See the GNU General Public License for more details.
27             *
28             * You should have received a copy of the GNU General Public License
29             * along with this program; if not, write to the Free Software
30             * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31             * http://www.gnu.org/copyleft/gpl.html
32             */
33             /******************************************************************************/
34              
35             #include "../cryptoImpl.h"
36              
37             /******************************************************************************/
38             /**
39             Open (initialize) the Crypto module.
40              
41             The config param should always be passed as:
42             PSCRYPTO_CONFIG
43             */
44             static char g_config[32] = "N";
45              
46 17           int32_t psCryptoOpen(const char *config)
47             {
48             uint32_t clen;
49            
50 17 50         if (*g_config == 'Y')
51             {
52 0           return PS_SUCCESS; /* Function has been called previously */
53             }
54              
55             /* 'config' is cryptoconfig + coreconfig */
56 17           clen = strlen(PSCRYPTO_CONFIG) - strlen(PSCORE_CONFIG);
57 17 50         if (strncmp(PSCRYPTO_CONFIG, config, clen) != 0)
58             {
59 0           psErrorStr( "Crypto config mismatch.\n" \
60             "Library: " PSCRYPTO_CONFIG \
61             "\nCurrent: %s\n", config);
62 0           return PS_FAILURE;
63             }
64 17 50         if (psCoreOpen(config + clen) < 0)
65             {
66 0           psError("pscore open failure\n");
67 0           return PS_FAILURE;
68             }
69              
70             #ifdef USE_FLPS_BINDING
71             flps_binding();
72             /* Check if FIPS Library Open failed. */
73             if ((int)CLS_LibStatus(flps_getCLS()) < 0)
74             {
75             return PS_SELFTEST_FAILED;
76             }
77             #endif /* USE_FLPS_BINDING */
78              
79 17           psOpenPrng();
80             #ifdef USE_CRL
81 17           psCrlOpen();
82             #endif
83              
84             /* Everything successful, store configuration. */
85 17           strncpy(g_config, PSCRYPTO_CONFIG, sizeof(g_config) - 1);
86              
87 17           return PS_SUCCESS;
88             }
89              
90 14           void psCryptoClose(void)
91             {
92 14 50         if (*g_config == 'Y')
93             {
94 14           *g_config = 'N';
95 14           psClosePrng();
96 14           psCoreClose();
97             #ifdef USE_CRL
98 14           psCrlClose();
99             #endif
100             }
101 14           }
102              
103             /******************************************************************************/