mirror of
https://github.com/openssl/openssl.git
synced 2024-11-21 01:15:20 +08:00
Add tests for OCB mode
Reviewed-by: Tim Hudson <tjh@openssl.org>
This commit is contained in:
parent
e6b336efa3
commit
d827c5edb5
@ -178,7 +178,7 @@ static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn,
|
||||
EVP_CIPHER_CTX_set_flags(ctx,EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);
|
||||
if (encdec != 0)
|
||||
{
|
||||
if (mode == EVP_CIPH_GCM_MODE)
|
||||
if ((mode == EVP_CIPH_GCM_MODE) || (mode == EVP_CIPH_OCB_MODE))
|
||||
{
|
||||
if(!EVP_EncryptInit_ex(ctx,c,NULL,NULL,NULL))
|
||||
{
|
||||
@ -186,12 +186,19 @@ static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn,
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(10);
|
||||
}
|
||||
if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, in, NULL))
|
||||
if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_IVLEN, in, NULL))
|
||||
{
|
||||
fprintf(stderr,"IV length set failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(11);
|
||||
}
|
||||
if((mode == EVP_CIPH_OCB_MODE) &&
|
||||
!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_OCB_SET_TAGLEN, tn, NULL))
|
||||
{
|
||||
fprintf(stderr,"Tag length set failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(15);
|
||||
}
|
||||
if(!EVP_EncryptInit_ex(ctx,NULL,NULL,key,iv))
|
||||
{
|
||||
fprintf(stderr,"Key/IV set failed\n");
|
||||
@ -290,13 +297,12 @@ static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn,
|
||||
hexdump(stderr,"Expected",ciphertext,cn);
|
||||
test1_exit(9);
|
||||
}
|
||||
if (mode == EVP_CIPH_GCM_MODE || mode == EVP_CIPH_CCM_MODE)
|
||||
if ((mode == EVP_CIPH_GCM_MODE) || (mode == EVP_CIPH_OCB_MODE)
|
||||
|| (mode == EVP_CIPH_CCM_MODE))
|
||||
{
|
||||
unsigned char rtag[16];
|
||||
/* Note: EVP_CTRL_CCM_GET_TAG has same value as
|
||||
* EVP_CTRL_GCM_GET_TAG
|
||||
*/
|
||||
if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, tn, rtag))
|
||||
|
||||
if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GET_TAG, tn, rtag))
|
||||
{
|
||||
fprintf(stderr,"Get tag failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
@ -314,27 +320,34 @@ static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn,
|
||||
|
||||
if (encdec <= 0)
|
||||
{
|
||||
if (mode == EVP_CIPH_GCM_MODE)
|
||||
if ((mode == EVP_CIPH_GCM_MODE) || (mode == EVP_CIPH_OCB_MODE))
|
||||
{
|
||||
if(!EVP_DecryptInit_ex(ctx,c,NULL,NULL,NULL))
|
||||
{
|
||||
fprintf(stderr,"EncryptInit failed\n");
|
||||
fprintf(stderr,"DecryptInit failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(10);
|
||||
}
|
||||
if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, in, NULL))
|
||||
if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_IVLEN, in, NULL))
|
||||
{
|
||||
fprintf(stderr,"IV length set failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(11);
|
||||
}
|
||||
if((mode == EVP_CIPH_OCB_MODE) &&
|
||||
!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_OCB_SET_TAGLEN, tn, NULL))
|
||||
{
|
||||
fprintf(stderr,"Tag length set failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(15);
|
||||
}
|
||||
if(!EVP_DecryptInit_ex(ctx,NULL,NULL,key,iv))
|
||||
{
|
||||
fprintf(stderr,"Key/IV set failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(12);
|
||||
}
|
||||
if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, tn, (void *)tag))
|
||||
if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_TAG, tn, (void *)tag))
|
||||
{
|
||||
fprintf(stderr,"Set tag failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
|
@ -372,6 +372,27 @@ aes-128-gcm:00000000000000000000000000000000:ffffffff000000000000000000000000000
|
||||
# 80 bytes plaintext, submitted by Intel
|
||||
aes-128-gcm:843ffcf5d2b72694d19ed01d01249412:dbcca32ebf9b804617c3aa9e:000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f:6268c6fa2a80b2d137467f092f657ac04d89be2beaa623d61b5a868c8f03ff95d3dcee23ad2f1ab3a6c80eaf4b140eb05de3457f0fbc111a6b43d0763aa422a3013cf1dc37fe417d1fbfc449b75d4cc5:00000000000000000000000000000000101112131415161718191a1b1c1d1e1f:3b629ccfbc1119b7319e1dce2cd6fd6d
|
||||
|
||||
#AES OCB Test vectors
|
||||
aes-128-ocb:000102030405060708090A0B0C0D0E0F:000102030405060708090A0B::::197B9C3C441D3C83EAFB2BEF633B9182
|
||||
aes-128-ocb:000102030405060708090A0B0C0D0E0F:000102030405060708090A0B:0001020304050607:92B657130A74B85A:0001020304050607:16DC76A46D47E1EAD537209E8A96D14E
|
||||
aes-128-ocb:000102030405060708090A0B0C0D0E0F:000102030405060708090A0B:::0001020304050607:98B91552C8C009185044E30A6EB2FE21
|
||||
aes-128-ocb:000102030405060708090A0B0C0D0E0F:000102030405060708090A0B:0001020304050607:92B657130A74B85A::971EFFCAE19AD4716F88E87B871FBEED
|
||||
aes-128-ocb:000102030405060708090A0B0C0D0E0F:000102030405060708090A0B:000102030405060708090A0B0C0D0E0F:BEA5E8798DBE7110031C144DA0B26122:000102030405060708090A0B0C0D0E0F:776C9924D6723A1FC4524532AC3E5BEB
|
||||
aes-128-ocb:000102030405060708090A0B0C0D0E0F:000102030405060708090A0B:::000102030405060708090A0B0C0D0E0F:7DDB8E6CEA6814866212509619B19CC6
|
||||
aes-128-ocb:000102030405060708090A0B0C0D0E0F:000102030405060708090A0B:000102030405060708090A0B0C0D0E0F:BEA5E8798DBE7110031C144DA0B26122::13CC8B747807121A4CBB3E4BD6B456AF
|
||||
aes-128-ocb:000102030405060708090A0B0C0D0E0F:000102030405060708090A0B:000102030405060708090A0B0C0D0E0F1011121314151617:BEA5E8798DBE7110031C144DA0B26122FCFCEE7A2A8D4D48:000102030405060708090A0B0C0D0E0F1011121314151617:5FA94FC3F38820F1DC3F3D1FD4E55E1C
|
||||
aes-128-ocb:000102030405060708090A0B0C0D0E0F:000102030405060708090A0B:::000102030405060708090A0B0C0D0E0F1011121314151617:282026DA3068BC9FA118681D559F10F6
|
||||
aes-128-ocb:000102030405060708090A0B0C0D0E0F:000102030405060708090A0B:000102030405060708090A0B0C0D0E0F1011121314151617:BEA5E8798DBE7110031C144DA0B26122FCFCEE7A2A8D4D48::6EF2F52587FDA0ED97DC7EEDE241DF68
|
||||
aes-128-ocb:000102030405060708090A0B0C0D0E0F:000102030405060708090A0B:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F:BEA5E8798DBE7110031C144DA0B26122CEAAB9B05DF771A657149D53773463CB:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F:B2A040DD3BD5164372D76D7BB6824240
|
||||
aes-128-ocb:000102030405060708090A0B0C0D0E0F:000102030405060708090A0B:::000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F:E1E072633BADE51A60E85951D9C42A1B
|
||||
aes-128-ocb:000102030405060708090A0B0C0D0E0F:000102030405060708090A0B:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F:BEA5E8798DBE7110031C144DA0B26122CEAAB9B05DF771A657149D53773463CB::4A3BAE824465CFDAF8C41FC50C7DF9D9
|
||||
aes-128-ocb:000102030405060708090A0B0C0D0E0F:000102030405060708090A0B:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627:BEA5E8798DBE7110031C144DA0B26122CEAAB9B05DF771A657149D53773463CB68C65778B058A635:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627:659C623211DEEA0DE30D2C381879F4C8
|
||||
aes-128-ocb:000102030405060708090A0B0C0D0E0F:000102030405060708090A0B:::000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627:7AEB7A69A1687DD082CA27B0D9A37096
|
||||
aes-128-ocb:000102030405060708090A0B0C0D0E0F:000102030405060708090A0B:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627:BEA5E8798DBE7110031C144DA0B26122CEAAB9B05DF771A657149D53773463CB68C65778B058A635::060C8467F4ABAB5E8B3C2067A2E115DC
|
||||
#AES OCB Non standard test vectors - generated from reference implementation
|
||||
aes-128-ocb:000102030405060708090A0B0C0D0E0F:000102030405060708090A0B:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627:09a4fd29de949d9a9aa9924248422097ad4883b4713e6c214ff6567ada08a96766fc4e2ee3e3a5a1:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627:1b6c44f34e3abb3cbf8976e7
|
||||
aes-128-ocb:000102030405060708090A0B0C0D0E0F:000102030405060708090A0B0C0D0E:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627:5e2fa7367ffbdb3938845cfd415fcc71ec79634eb31451609d27505f5e2978f43c44213d8fa441ee:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627:1ad62009901f40cba7cd7156f94a7324
|
||||
|
||||
# AES XTS test vectors from IEEE Std 1619-2007
|
||||
aes-128-xts:0000000000000000000000000000000000000000000000000000000000000000:00000000000000000000000000000000:0000000000000000000000000000000000000000000000000000000000000000:917cf69ebd68b2ec9b9fe9a3eadda692cd43d2f59598ed858c02c2652fbf922e
|
||||
aes-128-xts:1111111111111111111111111111111122222222222222222222222222222222:33333333330000000000000000000000:4444444444444444444444444444444444444444444444444444444444444444:c454185e6a16936e39334038acef838bfb186fff7480adc4289382ecd6d394f0
|
||||
|
Loading…
Reference in New Issue
Block a user