3.8.6
This commit is contained in:
@@ -804,6 +804,7 @@ int32 psAesTestGCM(void)
|
||||
if ((memcmp(ciphertext, tests[i].ct, tests[i].ptlen) != 0) ||
|
||||
(memcmp(tag, tests[i].tag, 16) != 0)) {
|
||||
printf("FAILED: memcmp mismatch\n");
|
||||
res = PS_FAILURE;
|
||||
} else {
|
||||
printf("PASSED\n");
|
||||
}
|
||||
@@ -977,6 +978,211 @@ int32 psAesTestGCM(void)
|
||||
}
|
||||
#endif /* USE_AES_GCM */
|
||||
|
||||
#ifdef USE_AES_CTR
|
||||
int32 psAesTestCTR(void)
|
||||
{
|
||||
static struct {
|
||||
int32 keylen, msglen;
|
||||
unsigned char key[32], IV[16], pt[64], ct[64];
|
||||
} tests[] = {
|
||||
/* 128-bit key, 16-byte pt */
|
||||
{
|
||||
16, 16,
|
||||
{0xAE,0x68,0x52,0xF8,0x12,0x10,0x67,0xCC,0x4B,0xF7,0xA5,0x76,0x55,0x77,0xF3,0x9E },
|
||||
{0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
|
||||
{0x53,0x69,0x6E,0x67,0x6C,0x65,0x20,0x62,0x6C,0x6F,0x63,0x6B,0x20,0x6D,0x73,0x67 },
|
||||
{0xE4,0x09,0x5D,0x4F,0xB7,0xA7,0xB3,0x79,0x2D,0x61,0x75,0xA3,0x26,0x13,0x11,0xB8 },
|
||||
},
|
||||
|
||||
/* 128-bit key, 36-byte pt */
|
||||
{
|
||||
16, 36,
|
||||
{0x76,0x91,0xBE,0x03,0x5E,0x50,0x20,0xA8,0xAC,0x6E,0x61,0x85,0x29,0xF9,0xA0,0xDC },
|
||||
{0x00,0xE0,0x01,0x7B,0x27,0x77,0x7F,0x3F,0x4A,0x17,0x86,0xF0,0x00,0x00,0x00,0x00 },
|
||||
{0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
|
||||
0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
|
||||
0x20,0x21,0x22,0x23},
|
||||
{0xC1,0xCF,0x48,0xA8,0x9F,0x2F,0xFD,0xD9,0xCF,0x46,0x52,0xE9,0xEF,0xDB,0x72,0xD7,
|
||||
0x45,0x40,0xA4,0x2B,0xDE,0x6D,0x78,0x36,0xD5,0x9A,0x5C,0xEA,0xAE,0xF3,0x10,0x53,
|
||||
0x25,0xB2,0x07,0x2F },
|
||||
},
|
||||
};
|
||||
|
||||
int err, x;
|
||||
unsigned char buf[64];
|
||||
psAesCtr_t ctr;
|
||||
|
||||
for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
|
||||
_psTraceInt(" AES-CTR-%d known vector test... ", tests[x].keylen * 8);
|
||||
if ((err = psAesInitExCTR(&ctr, tests[x].IV, tests[x].key,
|
||||
tests[x].keylen, CTR_COUNTER_BIG_ENDIAN|LTC_CTR_RFC3686,
|
||||
PS_AES_ENCRYPT)) != PS_SUCCESS) {
|
||||
_psTraceInt("FAILED: psAesInitExCTR %d\n", err);
|
||||
return err;
|
||||
}
|
||||
psAesEncryptCTR(&ctr, (unsigned char*)tests[x].pt, buf,
|
||||
tests[x].msglen);
|
||||
if (memcmp(buf, tests[x].ct, tests[x].msglen) != 0) {
|
||||
_psTrace("FAILED: memcmp\n");
|
||||
} else {
|
||||
_psTrace("PASSED\n");
|
||||
}
|
||||
psAesClearCTR(&ctr);
|
||||
}
|
||||
return PS_SUCCESS;
|
||||
}
|
||||
#endif /* USE_AES_CTR */
|
||||
|
||||
#ifdef USE_AES_CMAC
|
||||
int32 psAesTestCmac(void)
|
||||
{
|
||||
int32 err;
|
||||
static struct {
|
||||
int32 keylen, ptlen;
|
||||
unsigned char key[32], pt[64], ct[16];
|
||||
} tests[] = {
|
||||
{ 16, 16,
|
||||
{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2,
|
||||
0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c},
|
||||
{ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40,
|
||||
0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a },
|
||||
{ 0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44, 0xf7, 0x9b,
|
||||
0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c }
|
||||
},
|
||||
{ 16, 40,
|
||||
{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2,
|
||||
0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c},
|
||||
{ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d,
|
||||
0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, 0xae, 0x2d, 0x8a, 0x57,
|
||||
0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf,
|
||||
0x8e, 0x51, 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11 },
|
||||
{ 0xdf, 0xa6, 0x67, 0x47, 0xde, 0x9a, 0xe6, 0x30, 0x30, 0xca,
|
||||
0x32, 0x61, 0x14, 0x97, 0xc8, 0x27 }
|
||||
},
|
||||
{ 16, 64,
|
||||
{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2,
|
||||
0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c},
|
||||
{ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e,
|
||||
0x11, 0x73, 0x93, 0x17, 0x2a, 0xae, 0x2d, 0x8a, 0x57, 0x1e,
|
||||
0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e,
|
||||
0x51, 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5,
|
||||
0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, 0xf6, 0x9f, 0x24,
|
||||
0x45, 0xdf, 0x4f, 0x9b, 0x17, 0xad, 0x2b, 0x41, 0x7b, 0xe6,
|
||||
0x6c, 0x37, 0x10 },
|
||||
{ 0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92, 0xfc, 0x49, 0x74,
|
||||
0x17, 0x79, 0x36, 0x3c, 0xfe }
|
||||
},
|
||||
{ 24, 16,
|
||||
{ 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52, 0xc8, 0x10, 0xf3,
|
||||
0x2b, 0x80, 0x90, 0x79, 0xe5, 0x62, 0xf8, 0xea, 0xd2, 0x52,
|
||||
0x2c, 0x6b, 0x7b},
|
||||
{ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40,
|
||||
0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a },
|
||||
{ 0x9e, 0x99, 0xa7, 0xbf, 0x31, 0xe7, 0x10, 0x90, 0x06, 0x62, 0xf6,
|
||||
0x5e, 0x61, 0x7c, 0x51, 0x84 }
|
||||
},
|
||||
{ 32, 40,
|
||||
{ 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae,
|
||||
0xf0, 0x85, 0x7d, 0x77, 0x81, 0x1f, 0x35, 0x2c, 0x07, 0x3b,
|
||||
0x61, 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf,
|
||||
0xf4},
|
||||
{ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d,
|
||||
0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, 0xae, 0x2d, 0x8a, 0x57,
|
||||
0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf,
|
||||
0x8e, 0x51, 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11 },
|
||||
{ 0xaa, 0xf3, 0xd8, 0xf1, 0xde, 0x56, 0x40, 0xc2, 0x32, 0xf5,
|
||||
0xb1, 0x69, 0xb9, 0xc9, 0x11, 0xe6 }
|
||||
}
|
||||
};
|
||||
|
||||
int32 i;
|
||||
unsigned char cmac[16];
|
||||
|
||||
for (i = 0; i < (int32)(sizeof(tests)/sizeof(tests[0])); i++) {
|
||||
_psTraceInt(" AES CMAC %d known vector test... ", tests[i].keylen * 8);
|
||||
if ((err = matrixCmacGenerate(NULL, tests[i].key, tests[i].keylen,
|
||||
tests[i].pt, tests[i].ptlen, cmac)) != PS_SUCCESS) {
|
||||
_psTraceInt("FAILED: matrixCmacGenerate %d\n", err);
|
||||
return err;
|
||||
}
|
||||
if (memcmp(cmac, tests[i].ct, 16) != 0) {
|
||||
_psTrace("FAILED: memcmp\n");
|
||||
} else {
|
||||
_psTrace("PASSED\n");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif /* USE_AES_CMAC */
|
||||
|
||||
#ifdef USE_AES_WRAP
|
||||
int32 psAesTestWrap(void)
|
||||
{
|
||||
int32 err;
|
||||
static struct {
|
||||
int32 keylen, ptlen;
|
||||
unsigned char key[32], pt[32], ct[32];
|
||||
} tests[] = {
|
||||
{ 16, 16,
|
||||
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},
|
||||
{ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
|
||||
0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF },
|
||||
{ 0x1f, 0xa6, 0x8b, 0x0a, 0x81, 0x12, 0xb4, 0x47, 0xae,
|
||||
0xf3, 0x4b, 0xd8, 0xfb, 0x5a, 0x7b, 0x82, 0x9d, 0x3e,
|
||||
0x86, 0x23, 0x71, 0xd2, 0xcf, 0xe5}
|
||||
},
|
||||
{ 24, 16,
|
||||
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11,
|
||||
0x12, 0x13, 0x14, 0x15, 0x16, 0x17},
|
||||
{ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
|
||||
0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF },
|
||||
{ 0x96, 0x77, 0x8b, 0x25, 0xae, 0x6c, 0xa4, 0x35, 0xf9,
|
||||
0x2b, 0x5b, 0x97, 0xc0, 0x50, 0xae, 0xd2, 0x46, 0x8a,
|
||||
0xb8, 0xa1, 0x7a, 0xd8, 0x4e, 0x5d }
|
||||
},
|
||||
{ 32, 16,
|
||||
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11,
|
||||
0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A,
|
||||
0x1B, 0x1C, 0x1D, 0x1E, 0x1F},
|
||||
{ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
|
||||
0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF },
|
||||
{ 0x64, 0xe8, 0xc3, 0xf9, 0xce, 0x0f, 0x5b, 0xa2, 0x63,
|
||||
0xe9, 0x77, 0x79, 0x05, 0x81, 0x8a, 0x2a, 0x93, 0xc8,
|
||||
0x19, 0x1e, 0x7d, 0x6e, 0x8a, 0xe7}
|
||||
}
|
||||
};
|
||||
|
||||
int32_t i;
|
||||
uint32_t woutlen, uoutlen;
|
||||
unsigned char unwrapped[32];
|
||||
unsigned char wrapped[32];
|
||||
|
||||
for (i = 0; i < (uint32_t)(sizeof(tests)/sizeof(tests[0])); i++) {
|
||||
_psTraceInt(" AES KEY WRAP %d known vector test... ", tests[i].keylen * 8);
|
||||
if ((err = psAesWrap(tests[i].key, tests[i].keylen, tests[i].pt,
|
||||
tests[i].ptlen, wrapped, &woutlen)) != PS_SUCCESS) {
|
||||
_psTraceInt("FAILED: psAesWrap %d\n", err);
|
||||
return err;
|
||||
}
|
||||
if ((err = psAesUnwrap(tests[i].key, tests[i].keylen, wrapped,
|
||||
woutlen, unwrapped, &uoutlen)) != PS_SUCCESS) {
|
||||
_psTraceInt("FAILED: psAesWrap %d\n", err);
|
||||
return err;
|
||||
}
|
||||
if (memcmp(wrapped, tests[i].ct, woutlen) != 0 ||
|
||||
memcmp(unwrapped, tests[i].pt, uoutlen) != 0) {
|
||||
_psTrace("FAILED: memcmp\n");
|
||||
} else {
|
||||
_psTrace("PASSED\n");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif /* USE_AES_WRAP */
|
||||
|
||||
#endif /* USE_AES */
|
||||
|
||||
#if 0
|
||||
@@ -1651,6 +1857,7 @@ int32 psSha1Test(void)
|
||||
|
||||
for (i = 0; i < (int32)(sizeof(tests) / sizeof(tests[0])); i++) {
|
||||
_psTraceInt(" SHA-1 known vector test %d... ", i + 1);
|
||||
psSha1PreInit(&md);
|
||||
psSha1Init(&md);
|
||||
psSha1Update(&md, (unsigned char*)tests[i].msg, (uint32)strlen(tests[i].msg));
|
||||
psSha1Final(&md, tmp);
|
||||
@@ -1713,6 +1920,7 @@ int32 psSha256Test2(void)
|
||||
}
|
||||
|
||||
memset(hash, 0, sizeof(hash));
|
||||
psSha256PreInit(&md); /* Pre-init before first use. */
|
||||
psSha256Init(&md);
|
||||
psSha256Update(&md, array, 65536);
|
||||
psSha256Final(&md, hash);
|
||||
@@ -1724,6 +1932,7 @@ int32 psSha256Test2(void)
|
||||
}
|
||||
|
||||
memset(hash, 0, sizeof(hash));
|
||||
psSha256PreInit(&md2); /* Pre-init before first use. */
|
||||
psSha256Init(&md2);
|
||||
psSha256Update(&md2, array2, 65536);
|
||||
psSha256Final(&md2, hash);
|
||||
@@ -1735,6 +1944,7 @@ int32 psSha256Test2(void)
|
||||
}
|
||||
|
||||
memset(hash, 0, sizeof(hash));
|
||||
psSha256PreInit(&md3); /* Pre-init before first use. */
|
||||
psSha256Init(&md3);
|
||||
psSha256Update(&md3, array3, 65536);
|
||||
psSha256Final(&md3, hash);
|
||||
@@ -2121,6 +2331,7 @@ int32 psSha256Test(void)
|
||||
|
||||
for (i = 0; i < (int32)(sizeof(tests) / sizeof(tests[0])); i++) {
|
||||
_psTraceInt(" SHA-256 known vector test %d... ", i + 1);
|
||||
psSha256PreInit(&md);
|
||||
psSha256Init(&md);
|
||||
psSha256Update(&md, (unsigned char*)tests[i].msg,
|
||||
(uint32)strlen(tests[i].msg));
|
||||
@@ -2231,6 +2442,7 @@ int32 psSha512Test(void)
|
||||
|
||||
for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) {
|
||||
_psTraceInt(" SHA-512 known vector test %d... ", i + 1);
|
||||
psSha512PreInit(&md);
|
||||
psSha512Init(&md);
|
||||
psSha512Update(&md, (unsigned char *)tests[i].msg, (uint32)strlen(tests[i].msg));
|
||||
psSha512Final(&md, tmp);
|
||||
@@ -2275,6 +2487,7 @@ int32 psSha384Test(void)
|
||||
|
||||
for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) {
|
||||
_psTraceInt(" SHA-384 known vector test %d... ", i + 1);
|
||||
psSha384PreInit(&md);
|
||||
psSha384Init(&md);
|
||||
psSha384Update(&md, (unsigned char*)tests[i].msg, (uint32)strlen(tests[i].msg));
|
||||
psSha384Final(&md, tmp);
|
||||
@@ -2332,6 +2545,7 @@ int32 psMd5Sha1Test(void)
|
||||
|
||||
for (i = 0; i < (int32)(sizeof(tests) / sizeof(tests[0])); i++) {
|
||||
_psTraceInt(" MD5SHA1 known vector test %d... ", i + 1);
|
||||
psMd5Sha1PreInit(&md);
|
||||
psMd5Sha1Init(&md);
|
||||
psMd5Sha1Update(&md, (unsigned char*)tests[i].msg, (uint32)strlen(tests[i].msg));
|
||||
psMd5Sha1Final(&md, tmp);
|
||||
@@ -4619,6 +4833,15 @@ static test_t tests[] = {
|
||||
#ifdef USE_AES_GCM
|
||||
{psAesTestGCM, "***** AES-GCM TESTS *****"},
|
||||
#endif
|
||||
#ifdef USE_AES_WRAP
|
||||
{psAesTestWrap, "***** AES WRAP TEST *****"},
|
||||
#endif
|
||||
#ifdef USE_AES_CMAC
|
||||
{psAesTestCmac, "***** AES CMAC TEST *****"},
|
||||
#endif
|
||||
#ifdef USE_AES_CTR
|
||||
{psAesTestCTR, "***** AES-CTR TESTS *****"},
|
||||
#endif
|
||||
#else
|
||||
{NULL, "AES"},
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user