@ -23,7 +23,7 @@ static int test_kdf_tls1_prf(void)
EVP_KDF_CTX * kctx = NULL ;
const EVP_KDF * kdf ;
unsigned char out [ 16 ] ;
const unsigned char expected [ sizeof ( out ) ] = {
static const unsigned char expected [ sizeof ( out ) ] = {
0x8e , 0x4d , 0x93 , 0x25 , 0x30 , 0xd7 , 0x65 , 0xa0 ,
0xaa , 0xe9 , 0x74 , 0xc3 , 0x04 , 0x73 , 0x5e , 0xcc
} ;
@ -50,7 +50,7 @@ static int test_kdf_hkdf(void)
int ret ;
EVP_KDF_CTX * kctx ;
unsigned char out [ 10 ] ;
const unsigned char expected [ sizeof ( out ) ] = {
static const unsigned char expected [ sizeof ( out ) ] = {
0x2a , 0xc4 , 0x36 , 0x9f , 0x52 , 0x59 , 0x96 , 0xf8 , 0xde , 0x13
} ;
@ -75,7 +75,7 @@ static int test_kdf_pbkdf2(void)
int ret ;
EVP_KDF_CTX * kctx ;
unsigned char out [ 32 ] ;
const unsigned char expected [ sizeof ( out ) ] = {
static const unsigned char expected [ sizeof ( out ) ] = {
0xae , 0x4d , 0x0c , 0x95 , 0xaf , 0x6b , 0x46 , 0xd3 ,
0x2d , 0x0a , 0xdf , 0xf9 , 0x28 , 0xf0 , 0x6d , 0xd0 ,
0x2a , 0x30 , 0x3f , 0x8e , 0xf3 , 0xc2 , 0x51 , 0xdf ,
@ -103,7 +103,7 @@ static int test_kdf_scrypt(void)
int ret ;
EVP_KDF_CTX * kctx ;
unsigned char out [ 64 ] ;
const unsigned char expected [ sizeof ( out ) ] = {
static const unsigned char expected [ sizeof ( out ) ] = {
0xfd , 0xba , 0xbe , 0x1c , 0x9d , 0x34 , 0x72 , 0x00 ,
0x78 , 0x56 , 0xe7 , 0x19 , 0x0d , 0x01 , 0xe9 , 0xfe ,
0x7c , 0x6a , 0xd7 , 0xcb , 0xc8 , 0x23 , 0x78 , 0x30 ,
@ -144,22 +144,22 @@ static int test_kdf_ss_hash(void)
{
int ret ;
EVP_KDF_CTX * kctx = NULL ;
const unsigned char z [ ] = {
unsigned char out [ 14 ] ;
static const unsigned char z [ ] = {
0x6d , 0xbd , 0xc2 , 0x3f , 0x04 , 0x54 , 0x88 , 0xe4 , 0x06 , 0x27 , 0x57 , 0xb0 , 0x6b , 0x9e ,
0xba , 0xe1 , 0x83 , 0xfc , 0x5a , 0x59 , 0x46 , 0xd8 , 0x0d , 0xb9 , 0x3f , 0xec , 0x6f , 0x62 ,
0xec , 0x07 , 0xe3 , 0x72 , 0x7f , 0x01 , 0x26 , 0xae , 0xd1 , 0x2c , 0xe4 , 0xb2 , 0x62 , 0xf4 ,
0x7d , 0x48 , 0xd5 , 0x42 , 0x87 , 0xf8 , 0x1d , 0x47 , 0x4c , 0x7c , 0x3b , 0x18 , 0x50 , 0xe9
} ;
const unsigned char other [ ] = {
static const unsigned char other [ ] = {
0xa1 , 0xb2 , 0xc3 , 0xd4 , 0xe5 , 0x43 , 0x41 , 0x56 , 0x53 , 0x69 , 0x64 , 0x3c , 0x83 , 0x2e ,
0x98 , 0x49 , 0xdc , 0xdb , 0xa7 , 0x1e , 0x9a , 0x31 , 0x39 , 0xe6 , 0x06 , 0xe0 , 0x95 , 0xde ,
0x3c , 0x26 , 0x4a , 0x66 , 0xe9 , 0x8a , 0x16 , 0x58 , 0x54 , 0xcd , 0x07 , 0x98 , 0x9b , 0x1e ,
0xe0 , 0xec , 0x3f , 0x8d , 0xbe
} ;
const unsigned char expected [ ] = {
static const unsigned char expected [ sizeof ( out ) ] = {
0xa4 , 0x62 , 0xde , 0x16 , 0xa8 , 0x9d , 0xe8 , 0x46 , 0x6e , 0xf5 , 0x46 , 0x0b , 0x47 , 0xb8
} ;
unsigned char out [ 14 ] ;
ret =
TEST_ptr ( kctx = EVP_KDF_CTX_new_id ( EVP_KDF_SS ) )
@ -174,27 +174,75 @@ static int test_kdf_ss_hash(void)
return ret ;
}
static int test_kdf_x963 ( void )
{
int ret ;
EVP_KDF_CTX * kctx = NULL ;
unsigned char out [ 1024 / 8 ] ;
/*
* Test data from https : / / csrc . nist . gov / CSRC / media / Projects /
* Cryptographic - Algorithm - Validation - Program / documents / components /
* 800 - 135 testvectors / ansx963_2001 . zip
*/
static const unsigned char z [ ] = {
0x00 , 0xaa , 0x5b , 0xb7 , 0x9b , 0x33 , 0xe3 , 0x89 , 0xfa , 0x58 , 0xce , 0xad ,
0xc0 , 0x47 , 0x19 , 0x7f , 0x14 , 0xe7 , 0x37 , 0x12 , 0xf4 , 0x52 , 0xca , 0xa9 ,
0xfc , 0x4c , 0x9a , 0xdb , 0x36 , 0x93 , 0x48 , 0xb8 , 0x15 , 0x07 , 0x39 , 0x2f ,
0x1a , 0x86 , 0xdd , 0xfd , 0xb7 , 0xc4 , 0xff , 0x82 , 0x31 , 0xc4 , 0xbd , 0x0f ,
0x44 , 0xe4 , 0x4a , 0x1b , 0x55 , 0xb1 , 0x40 , 0x47 , 0x47 , 0xa9 , 0xe2 , 0xe7 ,
0x53 , 0xf5 , 0x5e , 0xf0 , 0x5a , 0x2d
} ;
static const unsigned char shared [ ] = {
0xe3 , 0xb5 , 0xb4 , 0xc1 , 0xb0 , 0xd5 , 0xcf , 0x1d , 0x2b , 0x3a , 0x2f , 0x99 ,
0x37 , 0x89 , 0x5d , 0x31
} ;
static const unsigned char expected [ sizeof ( out ) ] = {
0x44 , 0x63 , 0xf8 , 0x69 , 0xf3 , 0xcc , 0x18 , 0x76 , 0x9b , 0x52 , 0x26 , 0x4b ,
0x01 , 0x12 , 0xb5 , 0x85 , 0x8f , 0x7a , 0xd3 , 0x2a , 0x5a , 0x2d , 0x96 , 0xd8 ,
0xcf , 0xfa , 0xbf , 0x7f , 0xa7 , 0x33 , 0x63 , 0x3d , 0x6e , 0x4d , 0xd2 , 0xa5 ,
0x99 , 0xac , 0xce , 0xb3 , 0xea , 0x54 , 0xa6 , 0x21 , 0x7c , 0xe0 , 0xb5 , 0x0e ,
0xef , 0x4f , 0x6b , 0x40 , 0xa5 , 0xc3 , 0x02 , 0x50 , 0xa5 , 0xa8 , 0xee , 0xee ,
0x20 , 0x80 , 0x02 , 0x26 , 0x70 , 0x89 , 0xdb , 0xf3 , 0x51 , 0xf3 , 0xf5 , 0x02 ,
0x2a , 0xa9 , 0x63 , 0x8b , 0xf1 , 0xee , 0x41 , 0x9d , 0xea , 0x9c , 0x4f , 0xf7 ,
0x45 , 0xa2 , 0x5a , 0xc2 , 0x7b , 0xda , 0x33 , 0xca , 0x08 , 0xbd , 0x56 , 0xdd ,
0x1a , 0x59 , 0xb4 , 0x10 , 0x6c , 0xf2 , 0xdb , 0xbc , 0x0a , 0xb2 , 0xaa , 0x8e ,
0x2e , 0xfa , 0x7b , 0x17 , 0x90 , 0x2d , 0x34 , 0x27 , 0x69 , 0x51 , 0xce , 0xcc ,
0xab , 0x87 , 0xf9 , 0x66 , 0x1c , 0x3e , 0x88 , 0x16
} ;
ret =
TEST_ptr ( kctx = EVP_KDF_CTX_new_id ( EVP_KDF_X963 ) )
& & TEST_int_gt ( EVP_KDF_ctrl ( kctx , EVP_KDF_CTRL_SET_MD , EVP_sha512 ( ) ) , 0 )
& & TEST_int_gt ( EVP_KDF_ctrl ( kctx , EVP_KDF_CTRL_SET_KEY , z , sizeof ( z ) ) , 0 )
& & TEST_int_gt ( EVP_KDF_ctrl ( kctx , EVP_KDF_CTRL_SET_SHARED_INFO , shared ,
sizeof ( shared ) ) , 0 )
& & TEST_int_gt ( EVP_KDF_derive ( kctx , out , sizeof ( out ) ) , 0 )
& & TEST_mem_eq ( out , sizeof ( out ) , expected , sizeof ( expected ) ) ;
EVP_KDF_CTX_free ( kctx ) ;
return ret ;
}
static int test_kdf_ss_hmac ( void )
{
int ret ;
EVP_KDF_CTX * kctx ;
const EVP_MAC * mac ;
const unsigned char z [ ] = {
unsigned char out [ 16 ] ;
static const unsigned char z [ ] = {
0xb7 , 0x4a , 0x14 , 0x9a , 0x16 , 0x15 , 0x46 , 0xf8 , 0xc2 , 0x0b , 0x06 , 0xac , 0x4e , 0xd4
} ;
const unsigned char other [ ] = {
static const unsigned char other [ ] = {
0x34 , 0x8a , 0x37 , 0xa2 , 0x7e , 0xf1 , 0x28 , 0x2f , 0x5f , 0x02 , 0x0d , 0xcc
} ;
const unsigned char salt [ ] = {
static const unsigned char salt [ ] = {
0x36 , 0x38 , 0x27 , 0x1c , 0xcd , 0x68 , 0xa2 , 0x5d , 0xc2 , 0x4e , 0xcd , 0xdd , 0x39 , 0xef ,
0x3f , 0x89
} ;
const unsigned char expected [ ] = {
static const unsigned char expected [ sizeof ( out ) ] = {
0x44 , 0xf6 , 0x76 , 0xe8 , 0x5c , 0x1b , 0x1a , 0x8b , 0xbc , 0x3d , 0x31 , 0x92 , 0x18 , 0x63 ,
0x1c , 0xa3
} ;
unsigned char out [ 16 ] ;
ret =
TEST_ptr ( kctx = EVP_KDF_CTX_new_id ( EVP_KDF_SS ) )
@ -219,18 +267,17 @@ static int test_kdf_ss_kmac(void)
EVP_KDF_CTX * kctx ;
unsigned char out [ 64 ] ;
const EVP_MAC * mac ;
const unsigned char z [ ] = {
static const unsigned char z [ ] = {
0xb7 , 0x4a , 0x14 , 0x9a , 0x16 , 0x15 , 0x46 , 0xf8 , 0xc2 , 0x0b , 0x06 , 0xac , 0x4e , 0xd4
} ;
const unsigned char other [ ] = {
static const unsigned char other [ ] = {
0x34 , 0x8a , 0x37 , 0xa2 , 0x7e , 0xf1 , 0x28 , 0x2f , 0x5f , 0x02 , 0x0d , 0xcc
} ;
const unsigned char salt [ ] = {
static const unsigned char salt [ ] = {
0x36 , 0x38 , 0x27 , 0x1c , 0xcd , 0x68 , 0xa2 , 0x5d , 0xc2 , 0x4e , 0xcd , 0xdd , 0x39 , 0xef ,
0x3f , 0x89
} ;
const unsigned char expected [ ] = {
static const unsigned char expected [ sizeof ( out ) ] = {
0xe9 , 0xc1 , 0x84 , 0x53 , 0xa0 , 0x62 , 0xb5 , 0x3b , 0xdb , 0xfc , 0xbb , 0x5a , 0x34 , 0xbd ,
0xb8 , 0xe5 , 0xe7 , 0x07 , 0xee , 0xbb , 0x5d , 0xd1 , 0x34 , 0x42 , 0x43 , 0xd8 , 0xcf , 0xc2 ,
0xc2 , 0xe6 , 0x33 , 0x2f , 0x91 , 0xbd , 0xa5 , 0x86 , 0xf3 , 0x7d , 0xe4 , 0x8a , 0x65 , 0xd4 ,
@ -263,7 +310,7 @@ static int test_kdf_sshkdf(void)
EVP_KDF_CTX * kctx ;
unsigned char out [ 8 ] ;
/* Test data from NIST CAVS 14.1 test vectors */
const unsigned char key [ ] = {
static const unsigned char key [ ] = {
0x00 , 0x00 , 0x00 , 0x81 , 0x00 , 0x87 , 0x5c , 0x55 , 0x1c , 0xef , 0x52 , 0x6a ,
0x4a , 0x8b , 0xe1 , 0xa7 , 0xdf , 0x27 , 0xe9 , 0xed , 0x35 , 0x4b , 0xac , 0x9a ,
0xfb , 0x71 , 0xf5 , 0x3d , 0xba , 0xe9 , 0x05 , 0x67 , 0x9d , 0x14 , 0xf9 , 0xfa ,
@ -277,17 +324,17 @@ static int test_kdf_sshkdf(void)
0xaa , 0x22 , 0x76 , 0x93 , 0xe1 , 0x41 , 0xad , 0x16 , 0x30 , 0xce , 0x13 , 0x14 ,
0x4e
} ;
const unsigned char xcghash [ ] = {
static const unsigned char xcghash [ ] = {
0x0e , 0x68 , 0x3f , 0xc8 , 0xa9 , 0xed , 0x7c , 0x2f , 0xf0 , 0x2d , 0xef , 0x23 ,
0xb2 , 0x74 , 0x5e , 0xbc , 0x99 , 0xb2 , 0x67 , 0xda , 0xa8 , 0x6a , 0x4a , 0xa7 ,
0x69 , 0x72 , 0x39 , 0x08 , 0x82 , 0x53 , 0xf6 , 0x42
} ;
const unsigned char sessid [ ] = {
static const unsigned char sessid [ ] = {
0x0e , 0x68 , 0x3f , 0xc8 , 0xa9 , 0xed , 0x7c , 0x2f , 0xf0 , 0x2d , 0xef , 0x23 ,
0xb2 , 0x74 , 0x5e , 0xbc , 0x99 , 0xb2 , 0x67 , 0xda , 0xa8 , 0x6a , 0x4a , 0xa7 ,
0x69 , 0x72 , 0x39 , 0x08 , 0x82 , 0x53 , 0xf6 , 0x42
} ;
const unsigned char expected [ sizeof ( out ) ] = {
static const unsigned char expected [ sizeof ( out ) ] = {
0x41 , 0xff , 0x2e , 0xad , 0x16 , 0x83 , 0xf1 , 0xe6
} ;
@ -340,5 +387,6 @@ int setup_tests(void)
ADD_TEST ( test_kdf_ss_hmac ) ;
ADD_TEST ( test_kdf_ss_kmac ) ;
ADD_TEST ( test_kdf_sshkdf ) ;
ADD_TEST ( test_kdf_x963 ) ;
return 1 ;
}