Latest update.
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
SOURCE[../fips]=fipsprov.c self_test.c self_test_kats.c self_test_event.c
|
||||
SOURCE[../fips]=fipsprov.c self_test.c self_test_kats.c
|
||||
INCLUDE[../fips]=../implementations/include ../common/include ../..
|
||||
+34
-34
@@ -34,7 +34,7 @@
|
||||
#include "prov/provider_util.h"
|
||||
#include "self_test.h"
|
||||
|
||||
#define ALGC(NAMES, FUNC, CHECK) { { NAMES, "fips=yes", FUNC }, CHECK }
|
||||
#define ALGC(NAMES, FUNC, CHECK) { { NAMES, "provider=fips,fips=yes", FUNC }, CHECK }
|
||||
#define ALG(NAMES, FUNC) ALGC(NAMES, FUNC, NULL)
|
||||
|
||||
extern OSSL_core_thread_start_fn *c_thread_start;
|
||||
@@ -702,27 +702,27 @@ const char *ossl_prov_util_nid_to_name(int nid)
|
||||
*/
|
||||
static const OSSL_ALGORITHM fips_digests[] = {
|
||||
/* Our primary name:NiST name[:our older names] */
|
||||
{ "SHA1:SHA-1", "fips=yes", sha1_functions },
|
||||
{ "SHA2-224:SHA-224:SHA224", "fips=yes", sha224_functions },
|
||||
{ "SHA2-256:SHA-256:SHA256", "fips=yes", sha256_functions },
|
||||
{ "SHA2-384:SHA-384:SHA384", "fips=yes", sha384_functions },
|
||||
{ "SHA2-512:SHA-512:SHA512", "fips=yes", sha512_functions },
|
||||
{ "SHA2-512/224:SHA-512/224:SHA512-224", "fips=yes",
|
||||
{ "SHA1:SHA-1", "provider=fips,fips=yes", sha1_functions },
|
||||
{ "SHA2-224:SHA-224:SHA224", "provider=fips,fips=yes", sha224_functions },
|
||||
{ "SHA2-256:SHA-256:SHA256", "provider=fips,fips=yes", sha256_functions },
|
||||
{ "SHA2-384:SHA-384:SHA384", "provider=fips,fips=yes", sha384_functions },
|
||||
{ "SHA2-512:SHA-512:SHA512", "provider=fips,fips=yes", sha512_functions },
|
||||
{ "SHA2-512/224:SHA-512/224:SHA512-224", "provider=fips,fips=yes",
|
||||
sha512_224_functions },
|
||||
{ "SHA2-512/256:SHA-512/256:SHA512-256", "fips=yes",
|
||||
{ "SHA2-512/256:SHA-512/256:SHA512-256", "provider=fips,fips=yes",
|
||||
sha512_256_functions },
|
||||
|
||||
/* We agree with NIST here, so one name only */
|
||||
{ "SHA3-224", "fips=yes", sha3_224_functions },
|
||||
{ "SHA3-256", "fips=yes", sha3_256_functions },
|
||||
{ "SHA3-384", "fips=yes", sha3_384_functions },
|
||||
{ "SHA3-512", "fips=yes", sha3_512_functions },
|
||||
{ "SHA3-224", "provider=fips,fips=yes", sha3_224_functions },
|
||||
{ "SHA3-256", "provider=fips,fips=yes", sha3_256_functions },
|
||||
{ "SHA3-384", "provider=fips,fips=yes", sha3_384_functions },
|
||||
{ "SHA3-512", "provider=fips,fips=yes", sha3_512_functions },
|
||||
/*
|
||||
* KECCAK-KMAC-128 and KECCAK-KMAC-256 as hashes are mostly useful for
|
||||
* KMAC128 and KMAC256.
|
||||
*/
|
||||
{ "KECCAK-KMAC-128:KECCAK-KMAC128", "fips=yes", keccak_kmac_128_functions },
|
||||
{ "KECCAK-KMAC-256:KECCAK-KMAC256", "fips=yes", keccak_kmac_256_functions },
|
||||
{ "KECCAK-KMAC-128:KECCAK-KMAC128", "provider=fips,fips=yes", keccak_kmac_128_functions },
|
||||
{ "KECCAK-KMAC-256:KECCAK-KMAC256", "provider=fips,fips=yes", keccak_kmac_256_functions },
|
||||
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
@@ -773,51 +773,51 @@ static OSSL_ALGORITHM exported_fips_ciphers[OSSL_NELEM(fips_ciphers)];
|
||||
|
||||
static const OSSL_ALGORITHM fips_macs[] = {
|
||||
#ifndef OPENSSL_NO_CMAC
|
||||
{ "CMAC", "fips=yes", cmac_functions },
|
||||
{ "CMAC", "provider=fips,fips=yes", cmac_functions },
|
||||
#endif
|
||||
{ "GMAC", "fips=yes", gmac_functions },
|
||||
{ "HMAC", "fips=yes", hmac_functions },
|
||||
{ "KMAC-128:KMAC128", "fips=yes", kmac128_functions },
|
||||
{ "KMAC-256:KMAC256", "fips=yes", kmac256_functions },
|
||||
{ "GMAC", "provider=fips,fips=yes", gmac_functions },
|
||||
{ "HMAC", "provider=fips,fips=yes", hmac_functions },
|
||||
{ "KMAC-128:KMAC128", "provider=fips,fips=yes", kmac128_functions },
|
||||
{ "KMAC-256:KMAC256", "provider=fips,fips=yes", kmac256_functions },
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
static const OSSL_ALGORITHM fips_kdfs[] = {
|
||||
{ "HKDF", "fips=yes", kdf_hkdf_functions },
|
||||
{ "SSKDF", "fips=yes", kdf_sskdf_functions },
|
||||
{ "PBKDF2", "fips=yes", kdf_pbkdf2_functions },
|
||||
{ "TLS1-PRF", "fips=yes", kdf_tls1_prf_functions },
|
||||
{ "KBKDF", "fips=yes", kdf_kbkdf_functions },
|
||||
{ "HKDF", "provider=fips,fips=yes", kdf_hkdf_functions },
|
||||
{ "SSKDF", "provider=fips,fips=yes", kdf_sskdf_functions },
|
||||
{ "PBKDF2", "provider=fips,fips=yes", kdf_pbkdf2_functions },
|
||||
{ "TLS1-PRF", "provider=fips,fips=yes", kdf_tls1_prf_functions },
|
||||
{ "KBKDF", "provider=fips,fips=yes", kdf_kbkdf_functions },
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
static const OSSL_ALGORITHM fips_keyexch[] = {
|
||||
#ifndef OPENSSL_NO_DH
|
||||
{ "DH:dhKeyAgreement", "fips=yes", dh_keyexch_functions },
|
||||
{ "DH:dhKeyAgreement", "provider=fips,fips=yes", dh_keyexch_functions },
|
||||
#endif
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
static const OSSL_ALGORITHM fips_signature[] = {
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
{ "DSA:dsaEncryption", "fips=yes", dsa_signature_functions },
|
||||
{ "DSA:dsaEncryption", "provider=fips,fips=yes", dsa_signature_functions },
|
||||
#endif
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
static const OSSL_ALGORITHM fips_asym_cipher[] = {
|
||||
{ "RSA:rsaEncryption", "fips=yes", rsa_asym_cipher_functions },
|
||||
{ "RSA:rsaEncryption", "provider=fips,fips=yes", rsa_asym_cipher_functions },
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
static const OSSL_ALGORITHM fips_keymgmt[] = {
|
||||
#ifndef OPENSSL_NO_DH
|
||||
{ "DH:dhKeyAgreement", "fips=yes", dh_keymgmt_functions },
|
||||
{ "DH:dhKeyAgreement", "provider=fips,fips=yes", dh_keymgmt_functions },
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
{ "DSA", "fips=yes", dsa_keymgmt_functions },
|
||||
{ "DSA", "provider=fips,fips=yes", dsa_keymgmt_functions },
|
||||
#endif
|
||||
{ "RSA:rsaEncryption", "default=yes", rsa_keymgmt_functions },
|
||||
{ "RSA:rsaEncryption", "provider=fips,fips=yes", rsa_keymgmt_functions },
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
@@ -966,12 +966,12 @@ int OSSL_provider_init(const OSSL_PROVIDER *provider,
|
||||
}
|
||||
|
||||
if (stcbfn != NULL && c_get_libctx != NULL) {
|
||||
stcbfn(c_get_libctx(provider), &selftest_params.event_cb,
|
||||
&selftest_params.event_cb_arg);
|
||||
stcbfn(c_get_libctx(provider), &selftest_params.cb,
|
||||
&selftest_params.cb_arg);
|
||||
}
|
||||
else {
|
||||
selftest_params.event_cb = NULL;
|
||||
selftest_params.event_cb_arg = NULL;
|
||||
selftest_params.cb = NULL;
|
||||
selftest_params.cb_arg = NULL;
|
||||
}
|
||||
|
||||
if (!c_get_params(provider, core_params))
|
||||
|
||||
@@ -132,7 +132,7 @@ DEP_FINI_ATTRIBUTE void cleanup(void)
|
||||
*/
|
||||
static int verify_integrity(BIO *bio, OSSL_BIO_read_ex_fn read_ex_cb,
|
||||
unsigned char *expected, size_t expected_len,
|
||||
OPENSSL_CTX *libctx, OSSL_ST_EVENT *ev,
|
||||
OPENSSL_CTX *libctx, OSSL_SELF_TEST *ev,
|
||||
const char *event_type)
|
||||
{
|
||||
int ret = 0, status;
|
||||
@@ -143,7 +143,7 @@ static int verify_integrity(BIO *bio, OSSL_BIO_read_ex_fn read_ex_cb,
|
||||
EVP_MAC_CTX *ctx = NULL;
|
||||
OSSL_PARAM params[3], *p = params;
|
||||
|
||||
SELF_TEST_EVENT_onbegin(ev, event_type, OSSL_SELF_TEST_DESC_INTEGRITY_HMAC);
|
||||
OSSL_SELF_TEST_onbegin(ev, event_type, OSSL_SELF_TEST_DESC_INTEGRITY_HMAC);
|
||||
|
||||
mac = EVP_MAC_fetch(libctx, MAC_NAME, NULL);
|
||||
ctx = EVP_MAC_CTX_new(mac);
|
||||
@@ -170,13 +170,13 @@ static int verify_integrity(BIO *bio, OSSL_BIO_read_ex_fn read_ex_cb,
|
||||
if (!EVP_MAC_final(ctx, out, &out_len, sizeof(out)))
|
||||
goto err;
|
||||
|
||||
SELF_TEST_EVENT_oncorrupt_byte(ev, out);
|
||||
OSSL_SELF_TEST_oncorrupt_byte(ev, out);
|
||||
if (expected_len != out_len
|
||||
|| memcmp(expected, out, out_len) != 0)
|
||||
goto err;
|
||||
ret = 1;
|
||||
err:
|
||||
SELF_TEST_EVENT_onend(ev, ret);
|
||||
OSSL_SELF_TEST_onend(ev, ret);
|
||||
EVP_MAC_CTX_free(ctx);
|
||||
EVP_MAC_free(mac);
|
||||
return ret;
|
||||
@@ -192,7 +192,7 @@ int SELF_TEST_post(SELF_TEST_POST_PARAMS *st, int on_demand_test)
|
||||
unsigned char *module_checksum = NULL;
|
||||
unsigned char *indicator_checksum = NULL;
|
||||
int loclstate;
|
||||
OSSL_ST_EVENT ev;
|
||||
OSSL_SELF_TEST *ev = NULL;
|
||||
|
||||
if (!RUN_ONCE(&fips_self_test_init, do_fips_self_test_init))
|
||||
return 0;
|
||||
@@ -223,7 +223,9 @@ int SELF_TEST_post(SELF_TEST_POST_PARAMS *st, int on_demand_test)
|
||||
|| st->module_checksum_data == NULL)
|
||||
goto end;
|
||||
|
||||
SELF_TEST_EVENT_init(&ev, st->event_cb, st->event_cb_arg);
|
||||
ev = OSSL_SELF_TEST_new(st->cb, st->cb_arg);
|
||||
if (ev == NULL)
|
||||
goto end;
|
||||
|
||||
module_checksum = OPENSSL_hexstr2buf(st->module_checksum_data,
|
||||
&checksum_len);
|
||||
@@ -235,7 +237,7 @@ int SELF_TEST_post(SELF_TEST_POST_PARAMS *st, int on_demand_test)
|
||||
if (bio_module == NULL
|
||||
|| !verify_integrity(bio_module, st->bio_read_ex_cb,
|
||||
module_checksum, checksum_len, st->libctx,
|
||||
&ev, OSSL_SELF_TEST_TYPE_MODULE_INTEGRITY))
|
||||
ev, OSSL_SELF_TEST_TYPE_MODULE_INTEGRITY))
|
||||
goto end;
|
||||
|
||||
/* This will be NULL during installation - so the self test KATS will run */
|
||||
@@ -257,7 +259,7 @@ int SELF_TEST_post(SELF_TEST_POST_PARAMS *st, int on_demand_test)
|
||||
if (bio_indicator == NULL
|
||||
|| !verify_integrity(bio_indicator, st->bio_read_ex_cb,
|
||||
indicator_checksum, checksum_len,
|
||||
st->libctx, &ev,
|
||||
st->libctx, ev,
|
||||
OSSL_SELF_TEST_TYPE_INSTALL_INTEGRITY))
|
||||
goto end;
|
||||
else
|
||||
@@ -266,11 +268,12 @@ int SELF_TEST_post(SELF_TEST_POST_PARAMS *st, int on_demand_test)
|
||||
|
||||
/* Only runs the KAT's during installation OR on_demand() */
|
||||
if (on_demand_test || kats_already_passed == 0) {
|
||||
if (!SELF_TEST_kats(&ev, st->libctx))
|
||||
if (!SELF_TEST_kats(ev, st->libctx))
|
||||
goto end;
|
||||
}
|
||||
ok = 1;
|
||||
end:
|
||||
OSSL_SELF_TEST_free(ev);
|
||||
OPENSSL_free(module_checksum);
|
||||
OPENSSL_free(indicator_checksum);
|
||||
|
||||
|
||||
@@ -26,31 +26,11 @@ typedef struct self_test_post_params_st {
|
||||
OSSL_BIO_new_membuf_fn *bio_new_buffer_cb;
|
||||
OSSL_BIO_read_ex_fn *bio_read_ex_cb;
|
||||
OSSL_BIO_free_fn *bio_free_cb;
|
||||
OSSL_CALLBACK *event_cb;
|
||||
void *event_cb_arg;
|
||||
OSSL_CALLBACK *cb;
|
||||
void *cb_arg;
|
||||
OPENSSL_CTX *libctx;
|
||||
|
||||
} SELF_TEST_POST_PARAMS;
|
||||
|
||||
typedef struct st_event_st
|
||||
{
|
||||
/* local state variables */
|
||||
const char *phase;
|
||||
const char *type;
|
||||
const char *desc;
|
||||
OSSL_CALLBACK *cb;
|
||||
|
||||
/* callback related variables used to pass the state back to the user */
|
||||
OSSL_PARAM params[4];
|
||||
void *cb_arg;
|
||||
|
||||
} OSSL_ST_EVENT;
|
||||
|
||||
int SELF_TEST_post(SELF_TEST_POST_PARAMS *st, int on_demand_test);
|
||||
int SELF_TEST_kats(OSSL_ST_EVENT *event, OPENSSL_CTX *libctx);
|
||||
|
||||
void SELF_TEST_EVENT_init(OSSL_ST_EVENT *ev, OSSL_CALLBACK *cb, void *cbarg);
|
||||
void SELF_TEST_EVENT_onbegin(OSSL_ST_EVENT *ev, const char *type,
|
||||
const char *desc);
|
||||
void SELF_TEST_EVENT_onend(OSSL_ST_EVENT *ev, int ret);
|
||||
void SELF_TEST_EVENT_oncorrupt_byte(OSSL_ST_EVENT *ev, unsigned char *bytes);
|
||||
int SELF_TEST_kats(OSSL_SELF_TEST *event, OPENSSL_CTX *libctx);
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -42,6 +42,28 @@ typedef struct st_kat_kdf_st {
|
||||
size_t expected_len;
|
||||
} ST_KAT_KDF;
|
||||
|
||||
typedef struct st_kat_drbg_st {
|
||||
const char *desc;
|
||||
const char *algorithm;
|
||||
int nid;
|
||||
const unsigned char *entropyin;
|
||||
size_t entropyinlen;
|
||||
const unsigned char *nonce;
|
||||
size_t noncelen;
|
||||
const unsigned char *persstr;
|
||||
size_t persstrlen;
|
||||
const unsigned char *entropyinpr1;
|
||||
size_t entropyinpr1len;
|
||||
const unsigned char *entropyinpr2;
|
||||
size_t entropyinpr2len;
|
||||
const unsigned char *entropyaddin1;
|
||||
size_t entropyaddin1len;
|
||||
const unsigned char *entropyaddin2;
|
||||
size_t entropyaddin2len;
|
||||
const unsigned char *expected;
|
||||
size_t expectedlen;
|
||||
} ST_KAT_DRBG;
|
||||
|
||||
/* Macros to build Self test data */
|
||||
#define ITM(x) x, sizeof(x)
|
||||
#define ITM_STR(x) x, sizeof(x) - 1
|
||||
@@ -191,3 +213,212 @@ static const ST_KAT_KDF st_kat_kdf_tests[] =
|
||||
}
|
||||
};
|
||||
|
||||
/*-
|
||||
* DRBG test vectors are a small subset of
|
||||
* https://csrc.nist.rip/groups/STM/cavp/documents/drbg/drbgtestvectors.zip
|
||||
* Using the folder drbgvectors_pr_true
|
||||
* Generated for CAVS 14.3.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Hash_DRBG.rsp
|
||||
*
|
||||
* [SHA-256]
|
||||
* [PredictionResistance = True]
|
||||
* [EntropyInputLen = 256]
|
||||
* [NonceLen = 128]
|
||||
* [PersonalizationStringLen = 256]
|
||||
* [AdditionalInputLen = 256]
|
||||
* [ReturnedBitsLen = 1024]
|
||||
*
|
||||
* COUNT = 14
|
||||
*/
|
||||
static const unsigned char drbg_hash_sha256_pr_entropyin[] = {
|
||||
0x06, 0x6d, 0xc8, 0xce, 0x75, 0xb2, 0x89, 0x66, 0xa6, 0x85, 0x16, 0x3f,
|
||||
0xe2, 0xa4, 0xd4, 0x27, 0xfb, 0xdb, 0x61, 0x66, 0x50, 0x61, 0x6b, 0xa2,
|
||||
0x82, 0xfc, 0x33, 0x2b, 0x4e, 0x6f, 0x12, 0x20
|
||||
};
|
||||
static const unsigned char drbg_hash_sha256_pr_nonce[] = {
|
||||
0x55, 0x9f, 0x7c, 0x64, 0x89, 0x70, 0x83, 0xec, 0x2d, 0x73, 0x70, 0xd9,
|
||||
0xf0, 0xe5, 0x07, 0x1f
|
||||
};
|
||||
static const unsigned char drbg_hash_sha256_pr_persstr[] = {
|
||||
0x88, 0x6f, 0x54, 0x9a, 0xad, 0x1a, 0xc6, 0x3d, 0x18, 0xcb, 0xcc, 0x66,
|
||||
0x85, 0xda, 0xa2, 0xc2, 0xf7, 0x9e, 0xb0, 0x89, 0x4c, 0xb4, 0xae, 0xf1,
|
||||
0xac, 0x54, 0x4f, 0xce, 0x57, 0xf1, 0x5e, 0x11
|
||||
};
|
||||
static const unsigned char drbg_hash_sha256_pr_entropyinpr0[] = {
|
||||
0xff, 0x80, 0xb7, 0xd2, 0x6a, 0x05, 0xbc, 0x8a, 0x7a, 0xbe, 0x53, 0x28,
|
||||
0x6b, 0x0e, 0xeb, 0x73, 0x3b, 0x71, 0x5a, 0x20, 0x5b, 0xfa, 0x4f, 0xf6,
|
||||
0x37, 0x03, 0xde, 0xad, 0xb6, 0xea, 0x0e, 0xf4
|
||||
};
|
||||
static const unsigned char drbg_hash_sha256_pr_entropyinpr1[] = {
|
||||
0xc7, 0x38, 0x32, 0x53, 0x46, 0x81, 0xed, 0xe3, 0x7e, 0x03, 0x84, 0x6d,
|
||||
0x3c, 0x84, 0x17, 0x67, 0x29, 0x7d, 0x24, 0x6c, 0x68, 0x92, 0x41, 0xd2,
|
||||
0xe7, 0x75, 0xbe, 0x7e, 0xc9, 0x96, 0x29, 0x3d
|
||||
};
|
||||
static const unsigned char drbg_hash_sha256_pr_addin0[] = {
|
||||
0xb7, 0x21, 0x5f, 0x14, 0xac, 0x7b, 0xaf, 0xd0, 0xa9, 0x17, 0x72, 0xba,
|
||||
0x22, 0xf7, 0x19, 0xaf, 0xbd, 0x20, 0xb3, 0x11, 0x63, 0x6c, 0x2b, 0x1e,
|
||||
0x83, 0xe4, 0xa8, 0x23, 0x35, 0x3f, 0xc6, 0xea
|
||||
};
|
||||
static const unsigned char drbg_hash_sha256_pr_addin1[] = {
|
||||
0xce, 0xd3, 0x1f, 0x7e, 0x0d, 0xae, 0x5b, 0xb5, 0xc0, 0x43, 0xe2, 0x46,
|
||||
0xb2, 0x94, 0x73, 0xe2, 0xfd, 0x39, 0x51, 0x2e, 0xad, 0x45, 0x69, 0xee,
|
||||
0xe3, 0xe3, 0x80, 0x33, 0x14, 0xab, 0xa7, 0xa3
|
||||
};
|
||||
static const unsigned char drbg_hash_sha256_pr_expected[] = {
|
||||
0x60, 0xc2, 0x34, 0xcf, 0xaf, 0xb4, 0x68, 0x03, 0x3b, 0xf1, 0x95, 0xe5,
|
||||
0x78, 0xce, 0x26, 0x6e, 0x14, 0x65, 0x32, 0x6a, 0x96, 0xa9, 0xe0, 0x3f,
|
||||
0x8b, 0x89, 0x36, 0x70, 0xef, 0x62, 0x75, 0x4d, 0x5e, 0x80, 0xd5, 0x53,
|
||||
0xa1, 0xf8, 0x49, 0x50, 0x20, 0x8b, 0x93, 0x43, 0x07, 0x9f, 0x2e, 0xf8,
|
||||
0x56, 0xe9, 0xc5, 0x70, 0x61, 0x85, 0x97, 0xb5, 0xdc, 0x82, 0xa2, 0xda,
|
||||
0xea, 0xa3, 0xfd, 0x9b, 0x2f, 0xd2, 0xa0, 0xd7, 0x1b, 0xc6, 0x29, 0x35,
|
||||
0xcc, 0xb8, 0x3d, 0xa0, 0x67, 0x98, 0x05, 0xa0, 0xe3, 0x1e, 0xfe, 0xe4,
|
||||
0xf0, 0xe5, 0x13, 0xb0, 0x83, 0x17, 0xfa, 0xca, 0x93, 0x5e, 0x38, 0x29,
|
||||
0x48, 0xd2, 0x72, 0xdb, 0x76, 0x3e, 0x6d, 0xf3, 0x25, 0x10, 0xff, 0x1b,
|
||||
0x99, 0xff, 0xf8, 0xc6, 0x0e, 0xb0, 0xdd, 0x29, 0x2e, 0xbc, 0xbb, 0xc8,
|
||||
0x0a, 0x01, 0x6e, 0xd3, 0xb0, 0x0e, 0x4e, 0xab
|
||||
};
|
||||
|
||||
/*
|
||||
* CTR_DRBG.rsp
|
||||
*
|
||||
* [AES-128 use df]
|
||||
* [PredictionResistance = True]
|
||||
* [EntropyInputLen = 128]
|
||||
* [NonceLen = 64]
|
||||
* [PersonalizationStringLen = 128]
|
||||
* [AdditionalInputLen = 128]
|
||||
* [ReturnedBitsLen = 512]
|
||||
*
|
||||
* COUNT = 0
|
||||
*/
|
||||
static const unsigned char drbg_ctr_aes128_pr_df_entropyin[] = {
|
||||
0x92, 0x89, 0x8f, 0x31, 0xfa, 0x1c, 0xff, 0x6d, 0x18, 0x2f, 0x26, 0x06,
|
||||
0x43, 0xdf, 0xf8, 0x18
|
||||
};
|
||||
static const unsigned char drbg_ctr_aes128_pr_df_nonce[] = {
|
||||
0xc2, 0xa4, 0xd9, 0x72, 0xc3, 0xb9, 0xb6, 0x97
|
||||
};
|
||||
static const unsigned char drbg_ctr_aes128_pr_df_persstr[] = {
|
||||
0xea, 0x65, 0xee, 0x60, 0x26, 0x4e, 0x7e, 0xb6, 0x0e, 0x82, 0x68, 0xc4,
|
||||
0x37, 0x3c, 0x5c, 0x0b
|
||||
};
|
||||
static const unsigned char drbg_ctr_aes128_pr_df_entropyinpr0[] = {
|
||||
0x20, 0x72, 0x8a, 0x06, 0xf8, 0x6f, 0x8d, 0xd4, 0x41, 0xe2, 0x72, 0xb7,
|
||||
0xc4, 0x2c, 0xe8, 0x10
|
||||
};
|
||||
static const unsigned char drbg_ctr_aes128_pr_df_entropyinpr1[] = {
|
||||
0x3d, 0xb0, 0xf0, 0x94, 0xf3, 0x05, 0x50, 0x33, 0x17, 0x86, 0x3e, 0x22,
|
||||
0x08, 0xf7, 0xa5, 0x01
|
||||
};
|
||||
static const unsigned char drbg_ctr_aes128_pr_df_addin0[] = {
|
||||
0x1a, 0x40, 0xfa, 0xe3, 0xcc, 0x6c, 0x7c, 0xa0, 0xf8, 0xda, 0xba, 0x59,
|
||||
0x23, 0x6d, 0xad, 0x1d
|
||||
};
|
||||
static const unsigned char drbg_ctr_aes128_pr_df_addin1[] = {
|
||||
0x9f, 0x72, 0x76, 0x6c, 0xc7, 0x46, 0xe5, 0xed, 0x2e, 0x53, 0x20, 0x12,
|
||||
0xbc, 0x59, 0x31, 0x8c
|
||||
};
|
||||
static const unsigned char drbg_ctr_aes128_pr_df_expected[] = {
|
||||
0x5a, 0x35, 0x39, 0x87, 0x0f, 0x4d, 0x22, 0xa4, 0x09, 0x24, 0xee, 0x71,
|
||||
0xc9, 0x6f, 0xac, 0x72, 0x0a, 0xd6, 0xf0, 0x88, 0x82, 0xd0, 0x83, 0x28,
|
||||
0x73, 0xec, 0x3f, 0x93, 0xd8, 0xab, 0x45, 0x23, 0xf0, 0x7e, 0xac, 0x45,
|
||||
0x14, 0x5e, 0x93, 0x9f, 0xb1, 0xd6, 0x76, 0x43, 0x3d, 0xb6, 0xe8, 0x08,
|
||||
0x88, 0xf6, 0xda, 0x89, 0x08, 0x77, 0x42, 0xfe, 0x1a, 0xf4, 0x3f, 0xc4,
|
||||
0x23, 0xc5, 0x1f, 0x68
|
||||
};
|
||||
|
||||
/*
|
||||
* HMAC_DRBG.rsp
|
||||
*
|
||||
* [SHA-1]
|
||||
* [PredictionResistance = True]
|
||||
* [EntropyInputLen = 128]
|
||||
* [NonceLen = 64]
|
||||
* [PersonalizationStringLen = 128]
|
||||
* [AdditionalInputLen = 128]
|
||||
* [ReturnedBitsLen = 640]
|
||||
*
|
||||
* COUNT = 0
|
||||
*/
|
||||
static const unsigned char drbg_hmac_sha1_pr_entropyin[] = {
|
||||
0x68, 0x0f, 0xac, 0xe9, 0x0d, 0x7b, 0xca, 0x21, 0xd4, 0xa0, 0xed, 0xb7,
|
||||
0x79, 0x9e, 0xe5, 0xd8
|
||||
};
|
||||
static const unsigned char drbg_hmac_sha1_pr_nonce[] = {
|
||||
0xb7, 0xbe, 0x9e, 0xed, 0xdd, 0x0e, 0x3b, 0x4b
|
||||
};
|
||||
static const unsigned char drbg_hmac_sha1_pr_persstr[] = {
|
||||
0xf5, 0x8c, 0x40, 0xae, 0x70, 0xf7, 0xa5, 0x56, 0x48, 0xa9, 0x31, 0xa0,
|
||||
0xa9, 0x31, 0x3d, 0xd7
|
||||
};
|
||||
static const unsigned char drbg_hmac_sha1_pr_entropyinpr0[] = {
|
||||
0x7c, 0xaf, 0xe2, 0x31, 0x63, 0x0a, 0xa9, 0x5a, 0x74, 0x2c, 0x4e, 0x5f,
|
||||
0x5f, 0x22, 0xc6, 0xa4
|
||||
};
|
||||
static const unsigned char drbg_hmac_sha1_pr_entropyinpr1[] = {
|
||||
0x1c, 0x0d, 0x77, 0x92, 0x89, 0x88, 0x27, 0x94, 0x8a, 0x58, 0x9f, 0x82,
|
||||
0x2d, 0x1a, 0xf7, 0xa6
|
||||
};
|
||||
static const unsigned char drbg_hmac_sha1_pr_addin0[] = {
|
||||
0xdc, 0x36, 0x63, 0xf0, 0x62, 0x78, 0x9c, 0xd1, 0x5c, 0xbb, 0x20, 0xc3,
|
||||
0xc1, 0x8c, 0xd9, 0xd7
|
||||
};
|
||||
static const unsigned char drbg_hmac_sha1_pr_addin1[] = {
|
||||
0xfe, 0x85, 0xb0, 0xab, 0x14, 0xc6, 0x96, 0xe6, 0x9c, 0x24, 0xe7, 0xb5,
|
||||
0xa1, 0x37, 0x12, 0x0c
|
||||
};
|
||||
static const unsigned char drbg_hmac_sha1_pr_expected[] = {
|
||||
0x68, 0x00, 0x4b, 0x3a, 0x28, 0xf7, 0xf0, 0x1c, 0xf9, 0xe9, 0xb5, 0x71,
|
||||
0x20, 0x79, 0xef, 0x80, 0x87, 0x1b, 0x08, 0xb9, 0xa9, 0x1b, 0xcd, 0x2b,
|
||||
0x9f, 0x09, 0x4d, 0xa4, 0x84, 0x80, 0xb3, 0x4c, 0xaf, 0xd5, 0x59, 0x6b,
|
||||
0x0c, 0x0a, 0x48, 0xe1, 0x48, 0xda, 0xbc, 0x6f, 0x77, 0xb8, 0xff, 0xaf,
|
||||
0x18, 0x70, 0x28, 0xe1, 0x04, 0x13, 0x7a, 0x4f, 0xeb, 0x1c, 0x72, 0xb0,
|
||||
0xc4, 0x4f, 0xe8, 0xb1, 0xaf, 0xab, 0xa5, 0xbc, 0xfd, 0x86, 0x67, 0xf2,
|
||||
0xf5, 0x5b, 0x46, 0x06, 0x63, 0x2e, 0x3c, 0xbc
|
||||
};
|
||||
|
||||
static const ST_KAT_DRBG st_kat_drbg_tests[] =
|
||||
{
|
||||
{
|
||||
OSSL_SELF_TEST_DESC_DRBG_HASH,
|
||||
"SHA256",
|
||||
NID_sha256,
|
||||
ITM(drbg_hash_sha256_pr_entropyin),
|
||||
ITM(drbg_hash_sha256_pr_nonce),
|
||||
ITM(drbg_hash_sha256_pr_persstr),
|
||||
ITM(drbg_hash_sha256_pr_entropyinpr0),
|
||||
ITM(drbg_hash_sha256_pr_entropyinpr1),
|
||||
ITM(drbg_hash_sha256_pr_addin0),
|
||||
ITM(drbg_hash_sha256_pr_addin1),
|
||||
ITM(drbg_hash_sha256_pr_expected)
|
||||
},
|
||||
{
|
||||
OSSL_SELF_TEST_DESC_DRBG_CTR,
|
||||
"AES-128",
|
||||
NID_aes_128_ctr,
|
||||
ITM(drbg_ctr_aes128_pr_df_entropyin),
|
||||
ITM(drbg_ctr_aes128_pr_df_nonce),
|
||||
ITM(drbg_ctr_aes128_pr_df_persstr),
|
||||
ITM(drbg_ctr_aes128_pr_df_entropyinpr0),
|
||||
ITM(drbg_ctr_aes128_pr_df_entropyinpr1),
|
||||
ITM(drbg_ctr_aes128_pr_df_addin0),
|
||||
ITM(drbg_ctr_aes128_pr_df_addin1),
|
||||
ITM(drbg_ctr_aes128_pr_df_expected)
|
||||
},
|
||||
{
|
||||
OSSL_SELF_TEST_DESC_DRBG_HMAC,
|
||||
"SHA1",
|
||||
NID_sha1,
|
||||
ITM(drbg_hmac_sha1_pr_entropyin),
|
||||
ITM(drbg_hmac_sha1_pr_nonce),
|
||||
ITM(drbg_hmac_sha1_pr_persstr),
|
||||
ITM(drbg_hmac_sha1_pr_entropyinpr0),
|
||||
ITM(drbg_hmac_sha1_pr_entropyinpr1),
|
||||
ITM(drbg_hmac_sha1_pr_addin0),
|
||||
ITM(drbg_hmac_sha1_pr_addin1),
|
||||
ITM(drbg_hmac_sha1_pr_expected)
|
||||
}
|
||||
};
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <openssl/core_names.h>
|
||||
#include <openssl/params.h>
|
||||
#include "self_test.h"
|
||||
|
||||
static void self_test_event_setparams(OSSL_ST_EVENT *ev)
|
||||
{
|
||||
size_t n = 0;
|
||||
|
||||
if (ev->cb != NULL) {
|
||||
ev->params[n++] =
|
||||
OSSL_PARAM_construct_utf8_string(OSSL_PROV_PARAM_SELF_TEST_PHASE,
|
||||
(char *)ev->phase, 0);
|
||||
ev->params[n++] =
|
||||
OSSL_PARAM_construct_utf8_string(OSSL_PROV_PARAM_SELF_TEST_TYPE,
|
||||
(char *)ev->type, 0);
|
||||
ev->params[n++] =
|
||||
OSSL_PARAM_construct_utf8_string(OSSL_PROV_PARAM_SELF_TEST_DESC,
|
||||
(char *)ev->desc, 0);
|
||||
}
|
||||
ev->params[n++] = OSSL_PARAM_construct_end();
|
||||
}
|
||||
|
||||
void SELF_TEST_EVENT_init(OSSL_ST_EVENT *ev, OSSL_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
if (ev == NULL)
|
||||
return;
|
||||
|
||||
ev->cb = cb;
|
||||
ev->cb_arg = cbarg;
|
||||
ev->phase = "";
|
||||
ev->type = "";
|
||||
ev->desc = "";
|
||||
self_test_event_setparams(ev);
|
||||
}
|
||||
|
||||
/* Can be used during application testing to log that a test has started. */
|
||||
void SELF_TEST_EVENT_onbegin(OSSL_ST_EVENT *ev, const char *type,
|
||||
const char *desc)
|
||||
{
|
||||
if (ev != NULL && ev->cb != NULL) {
|
||||
ev->phase = OSSL_SELF_TEST_PHASE_START;
|
||||
ev->type = type;
|
||||
ev->desc = desc;
|
||||
self_test_event_setparams(ev);
|
||||
(void)ev->cb(ev->params, ev->cb_arg);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Can be used during application testing to log that a test has either
|
||||
* passed or failed.
|
||||
*/
|
||||
void SELF_TEST_EVENT_onend(OSSL_ST_EVENT *ev, int ret)
|
||||
{
|
||||
if (ev != NULL && ev->cb != NULL) {
|
||||
ev->phase =
|
||||
(ret == 1 ? OSSL_SELF_TEST_PHASE_PASS : OSSL_SELF_TEST_PHASE_FAIL);
|
||||
self_test_event_setparams(ev);
|
||||
(void)ev->cb(ev->params, ev->cb_arg);
|
||||
|
||||
ev->phase = OSSL_SELF_TEST_PHASE_NONE;
|
||||
ev->type = OSSL_SELF_TEST_TYPE_NONE;
|
||||
ev->desc = OSSL_SELF_TEST_DESC_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Used for failure testing.
|
||||
*
|
||||
* Call the applications SELF_TEST_cb() if it exists.
|
||||
* If the application callback decides to return 0 then the first byte of 'bytes'
|
||||
* is modified (corrupted). This is used to modify output signatures or
|
||||
* ciphertext before they are verified or decrypted.
|
||||
*/
|
||||
void SELF_TEST_EVENT_oncorrupt_byte(OSSL_ST_EVENT *ev, unsigned char *bytes)
|
||||
{
|
||||
if (ev != NULL && ev->cb != NULL) {
|
||||
ev->phase = OSSL_SELF_TEST_PHASE_CORRUPT;
|
||||
self_test_event_setparams(ev);
|
||||
if (!ev->cb(ev->params, ev->cb_arg))
|
||||
bytes[0] ^= 1;
|
||||
}
|
||||
}
|
||||
|
||||
+160
-40
@@ -10,12 +10,17 @@
|
||||
#include <string.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/kdf.h>
|
||||
#include <openssl/rand_drbg.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/nelem.h"
|
||||
#include "self_test.h"
|
||||
#include "self_test_data.inc"
|
||||
#include "../../crypto/rand/rand_local.h"
|
||||
|
||||
static int self_test_digest(const ST_KAT_DIGEST *t, OSSL_ST_EVENT *event,
|
||||
#define DRBG_PARAM_ENTROPY "DRBG-ENTROPY"
|
||||
#define DRBG_PARAM_NONCE "DRBG-NONCE"
|
||||
|
||||
static int self_test_digest(const ST_KAT_DIGEST *t, OSSL_SELF_TEST *st,
|
||||
OPENSSL_CTX *libctx)
|
||||
{
|
||||
int ok = 0;
|
||||
@@ -24,7 +29,7 @@ static int self_test_digest(const ST_KAT_DIGEST *t, OSSL_ST_EVENT *event,
|
||||
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
|
||||
EVP_MD *md = EVP_MD_fetch(libctx, t->algorithm, NULL);
|
||||
|
||||
SELF_TEST_EVENT_onbegin(event, OSSL_SELF_TEST_TYPE_KAT_DIGEST, t->desc);
|
||||
OSSL_SELF_TEST_onbegin(st, OSSL_SELF_TEST_TYPE_KAT_DIGEST, t->desc);
|
||||
|
||||
if (ctx == NULL
|
||||
|| md == NULL
|
||||
@@ -34,14 +39,14 @@ static int self_test_digest(const ST_KAT_DIGEST *t, OSSL_ST_EVENT *event,
|
||||
goto err;
|
||||
|
||||
/* Optional corruption */
|
||||
SELF_TEST_EVENT_oncorrupt_byte(event, out);
|
||||
OSSL_SELF_TEST_oncorrupt_byte(st, out);
|
||||
|
||||
if (out_len != t->expected_len
|
||||
|| memcmp(out, t->expected, out_len) != 0)
|
||||
goto err;
|
||||
ok = 1;
|
||||
err:
|
||||
SELF_TEST_EVENT_onend(event, ok);
|
||||
OSSL_SELF_TEST_onend(st, ok);
|
||||
EVP_MD_free(md);
|
||||
EVP_MD_CTX_free(ctx);
|
||||
|
||||
@@ -81,7 +86,7 @@ static int cipher_init(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
|
||||
}
|
||||
|
||||
/* Test a single KAT for encrypt/decrypt */
|
||||
static int self_test_cipher(const ST_KAT_CIPHER *t, OSSL_ST_EVENT *event,
|
||||
static int self_test_cipher(const ST_KAT_CIPHER *t, OSSL_SELF_TEST *st,
|
||||
OPENSSL_CTX *libctx)
|
||||
{
|
||||
int ret = 0, encrypt = 1, len, ct_len = 0, pt_len = 0;
|
||||
@@ -90,54 +95,54 @@ static int self_test_cipher(const ST_KAT_CIPHER *t, OSSL_ST_EVENT *event,
|
||||
unsigned char ct_buf[256] = { 0 };
|
||||
unsigned char pt_buf[256] = { 0 };
|
||||
|
||||
SELF_TEST_EVENT_onbegin(event, OSSL_SELF_TEST_TYPE_KAT_CIPHER, t->base.desc);
|
||||
OSSL_SELF_TEST_onbegin(st, OSSL_SELF_TEST_TYPE_KAT_CIPHER, t->base.desc);
|
||||
|
||||
ctx = EVP_CIPHER_CTX_new();
|
||||
if (ctx == NULL)
|
||||
goto end;
|
||||
goto err;
|
||||
cipher = EVP_CIPHER_fetch(libctx, t->base.algorithm, "");
|
||||
if (cipher == NULL)
|
||||
goto end;
|
||||
goto err;
|
||||
|
||||
/* Encrypt plain text message */
|
||||
if (!cipher_init(ctx, cipher, t, encrypt)
|
||||
|| !EVP_CipherUpdate(ctx, ct_buf, &len, t->base.pt, t->base.pt_len)
|
||||
|| !EVP_CipherFinal_ex(ctx, ct_buf + len, &ct_len))
|
||||
goto end;
|
||||
goto err;
|
||||
|
||||
SELF_TEST_EVENT_oncorrupt_byte(event, ct_buf);
|
||||
OSSL_SELF_TEST_oncorrupt_byte(st, ct_buf);
|
||||
ct_len += len;
|
||||
if (ct_len != (int)t->base.expected_len
|
||||
|| memcmp(t->base.expected, ct_buf, ct_len) != 0)
|
||||
goto end;
|
||||
goto err;
|
||||
|
||||
if (t->tag != NULL) {
|
||||
unsigned char tag[16] = { 0 };
|
||||
|
||||
if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, t->tag_len, tag)
|
||||
|| memcmp(tag, t->tag, t->tag_len) != 0)
|
||||
goto end;
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!(cipher_init(ctx, cipher, t, !encrypt)
|
||||
&& EVP_CipherUpdate(ctx, pt_buf, &len, ct_buf, ct_len)
|
||||
&& EVP_CipherFinal_ex(ctx, pt_buf + len, &pt_len)))
|
||||
goto end;
|
||||
goto err;
|
||||
pt_len += len;
|
||||
|
||||
if (pt_len != (int)t->base.pt_len
|
||||
|| memcmp(pt_buf, t->base.pt, pt_len) != 0)
|
||||
goto end;
|
||||
goto err;
|
||||
|
||||
ret = 1;
|
||||
end:
|
||||
err:
|
||||
EVP_CIPHER_free(cipher);
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
SELF_TEST_EVENT_onend(event, ret);
|
||||
OSSL_SELF_TEST_onend(st, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int self_test_kdf(const ST_KAT_KDF *t, OSSL_ST_EVENT *event,
|
||||
static int self_test_kdf(const ST_KAT_KDF *t, OSSL_SELF_TEST *st,
|
||||
OPENSSL_CTX *libctx)
|
||||
{
|
||||
int ret = 0;
|
||||
@@ -149,7 +154,7 @@ static int self_test_kdf(const ST_KAT_KDF *t, OSSL_ST_EVENT *event,
|
||||
const OSSL_PARAM *settables = NULL;
|
||||
|
||||
numparams = OSSL_NELEM(params);
|
||||
SELF_TEST_EVENT_onbegin(event, OSSL_SELF_TEST_TYPE_KAT_KDF, t->desc);
|
||||
OSSL_SELF_TEST_onbegin(st, OSSL_SELF_TEST_TYPE_KAT_KDF, t->desc);
|
||||
|
||||
/* Zeroize the params array to avoid mem leaks on error */
|
||||
for (i = 0; i < numparams; ++i)
|
||||
@@ -158,38 +163,140 @@ static int self_test_kdf(const ST_KAT_KDF *t, OSSL_ST_EVENT *event,
|
||||
kdf = EVP_KDF_fetch(libctx, t->algorithm, "");
|
||||
ctx = EVP_KDF_CTX_new(kdf);
|
||||
if (ctx == NULL)
|
||||
goto end;
|
||||
goto err;
|
||||
|
||||
settables = EVP_KDF_settable_ctx_params(kdf);
|
||||
for (i = 0; t->ctrls[i].name != NULL; ++i) {
|
||||
if (!ossl_assert(i < (numparams - 1)))
|
||||
goto end;
|
||||
goto err;
|
||||
if (!OSSL_PARAM_allocate_from_text(¶ms[i], settables,
|
||||
t->ctrls[i].name,
|
||||
t->ctrls[i].value,
|
||||
strlen(t->ctrls[i].value)))
|
||||
goto end;
|
||||
strlen(t->ctrls[i].value), NULL))
|
||||
goto err;
|
||||
}
|
||||
if (!EVP_KDF_CTX_set_params(ctx, params))
|
||||
goto end;
|
||||
goto err;
|
||||
|
||||
if (t->expected_len > sizeof(out))
|
||||
goto end;
|
||||
goto err;
|
||||
if (EVP_KDF_derive(ctx, out, t->expected_len) <= 0)
|
||||
goto end;
|
||||
goto err;
|
||||
|
||||
SELF_TEST_EVENT_oncorrupt_byte(event, out);
|
||||
OSSL_SELF_TEST_oncorrupt_byte(st, out);
|
||||
|
||||
if (memcmp(out, t->expected, t->expected_len) != 0)
|
||||
goto end;
|
||||
goto err;
|
||||
|
||||
ret = 1;
|
||||
end:
|
||||
err:
|
||||
for (i = 0; params[i].key != NULL; ++i)
|
||||
OPENSSL_free(params[i].data);
|
||||
EVP_KDF_free(kdf);
|
||||
EVP_KDF_CTX_free(ctx);
|
||||
SELF_TEST_EVENT_onend(event, ret);
|
||||
OSSL_SELF_TEST_onend(st, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static size_t drbg_kat_entropy_cb(RAND_DRBG *drbg, unsigned char **pout,
|
||||
int entropy, size_t min_len, size_t max_len,
|
||||
int prediction_resistance)
|
||||
{
|
||||
OSSL_PARAM *drbg_params = RAND_DRBG_get_callback_data(drbg);
|
||||
OSSL_PARAM *p = OSSL_PARAM_locate(drbg_params, DRBG_PARAM_ENTROPY);
|
||||
|
||||
if (p == NULL || p->data_type != OSSL_PARAM_OCTET_STRING)
|
||||
return 0;
|
||||
*pout = (unsigned char *)p->data;
|
||||
return p->data_size;
|
||||
}
|
||||
|
||||
static size_t drbg_kat_nonce_cb(RAND_DRBG *drbg, unsigned char **pout,
|
||||
int entropy, size_t min_len, size_t max_len)
|
||||
{
|
||||
OSSL_PARAM *drbg_params = RAND_DRBG_get_callback_data(drbg);
|
||||
OSSL_PARAM *p = OSSL_PARAM_locate(drbg_params, DRBG_PARAM_NONCE);
|
||||
|
||||
if (p == NULL || p->data_type != OSSL_PARAM_OCTET_STRING)
|
||||
return 0;
|
||||
*pout = (unsigned char *)p->data;
|
||||
return p->data_size;
|
||||
}
|
||||
|
||||
static int self_test_drbg(const ST_KAT_DRBG *t, OSSL_SELF_TEST *st,
|
||||
OPENSSL_CTX *libctx)
|
||||
{
|
||||
int ret = 0;
|
||||
unsigned char out[256];
|
||||
RAND_DRBG *drbg = NULL;
|
||||
unsigned int flags = 0;
|
||||
int prediction_resistance = 1; /* Causes a reseed */
|
||||
OSSL_PARAM drbg_params[3] = {
|
||||
OSSL_PARAM_END, OSSL_PARAM_END, OSSL_PARAM_END
|
||||
};
|
||||
static const unsigned char zero[sizeof(drbg->data)] = { 0 };
|
||||
|
||||
OSSL_SELF_TEST_onbegin(st, OSSL_SELF_TEST_TYPE_DRBG, t->desc);
|
||||
|
||||
if (strcmp(t->desc, OSSL_SELF_TEST_DESC_DRBG_HMAC) == 0)
|
||||
flags |= RAND_DRBG_FLAG_HMAC;
|
||||
|
||||
drbg = RAND_DRBG_new_ex(libctx, t->nid, flags, NULL);
|
||||
if (drbg == NULL)
|
||||
goto err;
|
||||
|
||||
if (!RAND_DRBG_set_callback_data(drbg, drbg_params))
|
||||
goto err;
|
||||
|
||||
if (!RAND_DRBG_set_callbacks(drbg, drbg_kat_entropy_cb, NULL,
|
||||
drbg_kat_nonce_cb, NULL))
|
||||
goto err;
|
||||
|
||||
drbg_params[0] =
|
||||
OSSL_PARAM_construct_octet_string(DRBG_PARAM_ENTROPY,
|
||||
(void *)t->entropyin, t->entropyinlen);
|
||||
drbg_params[1] =
|
||||
OSSL_PARAM_construct_octet_string(DRBG_PARAM_NONCE,
|
||||
(void *)t->nonce, t->noncelen);
|
||||
|
||||
if (!RAND_DRBG_instantiate(drbg, t->persstr, t->persstrlen))
|
||||
goto err;
|
||||
|
||||
drbg_params[0] =
|
||||
OSSL_PARAM_construct_octet_string(DRBG_PARAM_ENTROPY,
|
||||
(void *)t->entropyinpr1,
|
||||
t->entropyinpr1len);
|
||||
|
||||
if (!RAND_DRBG_generate(drbg, out, t->expectedlen, prediction_resistance,
|
||||
t->entropyaddin1, t->entropyaddin1len))
|
||||
goto err;
|
||||
|
||||
drbg_params[0] =
|
||||
OSSL_PARAM_construct_octet_string(DRBG_PARAM_ENTROPY,
|
||||
(void *)t->entropyinpr2,
|
||||
t->entropyinpr2len);
|
||||
/* This calls RAND_DRBG_reseed() internally when prediction_resistance = 1 */
|
||||
if (!RAND_DRBG_generate(drbg, out, t->expectedlen, prediction_resistance,
|
||||
t->entropyaddin2, t->entropyaddin2len))
|
||||
goto err;
|
||||
|
||||
OSSL_SELF_TEST_oncorrupt_byte(st, out);
|
||||
|
||||
if (memcmp(out, t->expected, t->expectedlen) != 0)
|
||||
goto err;
|
||||
|
||||
if (!RAND_DRBG_uninstantiate(drbg))
|
||||
goto err;
|
||||
/*
|
||||
* Check that the DRBG data has been zeroized after RAND_DRBG_uninstantiate.
|
||||
*/
|
||||
if (memcmp((unsigned char *)&drbg->data, zero, sizeof(drbg->data)) != 0)
|
||||
goto err;
|
||||
|
||||
ret = 1;
|
||||
err:
|
||||
RAND_DRBG_free(drbg);
|
||||
OSSL_SELF_TEST_onend(st, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -198,34 +305,45 @@ end:
|
||||
* All tests are run regardless of if they fail or not.
|
||||
* Return 0 if any test fails.
|
||||
*/
|
||||
static int self_test_digests(OSSL_ST_EVENT *event, OPENSSL_CTX *libctx)
|
||||
static int self_test_digests(OSSL_SELF_TEST *st, OPENSSL_CTX *libctx)
|
||||
{
|
||||
int i, ret = 1;
|
||||
|
||||
for (i = 0; i < (int)OSSL_NELEM(st_kat_digest_tests); ++i) {
|
||||
if (!self_test_digest(&st_kat_digest_tests[i], event, libctx))
|
||||
if (!self_test_digest(&st_kat_digest_tests[i], st, libctx))
|
||||
ret = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int self_test_ciphers(OSSL_ST_EVENT *event, OPENSSL_CTX *libctx)
|
||||
static int self_test_ciphers(OSSL_SELF_TEST *st, OPENSSL_CTX *libctx)
|
||||
{
|
||||
int i, ret = 1;
|
||||
|
||||
for (i = 0; i < (int)OSSL_NELEM(st_kat_cipher_tests); ++i) {
|
||||
if (!self_test_cipher(&st_kat_cipher_tests[i], event, libctx))
|
||||
if (!self_test_cipher(&st_kat_cipher_tests[i], st, libctx))
|
||||
ret = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int self_test_kdfs(OSSL_ST_EVENT *event, OPENSSL_CTX *libctx)
|
||||
static int self_test_kdfs(OSSL_SELF_TEST *st, OPENSSL_CTX *libctx)
|
||||
{
|
||||
int i, ret = 1;
|
||||
|
||||
for (i = 0; i < (int)OSSL_NELEM(st_kat_kdf_tests); ++i) {
|
||||
if (!self_test_kdf(&st_kat_kdf_tests[i], event, libctx))
|
||||
if (!self_test_kdf(&st_kat_kdf_tests[i], st, libctx))
|
||||
ret = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int self_test_drbgs(OSSL_SELF_TEST *st, OPENSSL_CTX *libctx)
|
||||
{
|
||||
int i, ret = 1;
|
||||
|
||||
for (i = 0; i < (int)OSSL_NELEM(st_kat_drbg_tests); ++i) {
|
||||
if (!self_test_drbg(&st_kat_drbg_tests[i], st, libctx))
|
||||
ret = 0;
|
||||
}
|
||||
return ret;
|
||||
@@ -236,17 +354,19 @@ static int self_test_kdfs(OSSL_ST_EVENT *event, OPENSSL_CTX *libctx)
|
||||
* Return 1 is successful, otherwise return 0.
|
||||
* This runs all the tests regardless of if any fail.
|
||||
*
|
||||
* TODO(3.0) Add self tests for KA, DRBG, Sign/Verify when they become available
|
||||
* TODO(3.0) Add self tests for KA, Sign/Verify when they become available
|
||||
*/
|
||||
int SELF_TEST_kats(OSSL_ST_EVENT *event, OPENSSL_CTX *libctx)
|
||||
int SELF_TEST_kats(OSSL_SELF_TEST *st, OPENSSL_CTX *libctx)
|
||||
{
|
||||
int ret = 1;
|
||||
|
||||
if (!self_test_digests(event, libctx))
|
||||
if (!self_test_digests(st, libctx))
|
||||
ret = 0;
|
||||
if (!self_test_ciphers(event, libctx))
|
||||
if (!self_test_ciphers(st, libctx))
|
||||
ret = 0;
|
||||
if (!self_test_kdfs(event, libctx))
|
||||
if (!self_test_kdfs(st, libctx))
|
||||
ret = 0;
|
||||
if (!self_test_drbgs(st, libctx))
|
||||
ret = 0;
|
||||
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user