These patches add tests for AES-XCBC-MAC.
---
crypto/tcrypt.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
crypto/tcrypt.h | 80 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 181 insertions(+), 2 deletions(-)
03dfa73836c8802a91bfd84b1a019b02667a74ea
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index 49e344f..5594dba 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -253,6 +253,102 @@ out:
#endif /* CONFIG_CRYPTO_HMAC */
+#ifdef CONFIG_CRYPTO_XCBC
+
+static void
+test_xcbc(char *algo, struct xcbc_testvec * template, unsigned int tcount)
+{
+ char *p;
+ unsigned int i, j, k, temp;
+ struct scatterlist sg[8];
+ char result[64];
+ struct crypto_tfm *tfm;
+ struct xcbc_testvec *xcbc_tv;
+ unsigned int tsize, klen;
+ u_int32_t ks[12] = {0x01010101, 0x01010101, 0x01010101, 0x01010101,
+ 0x02020202, 0x02020202, 0x02020202, 0x02020202,
+ 0x03030303, 0x03030303, 0x03030303, 0x03030303};
+
+ tfm = crypto_alloc_tfm(algo, CRYPTO_TFM_MODE_CBC);
+ if (tfm == NULL) {
+ printk("failed to load transform for %s\n", algo);
+ return;
+ }
+
+ tfm->crt_cipher.cit_xcbc_const = (u8*)ks;
+
+ printk("\ntesting xcbc_%s\n", algo);
+
+ tsize = sizeof (struct xcbc_testvec);
+ tsize *= tcount;
+ if (tsize > TVMEMSIZE) {
+ printk("template (%u) too big for tvmem (%u)\n", tsize,
+ TVMEMSIZE);
+ goto out;
+ }
+
+ memcpy(tvmem, template, tsize);
+ xcbc_tv = (void *) tvmem;
+
+ for (i = 0; i < tcount; i++) {
+ printk("test %u:\n", i + 1);
+ memset(result, 0, sizeof (result));
+
+ p = xcbc_tv[i].plaintext;
+ klen = xcbc_tv[i].ksize;
+ sg[0].page = virt_to_page(p);
+ sg[0].offset = offset_in_page(p);
+ sg[0].length = xcbc_tv[i].psize;
+
+ crypto_xcbc(tfm, xcbc_tv[i].key, klen, sg, 1, result);
+
+ hexdump(result, crypto_tfm_alg_blocksize(tfm));
+ printk("%s\n",
+ memcmp(result, xcbc_tv[i].digest,
+ crypto_tfm_alg_blocksize(tfm)) ? "fail" :
+ "pass");
+ }
+
+ printk("\ntesting xcbc_%s across pages\n", algo);
+
+ memset(xbuf, 0, XBUFSIZE);
+
+ j = 0;
+ for (i = 0; i < tcount; i++) {
+ if (xcbc_tv[i].np) {
+ j++;
+ printk ("test %u:\n",j);
+ memset (result, 0, 64);
+
+ temp = 0;
+ klen = xcbc_tv[i].ksize;
+ for (k = 0; k < xcbc_tv[i].np; k++) {
+ memcpy (&xbuf[IDX[k]], xcbc_tv[i].plaintext +
temp,
+ xcbc_tv[i].tap[k]);
+ temp += xcbc_tv[i].tap[k];
+ p = &xbuf[IDX[k]];
+ sg[k].page = virt_to_page (p);
+ sg[k].offset = offset_in_page (p);
+ sg[k].length = xcbc_tv[i].tap[k];
+ }
+
+ crypto_xcbc(tfm, xcbc_tv[i].key, klen, sg,
xcbc_tv[i].np,
+ result);
+ hexdump(result, crypto_tfm_alg_blocksize(tfm));
+
+ printk("%s\n",
+ memcmp(result, xcbc_tv[i].digest,
+ crypto_tfm_alg_blocksize(tfm)) ? "fail"
:
+ "pass");
+ }
+ }
+out:
+ crypto_free_tfm(tfm);
+}
+
+#endif /* CONFIG_CRYPTO_XCBC */
+
+
static void test_cipher(char *algo, int mode, int enc,
struct cipher_testvec *template, unsigned int tcount)
{
@@ -857,11 +953,14 @@ static void do_test(void)
test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
test_hmac("sha1", hmac_sha1_tv_template,
HMAC_SHA1_TEST_VECTORS);
test_hmac("sha256", hmac_sha256_tv_template,
HMAC_SHA256_TEST_VECTORS);
+#endif
+#ifdef CONFIG_CRYPTO_XCBC
+ test_xcbc("aes", aes_xcbc_tv_template, XCBC_AES_TEST_VECTORS);
#endif
-
+#ifdef CONFIG_CRYPTO_MICHAEL_MIC
test_hash("michael_mic", michael_mic_tv_template,
MICHAEL_MIC_TEST_VECTORS);
+#endif
break;
-
case 1:
test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
break;
diff --git a/crypto/tcrypt.h b/crypto/tcrypt.h
index 733d07e..326fe41 100644
--- a/crypto/tcrypt.h
+++ b/crypto/tcrypt.h
@@ -45,6 +45,16 @@ struct hmac_testvec {
unsigned char tap[MAX_TAP];
};
+struct xcbc_testvec {
+ char key[128];
+ unsigned char ksize;
+ char plaintext[128];
+ unsigned char psize;
+ char digest[MAX_DIGEST_SIZE];
+ unsigned char np;
+ unsigned char tap[MAX_TAP];
+};
+
struct cipher_testvec {
unsigned char fail;
unsigned char wk; /* weak key flag */
@@ -940,6 +950,76 @@ static struct hmac_testvec hmac_sha256_t
#endif /* CONFIG_CRYPTO_HMAC */
+#define XCBC_AES_TEST_VECTORS 6
+
+#ifdef CONFIG_CRYPTO_XCBC
+static struct xcbc_testvec aes_xcbc_tv_template[] = {
+ {
+ .key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
+ .ksize = 16,
+ .plaintext = { [0 ... 127] = 0 },
+ .psize = 0,
+ .digest = { 0x75, 0xf0, 0x25, 0x1d, 0x52, 0x8a, 0xc0, 0x1c,
+ 0x45, 0x73, 0xdf, 0xd5, 0x84, 0xd7, 0x9f, 0x29 },
+ }, {
+ .key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
+ .ksize = 16,
+ .plaintext = { 0x00, 0x01, 0x02 },
+ .psize = 3,
+ .digest = { 0x5b, 0x37, 0x65, 0x80, 0xae, 0x2f, 0x19, 0xaf,
+ 0xe7, 0x21, 0x9c, 0xee, 0xf1, 0x72, 0x75, 0x6f },
+ } , {
+ .key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
+ .ksize = 16,
+ .plaintext = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
+ .psize = 16,
+ .digest = { 0xd2, 0xa2, 0x46, 0xfa, 0x34, 0x9b, 0x68, 0xa7,
+ 0x99, 0x98, 0xa4, 0x39, 0x4f, 0xf7, 0xa2, 0x63 },
+ }, {
+ .key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
+ .ksize = 16,
+ .plaintext = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13 },
+ .psize = 20,
+ .digest = { 0x47, 0xf5, 0x1b, 0x45, 0x64, 0x96, 0x62, 0x15,
+ 0xb8, 0x98, 0x5c, 0x63, 0x05, 0x5e, 0xd3, 0x08 },
+ .np = 2,
+ .tap = {10, 10},
+ }, {
+ .key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
+ .ksize = 16,
+ .plaintext = { 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 },
+ .psize = 32,
+ .digest = { 0xf5, 0x4f, 0x0e, 0xc8, 0xd2, 0xb9, 0xf3, 0xd3,
+ 0x68, 0x07, 0x73, 0x4b, 0xd5, 0x28, 0x3f, 0xd4 },
+ }, {
+ .key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
+ .ksize = 16,
+ .plaintext = { 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 },
+ .psize = 34,
+ .digest = { 0xbe, 0xcb, 0xb3, 0xbc, 0xcd, 0xb5, 0x18, 0xa3,
+ 0x06, 0x77, 0xd5, 0x48, 0x1f, 0xb6, 0xb4, 0xd8 },
+ .np = 2,
+ .tap = {17,17},
+ }
+};
+#endif
+
/*
* DES test vectors.
*/
--
Kazunori Miyazawa
Subject: [PATCH] add tests of xcbc
From: Kazunori MIYAZAWA <[EMAIL PROTECTED]>
Date: 1138249654 +0900
---
crypto/tcrypt.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
crypto/tcrypt.h | 80 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 181 insertions(+), 2 deletions(-)
03dfa73836c8802a91bfd84b1a019b02667a74ea
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index 49e344f..5594dba 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -253,6 +253,102 @@ out:
#endif /* CONFIG_CRYPTO_HMAC */
+#ifdef CONFIG_CRYPTO_XCBC
+
+static void
+test_xcbc(char *algo, struct xcbc_testvec * template, unsigned int tcount)
+{
+ char *p;
+ unsigned int i, j, k, temp;
+ struct scatterlist sg[8];
+ char result[64];
+ struct crypto_tfm *tfm;
+ struct xcbc_testvec *xcbc_tv;
+ unsigned int tsize, klen;
+ u_int32_t ks[12] = {0x01010101, 0x01010101, 0x01010101, 0x01010101,
+ 0x02020202, 0x02020202, 0x02020202, 0x02020202,
+ 0x03030303, 0x03030303, 0x03030303, 0x03030303};
+
+ tfm = crypto_alloc_tfm(algo, CRYPTO_TFM_MODE_CBC);
+ if (tfm == NULL) {
+ printk("failed to load transform for %s\n", algo);
+ return;
+ }
+
+ tfm->crt_cipher.cit_xcbc_const = (u8*)ks;
+
+ printk("\ntesting xcbc_%s\n", algo);
+
+ tsize = sizeof (struct xcbc_testvec);
+ tsize *= tcount;
+ if (tsize > TVMEMSIZE) {
+ printk("template (%u) too big for tvmem (%u)\n", tsize,
+ TVMEMSIZE);
+ goto out;
+ }
+
+ memcpy(tvmem, template, tsize);
+ xcbc_tv = (void *) tvmem;
+
+ for (i = 0; i < tcount; i++) {
+ printk("test %u:\n", i + 1);
+ memset(result, 0, sizeof (result));
+
+ p = xcbc_tv[i].plaintext;
+ klen = xcbc_tv[i].ksize;
+ sg[0].page = virt_to_page(p);
+ sg[0].offset = offset_in_page(p);
+ sg[0].length = xcbc_tv[i].psize;
+
+ crypto_xcbc(tfm, xcbc_tv[i].key, klen, sg, 1, result);
+
+ hexdump(result, crypto_tfm_alg_blocksize(tfm));
+ printk("%s\n",
+ memcmp(result, xcbc_tv[i].digest,
+ crypto_tfm_alg_blocksize(tfm)) ? "fail" :
+ "pass");
+ }
+
+ printk("\ntesting xcbc_%s across pages\n", algo);
+
+ memset(xbuf, 0, XBUFSIZE);
+
+ j = 0;
+ for (i = 0; i < tcount; i++) {
+ if (xcbc_tv[i].np) {
+ j++;
+ printk ("test %u:\n",j);
+ memset (result, 0, 64);
+
+ temp = 0;
+ klen = xcbc_tv[i].ksize;
+ for (k = 0; k < xcbc_tv[i].np; k++) {
+ memcpy (&xbuf[IDX[k]], xcbc_tv[i].plaintext +
temp,
+ xcbc_tv[i].tap[k]);
+ temp += xcbc_tv[i].tap[k];
+ p = &xbuf[IDX[k]];
+ sg[k].page = virt_to_page (p);
+ sg[k].offset = offset_in_page (p);
+ sg[k].length = xcbc_tv[i].tap[k];
+ }
+
+ crypto_xcbc(tfm, xcbc_tv[i].key, klen, sg,
xcbc_tv[i].np,
+ result);
+ hexdump(result, crypto_tfm_alg_blocksize(tfm));
+
+ printk("%s\n",
+ memcmp(result, xcbc_tv[i].digest,
+ crypto_tfm_alg_blocksize(tfm)) ? "fail"
:
+ "pass");
+ }
+ }
+out:
+ crypto_free_tfm(tfm);
+}
+
+#endif /* CONFIG_CRYPTO_XCBC */
+
+
static void test_cipher(char *algo, int mode, int enc,
struct cipher_testvec *template, unsigned int tcount)
{
@@ -857,11 +953,14 @@ static void do_test(void)
test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
test_hmac("sha1", hmac_sha1_tv_template,
HMAC_SHA1_TEST_VECTORS);
test_hmac("sha256", hmac_sha256_tv_template,
HMAC_SHA256_TEST_VECTORS);
+#endif
+#ifdef CONFIG_CRYPTO_XCBC
+ test_xcbc("aes", aes_xcbc_tv_template, XCBC_AES_TEST_VECTORS);
#endif
-
+#ifdef CONFIG_CRYPTO_MICHAEL_MIC
test_hash("michael_mic", michael_mic_tv_template,
MICHAEL_MIC_TEST_VECTORS);
+#endif
break;
-
case 1:
test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
break;
diff --git a/crypto/tcrypt.h b/crypto/tcrypt.h
index 733d07e..326fe41 100644
--- a/crypto/tcrypt.h
+++ b/crypto/tcrypt.h
@@ -45,6 +45,16 @@ struct hmac_testvec {
unsigned char tap[MAX_TAP];
};
+struct xcbc_testvec {
+ char key[128];
+ unsigned char ksize;
+ char plaintext[128];
+ unsigned char psize;
+ char digest[MAX_DIGEST_SIZE];
+ unsigned char np;
+ unsigned char tap[MAX_TAP];
+};
+
struct cipher_testvec {
unsigned char fail;
unsigned char wk; /* weak key flag */
@@ -940,6 +950,76 @@ static struct hmac_testvec hmac_sha256_t
#endif /* CONFIG_CRYPTO_HMAC */
+#define XCBC_AES_TEST_VECTORS 6
+
+#ifdef CONFIG_CRYPTO_XCBC
+static struct xcbc_testvec aes_xcbc_tv_template[] = {
+ {
+ .key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
+ .ksize = 16,
+ .plaintext = { [0 ... 127] = 0 },
+ .psize = 0,
+ .digest = { 0x75, 0xf0, 0x25, 0x1d, 0x52, 0x8a, 0xc0, 0x1c,
+ 0x45, 0x73, 0xdf, 0xd5, 0x84, 0xd7, 0x9f, 0x29 },
+ }, {
+ .key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
+ .ksize = 16,
+ .plaintext = { 0x00, 0x01, 0x02 },
+ .psize = 3,
+ .digest = { 0x5b, 0x37, 0x65, 0x80, 0xae, 0x2f, 0x19, 0xaf,
+ 0xe7, 0x21, 0x9c, 0xee, 0xf1, 0x72, 0x75, 0x6f },
+ } , {
+ .key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
+ .ksize = 16,
+ .plaintext = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
+ .psize = 16,
+ .digest = { 0xd2, 0xa2, 0x46, 0xfa, 0x34, 0x9b, 0x68, 0xa7,
+ 0x99, 0x98, 0xa4, 0x39, 0x4f, 0xf7, 0xa2, 0x63 },
+ }, {
+ .key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
+ .ksize = 16,
+ .plaintext = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13 },
+ .psize = 20,
+ .digest = { 0x47, 0xf5, 0x1b, 0x45, 0x64, 0x96, 0x62, 0x15,
+ 0xb8, 0x98, 0x5c, 0x63, 0x05, 0x5e, 0xd3, 0x08 },
+ .np = 2,
+ .tap = {10, 10},
+ }, {
+ .key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
+ .ksize = 16,
+ .plaintext = { 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 },
+ .psize = 32,
+ .digest = { 0xf5, 0x4f, 0x0e, 0xc8, 0xd2, 0xb9, 0xf3, 0xd3,
+ 0x68, 0x07, 0x73, 0x4b, 0xd5, 0x28, 0x3f, 0xd4 },
+ }, {
+ .key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
+ .ksize = 16,
+ .plaintext = { 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 },
+ .psize = 34,
+ .digest = { 0xbe, 0xcb, 0xb3, 0xbc, 0xcd, 0xb5, 0x18, 0xa3,
+ 0x06, 0x77, 0xd5, 0x48, 0x1f, 0xb6, 0xb4, 0xd8 },
+ .np = 2,
+ .tap = {17,17},
+ }
+};
+#endif
+
/*
* DES test vectors.
*/
--
1.1.3