[openssl] master update

Dr. Paul Dale pauli at openssl.org
Thu Sep 24 10:06:19 UTC 2020


The branch master has been updated
       via  254b5dcabd205b2229439020c768a0c9da0d8d7b (commit)
      from  cdb5129e5c5fd8ad678c5efb1e87c91595d907b4 (commit)


- Log -----------------------------------------------------------------
commit 254b5dcabd205b2229439020c768a0c9da0d8d7b
Author: Pauli <paul.dale at oracle.com>
Date:   Fri Sep 18 12:12:33 2020 +1000

    ACVP: add test case for DRBG
    
    Reviewed-by: Tomas Mraz <tmraz at fedoraproject.org>
    (Merged from https://github.com/openssl/openssl/pull/12905)

-----------------------------------------------------------------------

Summary of changes:
 test/acvp_test.c   | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 test/acvp_test.inc | 54 ++++++++++++++++++++++++++++++++++++
 2 files changed, 135 insertions(+)

diff --git a/test/acvp_test.c b/test/acvp_test.c
index 3e9631065a..de1a2e1fbc 100644
--- a/test/acvp_test.c
+++ b/test/acvp_test.c
@@ -1338,6 +1338,85 @@ err:
     return ret;
 }
 
+static int drbg_test(int id)
+{
+    OSSL_PARAM params[3];
+    EVP_RAND *rand = NULL;
+    EVP_RAND_CTX *ctx = NULL, *parent = NULL;
+    unsigned char returned_bits[64];
+    const size_t returned_bits_len = sizeof(returned_bits);
+    unsigned int strength = 256;
+    const struct drbg_st *tst  = &drbg_data[id];
+    int res = 0;
+
+    /* Create the seed source */
+    if (!TEST_ptr(rand = EVP_RAND_fetch(libctx, "TEST-RAND", "-fips"))
+        || !TEST_ptr(parent = EVP_RAND_CTX_new(rand, NULL)))
+        goto err;
+    EVP_RAND_free(rand);
+    rand = NULL;
+
+    params[0] = OSSL_PARAM_construct_uint(OSSL_RAND_PARAM_STRENGTH, &strength);
+    params[1] = OSSL_PARAM_construct_end();
+    if (!TEST_true(EVP_RAND_set_ctx_params(parent, params)))
+        goto err;
+
+    /* Get the DRBG */
+    if (!TEST_ptr(rand = EVP_RAND_fetch(libctx, tst->drbg_name, ""))
+        || !TEST_ptr(ctx = EVP_RAND_CTX_new(rand, parent)))
+        goto err;
+
+    /* Set the DRBG up */
+    params[0] = OSSL_PARAM_construct_int(OSSL_DRBG_PARAM_USE_DF,
+                                         (int *)&tst->use_df);
+    params[1] = OSSL_PARAM_construct_utf8_string(OSSL_DRBG_PARAM_CIPHER,
+                                                 (char *)tst->cipher, 0);
+    params[2] = OSSL_PARAM_construct_end();
+    if (!TEST_true(EVP_RAND_set_ctx_params(ctx, params)))
+        goto err;
+
+    /* Feed in the entropy and nonce */
+    params[0] = OSSL_PARAM_construct_octet_string(OSSL_RAND_PARAM_TEST_ENTROPY,
+                                                  (void *)tst->entropy_input,
+                                                  tst->entropy_input_len);
+    params[1] = OSSL_PARAM_construct_octet_string(OSSL_RAND_PARAM_TEST_NONCE,
+                                                  (void *)tst->nonce,
+                                                  tst->nonce_len);
+    params[2] = OSSL_PARAM_construct_end();
+    if (!TEST_true(EVP_RAND_set_ctx_params(parent, params)))
+        goto err;
+
+    /*
+     * Run the test
+     * A NULL personalisation string defaults to the built in so something
+     * non-NULL is needed if there is no personalisation string
+     */
+    if (!TEST_true(EVP_RAND_instantiate(ctx, 0, 0, (void *)"", 0))
+        || !TEST_true(EVP_RAND_generate(ctx, returned_bits, returned_bits_len,
+                                        0, 0, NULL, 0))
+        || !TEST_true(EVP_RAND_generate(ctx, returned_bits, returned_bits_len,
+                                        0, 0, NULL, 0)))
+        goto err;
+
+    test_output_memory("returned bits", returned_bits, returned_bits_len);
+
+    /* Clean up */
+    if (!TEST_true(EVP_RAND_uninstantiate(ctx))
+        || !TEST_true(EVP_RAND_uninstantiate(parent)))
+        goto err;
+
+    /* Verify the output */
+    if (!TEST_mem_eq(returned_bits, returned_bits_len,
+                     tst->returned_bits, tst->returned_bits_len))
+        goto err;
+    res = 1;
+err:
+    EVP_RAND_CTX_free(ctx);
+    EVP_RAND_CTX_free(parent);
+    EVP_RAND_free(rand);
+    return res;
+}
+
 int setup_tests(void)
 {
     char *config_file = NULL;
@@ -1404,6 +1483,8 @@ int setup_tests(void)
     ADD_ALL_TESTS(ecdsa_siggen_test, OSSL_NELEM(ecdsa_siggen_data));
     ADD_ALL_TESTS(ecdsa_sigver_test, OSSL_NELEM(ecdsa_sigver_data));
 #endif /* OPENSSL_NO_EC */
+
+    ADD_ALL_TESTS(drbg_test, OSSL_NELEM(drbg_data));
     return 1;
 }
 
diff --git a/test/acvp_test.inc b/test/acvp_test.inc
index 01f6d0d668..eea66c0802 100644
--- a/test/acvp_test.inc
+++ b/test/acvp_test.inc
@@ -1982,3 +1982,57 @@ static const struct rsa_decrypt_prim_st rsa_decrypt_prim_data[] = {
 };
 
 #endif /* OPENSSL_NO_RSA */
+
+struct drbg_st {
+    const char *drbg_name;
+    const char *cipher;
+    int use_df;
+
+    const unsigned char *entropy_input;
+    size_t entropy_input_len;
+    const unsigned char *nonce;
+    size_t nonce_len;
+    const unsigned char *returned_bits;
+    size_t returned_bits_len;
+};
+
+static const unsigned char drbg_entropy_input[] = {
+    0x36, 0x40, 0x19, 0x40, 0xfa, 0x8b, 0x1f, 0xba,
+    0x91, 0xa1, 0x66, 0x1f, 0x21, 0x1d, 0x78, 0xa0,
+    0xb9, 0x38, 0x9a, 0x74, 0xe5, 0xbc, 0xcf, 0xec,
+    0xe8, 0xd7, 0x66, 0xaf, 0x1a, 0x6d, 0x3b, 0x14
+};
+
+static const unsigned char drbg_nonce[] = {
+    0x49, 0x6f, 0x25, 0xb0, 0xf1, 0x30, 0x1b, 0x4f,
+    0x50, 0x1b, 0xe3, 0x03, 0x80, 0xa1, 0x37, 0xeb
+};
+
+static const unsigned char drbg_returned_bits[] = {
+    0x58, 0x62, 0xeb, 0x38, 0xbd, 0x55, 0x8d, 0xd9,
+    0x78, 0xa6, 0x96, 0xe6, 0xdf, 0x16, 0x47, 0x82,
+    0xdd, 0xd8, 0x87, 0xe7, 0xe9, 0xa6, 0xc9, 0xf3,
+    0xf1, 0xfb, 0xaf, 0xb7, 0x89, 0x41, 0xb5, 0x35,
+    0xa6, 0x49, 0x12, 0xdf, 0xd2, 0x24, 0xc6, 0xdc,
+    0x74, 0x54, 0xe5, 0x25, 0x0b, 0x3d, 0x97, 0x16,
+    0x5e, 0x16, 0x26, 0x0c, 0x2f, 0xaf, 0x1c, 0xc7,
+    0x73, 0x5c, 0xb7, 0x5f, 0xb4, 0xf0, 0x7e, 0x1d
+};
+
+static const unsigned char drbg_key_0[] = {
+    0x33, 0x63, 0xd9, 0x00, 0x0e, 0x6d, 0xb4, 0x7c,
+    0x16, 0xd3, 0xfc, 0x65, 0xf2, 0x87, 0x2c, 0x08,
+    0xa3, 0x5f, 0x99, 0xb2, 0xd1, 0x74, 0xaf, 0xa5,
+    0x37, 0xa6, 0x6e, 0xc1, 0x53, 0x05, 0x2d, 0x98
+};
+
+static const struct drbg_st drbg_data[] = {
+    {
+        "CTR-DRBG",
+        "AES-256-CTR",
+        1,
+        ITM(drbg_entropy_input),
+        ITM(drbg_nonce),
+        ITM(drbg_returned_bits)
+    }
+};


More information about the openssl-commits mailing list