]> err.no Git - linux-2.6/commitdiff
[CRYPTO] camellia: added the testing code of Camellia cipher
authorNoriaki TAKAMIYA <takamiya@po.ntts.co.jp>
Wed, 24 Jan 2007 10:48:19 +0000 (21:48 +1100)
committerHerbert Xu <herbert@gondor.apana.org.au>
Tue, 6 Feb 2007 22:21:04 +0000 (09:21 +1100)
This patch adds the code of Camellia code for testing module.

Signed-off-by: Noriaki TAKAMIYA <takamiya@po.ntts.co.jp>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/tcrypt.c
crypto/tcrypt.h

index 8c8e2f95dc7ecfb89a21ab3ef663986ae840c94e..f5e9da319ece70cf6823a94947c3ee4f08273d89 100644 (file)
@@ -73,7 +73,7 @@ static char *check[] = {
        "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6",
        "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
        "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta",  "fcrypt",
-       NULL
+       "camellia", NULL
 };
 
 static void hexdump(unsigned char *buf, unsigned int len)
@@ -972,6 +972,20 @@ static void do_test(void)
                test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
                            FCRYPT_DEC_TEST_VECTORS);
 
+               //CAMELLIA
+               test_cipher("ecb(camellia)", ENCRYPT,
+                           camellia_enc_tv_template,
+                           CAMELLIA_ENC_TEST_VECTORS);
+               test_cipher("ecb(camellia)", DECRYPT,
+                           camellia_dec_tv_template,
+                           CAMELLIA_DEC_TEST_VECTORS);
+               test_cipher("cbc(camellia)", ENCRYPT,
+                           camellia_cbc_enc_tv_template,
+                           CAMELLIA_CBC_ENC_TEST_VECTORS);
+               test_cipher("cbc(camellia)", DECRYPT,
+                           camellia_cbc_dec_tv_template,
+                           CAMELLIA_CBC_DEC_TEST_VECTORS);
+
                test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
                test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
                test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
@@ -1196,6 +1210,21 @@ static void do_test(void)
                            FCRYPT_DEC_TEST_VECTORS);
                break;
 
+       case 32:
+               test_cipher("ecb(camellia)", ENCRYPT,
+                           camellia_enc_tv_template,
+                           CAMELLIA_ENC_TEST_VECTORS);
+               test_cipher("ecb(camellia)", DECRYPT,
+                           camellia_dec_tv_template,
+                           CAMELLIA_DEC_TEST_VECTORS);
+               test_cipher("cbc(camellia)", ENCRYPT,
+                           camellia_cbc_enc_tv_template,
+                           CAMELLIA_CBC_ENC_TEST_VECTORS);
+               test_cipher("cbc(camellia)", DECRYPT,
+                           camellia_cbc_dec_tv_template,
+                           CAMELLIA_CBC_DEC_TEST_VECTORS);
+               break;
+
        case 100:
                test_hash("hmac(md5)", hmac_md5_tv_template,
                          HMAC_MD5_TEST_VECTORS);
@@ -1289,6 +1318,17 @@ static void do_test(void)
                                  des_speed_template);
                break;
 
+       case 205:
+               test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
+                               camellia_speed_template);
+               test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
+                               camellia_speed_template);
+               test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
+                               camellia_speed_template);
+               test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
+                               camellia_speed_template);
+               break;
+
        case 300:
                /* fall through */
 
index ec77814d104e6253d9b388a2b0f71d84aadefc71..887527bd5bc6613260075f3bc9e3b850953ddcbf 100644 (file)
@@ -3687,6 +3687,150 @@ static struct cipher_testvec fcrypt_pcbc_dec_tv_template[] = {
        }
 };
 
+/*
+ * CAMELLIA test vectors.
+ */
+#define CAMELLIA_ENC_TEST_VECTORS 3
+#define CAMELLIA_DEC_TEST_VECTORS 3
+#define CAMELLIA_CBC_ENC_TEST_VECTORS 2
+#define CAMELLIA_CBC_DEC_TEST_VECTORS 2
+
+static struct cipher_testvec camellia_enc_tv_template[] = {
+       {
+               .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
+                           0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
+               .klen   = 16,
+               .input  = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
+                           0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
+               .ilen   = 16,
+               .result = { 0x67, 0x67, 0x31, 0x38, 0x54, 0x96, 0x69, 0x73,
+                           0x08, 0x57, 0x06, 0x56, 0x48, 0xea, 0xbe, 0x43 },
+               .rlen   = 16,
+       }, {
+               .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
+                           0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
+                           0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 },
+               .klen   = 24,
+               .input  = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
+                           0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
+               .ilen   = 16,
+               .result = { 0xb4, 0x99, 0x34, 0x01, 0xb3, 0xe9, 0x96, 0xf8,
+                           0x4e, 0xe5, 0xce, 0xe7, 0xd7, 0x9b, 0x09, 0xb9 },
+               .rlen   = 16,
+       }, {
+               .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
+                           0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
+                           0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+                           0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff },
+               .klen   = 32,
+               .input  = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
+                           0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
+               .ilen   = 16,
+               .result = { 0x9a, 0xcc, 0x23, 0x7d, 0xff, 0x16, 0xd7, 0x6c,
+                           0x20, 0xef, 0x7c, 0x91, 0x9e, 0x3a, 0x75, 0x09 },
+               .rlen   = 16,
+       },
+};
+
+static struct cipher_testvec camellia_dec_tv_template[] = {
+       {
+               .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
+                           0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
+               .klen   = 16,
+               .input  = { 0x67, 0x67, 0x31, 0x38, 0x54, 0x96, 0x69, 0x73,
+                           0x08, 0x57, 0x06, 0x56, 0x48, 0xea, 0xbe, 0x43 },
+               .ilen   = 16,
+               .result = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
+                           0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
+               .rlen   = 16,
+       }, {
+               .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
+                           0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
+                           0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 },
+               .klen   = 24,
+               .input  = { 0xb4, 0x99, 0x34, 0x01, 0xb3, 0xe9, 0x96, 0xf8,
+                           0x4e, 0xe5, 0xce, 0xe7, 0xd7, 0x9b, 0x09, 0xb9 },
+               .ilen   = 16,
+               .result = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
+                           0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
+               .rlen   = 16,
+       }, {
+               .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
+                           0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
+                           0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+                           0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff },
+               .klen   = 32,
+               .input  = { 0x9a, 0xcc, 0x23, 0x7d, 0xff, 0x16, 0xd7, 0x6c,
+                           0x20, 0xef, 0x7c, 0x91, 0x9e, 0x3a, 0x75, 0x09 },
+               .ilen   = 16,
+               .result = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
+                           0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
+               .rlen   = 16,
+       },
+};
+
+static struct cipher_testvec camellia_cbc_enc_tv_template[] = {
+       {
+               .key    = { 0x06, 0xa9, 0x21, 0x40, 0x36, 0xb8, 0xa1, 0x5b,
+                           0x51, 0x2e, 0x03, 0xd5, 0x34, 0x12, 0x00, 0x06 },
+               .klen   = 16,
+               .iv     = { 0x3d, 0xaf, 0xba, 0x42, 0x9d, 0x9e, 0xb4, 0x30,
+                           0xb4, 0x22, 0xda, 0x80, 0x2c, 0x9f, 0xac, 0x41 },
+               .input  = { "Single block msg" },
+               .ilen   = 16,
+               .result = { 0xea, 0x32, 0x12, 0x76, 0x3b, 0x50, 0x10, 0xe7,
+                           0x18, 0xf6, 0xfd, 0x5d, 0xf6, 0x8f, 0x13, 0x51 },
+               .rlen   = 16,
+       }, {
+               .key    = { 0xc2, 0x86, 0x69, 0x6d, 0x88, 0x7c, 0x9a, 0xa0,
+                           0x61, 0x1b, 0xbb, 0x3e, 0x20, 0x25, 0xa4, 0x5a },
+               .klen   = 16,
+               .iv     = { 0x56, 0x2e, 0x17, 0x99, 0x6d, 0x09, 0x3d, 0x28,
+                           0xdd, 0xb3, 0xba, 0x69, 0x5a, 0x2e, 0x6f, 0x58 },
+               .input  = { 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 },
+               .ilen   = 32,
+               .result = { 0xa5, 0xdf, 0x6e, 0x50, 0xda, 0x70, 0x6c, 0x01,
+                           0x4a, 0xab, 0xf3, 0xf2, 0xd6, 0xfc, 0x6c, 0xfd,
+                           0x19, 0xb4, 0x3e, 0x57, 0x1c, 0x02, 0x5e, 0xa0,
+                           0x15, 0x78, 0xe0, 0x5e, 0xf2, 0xcb, 0x87, 0x16 },
+               .rlen   = 32,
+       },
+};
+
+static struct cipher_testvec camellia_cbc_dec_tv_template[] = {
+       {
+               .key    = { 0x06, 0xa9, 0x21, 0x40, 0x36, 0xb8, 0xa1, 0x5b,
+                           0x51, 0x2e, 0x03, 0xd5, 0x34, 0x12, 0x00, 0x06 },
+               .klen   = 16,
+               .iv     = { 0x3d, 0xaf, 0xba, 0x42, 0x9d, 0x9e, 0xb4, 0x30,
+                           0xb4, 0x22, 0xda, 0x80, 0x2c, 0x9f, 0xac, 0x41 },
+               .input  = { 0xea, 0x32, 0x12, 0x76, 0x3b, 0x50, 0x10, 0xe7,
+                           0x18, 0xf6, 0xfd, 0x5d, 0xf6, 0x8f, 0x13, 0x51 },
+               .ilen   = 16,
+               .result = { "Single block msg" },
+               .rlen   = 16,
+       }, {
+               .key    = { 0xc2, 0x86, 0x69, 0x6d, 0x88, 0x7c, 0x9a, 0xa0,
+                           0x61, 0x1b, 0xbb, 0x3e, 0x20, 0x25, 0xa4, 0x5a },
+               .klen   = 16,
+               .iv     = { 0x56, 0x2e, 0x17, 0x99, 0x6d, 0x09, 0x3d, 0x28,
+                           0xdd, 0xb3, 0xba, 0x69, 0x5a, 0x2e, 0x6f, 0x58 },
+               .input = { 0xa5, 0xdf, 0x6e, 0x50, 0xda, 0x70, 0x6c, 0x01,
+                           0x4a, 0xab, 0xf3, 0xf2, 0xd6, 0xfc, 0x6c, 0xfd,
+                           0x19, 0xb4, 0x3e, 0x57, 0x1c, 0x02, 0x5e, 0xa0,
+                           0x15, 0x78, 0xe0, 0x5e, 0xf2, 0xcb, 0x87, 0x16 },
+               .ilen   = 32,
+               .result = { 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 },
+               .rlen   = 32,
+       },
+};
+
 /*
  * Compression stuff.
  */
@@ -4140,4 +4284,25 @@ static struct hash_speed generic_hash_speed_template[] = {
        {  .blen = 0,   .plen = 0, }
 };
 
+static struct cipher_speed camellia_speed_template[] = {
+      { .klen = 16, .blen = 16, },
+      { .klen = 16, .blen = 64, },
+      { .klen = 16, .blen = 256, },
+      { .klen = 16, .blen = 1024, },
+      { .klen = 16, .blen = 8192, },
+      { .klen = 24, .blen = 16, },
+      { .klen = 24, .blen = 64, },
+      { .klen = 24, .blen = 256, },
+      { .klen = 24, .blen = 1024, },
+      { .klen = 24, .blen = 8192, },
+      { .klen = 32, .blen = 16, },
+      { .klen = 32, .blen = 64, },
+      { .klen = 32, .blen = 256, },
+      { .klen = 32, .blen = 1024, },
+      { .klen = 32, .blen = 8192, },
+
+      /* End marker */
+      {  .klen = 0, .blen = 0, }
+};
+
 #endif /* _CRYPTO_TCRYPT_H */