|
|
cd0318 |
From 171b934a8c054e98b110892cae4130e1db64e656 Mon Sep 17 00:00:00 2001
|
|
|
cd0318 |
From: rpm-build <rpm-build>
|
|
|
cd0318 |
Date: Thu, 29 Sep 2022 21:28:19 +0900
|
|
|
cd0318 |
Subject: [PATCH] gnutls-3.7.6-fips-ecdsa-hash-check.patch
|
|
|
cd0318 |
|
|
|
cd0318 |
---
|
|
|
cd0318 |
lib/crypto-backend.h | 12 ++--
|
|
|
cd0318 |
lib/nettle/pk.c | 33 +++++-----
|
|
|
cd0318 |
lib/privkey.c | 42 ++++++++----
|
|
|
cd0318 |
lib/pubkey.c | 5 +-
|
|
|
cd0318 |
tests/fips-test.c | 150 ++++++++++++++++++++++++++++++++++++++++++-
|
|
|
cd0318 |
5 files changed, 205 insertions(+), 37 deletions(-)
|
|
|
cd0318 |
|
|
|
cd0318 |
diff --git a/lib/crypto-backend.h b/lib/crypto-backend.h
|
|
|
cd0318 |
index f0f68c3..4dd1ae2 100644
|
|
|
cd0318 |
--- a/lib/crypto-backend.h
|
|
|
cd0318 |
+++ b/lib/crypto-backend.h
|
|
|
cd0318 |
@@ -247,11 +247,13 @@ typedef enum {
|
|
|
cd0318 |
GNUTLS_PK_FLAG_RSA_PSS_FIXED_SALT_LENGTH = 4
|
|
|
cd0318 |
} gnutls_pk_flag_t;
|
|
|
cd0318 |
|
|
|
cd0318 |
-#define FIX_SIGN_PARAMS(params, flags, dig) do { \
|
|
|
cd0318 |
- if ((flags) & GNUTLS_PRIVKEY_FLAG_REPRODUCIBLE) { \
|
|
|
cd0318 |
- (params).flags |= GNUTLS_PK_FLAG_REPRODUCIBLE; \
|
|
|
cd0318 |
- (params).dsa_dig = (dig); \
|
|
|
cd0318 |
- } \
|
|
|
cd0318 |
+#define FIX_SIGN_PARAMS(params, flags, dig) do { \
|
|
|
cd0318 |
+ if ((flags) & GNUTLS_PRIVKEY_FLAG_REPRODUCIBLE) { \
|
|
|
cd0318 |
+ (params).flags |= GNUTLS_PK_FLAG_REPRODUCIBLE; \
|
|
|
cd0318 |
+ } \
|
|
|
cd0318 |
+ if ((params).pk == GNUTLS_PK_DSA || (params).pk == GNUTLS_PK_ECDSA) { \
|
|
|
cd0318 |
+ (params).dsa_dig = (dig); \
|
|
|
cd0318 |
+ } \
|
|
|
cd0318 |
} while (0)
|
|
|
cd0318 |
|
|
|
cd0318 |
void gnutls_pk_params_release(gnutls_pk_params_st * p);
|
|
|
cd0318 |
diff --git a/lib/nettle/pk.c b/lib/nettle/pk.c
|
|
|
cd0318 |
index f38016b..c098e2a 100644
|
|
|
cd0318 |
--- a/lib/nettle/pk.c
|
|
|
cd0318 |
+++ b/lib/nettle/pk.c
|
|
|
cd0318 |
@@ -1104,8 +1104,16 @@ _wrap_nettle_pk_sign(gnutls_pk_algorithm_t algo,
|
|
|
cd0318 |
me = _gnutls_dsa_q_to_hash(pk_params,
|
|
|
cd0318 |
&hash_len);
|
|
|
cd0318 |
|
|
|
cd0318 |
+ if (hash_len > vdata->size) {
|
|
|
cd0318 |
+ gnutls_assert();
|
|
|
cd0318 |
+ _gnutls_debug_log
|
|
|
cd0318 |
+ ("Security level of algorithm requires hash %s(%d) or better\n",
|
|
|
cd0318 |
+ _gnutls_mac_get_name(me), hash_len);
|
|
|
cd0318 |
+ hash_len = vdata->size;
|
|
|
cd0318 |
+ }
|
|
|
cd0318 |
+
|
|
|
cd0318 |
/* Only SHA-2 is allowed in FIPS 140-3 */
|
|
|
cd0318 |
- switch (me->id) {
|
|
|
cd0318 |
+ switch (DIG_TO_MAC(sign_params->dsa_dig)) {
|
|
|
cd0318 |
case GNUTLS_MAC_SHA256:
|
|
|
cd0318 |
case GNUTLS_MAC_SHA384:
|
|
|
cd0318 |
case GNUTLS_MAC_SHA512:
|
|
|
cd0318 |
@@ -1115,14 +1123,6 @@ _wrap_nettle_pk_sign(gnutls_pk_algorithm_t algo,
|
|
|
cd0318 |
not_approved = true;
|
|
|
cd0318 |
}
|
|
|
cd0318 |
|
|
|
cd0318 |
- if (hash_len > vdata->size) {
|
|
|
cd0318 |
- gnutls_assert();
|
|
|
cd0318 |
- _gnutls_debug_log
|
|
|
cd0318 |
- ("Security level of algorithm requires hash %s(%d) or better\n",
|
|
|
cd0318 |
- _gnutls_mac_get_name(me), hash_len);
|
|
|
cd0318 |
- hash_len = vdata->size;
|
|
|
cd0318 |
- }
|
|
|
cd0318 |
-
|
|
|
cd0318 |
mpz_init(k);
|
|
|
cd0318 |
if (_gnutls_get_lib_state() == LIB_STATE_SELFTEST ||
|
|
|
cd0318 |
(sign_params->flags & GNUTLS_PK_FLAG_REPRODUCIBLE)) {
|
|
|
cd0318 |
@@ -1545,7 +1545,6 @@ _wrap_nettle_pk_verify(gnutls_pk_algorithm_t algo,
|
|
|
cd0318 |
struct dsa_signature sig;
|
|
|
cd0318 |
int curve_id = pk_params->curve;
|
|
|
cd0318 |
const struct ecc_curve *curve;
|
|
|
cd0318 |
- const mac_entry_st *me;
|
|
|
cd0318 |
|
|
|
cd0318 |
curve = get_supported_nist_curve(curve_id);
|
|
|
cd0318 |
if (curve == NULL) {
|
|
|
cd0318 |
@@ -1571,11 +1570,14 @@ _wrap_nettle_pk_verify(gnutls_pk_algorithm_t algo,
|
|
|
cd0318 |
memcpy(sig.r, tmp[0], SIZEOF_MPZT);
|
|
|
cd0318 |
memcpy(sig.s, tmp[1], SIZEOF_MPZT);
|
|
|
cd0318 |
|
|
|
cd0318 |
- me = _gnutls_dsa_q_to_hash(pk_params, &hash_len);
|
|
|
cd0318 |
+ (void)_gnutls_dsa_q_to_hash(pk_params, &hash_len);
|
|
|
cd0318 |
+
|
|
|
cd0318 |
+ if (hash_len > vdata->size)
|
|
|
cd0318 |
+ hash_len = vdata->size;
|
|
|
cd0318 |
|
|
|
cd0318 |
/* SHA-1 is allowed for SigVer in FIPS 140-3 in legacy
|
|
|
cd0318 |
* mode */
|
|
|
cd0318 |
- switch (me->id) {
|
|
|
cd0318 |
+ switch (DIG_TO_MAC(sign_params->dsa_dig)) {
|
|
|
cd0318 |
case GNUTLS_MAC_SHA1:
|
|
|
cd0318 |
case GNUTLS_MAC_SHA256:
|
|
|
cd0318 |
case GNUTLS_MAC_SHA384:
|
|
|
cd0318 |
@@ -1586,9 +1588,6 @@ _wrap_nettle_pk_verify(gnutls_pk_algorithm_t algo,
|
|
|
cd0318 |
not_approved = true;
|
|
|
cd0318 |
}
|
|
|
cd0318 |
|
|
|
cd0318 |
- if (hash_len > vdata->size)
|
|
|
cd0318 |
- hash_len = vdata->size;
|
|
|
cd0318 |
-
|
|
|
cd0318 |
ret =
|
|
|
cd0318 |
ecdsa_verify(&pub, hash_len, vdata->data,
|
|
|
cd0318 |
&sig);
|
|
|
cd0318 |
@@ -2390,8 +2389,10 @@ static int pct_test(gnutls_pk_algorithm_t algo, const gnutls_pk_params_st* param
|
|
|
cd0318 |
|
|
|
cd0318 |
if (algo == GNUTLS_PK_DSA || algo == GNUTLS_PK_EC) {
|
|
|
cd0318 |
unsigned hash_len;
|
|
|
cd0318 |
+ const mac_entry_st *me;
|
|
|
cd0318 |
|
|
|
cd0318 |
- _gnutls_dsa_q_to_hash(params, &hash_len);
|
|
|
cd0318 |
+ me = _gnutls_dsa_q_to_hash(params, &hash_len);
|
|
|
cd0318 |
+ spki.dsa_dig = MAC_TO_DIG(me->id);
|
|
|
cd0318 |
gen_data = gnutls_malloc(hash_len);
|
|
|
cd0318 |
gnutls_rnd(GNUTLS_RND_NONCE, gen_data, hash_len);
|
|
|
cd0318 |
|
|
|
cd0318 |
diff --git a/lib/privkey.c b/lib/privkey.c
|
|
|
cd0318 |
index 0b77443..2069fc0 100644
|
|
|
cd0318 |
--- a/lib/privkey.c
|
|
|
cd0318 |
+++ b/lib/privkey.c
|
|
|
cd0318 |
@@ -1251,27 +1251,36 @@ gnutls_privkey_sign_hash2(gnutls_privkey_t signer,
|
|
|
cd0318 |
se = _gnutls_sign_to_entry(GNUTLS_SIGN_RSA_RAW);
|
|
|
cd0318 |
} else {
|
|
|
cd0318 |
se = _gnutls_sign_to_entry(algo);
|
|
|
cd0318 |
- if (unlikely(se == NULL))
|
|
|
cd0318 |
- return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
|
|
|
cd0318 |
-
|
|
|
cd0318 |
+ if (unlikely(se == NULL)) {
|
|
|
cd0318 |
+ ret = gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
|
|
|
cd0318 |
+ goto cleanup;
|
|
|
cd0318 |
+ }
|
|
|
cd0318 |
}
|
|
|
cd0318 |
|
|
|
cd0318 |
ret = _gnutls_privkey_get_spki_params(signer, ¶ms);
|
|
|
cd0318 |
if (ret < 0) {
|
|
|
cd0318 |
gnutls_assert();
|
|
|
cd0318 |
- return ret;
|
|
|
cd0318 |
+ goto cleanup;
|
|
|
cd0318 |
}
|
|
|
cd0318 |
|
|
|
cd0318 |
ret = _gnutls_privkey_update_spki_params(signer, se->pk, se->hash,
|
|
|
cd0318 |
flags, ¶ms);
|
|
|
cd0318 |
if (ret < 0) {
|
|
|
cd0318 |
gnutls_assert();
|
|
|
cd0318 |
- return ret;
|
|
|
cd0318 |
+ goto cleanup;
|
|
|
cd0318 |
}
|
|
|
cd0318 |
|
|
|
cd0318 |
FIX_SIGN_PARAMS(params, flags, se->hash);
|
|
|
cd0318 |
|
|
|
cd0318 |
- return privkey_sign_prehashed(signer, se, hash_data, signature, ¶ms);
|
|
|
cd0318 |
+ ret = privkey_sign_prehashed(signer, se, hash_data, signature, ¶ms);
|
|
|
cd0318 |
+
|
|
|
cd0318 |
+ cleanup:
|
|
|
cd0318 |
+ if (ret < 0) {
|
|
|
cd0318 |
+ _gnutls_switch_fips_state(GNUTLS_FIPS140_OP_ERROR);
|
|
|
cd0318 |
+ } else {
|
|
|
cd0318 |
+ _gnutls_switch_fips_state(GNUTLS_FIPS140_OP_NOT_APPROVED);
|
|
|
cd0318 |
+ }
|
|
|
cd0318 |
+ return ret;
|
|
|
cd0318 |
}
|
|
|
cd0318 |
|
|
|
cd0318 |
int
|
|
|
cd0318 |
@@ -1366,14 +1375,14 @@ gnutls_privkey_sign_hash(gnutls_privkey_t signer,
|
|
|
cd0318 |
ret = _gnutls_privkey_get_spki_params(signer, ¶ms);
|
|
|
cd0318 |
if (ret < 0) {
|
|
|
cd0318 |
gnutls_assert();
|
|
|
cd0318 |
- return ret;
|
|
|
cd0318 |
+ goto cleanup;
|
|
|
cd0318 |
}
|
|
|
cd0318 |
|
|
|
cd0318 |
ret = _gnutls_privkey_update_spki_params(signer, signer->pk_algorithm,
|
|
|
cd0318 |
hash_algo, flags, ¶ms);
|
|
|
cd0318 |
if (ret < 0) {
|
|
|
cd0318 |
gnutls_assert();
|
|
|
cd0318 |
- return ret;
|
|
|
cd0318 |
+ goto cleanup;
|
|
|
cd0318 |
}
|
|
|
cd0318 |
|
|
|
cd0318 |
/* legacy callers of this API could use a hash algorithm of 0 (unknown)
|
|
|
cd0318 |
@@ -1391,13 +1400,22 @@ gnutls_privkey_sign_hash(gnutls_privkey_t signer,
|
|
|
cd0318 |
se = _gnutls_pk_to_sign_entry(params.pk, hash_algo);
|
|
|
cd0318 |
}
|
|
|
cd0318 |
|
|
|
cd0318 |
- if (unlikely(se == NULL))
|
|
|
cd0318 |
- return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
|
|
|
cd0318 |
+ if (unlikely(se == NULL)) {
|
|
|
cd0318 |
+ ret = gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
|
|
|
cd0318 |
+ goto cleanup;
|
|
|
cd0318 |
+ }
|
|
|
cd0318 |
|
|
|
cd0318 |
FIX_SIGN_PARAMS(params, flags, hash_algo);
|
|
|
cd0318 |
|
|
|
cd0318 |
- return privkey_sign_prehashed(signer, se,
|
|
|
cd0318 |
- hash_data, signature, ¶ms);
|
|
|
cd0318 |
+ ret = privkey_sign_prehashed(signer, se,
|
|
|
cd0318 |
+ hash_data, signature, ¶ms);
|
|
|
cd0318 |
+ cleanup:
|
|
|
cd0318 |
+ if (ret < 0) {
|
|
|
cd0318 |
+ _gnutls_switch_fips_state(GNUTLS_FIPS140_OP_ERROR);
|
|
|
cd0318 |
+ } else {
|
|
|
cd0318 |
+ _gnutls_switch_fips_state(GNUTLS_FIPS140_OP_NOT_APPROVED);
|
|
|
cd0318 |
+ }
|
|
|
cd0318 |
+ return ret;
|
|
|
cd0318 |
}
|
|
|
cd0318 |
|
|
|
cd0318 |
static int
|
|
|
cd0318 |
diff --git a/lib/pubkey.c b/lib/pubkey.c
|
|
|
cd0318 |
index eba1f5b..35126f3 100644
|
|
|
cd0318 |
--- a/lib/pubkey.c
|
|
|
cd0318 |
+++ b/lib/pubkey.c
|
|
|
cd0318 |
@@ -1985,7 +1985,7 @@ gnutls_pubkey_import_dsa_raw(gnutls_pubkey_t key,
|
|
|
cd0318 |
* parameters (if any) with the signature algorithm */
|
|
|
cd0318 |
static
|
|
|
cd0318 |
int fixup_spki_params(const gnutls_pk_params_st *key_params, const gnutls_sign_entry_st *se,
|
|
|
cd0318 |
- const mac_entry_st *me, gnutls_x509_spki_st *params)
|
|
|
cd0318 |
+ const mac_entry_st *me, gnutls_x509_spki_st *params)
|
|
|
cd0318 |
{
|
|
|
cd0318 |
unsigned bits;
|
|
|
cd0318 |
|
|
|
cd0318 |
@@ -2018,6 +2018,9 @@ int fixup_spki_params(const gnutls_pk_params_st *key_params, const gnutls_sign_e
|
|
|
cd0318 |
|
|
|
cd0318 |
if (params->rsa_pss_dig != se->hash)
|
|
|
cd0318 |
return gnutls_assert_val(GNUTLS_E_CONSTRAINT_ERROR);
|
|
|
cd0318 |
+ } else if (params->pk == GNUTLS_PK_DSA ||
|
|
|
cd0318 |
+ params->pk == GNUTLS_PK_ECDSA) {
|
|
|
cd0318 |
+ params->dsa_dig = se->hash;
|
|
|
cd0318 |
}
|
|
|
cd0318 |
|
|
|
cd0318 |
return 0;
|
|
|
cd0318 |
diff --git a/tests/fips-test.c b/tests/fips-test.c
|
|
|
cd0318 |
index 788f4ab..ec0f4b4 100644
|
|
|
cd0318 |
--- a/tests/fips-test.c
|
|
|
cd0318 |
+++ b/tests/fips-test.c
|
|
|
cd0318 |
@@ -80,8 +80,22 @@ static const gnutls_datum_t rsa2342_sha1_sig = {
|
|
|
cd0318 |
.size = sizeof(rsa2342_sha1_sig_data),
|
|
|
cd0318 |
};
|
|
|
cd0318 |
|
|
|
cd0318 |
+static const uint8_t ecc256_sha1_sig_data[] = {
|
|
|
cd0318 |
+ 0x30, 0x45, 0x02, 0x21, 0x00, 0x9a, 0x28, 0xc9, 0xbf, 0xc8, 0x70, 0x4f,
|
|
|
cd0318 |
+ 0x27, 0x2d, 0xe1, 0x66, 0xc4, 0xa5, 0xc6, 0xf2, 0xdc, 0x33, 0xb9, 0x41,
|
|
|
cd0318 |
+ 0xdf, 0x78, 0x98, 0x8a, 0x22, 0x4d, 0x29, 0x37, 0xa0, 0x0f, 0x6f, 0xd4,
|
|
|
cd0318 |
+ 0xed, 0x02, 0x20, 0x0b, 0x15, 0xca, 0x30, 0x09, 0x2d, 0x55, 0x44, 0xb4,
|
|
|
cd0318 |
+ 0x1d, 0x3f, 0x48, 0x7a, 0xc3, 0xd1, 0x2a, 0xc1, 0x0e, 0x47, 0xfa, 0xe6,
|
|
|
cd0318 |
+ 0xe9, 0x0f, 0x03, 0xe2, 0x01, 0x4e, 0xe4, 0x73, 0x37, 0xa7, 0x90,
|
|
|
cd0318 |
+};
|
|
|
cd0318 |
+
|
|
|
cd0318 |
+static const gnutls_datum_t ecc256_sha1_sig = {
|
|
|
cd0318 |
+ .data = (unsigned char *)ecc256_sha1_sig_data,
|
|
|
cd0318 |
+ .size = sizeof(ecc256_sha1_sig_data),
|
|
|
cd0318 |
+};
|
|
|
cd0318 |
+
|
|
|
cd0318 |
static void
|
|
|
cd0318 |
-rsa_import_keypair(gnutls_privkey_t *privkey, gnutls_pubkey_t *pubkey,
|
|
|
cd0318 |
+import_keypair(gnutls_privkey_t *privkey, gnutls_pubkey_t *pubkey,
|
|
|
cd0318 |
const char *filename)
|
|
|
cd0318 |
{
|
|
|
cd0318 |
const char *srcdir;
|
|
|
cd0318 |
@@ -274,6 +288,8 @@ void doit(void)
|
|
|
cd0318 |
gnutls_datum_t signature;
|
|
|
cd0318 |
unsigned int bits;
|
|
|
cd0318 |
uint8_t hmac[64];
|
|
|
cd0318 |
+ uint8_t hash[64];
|
|
|
cd0318 |
+ gnutls_datum_t hashed_data;
|
|
|
cd0318 |
uint8_t pbkdf2[64];
|
|
|
cd0318 |
gnutls_datum_t temp_key = { NULL, 0 };
|
|
|
cd0318 |
|
|
|
cd0318 |
@@ -473,7 +489,7 @@ void doit(void)
|
|
|
cd0318 |
|
|
|
cd0318 |
/* Import 2432-bit RSA key; not a security function */
|
|
|
cd0318 |
FIPS_PUSH_CONTEXT();
|
|
|
cd0318 |
- rsa_import_keypair(&privkey, &pubkey, "rsa-2432.pem");
|
|
|
cd0318 |
+ import_keypair(&privkey, &pubkey, "rsa-2432.pem");
|
|
|
cd0318 |
FIPS_POP_CONTEXT(INITIAL);
|
|
|
cd0318 |
|
|
|
cd0318 |
/* Create a signature with 2432-bit RSA and SHA256; approved */
|
|
|
cd0318 |
@@ -519,7 +535,7 @@ void doit(void)
|
|
|
cd0318 |
|
|
|
cd0318 |
/* Import 512-bit RSA key; not a security function */
|
|
|
cd0318 |
FIPS_PUSH_CONTEXT();
|
|
|
cd0318 |
- rsa_import_keypair(&privkey, &pubkey, "rsa-512.pem");
|
|
|
cd0318 |
+ import_keypair(&privkey, &pubkey, "rsa-512.pem");
|
|
|
cd0318 |
FIPS_POP_CONTEXT(INITIAL);
|
|
|
cd0318 |
|
|
|
cd0318 |
/* Create a signature with 512-bit RSA and SHA256; not approved */
|
|
|
cd0318 |
@@ -543,6 +559,134 @@ void doit(void)
|
|
|
cd0318 |
gnutls_pubkey_deinit(pubkey);
|
|
|
cd0318 |
gnutls_privkey_deinit(privkey);
|
|
|
cd0318 |
|
|
|
cd0318 |
+ /* Import ECDSA key; not a security function */
|
|
|
cd0318 |
+ FIPS_PUSH_CONTEXT();
|
|
|
cd0318 |
+ import_keypair(&privkey, &pubkey, "ecc256.pem");
|
|
|
cd0318 |
+ FIPS_POP_CONTEXT(INITIAL);
|
|
|
cd0318 |
+
|
|
|
cd0318 |
+ /* Create a signature with ECDSA and SHA256; approved */
|
|
|
cd0318 |
+ FIPS_PUSH_CONTEXT();
|
|
|
cd0318 |
+ ret = gnutls_privkey_sign_data2(privkey, GNUTLS_SIGN_ECDSA_SHA256, 0,
|
|
|
cd0318 |
+ &data, &signature);
|
|
|
cd0318 |
+ if (ret < 0) {
|
|
|
cd0318 |
+ fail("gnutls_privkey_sign_data2 failed\n");
|
|
|
cd0318 |
+ }
|
|
|
cd0318 |
+ FIPS_POP_CONTEXT(APPROVED);
|
|
|
cd0318 |
+
|
|
|
cd0318 |
+ /* Verify a signature with ECDSA and SHA256; approved */
|
|
|
cd0318 |
+ FIPS_PUSH_CONTEXT();
|
|
|
cd0318 |
+ ret = gnutls_pubkey_verify_data2(pubkey, GNUTLS_SIGN_ECDSA_SHA256, 0,
|
|
|
cd0318 |
+ &data, &signature);
|
|
|
cd0318 |
+ if (ret < 0) {
|
|
|
cd0318 |
+ fail("gnutls_pubkey_verify_data2 failed\n");
|
|
|
cd0318 |
+ }
|
|
|
cd0318 |
+ FIPS_POP_CONTEXT(APPROVED);
|
|
|
cd0318 |
+ gnutls_free(signature.data);
|
|
|
cd0318 |
+
|
|
|
cd0318 |
+ /* Create a signature with ECDSA and SHA256 (old API); approved */
|
|
|
cd0318 |
+ FIPS_PUSH_CONTEXT();
|
|
|
cd0318 |
+ ret = gnutls_privkey_sign_data(privkey, GNUTLS_DIG_SHA256, 0,
|
|
|
cd0318 |
+ &data, &signature);
|
|
|
cd0318 |
+ if (ret < 0) {
|
|
|
cd0318 |
+ fail("gnutls_privkey_sign_data failed\n");
|
|
|
cd0318 |
+ }
|
|
|
cd0318 |
+ FIPS_POP_CONTEXT(APPROVED);
|
|
|
cd0318 |
+
|
|
|
cd0318 |
+ /* Create a SHA256 hashed data for 2-pass signature API; not a
|
|
|
cd0318 |
+ * crypto operation */
|
|
|
cd0318 |
+ FIPS_PUSH_CONTEXT();
|
|
|
cd0318 |
+ ret = gnutls_hash_fast(GNUTLS_DIG_SHA256, data.data, data.size, hash);
|
|
|
cd0318 |
+ if (ret < 0) {
|
|
|
cd0318 |
+ fail("gnutls_hash_fast failed\n");
|
|
|
cd0318 |
+ }
|
|
|
cd0318 |
+ hashed_data.data = hash;
|
|
|
cd0318 |
+ hashed_data.size = 32;
|
|
|
cd0318 |
+ FIPS_POP_CONTEXT(INITIAL);
|
|
|
cd0318 |
+
|
|
|
cd0318 |
+ /* Create a signature with ECDSA and SHA256 (2-pass API); not-approved */
|
|
|
cd0318 |
+ FIPS_PUSH_CONTEXT();
|
|
|
cd0318 |
+ ret = gnutls_privkey_sign_hash2(privkey, GNUTLS_SIGN_ECDSA_SHA256, 0,
|
|
|
cd0318 |
+ &hashed_data, &signature);
|
|
|
cd0318 |
+ if (ret < 0) {
|
|
|
cd0318 |
+ fail("gnutls_privkey_sign_hash2 failed\n");
|
|
|
cd0318 |
+ }
|
|
|
cd0318 |
+ FIPS_POP_CONTEXT(NOT_APPROVED);
|
|
|
cd0318 |
+ gnutls_free(signature.data);
|
|
|
cd0318 |
+
|
|
|
cd0318 |
+ /* Create a signature with ECDSA and SHA256 (2-pass old API); not-approved */
|
|
|
cd0318 |
+ FIPS_PUSH_CONTEXT();
|
|
|
cd0318 |
+ ret = gnutls_privkey_sign_hash(privkey, GNUTLS_DIG_SHA256, 0,
|
|
|
cd0318 |
+ &hashed_data, &signature);
|
|
|
cd0318 |
+ if (ret < 0) {
|
|
|
cd0318 |
+ fail("gnutls_privkey_sign_hash failed\n");
|
|
|
cd0318 |
+ }
|
|
|
cd0318 |
+ FIPS_POP_CONTEXT(NOT_APPROVED);
|
|
|
cd0318 |
+ gnutls_free(signature.data);
|
|
|
cd0318 |
+
|
|
|
cd0318 |
+ /* Create a signature with ECDSA and SHA-1; not approved */
|
|
|
cd0318 |
+ FIPS_PUSH_CONTEXT();
|
|
|
cd0318 |
+ ret = gnutls_privkey_sign_data2(privkey, GNUTLS_SIGN_ECDSA_SHA1, 0,
|
|
|
cd0318 |
+ &data, &signature);
|
|
|
cd0318 |
+ if (ret < 0) {
|
|
|
cd0318 |
+ fail("gnutls_privkey_sign_data2 failed\n");
|
|
|
cd0318 |
+ }
|
|
|
cd0318 |
+ FIPS_POP_CONTEXT(NOT_APPROVED);
|
|
|
cd0318 |
+
|
|
|
cd0318 |
+ /* Verify a signature created with ECDSA and SHA-1; approved */
|
|
|
cd0318 |
+ FIPS_PUSH_CONTEXT();
|
|
|
cd0318 |
+ ret = gnutls_pubkey_verify_data2(pubkey, GNUTLS_SIGN_ECDSA_SHA1,
|
|
|
cd0318 |
+ GNUTLS_VERIFY_ALLOW_SIGN_WITH_SHA1, &data,
|
|
|
cd0318 |
+ &ecc256_sha1_sig);
|
|
|
cd0318 |
+ if (ret < 0) {
|
|
|
cd0318 |
+ fail("gnutls_pubkey_verify_data2 failed\n");
|
|
|
cd0318 |
+ }
|
|
|
cd0318 |
+ FIPS_POP_CONTEXT(APPROVED);
|
|
|
cd0318 |
+ gnutls_free(signature.data);
|
|
|
cd0318 |
+
|
|
|
cd0318 |
+ /* Create a signature with ECDSA and SHA-1 (old API); not approved */
|
|
|
cd0318 |
+ FIPS_PUSH_CONTEXT();
|
|
|
cd0318 |
+ ret = gnutls_privkey_sign_data(privkey, GNUTLS_DIG_SHA1, 0,
|
|
|
cd0318 |
+ &data, &signature);
|
|
|
cd0318 |
+ if (ret < 0) {
|
|
|
cd0318 |
+ fail("gnutls_privkey_sign_data failed\n");
|
|
|
cd0318 |
+ }
|
|
|
cd0318 |
+ FIPS_POP_CONTEXT(NOT_APPROVED);
|
|
|
cd0318 |
+ gnutls_free(signature.data);
|
|
|
cd0318 |
+
|
|
|
cd0318 |
+ /* Create a SHA1 hashed data for 2-pass signature API; not a
|
|
|
cd0318 |
+ * crypto operation */
|
|
|
cd0318 |
+ FIPS_PUSH_CONTEXT();
|
|
|
cd0318 |
+ ret = gnutls_hash_fast(GNUTLS_DIG_SHA1, data.data, data.size, hash);
|
|
|
cd0318 |
+ if (ret < 0) {
|
|
|
cd0318 |
+ fail("gnutls_hash_fast failed\n");
|
|
|
cd0318 |
+ }
|
|
|
cd0318 |
+ hashed_data.data = hash;
|
|
|
cd0318 |
+ hashed_data.size = 20;
|
|
|
cd0318 |
+ FIPS_POP_CONTEXT(INITIAL);
|
|
|
cd0318 |
+
|
|
|
cd0318 |
+ /* Create a signature with ECDSA and SHA1 (2-pass API); not-approved */
|
|
|
cd0318 |
+ FIPS_PUSH_CONTEXT();
|
|
|
cd0318 |
+ ret = gnutls_privkey_sign_hash2(privkey, GNUTLS_SIGN_ECDSA_SHA1, 0,
|
|
|
cd0318 |
+ &hashed_data, &signature);
|
|
|
cd0318 |
+ if (ret < 0) {
|
|
|
cd0318 |
+ fail("gnutls_privkey_sign_hash2 failed\n");
|
|
|
cd0318 |
+ }
|
|
|
cd0318 |
+ FIPS_POP_CONTEXT(NOT_APPROVED);
|
|
|
cd0318 |
+ gnutls_free(signature.data);
|
|
|
cd0318 |
+
|
|
|
cd0318 |
+ /* Create a signature with ECDSA and SHA1 (2-pass old API); not-approved */
|
|
|
cd0318 |
+ FIPS_PUSH_CONTEXT();
|
|
|
cd0318 |
+ ret = gnutls_privkey_sign_hash(privkey, GNUTLS_DIG_SHA1, 0,
|
|
|
cd0318 |
+ &hashed_data, &signature);
|
|
|
cd0318 |
+ if (ret < 0) {
|
|
|
cd0318 |
+ fail("gnutls_privkey_sign_hash failed\n");
|
|
|
cd0318 |
+ }
|
|
|
cd0318 |
+ FIPS_POP_CONTEXT(NOT_APPROVED);
|
|
|
cd0318 |
+ gnutls_free(signature.data);
|
|
|
cd0318 |
+
|
|
|
cd0318 |
+ gnutls_pubkey_deinit(pubkey);
|
|
|
cd0318 |
+ gnutls_privkey_deinit(privkey);
|
|
|
cd0318 |
+
|
|
|
cd0318 |
/* Test RND functions */
|
|
|
cd0318 |
FIPS_PUSH_CONTEXT();
|
|
|
cd0318 |
ret = gnutls_rnd(GNUTLS_RND_RANDOM, key16, sizeof(key16));
|
|
|
cd0318 |
--
|
|
|
cd0318 |
2.37.3
|
|
|
cd0318 |
|