FIPS140 mode is detected on run-time.
[gnutls:gnutls.git] / lib / fips.h
1 /*
2  * Copyright (C) 2013 Red Hat
3  *
4  * Author: Nikos Mavrogiannopoulos
5  *
6  * This file is part of GnuTLS.
7  *
8  * The GnuTLS is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; either version 2.1 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>
20  *
21  */
22
23 #ifndef FIPS_H
24 # define FIPS_H
25
26 #include <gnutls_int.h>
27 #include <gnutls/gnutls.h>
28
29 #define FIPS140_RND_KEY_SIZE 32
30
31 typedef enum {
32   LIB_STATE_POWERON,
33   LIB_STATE_INIT,
34   LIB_STATE_SELFTEST,
35   LIB_STATE_OPERATIONAL,
36   LIB_STATE_ERROR,
37   LIB_STATE_SHUTDOWN
38 } gnutls_lib_state_t;
39
40 /* do not access directly */
41 extern unsigned int _gnutls_lib_mode;
42
43 inline static 
44 void _gnutls_switch_lib_state(gnutls_lib_state_t state)
45 {
46         /* Once into zombie state no errors can change us */
47         _gnutls_lib_mode = state;
48 }
49
50 inline static gnutls_lib_state_t _gnutls_get_lib_state(void)
51 {
52         return _gnutls_lib_mode;
53 }
54
55 int _gnutls_fips_perform_self_checks(void);
56
57 #ifdef ENABLE_FIPS140
58 unsigned _gnutls_fips_mode_enabled(void);
59 #else
60 # define _gnutls_fips_mode_enabled() 0
61 #endif
62
63 # define FAIL_IF_LIB_ERROR \
64         if (_gnutls_get_lib_state() != LIB_STATE_OPERATIONAL && \
65           _gnutls_get_lib_state() != LIB_STATE_SELFTEST) \
66         return GNUTLS_E_LIB_IN_ERROR_STATE
67
68 void _gnutls_switch_lib_state(gnutls_lib_state_t state);
69
70 void _gnutls_lib_simulate_error(void);
71
72 #endif /* FIPS_H */