[CRYPTO] tcrypt: Add CCM vectors

This patch adds 7 test vectors to tcrypt for CCM.
The test vectors are from rfc 3610.
There are about 10 more test vectors in RFC 3610
and 4 or 5 more in NIST. I can add these as time permits.

I also needed to set authsize. CCM has a prerequisite of
authsize. 

Signed-off-by: Joy Latten <latten@austin.ibm.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
Joy Latten 2007-12-12 20:24:22 +08:00 коммит произвёл Herbert Xu
Родитель 4a49b499df
Коммит 93cc74e078
2 изменённых файлов: 289 добавлений и 2 удалений

Просмотреть файл

@ -266,8 +266,6 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template,
return;
}
authsize = crypto_aead_authsize(tfm);
req = aead_request_alloc(tfm, GFP_KERNEL);
if (!req) {
printk(KERN_INFO "failed to allocate request for %s\n", algo);
@ -298,6 +296,15 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template,
goto out;
}
authsize = abs(aead_tv[i].rlen - aead_tv[i].ilen);
ret = crypto_aead_setauthsize(tfm, authsize);
if (ret) {
printk(KERN_INFO
"failed to set authsize = %u\n",
authsize);
goto out;
}
sg_init_one(&sg[0], aead_tv[i].input,
aead_tv[i].ilen + (enc ? authsize : 0));
@ -374,6 +381,15 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template,
aead_tv[i].tap[k]);
}
authsize = abs(aead_tv[i].rlen - aead_tv[i].ilen);
ret = crypto_aead_setauthsize(tfm, authsize);
if (ret) {
printk(KERN_INFO
"failed to set authsize = %u\n",
authsize);
goto out;
}
if (enc)
sg[k - 1].length += authsize;
@ -1201,6 +1217,10 @@ static void do_test(void)
AES_GCM_ENC_TEST_VECTORS);
test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
AES_GCM_DEC_TEST_VECTORS);
test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
AES_CCM_ENC_TEST_VECTORS);
test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
AES_CCM_DEC_TEST_VECTORS);
//CAST5
test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
@ -1557,6 +1577,13 @@ static void do_test(void)
LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
break;
case 37:
test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
AES_CCM_ENC_TEST_VECTORS);
test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
AES_CCM_DEC_TEST_VECTORS);
break;
case 100:
test_hash("hmac(md5)", hmac_md5_tv_template,
HMAC_MD5_TEST_VECTORS);

Просмотреть файл

@ -2313,6 +2313,8 @@ static struct cipher_testvec cast6_dec_tv_template[] = {
#define AES_CTR_DEC_TEST_VECTORS 6
#define AES_GCM_ENC_TEST_VECTORS 9
#define AES_GCM_DEC_TEST_VECTORS 8
#define AES_CCM_ENC_TEST_VECTORS 7
#define AES_CCM_DEC_TEST_VECTORS 7
static struct cipher_testvec aes_enc_tv_template[] = {
{ /* From FIPS-197 */
@ -5028,6 +5030,264 @@ static struct aead_testvec aes_gcm_dec_tv_template[] = {
}
};
static struct aead_testvec aes_ccm_enc_tv_template[] = {
{ /* From RFC 3610 */
.key = { 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf },
.klen = 16,
.iv = { 0x01, 0x00, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0x00, 0x00 },
.assoc = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 },
.alen = 8,
.input = { 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e },
.ilen = 23,
.result = { 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84, 0x17,
0xe8, 0xd1, 0x2c, 0xfd, 0xf9, 0x26, 0xe0 },
.rlen = 31,
}, {
.key = { 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf },
.klen = 16,
.iv = { 0x01, 0x00, 0x00, 0x00, 0x07, 0x06, 0x05, 0x04,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0x00, 0x00 },
.assoc = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b },
.alen = 12,
.input = { 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
0x1c, 0x1d, 0x1e, 0x1f },
.ilen = 20,
.result = { 0xdc, 0xf1, 0xfb, 0x7b, 0x5d, 0x9e, 0x23, 0xfb,
0x9d, 0x4e, 0x13, 0x12, 0x53, 0x65, 0x8a, 0xd8,
0x6e, 0xbd, 0xca, 0x3e, 0x51, 0xe8, 0x3f, 0x07,
0x7d, 0x9c, 0x2d, 0x93 },
.rlen = 28,
}, {
.key = { 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf },
.klen = 16,
.iv = { 0x01, 0x00, 0x00, 0x00, 0x0b, 0x0a, 0x09, 0x08,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0x00, 0x00 },
.assoc = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 },
.alen = 8,
.input = { 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 },
.ilen = 25,
.result = { 0x82, 0x53, 0x1a, 0x60, 0xcc, 0x24, 0x94, 0x5a,
0x4b, 0x82, 0x79, 0x18, 0x1a, 0xb5, 0xc8, 0x4d,
0xf2, 0x1c, 0xe7, 0xf9, 0xb7, 0x3f, 0x42, 0xe1,
0x97, 0xea, 0x9c, 0x07, 0xe5, 0x6b, 0x5e, 0xb1,
0x7e, 0x5f, 0x4e },
.rlen = 35,
}, {
.key = { 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf },
.klen = 16,
.iv = { 0x01, 0x00, 0x00, 0x00, 0x0c, 0x0b, 0x0a, 0x09,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0x00, 0x00 },
.assoc = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b },
.alen = 12,
.input = { 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
0x1c, 0x1d, 0x1e },
.ilen = 19,
.result = { 0x07, 0x34, 0x25, 0x94, 0x15, 0x77, 0x85, 0x15,
0x2b, 0x07, 0x40, 0x98, 0x33, 0x0a, 0xbb, 0x14,
0x1b, 0x94, 0x7b, 0x56, 0x6a, 0xa9, 0x40, 0x6b,
0x4d, 0x99, 0x99, 0x88, 0xdd },
.rlen = 29,
}, {
.key = { 0xd7, 0x82, 0x8d, 0x13, 0xb2, 0xb0, 0xbd, 0xc3,
0x25, 0xa7, 0x62, 0x36, 0xdf, 0x93, 0xcc, 0x6b },
.klen = 16,
.iv = { 0x01, 0x00, 0x33, 0x56, 0x8e, 0xf7, 0xb2, 0x63,
0x3c, 0x96, 0x96, 0x76, 0x6c, 0xfa, 0x00, 0x00 },
.assoc = { 0x63, 0x01, 0x8f, 0x76, 0xdc, 0x8a, 0x1b, 0xcb },
.alen = 8,
.input = { 0x90, 0x20, 0xea, 0x6f, 0x91, 0xbd, 0xd8, 0x5a,
0xfa, 0x00, 0x39, 0xba, 0x4b, 0xaf, 0xf9, 0xbf,
0xb7, 0x9c, 0x70, 0x28, 0x94, 0x9c, 0xd0, 0xec },
.ilen = 24,
.result = { 0x4c, 0xcb, 0x1e, 0x7c, 0xa9, 0x81, 0xbe, 0xfa,
0xa0, 0x72, 0x6c, 0x55, 0xd3, 0x78, 0x06, 0x12,
0x98, 0xc8, 0x5c, 0x92, 0x81, 0x4a, 0xbc, 0x33,
0xc5, 0x2e, 0xe8, 0x1d, 0x7d, 0x77, 0xc0, 0x8a },
.rlen = 32,
}, {
.key = { 0xd7, 0x82, 0x8d, 0x13, 0xb2, 0xb0, 0xbd, 0xc3,
0x25, 0xa7, 0x62, 0x36, 0xdf, 0x93, 0xcc, 0x6b },
.klen = 16,
.iv = { 0x01, 0x00, 0xd5, 0x60, 0x91, 0x2d, 0x3f, 0x70,
0x3c, 0x96, 0x96, 0x76, 0x6c, 0xfa, 0x00, 0x00 },
.assoc = { 0xcd, 0x90, 0x44, 0xd2, 0xb7, 0x1f, 0xdb, 0x81,
0x20, 0xea, 0x60, 0xc0 },
.alen = 12,
.input = { 0x64, 0x35, 0xac, 0xba, 0xfb, 0x11, 0xa8, 0x2e,
0x2f, 0x07, 0x1d, 0x7c, 0xa4, 0xa5, 0xeb, 0xd9,
0x3a, 0x80, 0x3b, 0xa8, 0x7f },
.ilen = 21,
.result = { 0x00, 0x97, 0x69, 0xec, 0xab, 0xdf, 0x48, 0x62,
0x55, 0x94, 0xc5, 0x92, 0x51, 0xe6, 0x03, 0x57,
0x22, 0x67, 0x5e, 0x04, 0xc8, 0x47, 0x09, 0x9e,
0x5a, 0xe0, 0x70, 0x45, 0x51 },
.rlen = 29,
}, {
.key = { 0xd7, 0x82, 0x8d, 0x13, 0xb2, 0xb0, 0xbd, 0xc3,
0x25, 0xa7, 0x62, 0x36, 0xdf, 0x93, 0xcc, 0x6b },
.klen = 16,
.iv = { 0x01, 0x00, 0x42, 0xff, 0xf8, 0xf1, 0x95, 0x1c,
0x3c, 0x96, 0x96, 0x76, 0x6c, 0xfa, 0x00, 0x00 },
.assoc = { 0xd8, 0x5b, 0xc7, 0xe6, 0x9f, 0x94, 0x4f, 0xb8 },
.alen = 8,
.input = { 0x8a, 0x19, 0xb9, 0x50, 0xbc, 0xf7, 0x1a, 0x01,
0x8e, 0x5e, 0x67, 0x01, 0xc9, 0x17, 0x87, 0x65,
0x98, 0x09, 0xd6, 0x7d, 0xbe, 0xdd, 0x18 },
.ilen = 23,
.result = { 0xbc, 0x21, 0x8d, 0xaa, 0x94, 0x74, 0x27, 0xb6,
0xdb, 0x38, 0x6a, 0x99, 0xac, 0x1a, 0xef, 0x23,
0xad, 0xe0, 0xb5, 0x29, 0x39, 0xcb, 0x6a, 0x63,
0x7c, 0xf9, 0xbe, 0xc2, 0x40, 0x88, 0x97, 0xc6,
0xba },
.rlen = 33,
},
};
static struct aead_testvec aes_ccm_dec_tv_template[] = {
{ /* From RFC 3610 */
.key = { 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf },
.klen = 16,
.iv = { 0x01, 0x00, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0x00, 0x00 },
.assoc = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 },
.alen = 8,
.input = { 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84, 0x17,
0xe8, 0xd1, 0x2c, 0xfd, 0xf9, 0x26, 0xe0 },
.ilen = 31,
.result = { 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e },
.rlen = 23,
}, {
.key = { 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf },
.klen = 16,
.iv = { 0x01, 0x00, 0x00, 0x00, 0x07, 0x06, 0x05, 0x04,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0x00, 0x00 },
.assoc = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b },
.alen = 12,
.input = { 0xdc, 0xf1, 0xfb, 0x7b, 0x5d, 0x9e, 0x23, 0xfb,
0x9d, 0x4e, 0x13, 0x12, 0x53, 0x65, 0x8a, 0xd8,
0x6e, 0xbd, 0xca, 0x3e, 0x51, 0xe8, 0x3f, 0x07,
0x7d, 0x9c, 0x2d, 0x93 },
.ilen = 28,
.result = { 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
0x1c, 0x1d, 0x1e, 0x1f },
.rlen = 20,
}, {
.key = { 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf },
.klen = 16,
.iv = { 0x01, 0x00, 0x00, 0x00, 0x0b, 0x0a, 0x09, 0x08,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0x00, 0x00 },
.assoc = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 },
.alen = 8,
.input = { 0x82, 0x53, 0x1a, 0x60, 0xcc, 0x24, 0x94, 0x5a,
0x4b, 0x82, 0x79, 0x18, 0x1a, 0xb5, 0xc8, 0x4d,
0xf2, 0x1c, 0xe7, 0xf9, 0xb7, 0x3f, 0x42, 0xe1,
0x97, 0xea, 0x9c, 0x07, 0xe5, 0x6b, 0x5e, 0xb1,
0x7e, 0x5f, 0x4e },
.ilen = 35,
.result = { 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 },
.rlen = 25,
}, {
.key = { 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf },
.klen = 16,
.iv = { 0x01, 0x00, 0x00, 0x00, 0x0c, 0x0b, 0x0a, 0x09,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0x00, 0x00 },
.assoc = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b },
.alen = 12,
.input = { 0x07, 0x34, 0x25, 0x94, 0x15, 0x77, 0x85, 0x15,
0x2b, 0x07, 0x40, 0x98, 0x33, 0x0a, 0xbb, 0x14,
0x1b, 0x94, 0x7b, 0x56, 0x6a, 0xa9, 0x40, 0x6b,
0x4d, 0x99, 0x99, 0x88, 0xdd },
.ilen = 29,
.result = { 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
0x1c, 0x1d, 0x1e },
.rlen = 19,
}, {
.key = { 0xd7, 0x82, 0x8d, 0x13, 0xb2, 0xb0, 0xbd, 0xc3,
0x25, 0xa7, 0x62, 0x36, 0xdf, 0x93, 0xcc, 0x6b },
.klen = 16,
.iv = { 0x01, 0x00, 0x33, 0x56, 0x8e, 0xf7, 0xb2, 0x63,
0x3c, 0x96, 0x96, 0x76, 0x6c, 0xfa, 0x00, 0x00 },
.assoc = { 0x63, 0x01, 0x8f, 0x76, 0xdc, 0x8a, 0x1b, 0xcb },
.alen = 8,
.input = { 0x4c, 0xcb, 0x1e, 0x7c, 0xa9, 0x81, 0xbe, 0xfa,
0xa0, 0x72, 0x6c, 0x55, 0xd3, 0x78, 0x06, 0x12,
0x98, 0xc8, 0x5c, 0x92, 0x81, 0x4a, 0xbc, 0x33,
0xc5, 0x2e, 0xe8, 0x1d, 0x7d, 0x77, 0xc0, 0x8a },
.ilen = 32,
.result = { 0x90, 0x20, 0xea, 0x6f, 0x91, 0xbd, 0xd8, 0x5a,
0xfa, 0x00, 0x39, 0xba, 0x4b, 0xaf, 0xf9, 0xbf,
0xb7, 0x9c, 0x70, 0x28, 0x94, 0x9c, 0xd0, 0xec },
.rlen = 24,
}, {
.key = { 0xd7, 0x82, 0x8d, 0x13, 0xb2, 0xb0, 0xbd, 0xc3,
0x25, 0xa7, 0x62, 0x36, 0xdf, 0x93, 0xcc, 0x6b },
.klen = 16,
.iv = { 0x01, 0x00, 0xd5, 0x60, 0x91, 0x2d, 0x3f, 0x70,
0x3c, 0x96, 0x96, 0x76, 0x6c, 0xfa, 0x00, 0x00 },
.assoc = { 0xcd, 0x90, 0x44, 0xd2, 0xb7, 0x1f, 0xdb, 0x81,
0x20, 0xea, 0x60, 0xc0 },
.alen = 12,
.input = { 0x00, 0x97, 0x69, 0xec, 0xab, 0xdf, 0x48, 0x62,
0x55, 0x94, 0xc5, 0x92, 0x51, 0xe6, 0x03, 0x57,
0x22, 0x67, 0x5e, 0x04, 0xc8, 0x47, 0x09, 0x9e,
0x5a, 0xe0, 0x70, 0x45, 0x51 },
.ilen = 29,
.result = { 0x64, 0x35, 0xac, 0xba, 0xfb, 0x11, 0xa8, 0x2e,
0x2f, 0x07, 0x1d, 0x7c, 0xa4, 0xa5, 0xeb, 0xd9,
0x3a, 0x80, 0x3b, 0xa8, 0x7f },
.rlen = 21,
}, {
.key = { 0xd7, 0x82, 0x8d, 0x13, 0xb2, 0xb0, 0xbd, 0xc3,
0x25, 0xa7, 0x62, 0x36, 0xdf, 0x93, 0xcc, 0x6b },
.klen = 16,
.iv = { 0x01, 0x00, 0x42, 0xff, 0xf8, 0xf1, 0x95, 0x1c,
0x3c, 0x96, 0x96, 0x76, 0x6c, 0xfa, 0x00, 0x00 },
.assoc = { 0xd8, 0x5b, 0xc7, 0xe6, 0x9f, 0x94, 0x4f, 0xb8 },
.alen = 8,
.input = { 0xbc, 0x21, 0x8d, 0xaa, 0x94, 0x74, 0x27, 0xb6,
0xdb, 0x38, 0x6a, 0x99, 0xac, 0x1a, 0xef, 0x23,
0xad, 0xe0, 0xb5, 0x29, 0x39, 0xcb, 0x6a, 0x63,
0x7c, 0xf9, 0xbe, 0xc2, 0x40, 0x88, 0x97, 0xc6,
0xba },
.ilen = 33,
.result = { 0x8a, 0x19, 0xb9, 0x50, 0xbc, 0xf7, 0x1a, 0x01,
0x8e, 0x5e, 0x67, 0x01, 0xc9, 0x17, 0x87, 0x65,
0x98, 0x09, 0xd6, 0x7d, 0xbe, 0xdd, 0x18 },
.rlen = 23,
},
};
/* Cast5 test vectors from RFC 2144 */
#define CAST5_ENC_TEST_VECTORS 3
#define CAST5_DEC_TEST_VECTORS 3