Latest update.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
SUBDIRS=ossl_shim
|
||||
{-
|
||||
use File::Spec::Functions;
|
||||
sub rebase_files
|
||||
|
||||
+43
-24
@@ -581,6 +581,8 @@ static void reset_drbg_hook_ctx(void)
|
||||
* 1: it is expected that the specified DRBG is reseeded
|
||||
* 0: it is expected that the specified DRBG is not reseeded
|
||||
* -1: don't check whether the specified DRBG was reseeded or not
|
||||
* |reseed_time|: if nonzero, used instead of time(NULL) to set the
|
||||
* |before_reseed| time.
|
||||
*/
|
||||
static int test_drbg_reseed(int expect_success,
|
||||
RAND_DRBG *master,
|
||||
@@ -588,7 +590,8 @@ static int test_drbg_reseed(int expect_success,
|
||||
RAND_DRBG *private,
|
||||
int expect_master_reseed,
|
||||
int expect_public_reseed,
|
||||
int expect_private_reseed
|
||||
int expect_private_reseed,
|
||||
time_t reseed_time
|
||||
)
|
||||
{
|
||||
unsigned char buf[32];
|
||||
@@ -614,8 +617,11 @@ static int test_drbg_reseed(int expect_success,
|
||||
* step 2: generate random output
|
||||
*/
|
||||
|
||||
if (reseed_time == 0)
|
||||
reseed_time = time(NULL);
|
||||
|
||||
/* Generate random output from the public and private DRBG */
|
||||
before_reseed = expect_master_reseed == 1 ? time(NULL) : 0;
|
||||
before_reseed = expect_master_reseed == 1 ? reseed_time : 0;
|
||||
if (!TEST_int_eq(RAND_bytes(buf, sizeof(buf)), expect_success)
|
||||
|| !TEST_int_eq(RAND_priv_bytes(buf, sizeof(buf)), expect_success))
|
||||
return 0;
|
||||
@@ -682,6 +688,7 @@ static int test_rand_drbg_reseed(void)
|
||||
RAND_DRBG *master, *public, *private;
|
||||
unsigned char rand_add_buf[256];
|
||||
int rv=0;
|
||||
time_t before_reseed;
|
||||
|
||||
/* Check whether RAND_OpenSSL() is the default method */
|
||||
if (!TEST_ptr_eq(RAND_get_rand_method(), RAND_OpenSSL()))
|
||||
@@ -716,7 +723,7 @@ static int test_rand_drbg_reseed(void)
|
||||
/*
|
||||
* Test initial seeding of shared DRBGs
|
||||
*/
|
||||
if (!TEST_true(test_drbg_reseed(1, master, public, private, 1, 1, 1)))
|
||||
if (!TEST_true(test_drbg_reseed(1, master, public, private, 1, 1, 1, 0)))
|
||||
goto error;
|
||||
reset_drbg_hook_ctx();
|
||||
|
||||
@@ -724,7 +731,7 @@ static int test_rand_drbg_reseed(void)
|
||||
/*
|
||||
* Test initial state of shared DRBGs
|
||||
*/
|
||||
if (!TEST_true(test_drbg_reseed(1, master, public, private, 0, 0, 0)))
|
||||
if (!TEST_true(test_drbg_reseed(1, master, public, private, 0, 0, 0, 0)))
|
||||
goto error;
|
||||
reset_drbg_hook_ctx();
|
||||
|
||||
@@ -733,7 +740,7 @@ static int test_rand_drbg_reseed(void)
|
||||
* reseed counters differ from the master's reseed counter.
|
||||
*/
|
||||
master->reseed_prop_counter++;
|
||||
if (!TEST_true(test_drbg_reseed(1, master, public, private, 0, 1, 1)))
|
||||
if (!TEST_true(test_drbg_reseed(1, master, public, private, 0, 1, 1, 0)))
|
||||
goto error;
|
||||
reset_drbg_hook_ctx();
|
||||
|
||||
@@ -743,7 +750,7 @@ static int test_rand_drbg_reseed(void)
|
||||
*/
|
||||
master->reseed_prop_counter++;
|
||||
private->reseed_prop_counter++;
|
||||
if (!TEST_true(test_drbg_reseed(1, master, public, private, 0, 1, 0)))
|
||||
if (!TEST_true(test_drbg_reseed(1, master, public, private, 0, 1, 0, 0)))
|
||||
goto error;
|
||||
reset_drbg_hook_ctx();
|
||||
|
||||
@@ -753,7 +760,7 @@ static int test_rand_drbg_reseed(void)
|
||||
*/
|
||||
master->reseed_prop_counter++;
|
||||
public->reseed_prop_counter++;
|
||||
if (!TEST_true(test_drbg_reseed(1, master, public, private, 0, 0, 1)))
|
||||
if (!TEST_true(test_drbg_reseed(1, master, public, private, 0, 0, 1, 0)))
|
||||
goto error;
|
||||
reset_drbg_hook_ctx();
|
||||
|
||||
@@ -762,10 +769,17 @@ static int test_rand_drbg_reseed(void)
|
||||
memset(rand_add_buf, 'r', sizeof(rand_add_buf));
|
||||
|
||||
/*
|
||||
* Test whether all three DRBGs are reseeded by RAND_add()
|
||||
* Test whether all three DRBGs are reseeded by RAND_add().
|
||||
* The before_reseed time has to be measured here and passed into the
|
||||
* test_drbg_reseed() test, because the master DRBG gets already reseeded
|
||||
* in RAND_add(), whence the check for the condition
|
||||
* before_reseed <= master->reseed_time will fail if the time value happens
|
||||
* to increase between the RAND_add() and the test_drbg_reseed() call.
|
||||
*/
|
||||
before_reseed = time(NULL);
|
||||
RAND_add(rand_add_buf, sizeof(rand_add_buf), sizeof(rand_add_buf));
|
||||
if (!TEST_true(test_drbg_reseed(1, master, public, private, 1, 1, 1)))
|
||||
if (!TEST_true(test_drbg_reseed(1, master, public, private, 1, 1, 1,
|
||||
before_reseed)))
|
||||
goto error;
|
||||
reset_drbg_hook_ctx();
|
||||
|
||||
@@ -776,7 +790,7 @@ static int test_rand_drbg_reseed(void)
|
||||
master_ctx.fail = 1;
|
||||
master->reseed_prop_counter++;
|
||||
RAND_add(rand_add_buf, sizeof(rand_add_buf), sizeof(rand_add_buf));
|
||||
if (!TEST_true(test_drbg_reseed(0, master, public, private, 0, 0, 0)))
|
||||
if (!TEST_true(test_drbg_reseed(0, master, public, private, 0, 0, 0, 0)))
|
||||
goto error;
|
||||
reset_drbg_hook_ctx();
|
||||
|
||||
@@ -799,12 +813,15 @@ static void run_multi_thread_test(void)
|
||||
{
|
||||
unsigned char buf[256];
|
||||
time_t start = time(NULL);
|
||||
RAND_DRBG *public, *private;
|
||||
RAND_DRBG *public = NULL, *private = NULL;
|
||||
|
||||
public = RAND_DRBG_get0_public();
|
||||
private = RAND_DRBG_get0_private();
|
||||
RAND_DRBG_set_reseed_time_interval(public, 1);
|
||||
if (!TEST_ptr(public = RAND_DRBG_get0_public())
|
||||
|| !TEST_ptr(private = RAND_DRBG_get0_private())) {
|
||||
multi_thread_rand_bytes_succeeded = 0;
|
||||
return;
|
||||
}
|
||||
RAND_DRBG_set_reseed_time_interval(private, 1);
|
||||
RAND_DRBG_set_reseed_time_interval(public, 1);
|
||||
|
||||
do {
|
||||
if (RAND_bytes(buf, sizeof(buf)) <= 0)
|
||||
@@ -936,13 +953,16 @@ static size_t rand_drbg_seedlen(RAND_DRBG *drbg)
|
||||
*/
|
||||
static int test_rand_seed(void)
|
||||
{
|
||||
RAND_DRBG *master = RAND_DRBG_get0_master();
|
||||
RAND_DRBG *master = NULL;
|
||||
unsigned char rand_buf[256];
|
||||
size_t rand_buflen;
|
||||
#ifdef OPENSSL_RAND_SEED_NONE
|
||||
size_t required_seed_buflen = rand_drbg_seedlen(master);
|
||||
#else
|
||||
size_t required_seed_buflen = 0;
|
||||
|
||||
if (!TEST_ptr(master = RAND_DRBG_get0_master()))
|
||||
return 0;
|
||||
|
||||
#ifdef OPENSSL_RAND_SEED_NONE
|
||||
required_seed_buflen = rand_drbg_seedlen(master);
|
||||
#endif
|
||||
|
||||
memset(rand_buf, 0xCD, sizeof(rand_buf));
|
||||
@@ -1025,14 +1045,13 @@ err:
|
||||
|
||||
static int test_set_defaults(void)
|
||||
{
|
||||
RAND_DRBG *master, *public, *private;
|
||||
|
||||
master = RAND_DRBG_get0_master();
|
||||
public = RAND_DRBG_get0_public();
|
||||
private = RAND_DRBG_get0_private();
|
||||
RAND_DRBG *master = NULL, *public = NULL, *private = NULL;
|
||||
|
||||
/* Check the default type and flags for master, public and private */
|
||||
return TEST_int_eq(master->type, RAND_DRBG_TYPE)
|
||||
return TEST_ptr(master = RAND_DRBG_get0_master())
|
||||
&& TEST_ptr(public = RAND_DRBG_get0_public())
|
||||
&& TEST_ptr(private = RAND_DRBG_get0_private())
|
||||
&& TEST_int_eq(master->type, RAND_DRBG_TYPE)
|
||||
&& TEST_int_eq(master->flags,
|
||||
RAND_DRBG_FLAGS | RAND_DRBG_FLAG_MASTER)
|
||||
&& TEST_int_eq(public->type, RAND_DRBG_TYPE)
|
||||
|
||||
@@ -838,6 +838,9 @@ typedef struct mac_data_st {
|
||||
/* MAC key */
|
||||
unsigned char *key;
|
||||
size_t key_len;
|
||||
/* MAC IV (GMAC) */
|
||||
unsigned char *iv;
|
||||
size_t iv_len;
|
||||
/* Input to MAC */
|
||||
unsigned char *input;
|
||||
size_t input_len;
|
||||
@@ -925,6 +928,7 @@ static void mac_test_cleanup(EVP_TEST *t)
|
||||
sk_OPENSSL_STRING_pop_free(mdat->controls, openssl_free);
|
||||
OPENSSL_free(mdat->alg);
|
||||
OPENSSL_free(mdat->key);
|
||||
OPENSSL_free(mdat->iv);
|
||||
OPENSSL_free(mdat->input);
|
||||
OPENSSL_free(mdat->output);
|
||||
}
|
||||
@@ -936,6 +940,8 @@ static int mac_test_parse(EVP_TEST *t,
|
||||
|
||||
if (strcmp(keyword, "Key") == 0)
|
||||
return parse_bin(value, &mdata->key, &mdata->key_len);
|
||||
if (strcmp(keyword, "IV") == 0)
|
||||
return parse_bin(value, &mdata->iv, &mdata->iv_len);
|
||||
if (strcmp(keyword, "Algorithm") == 0) {
|
||||
mdata->alg = OPENSSL_strdup(value);
|
||||
if (!mdata->alg)
|
||||
@@ -1119,6 +1125,18 @@ static int mac_test_run_mac(EVP_TEST *t)
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (expected->iv != NULL) {
|
||||
rv = EVP_MAC_ctrl(ctx, EVP_MAC_CTRL_SET_IV,
|
||||
expected->iv, expected->iv_len);
|
||||
if (rv == -2) {
|
||||
t->err = "MAC_CTRL_INVALID";
|
||||
goto err;
|
||||
} else if (rv <= 0) {
|
||||
t->err = "MAC_CTRL_ERROR";
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (!EVP_MAC_init(ctx)) {
|
||||
t->err = "MAC_INIT_ERROR";
|
||||
goto err;
|
||||
|
||||
@@ -386,6 +386,75 @@ Key = 89BCD952A8C8AB371AF48AC7D07085D5EFF702E6D62CDC23
|
||||
Input = FA620C1BBE97319E9A0CF0492121F7A20EB08A6A709DCBD00AAF38E4F99E754E
|
||||
Output = 8F49A1B7D6AA2258
|
||||
|
||||
|
||||
Title = GMAC Tests (from NIST)
|
||||
|
||||
MAC = GMAC
|
||||
Algorithm = AES-128-GCM
|
||||
Key = 77BE63708971C4E240D1CB79E8D77FEB
|
||||
IV = E0E00F19FED7BA0136A797F3
|
||||
Input = 7A43EC1D9C0A5A78A0B16533A6213CAB
|
||||
Output = 209FCC8D3675ED938E9C7166709DD946
|
||||
|
||||
Title = GMAC Tests (from http://www.ieee802.org/1/files/public/docs2011/bn-randall-test-vectors-0511-v1.pdf)
|
||||
|
||||
MAC = GMAC
|
||||
Algorithm = AES-128-GCM
|
||||
Key = AD7A2BD03EAC835A6F620FDCB506B345
|
||||
IV = 12153524C0895E81B2C28465
|
||||
Input = D609B1F056637A0D46DF998D88E5222AB2C2846512153524C0895E8108000F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F30313233340001
|
||||
Output = F09478A9B09007D06F46E9B6A1DA25DD
|
||||
|
||||
MAC = GMAC
|
||||
Algorithm = AES-256-GCM
|
||||
Key = E3C08A8F06C6E3AD95A70557B23F75483CE33021A9C72B7025666204C69C0B72
|
||||
IV = 12153524C0895E81B2C28465
|
||||
Input = D609B1F056637A0D46DF998D88E5222AB2C2846512153524C0895E8108000F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F30313233340001
|
||||
Output = 2F0BC5AF409E06D609EA8B7D0FA5EA50
|
||||
|
||||
MAC = GMAC
|
||||
Algorithm = AES-128-GCM
|
||||
Key = 071B113B0CA743FECCCF3D051F737382
|
||||
IV = F0761E8DCD3D000176D457ED
|
||||
Input = E20106D7CD0DF0761E8DCD3D88E5400076D457ED08000F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A0003
|
||||
Output = 0C017BC73B227DFCC9BAFA1C41ACC353
|
||||
|
||||
MAC = GMAC
|
||||
Algorithm = AES-256-GCM
|
||||
Key = 691D3EE909D7F54167FD1CA0B5D769081F2BDE1AEE655FDBAB80BD5295AE6BE7
|
||||
IV = F0761E8DCD3D000176D457ED
|
||||
Input = E20106D7CD0DF0761E8DCD3D88E5400076D457ED08000F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A0003
|
||||
Output = 35217C774BBC31B63166BCF9D4ABED07
|
||||
|
||||
MAC = GMAC
|
||||
Algorithm = AES-128-GCM
|
||||
Key = 013FE00B5F11BE7F866D0CBBC55A7A90
|
||||
IV = 7CFDE9F9E33724C68932D612
|
||||
Input = 84C5D513D2AAF6E5BBD2727788E523008932D6127CFDE9F9E33724C608000F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F0005
|
||||
Output = 217867E50C2DAD74C28C3B50ABDF695A
|
||||
|
||||
MAC = GMAC
|
||||
Algorithm = AES-256-GCM
|
||||
Key = 83C093B58DE7FFE1C0DA926AC43FB3609AC1C80FEE1B624497EF942E2F79A823
|
||||
IV = 7CFDE9F9E33724C68932D612
|
||||
Input = 84C5D513D2AAF6E5BBD2727788E523008932D6127CFDE9F9E33724C608000F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F0005
|
||||
Output = 6EE160E8FAECA4B36C86B234920CA975
|
||||
|
||||
MAC = GMAC
|
||||
Algorithm = AES-128-GCM
|
||||
Key = 88EE087FD95DA9FBF6725AA9D757B0CD
|
||||
IV = 7AE8E2CA4EC500012E58495C
|
||||
Input = 68F2E77696CE7AE8E2CA4EC588E541002E58495C08000F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D0007
|
||||
Output = 07922B8EBCF10BB2297588CA4C614523
|
||||
|
||||
MAC = GMAC
|
||||
Algorithm = AES-256-GCM
|
||||
Key = 4C973DBC7364621674F8B5B89E5C15511FCED9216490FB1C1A2CAA0FFE0407E5
|
||||
IV = 7AE8E2CA4EC500012E58495C
|
||||
Input = 68F2E77696CE7AE8E2CA4EC588E541002E58495C08000F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D0007
|
||||
Output = 00BDA1B7E87608BCBF470F12157F4C07
|
||||
|
||||
|
||||
Title = Poly1305 Tests (from RFC 7539 and others)
|
||||
|
||||
MAC = Poly1305
|
||||
@@ -641,3 +710,23 @@ Input = e33594d7505e43b900000000000000003394d7505e4379cd010000000000000000000000
|
||||
Key = 0100000000000000040000000000000000000000000000000000000000000000
|
||||
Output = 13000000000000000000000000000000
|
||||
|
||||
# Here are 4 duplicated cases for Poly1305 by EVP_PKEY
|
||||
MAC = Poly1305 by EVP_PKEY
|
||||
Key = 0000000000000000000000000000000000000000000000000000000000000000
|
||||
Input = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
Output = 00000000000000000000000000000000
|
||||
|
||||
MAC = Poly1305 by EVP_PKEY
|
||||
Key = 0000000000000000000000000000000036e5f6b5c5e06070f0efca96227a863e
|
||||
Input = 416e79207375626d697373696f6e20746f20746865204945544620696e74656e6465642062792074686520436f6e7472696275746f7220666f72207075626c69636174696f6e20617320616c6c206f722070617274206f6620616e204945544620496e7465726e65742d4472616674206f722052464320616e6420616e792073746174656d656e74206d6164652077697468696e2074686520636f6e74657874206f6620616e204945544620616374697669747920697320636f6e7369646572656420616e20224945544620436f6e747269627574696f6e222e20537563682073746174656d656e747320696e636c756465206f72616c2073746174656d656e747320696e20494554462073657373696f6e732c2061732077656c6c206173207772697474656e20616e6420656c656374726f6e696320636f6d6d756e69636174696f6e73206d61646520617420616e792074696d65206f7220706c6163652c207768696368206172652061646472657373656420746f
|
||||
Output = 36e5f6b5c5e06070f0efca96227a863e
|
||||
|
||||
MAC = Poly1305 by EVP_PKEY
|
||||
Key = 36e5f6b5c5e06070f0efca96227a863e00000000000000000000000000000000
|
||||
Input = 416e79207375626d697373696f6e20746f20746865204945544620696e74656e6465642062792074686520436f6e7472696275746f7220666f72207075626c69636174696f6e20617320616c6c206f722070617274206f6620616e204945544620496e7465726e65742d4472616674206f722052464320616e6420616e792073746174656d656e74206d6164652077697468696e2074686520636f6e74657874206f6620616e204945544620616374697669747920697320636f6e7369646572656420616e20224945544620436f6e747269627574696f6e222e20537563682073746174656d656e747320696e636c756465206f72616c2073746174656d656e747320696e20494554462073657373696f6e732c2061732077656c6c206173207772697474656e20616e6420656c656374726f6e696320636f6d6d756e69636174696f6e73206d61646520617420616e792074696d65206f7220706c6163652c207768696368206172652061646472657373656420746f
|
||||
Output = f3477e7cd95417af89a6b8794c310cf0
|
||||
|
||||
MAC = Poly1305 by EVP_PKEY
|
||||
Key = 1c9240a5eb55d38af333888604f6b5f0473917c1402b80099dca5cbc207075c0
|
||||
Input = 2754776173206272696c6c69672c20616e642074686520736c6974687920746f7665730a446964206779726520616e642067696d626c6520696e2074686520776162653a0a416c6c206d696d737920776572652074686520626f726f676f7665732c0a416e6420746865206d6f6d65207261746873206f757467726162652e
|
||||
Output = 4541669a7eaaee61e708dc7cbcc5eb62
|
||||
Reference in New Issue
Block a user