MatrixSSL 3.9.5
This commit is contained in:
@@ -1356,151 +1356,144 @@ L_CBC_TIMING:
|
||||
}
|
||||
#endif /* 0 */
|
||||
|
||||
#ifdef USE_CHACHA20_POLY1305
|
||||
#ifdef USE_CHACHA20_POLY1305_IETF
|
||||
# define TEST_TEXT_MAXLEN 128
|
||||
# define TEST_AAD_MAXLEN 32
|
||||
# ifdef USE_LIBSODIUM_CHACHA20_POLY1305
|
||||
# define TEST_TAG_LEN crypto_aead_chacha20poly1305_ABYTES
|
||||
# define TEST_KEY_LEN crypto_aead_chacha20poly1305_KEYBYTES
|
||||
# ifdef CHACHA20POLY1305_IETF
|
||||
# define TEST_IV_LEN crypto_aead_chacha20poly1305_IETF_NPUBBYTES
|
||||
# else
|
||||
# define TEST_IV_LEN crypto_aead_chacha20poly1305_NPUBBYTES
|
||||
# endif
|
||||
# ifdef USE_LIBSODIUM_CHACHA20_POLY1305_IETF
|
||||
# define TEST_TAG_LEN crypto_aead_chacha20poly1305_IETF_ABYTES
|
||||
# define TEST_KEY_LEN crypto_aead_chacha20poly1305_IETF_KEYBYTES
|
||||
# define TEST_IV_LEN crypto_aead_chacha20poly1305_IETF_NPUBBYTES
|
||||
# else
|
||||
# define TEST_TAG_LEN 16
|
||||
# define TEST_KEY_LEN 32
|
||||
# define TEST_IV_LEN 12
|
||||
# endif
|
||||
|
||||
int32 psChacha20Poly1305Test(void)
|
||||
int32 psChacha20Poly1305IetfTest(void)
|
||||
{
|
||||
int32 i;
|
||||
psChacha20Poly1305_t eCtx, dCtx;
|
||||
psChacha20Poly1305Ietf_t eCtx, dCtx;
|
||||
unsigned char ciphertext[TEST_TEXT_MAXLEN];
|
||||
unsigned char plaintext[TEST_TEXT_MAXLEN];
|
||||
unsigned char plaintext2[TEST_TEXT_MAXLEN];
|
||||
unsigned char ciphertext_tag[TEST_TEXT_MAXLEN + TEST_TAG_LEN];
|
||||
unsigned char tag[TEST_TAG_LEN];
|
||||
psResSize_t sz1;
|
||||
psResSize_t sz2;
|
||||
|
||||
static struct
|
||||
{
|
||||
int32 keylen, ptlen, aadlen;
|
||||
unsigned char key[TEST_KEY_LEN], iv[TEST_IV_LEN], pt[TEST_TEXT_MAXLEN], aad[TEST_AAD_MAXLEN], ct[TEST_TEXT_MAXLEN], tag[TEST_TAG_LEN];
|
||||
} tests[] = {
|
||||
|
||||
# ifdef CHACHA20POLY1305_IETF
|
||||
{ TEST_KEY_LEN, 114, 12,
|
||||
{ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
|
||||
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
|
||||
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f },
|
||||
|
||||
{
|
||||
TEST_KEY_LEN, 114, 12,
|
||||
{
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
|
||||
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
|
||||
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f },
|
||||
/* IV */
|
||||
{ 0x07, 0x00, 0x00, 0x00,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47 },
|
||||
{
|
||||
0x07, 0x00, 0x00, 0x00,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47 },
|
||||
/* pt */
|
||||
{ 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61,
|
||||
0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c,
|
||||
0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20,
|
||||
0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73,
|
||||
0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39,
|
||||
0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63,
|
||||
0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66,
|
||||
0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f,
|
||||
0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20,
|
||||
0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20,
|
||||
0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75,
|
||||
0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73,
|
||||
0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f,
|
||||
0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69,
|
||||
0x74, 0x2e },
|
||||
{
|
||||
0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61,
|
||||
0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c,
|
||||
0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20,
|
||||
0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73,
|
||||
0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39,
|
||||
0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63,
|
||||
0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66,
|
||||
0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f,
|
||||
0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20,
|
||||
0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20,
|
||||
0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75,
|
||||
0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73,
|
||||
0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f,
|
||||
0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69,
|
||||
0x74, 0x2e },
|
||||
/* aad */
|
||||
{ 0x50, 0x51, 0x52, 0x53,
|
||||
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7 },
|
||||
{
|
||||
0x50, 0x51, 0x52, 0x53,
|
||||
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7 },
|
||||
/* ct */
|
||||
{ 0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb,
|
||||
0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2,
|
||||
0xa4, 0xad, 0xed, 0x51, 0x29, 0x6e, 0x08, 0xfe,
|
||||
0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6,
|
||||
0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, 0x67, 0x12,
|
||||
0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, 0x72, 0x8b,
|
||||
0x1a, 0x71, 0xde, 0x0a, 0x9e, 0x06, 0x0b, 0x29,
|
||||
0x05, 0xd6, 0xa5, 0xb6, 0x7e, 0xcd, 0x3b, 0x36,
|
||||
0x92, 0xdd, 0xbd, 0x7f, 0x2d, 0x77, 0x8b, 0x8c,
|
||||
0x98, 0x03, 0xae, 0xe3, 0x28, 0x09, 0x1b, 0x58,
|
||||
0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94,
|
||||
0x55, 0x85, 0x80, 0x8b, 0x48, 0x31, 0xd7, 0xbc,
|
||||
0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d,
|
||||
0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b,
|
||||
0x61, 0x16 },
|
||||
{
|
||||
0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb,
|
||||
0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2,
|
||||
0xa4, 0xad, 0xed, 0x51, 0x29, 0x6e, 0x08, 0xfe,
|
||||
0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6,
|
||||
0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, 0x67, 0x12,
|
||||
0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, 0x72, 0x8b,
|
||||
0x1a, 0x71, 0xde, 0x0a, 0x9e, 0x06, 0x0b, 0x29,
|
||||
0x05, 0xd6, 0xa5, 0xb6, 0x7e, 0xcd, 0x3b, 0x36,
|
||||
0x92, 0xdd, 0xbd, 0x7f, 0x2d, 0x77, 0x8b, 0x8c,
|
||||
0x98, 0x03, 0xae, 0xe3, 0x28, 0x09, 0x1b, 0x58,
|
||||
0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94,
|
||||
0x55, 0x85, 0x80, 0x8b, 0x48, 0x31, 0xd7, 0xbc,
|
||||
0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d,
|
||||
0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b,
|
||||
0x61, 0x16 },
|
||||
/* tag */
|
||||
{ 0x1a, 0xe1, 0x0b, 0x59, 0x4f, 0x09, 0xe2, 0x6a,
|
||||
0x7e, 0x90, 0x2e, 0xcb, 0xd0, 0x60, 0x06, 0x91 } },
|
||||
{
|
||||
0x1a, 0xe1, 0x0b, 0x59, 0x4f, 0x09, 0xe2, 0x6a,
|
||||
0x7e, 0x90, 0x2e, 0xcb, 0xd0, 0x60, 0x06, 0x91 } },
|
||||
|
||||
{ TEST_KEY_LEN, 114, 0,
|
||||
{ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
|
||||
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
|
||||
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f },
|
||||
{
|
||||
TEST_KEY_LEN, 114, 0,
|
||||
{
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
|
||||
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
|
||||
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f },
|
||||
/* IV */
|
||||
{ 0x07, 0x00, 0x00, 0x00,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47 },
|
||||
{
|
||||
0x07, 0x00, 0x00, 0x00,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47 },
|
||||
/* pt */
|
||||
{ 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61,
|
||||
0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c,
|
||||
0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20,
|
||||
0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73,
|
||||
0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39,
|
||||
0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63,
|
||||
0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66,
|
||||
0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f,
|
||||
0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20,
|
||||
0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20,
|
||||
0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75,
|
||||
0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73,
|
||||
0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f,
|
||||
0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69,
|
||||
0x74, 0x2e },
|
||||
{
|
||||
0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61,
|
||||
0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c,
|
||||
0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20,
|
||||
0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73,
|
||||
0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39,
|
||||
0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63,
|
||||
0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66,
|
||||
0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f,
|
||||
0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20,
|
||||
0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20,
|
||||
0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75,
|
||||
0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73,
|
||||
0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f,
|
||||
0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69,
|
||||
0x74, 0x2e },
|
||||
/* aad */
|
||||
{ "" },
|
||||
{
|
||||
""
|
||||
},
|
||||
/* ct */
|
||||
{ 0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb,
|
||||
0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2,
|
||||
0xa4, 0xad, 0xed, 0x51, 0x29, 0x6e, 0x08, 0xfe,
|
||||
0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6,
|
||||
0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, 0x67, 0x12,
|
||||
0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, 0x72, 0x8b,
|
||||
0x1a, 0x71, 0xde, 0x0a, 0x9e, 0x06, 0x0b, 0x29,
|
||||
0x05, 0xd6, 0xa5, 0xb6, 0x7e, 0xcd, 0x3b, 0x36,
|
||||
0x92, 0xdd, 0xbd, 0x7f, 0x2d, 0x77, 0x8b, 0x8c,
|
||||
0x98, 0x03, 0xae, 0xe3, 0x28, 0x09, 0x1b, 0x58,
|
||||
0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94,
|
||||
0x55, 0x85, 0x80, 0x8b, 0x48, 0x31, 0xd7, 0xbc,
|
||||
0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d,
|
||||
0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b,
|
||||
0x61, 0x16 },
|
||||
{
|
||||
0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb,
|
||||
0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2,
|
||||
0xa4, 0xad, 0xed, 0x51, 0x29, 0x6e, 0x08, 0xfe,
|
||||
0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6,
|
||||
0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, 0x67, 0x12,
|
||||
0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, 0x72, 0x8b,
|
||||
0x1a, 0x71, 0xde, 0x0a, 0x9e, 0x06, 0x0b, 0x29,
|
||||
0x05, 0xd6, 0xa5, 0xb6, 0x7e, 0xcd, 0x3b, 0x36,
|
||||
0x92, 0xdd, 0xbd, 0x7f, 0x2d, 0x77, 0x8b, 0x8c,
|
||||
0x98, 0x03, 0xae, 0xe3, 0x28, 0x09, 0x1b, 0x58,
|
||||
0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94,
|
||||
0x55, 0x85, 0x80, 0x8b, 0x48, 0x31, 0xd7, 0xbc,
|
||||
0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d,
|
||||
0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b,
|
||||
0x61, 0x16 },
|
||||
/* tag */
|
||||
{ 0x6a, 0x23, 0xa4, 0x68, 0x1f, 0xd5, 0x94, 0x56,
|
||||
0xae, 0xa1, 0xd2, 0x9f, 0x82, 0x47, 0x72, 0x16 } }
|
||||
# else
|
||||
{ TEST_KEY_LEN, 16, 13,
|
||||
{ 0x70, 0xd5, 0xbd, 0x03, 0xc6, 0x17, 0x68, 0xb2,
|
||||
0xd5, 0xce, 0xb4, 0xa4, 0x15, 0xc6, 0xf8, 0x40,
|
||||
0xf5, 0xd4, 0xbf, 0x5e, 0x63, 0x2b, 0xb6, 0xf3,
|
||||
0x73, 0xaf, 0xcd, 0xd7, 0xbb, 0xba, 0x85, 0xa7 },
|
||||
/* Nonce */
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
/* pt */
|
||||
{ 0x14, 0x00, 0x00, 0x0c,
|
||||
0x9c, 0x49, 0x65, 0xfc, 0xeb, 0x2e, 0xfa, 0x01, 0xfc, 0xa1, 0x2a, 0xaf },
|
||||
/* aad */
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x16, 0x03, 0x03, 0x00, 0x10 },
|
||||
/* ct */
|
||||
{ 0x25, 0xd8, 0x3d, 0x53, 0xbd, 0x03, 0xdd, 0x69,
|
||||
0x5a, 0x44, 0x6f, 0xde, 0x0c, 0x3d, 0x87, 0x93 },
|
||||
/* tag */
|
||||
{ 0x80, 0x53, 0x32, 0x2f, 0x5c, 0x27, 0x8f, 0x9d,
|
||||
0x78, 0xb5, 0x25, 0x3d, 0x5c, 0xc3, 0x8c, 0x9b } }
|
||||
# endif
|
||||
{
|
||||
0x6a, 0x23, 0xa4, 0x68, 0x1f, 0xd5, 0x94, 0x56,
|
||||
0xae, 0xa1, 0xd2, 0x9f, 0x82, 0x47, 0x72, 0x16 } }
|
||||
};
|
||||
|
||||
/* Test AEAD CHACHA20-POLY1305 */
|
||||
@@ -1508,36 +1501,36 @@ int32 psChacha20Poly1305Test(void)
|
||||
for (i = 0; i < (int32) (sizeof(tests) / sizeof(tests[0])); i++)
|
||||
{
|
||||
_psTraceInt(" CHACHA20-POLY1305-%d "
|
||||
# ifdef CHACHA20POLY1305_IETF
|
||||
"IETF "
|
||||
# endif
|
||||
"known vector encrypt test... ", tests[i].keylen * 8);
|
||||
|
||||
psChacha20Poly1305Init(&eCtx, tests[i].key, tests[i].keylen);
|
||||
psChacha20Poly1305Ready(&eCtx, tests[i].iv, tests[i].aad, tests[i].aadlen);
|
||||
psChacha20Poly1305Encrypt(&eCtx, tests[i].pt, ciphertext, tests[i].ptlen);
|
||||
psChacha20Poly1305GetTag(&eCtx, TEST_TAG_LEN, tag);
|
||||
psChacha20Poly1305IetfInit(&eCtx, tests[i].key);
|
||||
sz1 = psChacha20Poly1305IetfEncryptDetached(&eCtx, tests[i].pt, tests[i].ptlen, tests[i].iv, tests[i].aad, tests[i].aadlen, ciphertext, tag);
|
||||
|
||||
if ((memcmp(ciphertext, tests[i].ct, tests[i].ptlen) != 0) ||
|
||||
(memcmp(tag, tests[i].tag, TEST_TAG_LEN) != 0))
|
||||
sz2 = psChacha20Poly1305IetfEncrypt(&eCtx, tests[i].pt, tests[i].ptlen, tests[i].iv, tests[i].aad, tests[i].aadlen, ciphertext_tag);
|
||||
|
||||
if (sz1 != tests[i].ptlen ||
|
||||
memcmp(ciphertext, tests[i].ct, tests[i].ptlen) != 0 ||
|
||||
memcmp(tag, tests[i].tag, TEST_TAG_LEN) != 0)
|
||||
{
|
||||
printf("FAILED: memcmp mismatch\n");
|
||||
printf("FAILED: memcmp mismatch (psChacha20Poly1305IetfEncryptDetached)\n");
|
||||
}
|
||||
else if (sz2 != tests[i].ptlen + TEST_TAG_LEN ||
|
||||
memcmp(ciphertext_tag, tests[i].ct, tests[i].ptlen) != 0 ||
|
||||
memcmp(ciphertext_tag + tests[i].ptlen, tests[i].tag, TEST_TAG_LEN) != 0)
|
||||
{
|
||||
printf("FAILED: memcmp mismatch (psChacha20Poly1305IetfEncrypt)\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("PASSED\n");
|
||||
}
|
||||
psChacha20Poly1305Clear(&eCtx);
|
||||
memset(tag, 0x0, TEST_TAG_LEN);
|
||||
memset(ciphertext, 0x0, TEST_TEXT_MAXLEN);
|
||||
psChacha20Poly1305IetfClear(&eCtx);
|
||||
|
||||
_psTraceInt(" CHACHA20-POLY1305-%d "
|
||||
# ifdef CHACHA20POLY1305_IETF
|
||||
"IETF "
|
||||
# endif
|
||||
"known vector decrypt test... ", tests[i].keylen * 8);
|
||||
psChacha20Poly1305Init(&dCtx, tests[i].key, tests[i].keylen);
|
||||
psChacha20Poly1305Ready(&dCtx, tests[i].iv, tests[i].aad, tests[i].aadlen);
|
||||
psChacha20Poly1305IetfInit(&dCtx, tests[i].key);
|
||||
|
||||
/* Cipher text must include the tag */
|
||||
unsigned char *cipherTextAuthData;
|
||||
@@ -1546,27 +1539,51 @@ int32 psChacha20Poly1305Test(void)
|
||||
memcpy(cipherTextAuthData, tests[i].ct, tests[i].ptlen);
|
||||
memcpy(cipherTextAuthData + tests[i].ptlen, tests[i].tag, TEST_TAG_LEN);
|
||||
|
||||
if (psChacha20Poly1305Decrypt(&dCtx, cipherTextAuthData,
|
||||
tests[i].ptlen + TEST_TAG_LEN, plaintext, tests[i].ptlen) < 0)
|
||||
sz1 = psChacha20Poly1305IetfDecrypt(
|
||||
&dCtx,
|
||||
cipherTextAuthData,
|
||||
tests[i].ptlen + TEST_TAG_LEN,
|
||||
tests[i].iv,
|
||||
tests[i].aad,
|
||||
tests[i].aadlen,
|
||||
plaintext);
|
||||
|
||||
sz2 = psChacha20Poly1305IetfDecryptDetached(
|
||||
&dCtx,
|
||||
ciphertext,
|
||||
tests[i].ptlen,
|
||||
tests[i].iv,
|
||||
tests[i].aad,
|
||||
tests[i].aadlen,
|
||||
tests[i].tag,
|
||||
plaintext2);
|
||||
|
||||
if (sz1 != tests[i].ptlen)
|
||||
{
|
||||
printf("FAILED: authentication failed\n");
|
||||
printf("FAILED: authentication failed (psChacha20Poly1305IetfDecrypt)\n");
|
||||
}
|
||||
else if (memcmp(plaintext, tests[i].pt, tests[i].ptlen) != 0)
|
||||
{
|
||||
printf("FAILED: data mismatch\n");
|
||||
printf("FAILED: data mismatch (psChacha20Poly1305IetfDecryptDetached)\n");
|
||||
}
|
||||
else if (sz2 != (psResSize_t) tests[i].ptlen)
|
||||
{
|
||||
printf("FAILED: authentication failed (psChacha20Poly1305IetfDecryptDetached)\n");
|
||||
}
|
||||
else if (memcmp(plaintext2, tests[i].pt, tests[i].ptlen) != 0)
|
||||
{
|
||||
printf("FAILED: data mismatch (psChacha20Poly1305IetfDecryptDetached)\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("PASSED\n");
|
||||
}
|
||||
psFree(cipherTextAuthData, NULL);
|
||||
psChacha20Poly1305Clear(&dCtx);
|
||||
memset(tag, 0x0, TEST_TAG_LEN);
|
||||
memset(plaintext, 0x0, TEST_TEXT_MAXLEN);
|
||||
psChacha20Poly1305IetfClear(&dCtx);
|
||||
}
|
||||
return PS_SUCCESS;
|
||||
}
|
||||
#endif /* USE_CHACHA20_POLY1305 */
|
||||
#endif /* USE_CHACHA20_POLY1305_IETF */
|
||||
|
||||
/******************************************************************************/
|
||||
#ifdef USE_DES
|
||||
@@ -5243,8 +5260,8 @@ static test_t tests[] = {
|
||||
{ NULL, "AES" },
|
||||
#endif
|
||||
|
||||
#ifdef USE_CHACHA20_POLY1305
|
||||
{ psChacha20Poly1305Test, "***** CHACHA20_POLY1305 TESTS *****" },
|
||||
#ifdef USE_CHACHA20_POLY1305_IETF
|
||||
{ psChacha20Poly1305IetfTest, "***** CHACHA20_POLY1305 TESTS *****" },
|
||||
#endif
|
||||
|
||||
#ifdef USE_PKCS5
|
||||
|
||||
Reference in New Issue
Block a user