|
|
0bf02d |
diff -up openssl-1.1.1g/crypto/ec/ec_curve.c.fips-curves openssl-1.1.1g/crypto/ec/ec_curve.c
|
|
|
0bf02d |
--- openssl-1.1.1g/crypto/ec/ec_curve.c.fips-curves 2020-05-18 12:59:54.839643980 +0200
|
|
|
0bf02d |
+++ openssl-1.1.1g/crypto/ec/ec_curve.c 2020-05-18 12:59:54.852644093 +0200
|
|
|
0bf02d |
@@ -13,6 +13,7 @@
|
|
|
0bf02d |
#include <openssl/err.h>
|
|
|
0bf02d |
#include <openssl/obj_mac.h>
|
|
|
0bf02d |
#include <openssl/opensslconf.h>
|
|
|
0bf02d |
+#include <openssl/crypto.h>
|
|
|
0bf02d |
#include "internal/nelem.h"
|
|
|
0bf02d |
|
|
|
0bf02d |
typedef struct {
|
|
|
0bf02d |
@@ -237,6 +238,7 @@ static const struct {
|
|
|
0bf02d |
|
|
|
0bf02d |
typedef struct _ec_list_element_st {
|
|
|
0bf02d |
int nid;
|
|
|
0bf02d |
+ int fips_allowed;
|
|
|
0bf02d |
const EC_CURVE_DATA *data;
|
|
|
0bf02d |
const EC_METHOD *(*meth) (void);
|
|
|
0bf02d |
const char *comment;
|
|
|
0bf02d |
@@ -246,23 +248,23 @@ static const ec_list_element curve_list[
|
|
|
0bf02d |
/* prime field curves */
|
|
|
0bf02d |
/* secg curves */
|
|
|
0bf02d |
#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128
|
|
|
0bf02d |
- {NID_secp224r1, &_EC_NIST_PRIME_224.h, EC_GFp_nistp224_method,
|
|
|
0bf02d |
+ {NID_secp224r1, 1, &_EC_NIST_PRIME_224.h, EC_GFp_nistp224_method,
|
|
|
0bf02d |
"NIST/SECG curve over a 224 bit prime field"},
|
|
|
0bf02d |
#else
|
|
|
0bf02d |
- {NID_secp224r1, &_EC_NIST_PRIME_224.h, 0,
|
|
|
0bf02d |
+ {NID_secp224r1, 1, &_EC_NIST_PRIME_224.h, 0,
|
|
|
0bf02d |
"NIST/SECG curve over a 224 bit prime field"},
|
|
|
0bf02d |
#endif
|
|
|
0bf02d |
- {NID_secp256k1, &_EC_SECG_PRIME_256K1.h, 0,
|
|
|
0bf02d |
+ {NID_secp256k1, 0, &_EC_SECG_PRIME_256K1.h, 0,
|
|
|
0bf02d |
"SECG curve over a 256 bit prime field"},
|
|
|
0bf02d |
/* SECG secp256r1 is the same as X9.62 prime256v1 and hence omitted */
|
|
|
0bf02d |
- {NID_secp384r1, &_EC_NIST_PRIME_384.h,
|
|
|
0bf02d |
+ {NID_secp384r1, 1, &_EC_NIST_PRIME_384.h,
|
|
|
0bf02d |
# if defined(S390X_EC_ASM)
|
|
|
0bf02d |
EC_GFp_s390x_nistp384_method,
|
|
|
0bf02d |
# else
|
|
|
0bf02d |
0,
|
|
|
0bf02d |
# endif
|
|
|
0bf02d |
"NIST/SECG curve over a 384 bit prime field"},
|
|
|
0bf02d |
- {NID_secp521r1, &_EC_NIST_PRIME_521.h,
|
|
|
0bf02d |
+ {NID_secp521r1, 1, &_EC_NIST_PRIME_521.h,
|
|
|
0bf02d |
# if defined(S390X_EC_ASM)
|
|
|
0bf02d |
EC_GFp_s390x_nistp521_method,
|
|
|
0bf02d |
# elif !defined(OPENSSL_NO_EC_NISTP_64_GCC_128)
|
|
|
0bf02d |
@@ -272,7 +274,7 @@ static const ec_list_element curve_list[
|
|
|
0bf02d |
# endif
|
|
|
0bf02d |
"NIST/SECG curve over a 521 bit prime field"},
|
|
|
0bf02d |
/* X9.62 curves */
|
|
|
0bf02d |
- {NID_X9_62_prime256v1, &_EC_X9_62_PRIME_256V1.h,
|
|
|
0bf02d |
+ {NID_X9_62_prime256v1, 1, &_EC_X9_62_PRIME_256V1.h,
|
|
|
0bf02d |
#if defined(ECP_NISTZ256_ASM)
|
|
|
0bf02d |
EC_GFp_nistz256_method,
|
|
|
0bf02d |
# elif defined(S390X_EC_ASM)
|
|
|
0bf02d |
@@ -404,6 +406,10 @@ EC_GROUP *EC_GROUP_new_by_curve_name(int
|
|
|
0bf02d |
|
|
|
0bf02d |
for (i = 0; i < curve_list_length; i++)
|
|
|
0bf02d |
if (curve_list[i].nid == nid) {
|
|
|
0bf02d |
+ if (!curve_list[i].fips_allowed && FIPS_mode()) {
|
|
|
0bf02d |
+ ECerr(EC_F_EC_GROUP_NEW_BY_CURVE_NAME, EC_R_NOT_A_NIST_PRIME);
|
|
|
0bf02d |
+ return NULL;
|
|
|
0bf02d |
+ }
|
|
|
0bf02d |
ret = ec_group_new_from_data(curve_list[i]);
|
|
|
0bf02d |
break;
|
|
|
0bf02d |
}
|
|
|
0bf02d |
@@ -418,19 +424,31 @@ EC_GROUP *EC_GROUP_new_by_curve_name(int
|
|
|
0bf02d |
|
|
|
0bf02d |
size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems)
|
|
|
0bf02d |
{
|
|
|
0bf02d |
- size_t i, min;
|
|
|
0bf02d |
+ size_t i, j, num;
|
|
|
0bf02d |
+ int fips_mode = FIPS_mode();
|
|
|
0bf02d |
|
|
|
0bf02d |
- if (r == NULL || nitems == 0)
|
|
|
0bf02d |
- return curve_list_length;
|
|
|
0bf02d |
+ num = curve_list_length;
|
|
|
0bf02d |
+ if (fips_mode)
|
|
|
0bf02d |
+ for (i = 0; i < curve_list_length; i++) {
|
|
|
0bf02d |
+ if (!curve_list[i].fips_allowed)
|
|
|
0bf02d |
+ --num;
|
|
|
0bf02d |
+ }
|
|
|
0bf02d |
|
|
|
0bf02d |
- min = nitems < curve_list_length ? nitems : curve_list_length;
|
|
|
0bf02d |
+ if (r == NULL || nitems == 0) {
|
|
|
0bf02d |
+ return num;
|
|
|
0bf02d |
+ }
|
|
|
0bf02d |
|
|
|
0bf02d |
- for (i = 0; i < min; i++) {
|
|
|
0bf02d |
- r[i].nid = curve_list[i].nid;
|
|
|
0bf02d |
- r[i].comment = curve_list[i].comment;
|
|
|
0bf02d |
+ for (i = 0, j = 0; i < curve_list_length; i++) {
|
|
|
0bf02d |
+ if (j >= nitems)
|
|
|
0bf02d |
+ break;
|
|
|
0bf02d |
+ if (!fips_mode || curve_list[i].fips_allowed) {
|
|
|
0bf02d |
+ r[j].nid = curve_list[i].nid;
|
|
|
0bf02d |
+ r[j].comment = curve_list[i].comment;
|
|
|
0bf02d |
+ ++j;
|
|
|
0bf02d |
+ }
|
|
|
0bf02d |
}
|
|
|
0bf02d |
|
|
|
0bf02d |
- return curve_list_length;
|
|
|
0bf02d |
+ return num;
|
|
|
0bf02d |
}
|
|
|
0bf02d |
|
|
|
0bf02d |
/* Functions to translate between common NIST curve names and NIDs */
|
|
|
0bf02d |
diff -up openssl-1.1.1g/ssl/t1_lib.c.fips-curves openssl-1.1.1g/ssl/t1_lib.c
|
|
|
0bf02d |
--- openssl-1.1.1g/ssl/t1_lib.c.fips-curves 2020-05-18 12:59:54.797643616 +0200
|
|
|
0bf02d |
+++ openssl-1.1.1g/ssl/t1_lib.c 2020-05-18 13:03:54.748725463 +0200
|
|
|
0bf02d |
@@ -678,6 +678,36 @@ static const uint16_t tls12_sigalgs[] =
|
|
|
0bf02d |
#endif
|
|
|
0bf02d |
};
|
|
|
0bf02d |
|
|
|
0bf02d |
+static const uint16_t tls12_fips_sigalgs[] = {
|
|
|
0bf02d |
+#ifndef OPENSSL_NO_EC
|
|
|
0bf02d |
+ TLSEXT_SIGALG_ecdsa_secp256r1_sha256,
|
|
|
0bf02d |
+ TLSEXT_SIGALG_ecdsa_secp384r1_sha384,
|
|
|
0bf02d |
+ TLSEXT_SIGALG_ecdsa_secp521r1_sha512,
|
|
|
0bf02d |
+#endif
|
|
|
0bf02d |
+
|
|
|
0bf02d |
+ TLSEXT_SIGALG_rsa_pss_pss_sha256,
|
|
|
0bf02d |
+ TLSEXT_SIGALG_rsa_pss_pss_sha384,
|
|
|
0bf02d |
+ TLSEXT_SIGALG_rsa_pss_pss_sha512,
|
|
|
0bf02d |
+ TLSEXT_SIGALG_rsa_pss_rsae_sha256,
|
|
|
0bf02d |
+ TLSEXT_SIGALG_rsa_pss_rsae_sha384,
|
|
|
0bf02d |
+ TLSEXT_SIGALG_rsa_pss_rsae_sha512,
|
|
|
0bf02d |
+
|
|
|
0bf02d |
+ TLSEXT_SIGALG_rsa_pkcs1_sha256,
|
|
|
0bf02d |
+ TLSEXT_SIGALG_rsa_pkcs1_sha384,
|
|
|
0bf02d |
+ TLSEXT_SIGALG_rsa_pkcs1_sha512,
|
|
|
0bf02d |
+
|
|
|
0bf02d |
+#ifndef OPENSSL_NO_EC
|
|
|
0bf02d |
+ TLSEXT_SIGALG_ecdsa_sha224,
|
|
|
0bf02d |
+#endif
|
|
|
0bf02d |
+ TLSEXT_SIGALG_rsa_pkcs1_sha224,
|
|
|
0bf02d |
+#ifndef OPENSSL_NO_DSA
|
|
|
0bf02d |
+ TLSEXT_SIGALG_dsa_sha224,
|
|
|
0bf02d |
+ TLSEXT_SIGALG_dsa_sha256,
|
|
|
0bf02d |
+ TLSEXT_SIGALG_dsa_sha384,
|
|
|
0bf02d |
+ TLSEXT_SIGALG_dsa_sha512,
|
|
|
0bf02d |
+#endif
|
|
|
0bf02d |
+};
|
|
|
0bf02d |
+
|
|
|
0bf02d |
#ifndef OPENSSL_NO_EC
|
|
|
0bf02d |
static const uint16_t suiteb_sigalgs[] = {
|
|
|
0bf02d |
TLSEXT_SIGALG_ecdsa_secp256r1_sha256,
|
|
|
0bf02d |
@@ -894,6 +924,8 @@ static const SIGALG_LOOKUP *tls1_get_leg
|
|
|
0bf02d |
}
|
|
|
0bf02d |
if (idx < 0 || idx >= (int)OSSL_NELEM(tls_default_sigalg))
|
|
|
0bf02d |
return NULL;
|
|
|
0bf02d |
+ if (FIPS_mode()) /* We do not allow legacy SHA1 signatures in FIPS mode */
|
|
|
0bf02d |
+ return NULL;
|
|
|
0bf02d |
if (SSL_USE_SIGALGS(s) || idx != SSL_PKEY_RSA) {
|
|
|
0bf02d |
const SIGALG_LOOKUP *lu = tls1_lookup_sigalg(tls_default_sigalg[idx]);
|
|
|
0bf02d |
|
|
|
0bf02d |
@@ -954,6 +986,9 @@ size_t tls12_get_psigalgs(SSL *s, int se
|
|
|
0bf02d |
} else if (s->cert->conf_sigalgs) {
|
|
|
0bf02d |
*psigs = s->cert->conf_sigalgs;
|
|
|
0bf02d |
return s->cert->conf_sigalgslen;
|
|
|
0bf02d |
+ } else if (FIPS_mode()) {
|
|
|
0bf02d |
+ *psigs = tls12_fips_sigalgs;
|
|
|
0bf02d |
+ return OSSL_NELEM(tls12_fips_sigalgs);
|
|
|
0bf02d |
} else {
|
|
|
0bf02d |
*psigs = tls12_sigalgs;
|
|
|
0bf02d |
return OSSL_NELEM(tls12_sigalgs);
|
|
|
0bf02d |
@@ -973,6 +1008,9 @@ int tls_check_sigalg_curve(const SSL *s,
|
|
|
0bf02d |
if (s->cert->conf_sigalgs) {
|
|
|
0bf02d |
sigs = s->cert->conf_sigalgs;
|
|
|
0bf02d |
siglen = s->cert->conf_sigalgslen;
|
|
|
0bf02d |
+ } else if (FIPS_mode()) {
|
|
|
0bf02d |
+ sigs = tls12_fips_sigalgs;
|
|
|
0bf02d |
+ siglen = OSSL_NELEM(tls12_fips_sigalgs);
|
|
|
0bf02d |
} else {
|
|
|
0bf02d |
sigs = tls12_sigalgs;
|
|
|
0bf02d |
siglen = OSSL_NELEM(tls12_sigalgs);
|
|
|
0bf02d |
@@ -1617,6 +1655,8 @@ static int tls12_sigalg_allowed(const SS
|
|
|
0bf02d |
if (lu->sig == NID_id_GostR3410_2012_256
|
|
|
0bf02d |
|| lu->sig == NID_id_GostR3410_2012_512
|
|
|
0bf02d |
|| lu->sig == NID_id_GostR3410_2001) {
|
|
|
0bf02d |
+ if (FIPS_mode())
|
|
|
0bf02d |
+ return 0;
|
|
|
0bf02d |
/* We never allow GOST sig algs on the server with TLSv1.3 */
|
|
|
0bf02d |
if (s->server && SSL_IS_TLS13(s))
|
|
|
0bf02d |
return 0;
|
|
|
0bf02d |
@@ -2842,6 +2882,13 @@ int tls_choose_sigalg(SSL *s, int fatale
|
|
|
0bf02d |
const uint16_t *sent_sigs;
|
|
|
0bf02d |
size_t sent_sigslen;
|
|
|
0bf02d |
|
|
|
0bf02d |
+ if (fatalerrs && FIPS_mode()) {
|
|
|
0bf02d |
+ /* There are no suitable legacy algorithms in FIPS mode */
|
|
|
0bf02d |
+ SSLfatal(s, SSL_AD_HANDSHAKE_FAILURE,
|
|
|
0bf02d |
+ SSL_F_TLS_CHOOSE_SIGALG,
|
|
|
0bf02d |
+ SSL_R_NO_SUITABLE_SIGNATURE_ALGORITHM);
|
|
|
0bf02d |
+ return 0;
|
|
|
0bf02d |
+ }
|
|
|
0bf02d |
if ((lu = tls1_get_legacy_sigalg(s, -1)) == NULL) {
|
|
|
0bf02d |
if (!fatalerrs)
|
|
|
0bf02d |
return 1;
|