Commit c63f5cf8 authored by Kartikey Mahendra Bhatt's avatar Kartikey Mahendra Bhatt Committed by Dave Jones

[CRYPTO]: Add cast5, integration by jmorris@intercode.com.au

parent 6e6c3a14
...@@ -186,7 +186,6 @@ Original developers of the crypto algorithms: ...@@ -186,7 +186,6 @@ Original developers of the crypto algorithms:
Dag Arne Osvik (Serpent) Dag Arne Osvik (Serpent)
Brian Gladman (AES) Brian Gladman (AES)
SHA1 algorithm contributors: SHA1 algorithm contributors:
Jean-Francois Dive Jean-Francois Dive
...@@ -214,6 +213,9 @@ AES algorithm contributors: ...@@ -214,6 +213,9 @@ AES algorithm contributors:
Kyle McMartin Kyle McMartin
Adam J. Richter Adam J. Richter
CAST5 algorithm contributors:
Kartikey Mahendra Bhatt (original developers unknown, FSF copyright).
Generic scatterwalk code by Adam J. Richter <adam@yggdrasil.com> Generic scatterwalk code by Adam J. Richter <adam@yggdrasil.com>
Please send any credits updates or corrections to: Please send any credits updates or corrections to:
......
...@@ -126,6 +126,13 @@ config CRYPTO_AES ...@@ -126,6 +126,13 @@ config CRYPTO_AES
See http://csrc.nist.gov/encryption/aes/ for more information. See http://csrc.nist.gov/encryption/aes/ for more information.
config CRYPTO_CAST5
tristate "CAST5 (CAST-128) cipher algorithm"
depends on CRYPTO
help
The CAST5 encryption algorithm (synonymous with CAST-128) is
described in RFC2144.
config CRYPTO_DEFLATE config CRYPTO_DEFLATE
tristate "Deflate compression algorithm" tristate "Deflate compression algorithm"
depends on CRYPTO depends on CRYPTO
......
...@@ -20,6 +20,7 @@ obj-$(CONFIG_CRYPTO_BLOWFISH) += blowfish.o ...@@ -20,6 +20,7 @@ obj-$(CONFIG_CRYPTO_BLOWFISH) += blowfish.o
obj-$(CONFIG_CRYPTO_TWOFISH) += twofish.o obj-$(CONFIG_CRYPTO_TWOFISH) += twofish.o
obj-$(CONFIG_CRYPTO_SERPENT) += serpent.o obj-$(CONFIG_CRYPTO_SERPENT) += serpent.o
obj-$(CONFIG_CRYPTO_AES) += aes.o obj-$(CONFIG_CRYPTO_AES) += aes.o
obj-$(CONFIG_CRYPTO_CAST5) += cast5.o
obj-$(CONFIG_CRYPTO_DEFLATE) += deflate.o obj-$(CONFIG_CRYPTO_DEFLATE) += deflate.o
obj-$(CONFIG_CRYPTO_TEST) += tcrypt.o obj-$(CONFIG_CRYPTO_TEST) += tcrypt.o
This diff is collapsed.
...@@ -2192,6 +2192,102 @@ test_aes(void) ...@@ -2192,6 +2192,102 @@ test_aes(void)
crypto_free_tfm(tfm); crypto_free_tfm(tfm);
} }
void
test_cast5(void)
{
unsigned int ret, i, tsize;
u8 *p, *q, *key;
struct crypto_tfm *tfm;
struct cast5_tv *c5_tv;
struct scatterlist sg[1];
printk("\ntesting cast5 encryption\n");
tfm = crypto_alloc_tfm("cast5", 0);
if (tfm == NULL) {
printk("failed to load transform for cast5 (default ecb)\n");
return;
}
tsize = sizeof (cast5_enc_tv_template);
if (tsize > TVMEMSIZE) {
printk("template (%u) too big for tvmem (%u)\n", tsize,
TVMEMSIZE);
return;
}
memcpy(tvmem, cast5_enc_tv_template, tsize);
c5_tv = (void *) tvmem;
for (i = 0; i < CAST5_ENC_TEST_VECTORS; i++) {
printk("test %u (%d bit key):\n", i + 1, c5_tv[i].keylen * 8);
key = c5_tv[i].key;
ret = crypto_cipher_setkey(tfm, key, c5_tv[i].keylen);
if (ret) {
printk("setkey() failed flags=%x\n", tfm->crt_flags);
if (!c5_tv[i].fail)
goto out;
}
p = c5_tv[i].plaintext;
sg[0].page = virt_to_page(p);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = sizeof(c5_tv[i].plaintext);
ret = crypto_cipher_encrypt(tfm, sg, sg, sg[0].length);
if (ret) {
printk("encrypt() failed flags=%x\n", tfm->crt_flags);
goto out;
}
q = kmap(sg[0].page) + sg[0].offset;
hexdump(q, sizeof(c5_tv[i].ciphertext));
printk("%s\n", memcmp(q, c5_tv[i].ciphertext,
sizeof(c5_tv[i].ciphertext)) ? "fail" : "pass");
}
tsize = sizeof (cast5_dec_tv_template);
if (tsize > TVMEMSIZE) {
printk("template (%u) too big for tvmem (%u)\n", tsize,
TVMEMSIZE);
return;
}
memcpy(tvmem, cast5_dec_tv_template, tsize);
c5_tv = (void *) tvmem;
for (i = 0; i < CAST5_DEC_TEST_VECTORS; i++) {
printk("test %u (%d bit key):\n", i + 1, c5_tv[i].keylen * 8);
key = c5_tv[i].key;
ret = crypto_cipher_setkey(tfm, key, c5_tv[i].keylen);
if (ret) {
printk("setkey() failed flags=%x\n", tfm->crt_flags);
if (!c5_tv[i].fail)
goto out;
}
p = c5_tv[i].plaintext;
sg[0].page = virt_to_page(p);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = sizeof(c5_tv[i].plaintext);
ret = crypto_cipher_decrypt(tfm, sg, sg, sg[0].length);
if (ret) {
printk("decrypt() failed flags=%x\n", tfm->crt_flags);
goto out;
}
q = kmap(sg[0].page) + sg[0].offset;
hexdump(q, sizeof(c5_tv[i].ciphertext));
printk("%s\n", memcmp(q, c5_tv[i].ciphertext,
sizeof(c5_tv[i].ciphertext)) ? "fail" : "pass");
}
out:
crypto_free_tfm (tfm);
}
static void static void
test_deflate(void) test_deflate(void)
{ {
...@@ -2304,6 +2400,7 @@ do_test(void) ...@@ -2304,6 +2400,7 @@ do_test(void)
test_sha384(); test_sha384();
test_sha512(); test_sha512();
test_deflate(); test_deflate();
test_cast5();
#ifdef CONFIG_CRYPTO_HMAC #ifdef CONFIG_CRYPTO_HMAC
test_hmac_md5(); test_hmac_md5();
test_hmac_sha1(); test_hmac_sha1();
...@@ -2363,6 +2460,10 @@ do_test(void) ...@@ -2363,6 +2460,10 @@ do_test(void)
test_deflate(); test_deflate();
break; break;
case 14:
test_cast5();
break;
#ifdef CONFIG_CRYPTO_HMAC #ifdef CONFIG_CRYPTO_HMAC
case 100: case 100:
test_hmac_md5(); test_hmac_md5();
......
...@@ -1682,6 +1682,74 @@ struct aes_tv aes_dec_tv_template[] = { ...@@ -1682,6 +1682,74 @@ struct aes_tv aes_dec_tv_template[] = {
}, },
}; };
/* Cast5 test vectors from RFC 2144 */
#define CAST5_ENC_TEST_VECTORS 3
#define CAST5_DEC_TEST_VECTORS 3
struct cast5_tv {
unsigned keylen;
unsigned fail;
u8 key[16];
u8 plaintext[8];
u8 ciphertext[8];
};
struct cast5_tv cast5_enc_tv_template[] =
{
{
16,
0,
{ 0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78,
0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9A },
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
{ 0x23, 0x8b, 0x4f, 0xe5, 0x84, 0x7e, 0x44, 0xb2 },
},
{
10,
0,
{ 0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78,
0x23, 0x45 },
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
{ 0xeb, 0x6a, 0x71, 0x1a, 0x2c, 0x02, 0x27, 0x1b },
},
{
5,
0,
{ 0x01, 0x23, 0x45, 0x67, 0x12 },
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
{ 0x7a, 0xc8, 0x16, 0xd1, 0x6e, 0x9b, 0x30, 0x2e },
}
};
struct cast5_tv cast5_dec_tv_template[] =
{
{
16,
0,
{ 0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78,
0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9A },
{ 0x23, 0x8b, 0x4f, 0xe5, 0x84, 0x7e, 0x44, 0xb2 },
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
},
{
10,
0,
{ 0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78,
0x23, 0x45 },
{ 0xeb, 0x6a, 0x71, 0x1a, 0x2c, 0x02, 0x27, 0x1b },
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
},
{
5,
0,
{ 0x01, 0x23, 0x45, 0x67, 0x12 },
{ 0x7a, 0xc8, 0x16, 0xd1, 0x6e, 0x9b, 0x30, 0x2e },
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
}
};
/* /*
* Compression stuff. * Compression stuff.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment