|
Packit Service |
4684c1 |
/*
|
|
Packit Service |
4684c1 |
* Copyright (C) 2013 Red Hat
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Author: Nikos Mavrogiannopoulos
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This file is part of GnuTLS.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* The GnuTLS is free software; you can redistribute it and/or
|
|
Packit Service |
4684c1 |
* modify it under the terms of the GNU Lesser General Public License
|
|
Packit Service |
4684c1 |
* as published by the Free Software Foundation; either version 2.1 of
|
|
Packit Service |
4684c1 |
* the License, or (at your option) any later version.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This library is distributed in the hope that it will be useful, but
|
|
Packit Service |
4684c1 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
4684c1 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
4684c1 |
* Lesser General Public License for more details.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit Service |
4684c1 |
* along with this program. If not, see <https://www.gnu.org/licenses/>
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifndef GNUTLS_LIB_FIPS_H
|
|
Packit Service |
4684c1 |
#define GNUTLS_LIB_FIPS_H
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include "gnutls_int.h"
|
|
Packit Service |
4684c1 |
#include <gnutls/gnutls.h>
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#define FIPS140_RND_KEY_SIZE 32
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
typedef enum {
|
|
Packit Service |
4684c1 |
LIB_STATE_POWERON,
|
|
Packit Service |
4684c1 |
LIB_STATE_INIT,
|
|
Packit Service |
4684c1 |
LIB_STATE_SELFTEST,
|
|
Packit Service |
4684c1 |
LIB_STATE_OPERATIONAL,
|
|
Packit Service |
4684c1 |
LIB_STATE_ERROR,
|
|
Packit Service |
4684c1 |
LIB_STATE_SHUTDOWN
|
|
Packit Service |
4684c1 |
} gnutls_lib_state_t;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* do not access directly */
|
|
Packit Service |
4684c1 |
extern unsigned int _gnutls_lib_state;
|
|
Packit Service |
4684c1 |
extern gnutls_crypto_rnd_st _gnutls_fips_rnd_ops;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
inline static
|
|
Packit Service |
4684c1 |
void _gnutls_switch_lib_state(gnutls_lib_state_t state)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
/* Once into zombie state no errors can change us */
|
|
Packit Service |
4684c1 |
_gnutls_lib_state = state;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
inline static gnutls_lib_state_t _gnutls_get_lib_state(void)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
return _gnutls_lib_state;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
int _gnutls_fips_perform_self_checks1(void);
|
|
Packit Service |
4684c1 |
int _gnutls_fips_perform_self_checks2(void);
|
|
Packit Service |
4684c1 |
void _gnutls_fips_mode_reset_zombie(void);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifdef ENABLE_FIPS140
|
|
Packit Service |
4684c1 |
unsigned _gnutls_fips_mode_enabled(void);
|
|
Packit Service |
4684c1 |
#else
|
|
Packit Service |
4684c1 |
# define _gnutls_fips_mode_enabled() 0
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
# define HAVE_LIB_ERROR() unlikely(_gnutls_get_lib_state() != LIB_STATE_OPERATIONAL && _gnutls_get_lib_state() != LIB_STATE_SELFTEST)
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
# define FAIL_IF_LIB_ERROR \
|
|
Packit Service |
4684c1 |
if (HAVE_LIB_ERROR()) return GNUTLS_E_LIB_IN_ERROR_STATE
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
void _gnutls_switch_lib_state(gnutls_lib_state_t state);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
void _gnutls_lib_simulate_error(void);
|
|
Packit Service |
4684c1 |
void _gnutls_lib_force_operational(void);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifdef ENABLE_FIPS140
|
|
Packit Service |
4684c1 |
/* This will test the condition when in FIPS140-2 mode
|
|
Packit Service |
4684c1 |
* and return an error if necessary or ignore */
|
|
Packit Service |
4684c1 |
# define FIPS_RULE(condition, ret_error, ...) { \
|
|
Packit Service |
4684c1 |
gnutls_fips_mode_t _mode = _gnutls_fips_mode_enabled(); \
|
|
Packit Service |
4684c1 |
if (_mode != GNUTLS_FIPS140_DISABLED) { \
|
|
Packit Service |
4684c1 |
if (condition) { \
|
|
Packit Service |
4684c1 |
if (_mode == GNUTLS_FIPS140_LOG) { \
|
|
Packit Service |
4684c1 |
_gnutls_audit_log(NULL, "fips140-2: allowing "__VA_ARGS__); \
|
|
Packit Service |
4684c1 |
} else if (_mode != GNUTLS_FIPS140_LAX) { \
|
|
Packit Service |
4684c1 |
_gnutls_debug_log("fips140-2: disallowing "__VA_ARGS__); \
|
|
Packit Service |
4684c1 |
return ret_error; \
|
|
Packit Service |
4684c1 |
} \
|
|
Packit Service |
4684c1 |
} \
|
|
Packit Service |
4684c1 |
}}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
inline
|
|
Packit Service |
4684c1 |
static unsigned is_mac_algo_forbidden(gnutls_mac_algorithm_t algo)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
gnutls_fips_mode_t mode = _gnutls_fips_mode_enabled();
|
|
Packit Service |
4684c1 |
if (mode != GNUTLS_FIPS140_DISABLED &&
|
|
Packit Service |
4684c1 |
_gnutls_get_lib_state() != LIB_STATE_SELFTEST) {
|
|
Packit Service |
4684c1 |
switch(algo) {
|
|
Packit Service |
4684c1 |
case GNUTLS_MAC_SHA1:
|
|
Packit Service |
4684c1 |
case GNUTLS_MAC_SHA256:
|
|
Packit Service |
4684c1 |
case GNUTLS_MAC_SHA384:
|
|
Packit Service |
4684c1 |
case GNUTLS_MAC_SHA512:
|
|
Packit Service |
4684c1 |
case GNUTLS_MAC_SHA224:
|
|
Packit Service |
4684c1 |
case GNUTLS_MAC_SHA3_224:
|
|
Packit Service |
4684c1 |
case GNUTLS_MAC_SHA3_256:
|
|
Packit Service |
4684c1 |
case GNUTLS_MAC_SHA3_384:
|
|
Packit Service |
4684c1 |
case GNUTLS_MAC_SHA3_512:
|
|
Packit Service |
4684c1 |
case GNUTLS_MAC_AES_CMAC_128:
|
|
Packit Service |
4684c1 |
case GNUTLS_MAC_AES_CMAC_256:
|
|
Packit Service |
4684c1 |
case GNUTLS_MAC_AES_GMAC_128:
|
|
Packit Service |
4684c1 |
case GNUTLS_MAC_AES_GMAC_192:
|
|
Packit Service |
4684c1 |
case GNUTLS_MAC_AES_GMAC_256:
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
default:
|
|
Packit Service |
4684c1 |
if (mode == GNUTLS_FIPS140_LAX)
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
else if (mode == GNUTLS_FIPS140_LOG) {
|
|
Packit Service |
4684c1 |
_gnutls_audit_log(NULL, "fips140-2: allowing access to %s\n",
|
|
Packit Service |
4684c1 |
gnutls_mac_get_name(algo));
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
return 1;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
inline
|
|
Packit Service |
4684c1 |
static unsigned is_cipher_algo_forbidden(gnutls_cipher_algorithm_t algo)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
gnutls_fips_mode_t mode = _gnutls_fips_mode_enabled();
|
|
Packit Service |
4684c1 |
if (mode != GNUTLS_FIPS140_DISABLED &&
|
|
Packit Service |
4684c1 |
_gnutls_get_lib_state() != LIB_STATE_SELFTEST) {
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
switch(algo) {
|
|
Packit Service |
4684c1 |
case GNUTLS_CIPHER_AES_128_CBC:
|
|
Packit Service |
4684c1 |
case GNUTLS_CIPHER_AES_256_CBC:
|
|
Packit Service |
4684c1 |
case GNUTLS_CIPHER_AES_192_CBC:
|
|
Packit Service |
4684c1 |
case GNUTLS_CIPHER_AES_128_GCM:
|
|
Packit Service |
4684c1 |
case GNUTLS_CIPHER_AES_192_GCM:
|
|
Packit Service |
4684c1 |
case GNUTLS_CIPHER_AES_256_GCM:
|
|
Packit Service |
4684c1 |
case GNUTLS_CIPHER_AES_128_CCM:
|
|
Packit Service |
4684c1 |
case GNUTLS_CIPHER_AES_256_CCM:
|
|
Packit Service |
4684c1 |
case GNUTLS_CIPHER_3DES_CBC:
|
|
Packit Service |
4684c1 |
case GNUTLS_CIPHER_AES_128_CCM_8:
|
|
Packit Service |
4684c1 |
case GNUTLS_CIPHER_AES_256_CCM_8:
|
|
Packit Service |
4684c1 |
case GNUTLS_CIPHER_AES_128_CFB8:
|
|
Packit Service |
4684c1 |
case GNUTLS_CIPHER_AES_192_CFB8:
|
|
Packit Service |
4684c1 |
case GNUTLS_CIPHER_AES_256_CFB8:
|
|
Packit Service |
4684c1 |
case GNUTLS_CIPHER_AES_128_XTS:
|
|
Packit Service |
4684c1 |
case GNUTLS_CIPHER_AES_256_XTS:
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
default:
|
|
Packit Service |
4684c1 |
if (mode == GNUTLS_FIPS140_LAX)
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
else if (mode == GNUTLS_FIPS140_LOG) {
|
|
Packit Service |
4684c1 |
_gnutls_audit_log(NULL, "fips140-2: allowing access to %s\n",
|
|
Packit Service |
4684c1 |
gnutls_cipher_get_name(algo));
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
return 1;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
#else
|
|
Packit Service |
4684c1 |
# define is_mac_algo_forbidden(x) 0
|
|
Packit Service |
4684c1 |
# define is_cipher_algo_forbidden(x) 0
|
|
Packit Service |
4684c1 |
# define FIPS_RULE(condition, ret_error, ...)
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#endif /* GNUTLS_LIB_FIPS_H */
|