diff options
author | James Morris <jmorris@intercode.com.au> | 2002-10-26 11:41:27 -0800 |
---|---|---|
committer | James Morris <jmorris@intercode.com.au> | 2002-10-26 11:41:27 -0800 |
commit | dd26a14cffaec35475ec730c49a5dd5e059bcfb3 (patch) | |
tree | 5d4cfd1e2d26216e59062f7492df07aaff119082 /crypto | |
parent | f8b20525502360b9c37c901a49b08a45465ae648 (diff) | |
download | history-dd26a14cffaec35475ec730c49a5dd5e059bcfb3.tar.gz |
[CRYPTO]: Add MD4.
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/Config.help | 3 | ||||
-rw-r--r-- | crypto/Config.in | 1 | ||||
-rw-r--r-- | crypto/Makefile | 1 | ||||
-rw-r--r-- | crypto/autoload.c | 3 | ||||
-rw-r--r-- | crypto/md5.c | 3 | ||||
-rw-r--r-- | crypto/tcrypt.c | 51 | ||||
-rw-r--r-- | crypto/tcrypt.h | 46 |
7 files changed, 104 insertions, 4 deletions
diff --git a/crypto/Config.help b/crypto/Config.help index e45cd9f9420aa6..50351bcad97751 100644 --- a/crypto/Config.help +++ b/crypto/Config.help @@ -3,6 +3,9 @@ # CONFIG_CRYPTO This option provides the core Cryptographic API. + +CONFIG_CRYPTO_MD4 + MD4 message digest algorithm (RFC1320), including HMAC (RFC2104). CONFIG_CRYPTO_MD5 MD5 message digest algorithm (RFC1321), including HMAC (RFC2104, RFC2403). diff --git a/crypto/Config.in b/crypto/Config.in index f7d96f6dc96484..63b7bc27b4a569 100644 --- a/crypto/Config.in +++ b/crypto/Config.in @@ -6,6 +6,7 @@ comment 'Cryptographic options' bool 'Cryptographic API' CONFIG_CRYPTO if [ "$CONFIG_CRYPTO" = "y" ]; then + tristate ' MD4 digest algorithm' CONFIG_CRYPTO_MD4 tristate ' MD5 digest algorithm' CONFIG_CRYPTO_MD5 tristate ' SHA-1 digest algorithm' CONFIG_CRYPTO_SHA1 tristate ' DES and Triple DES EDE cipher algorithms' CONFIG_CRYPTO_DES diff --git a/crypto/Makefile b/crypto/Makefile index 262cff47dd3977..a9eb930fcbd33e 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -7,6 +7,7 @@ export-objs := api.o obj-$(CONFIG_CRYPTO) += api.o cipher.o digest.o compress.o obj-$(CONFIG_KMOD) += autoload.o +obj-$(CONFIG_CRYPTO_MD4) += md4.o obj-$(CONFIG_CRYPTO_MD5) += md5.o obj-$(CONFIG_CRYPTO_SHA1) += sha1.o obj-$(CONFIG_CRYPTO_DES) += des.o diff --git a/crypto/autoload.c b/crypto/autoload.c index bc263cd4e22c7e..0b9b12a2b788f8 100644 --- a/crypto/autoload.c +++ b/crypto/autoload.c @@ -25,10 +25,11 @@ static struct { } alg_modmap[] = { { CRYPTO_ALG_DES, "des" }, { CRYPTO_ALG_DES3_EDE, "des" }, + { CRYPTO_ALG_MD4, "md4" }, { CRYPTO_ALG_MD5, "md5" }, { CRYPTO_ALG_SHA1, "sha1" }, }; -#define ALG_MAX_MODMAP 4 +#define ALG_MAX_MODMAP 5 void crypto_alg_autoload(u32 algid) { diff --git a/crypto/md5.c b/crypto/md5.c index 5587608a709bc9..a30b687b7dd7e4 100644 --- a/crypto/md5.c +++ b/crypto/md5.c @@ -19,7 +19,6 @@ #include <linux/module.h> #include <linux/string.h> #include <linux/crypto.h> - #include <asm/byteorder.h> #define MD5_DIGEST_SIZE 16 @@ -43,7 +42,7 @@ struct md5_ctx { static inline void md5_transform(u32 *hash, u32 const *in) { - register u32 a, b, c, d; + u32 a, b, c, d; a = hash[0]; b = hash[1]; diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index 9a470b0b5b66c3..ae10c643a31ff6 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c @@ -174,6 +174,51 @@ static void test_md5(void) crypto_free_tfm(tfm); } +static void test_md4(void) +{ + char *p; + int i; + struct scatterlist sg[1]; + char result[128]; + struct crypto_tfm *tfm; + struct md4_testvec *md4_tv; + size_t tsize; + + printk("\ntesting md4\n"); + + tsize = sizeof(md4_tv_template); + if (tsize > TVMEMSIZE) { + printk("template (%Zd) too big for tvmem (%d)\n", tsize, TVMEMSIZE); + return; + } + + memcpy(tvmem, md4_tv_template, tsize); + md4_tv = (void *)tvmem; + + tfm = crypto_alloc_tfm(CRYPTO_ALG_MD4); + if (tfm == NULL) { + printk("failed to load transform for CRYPTO_ALG_MD4\n"); + return; + } + + for (i = 0; i < MD4_TEST_VECTORS; i++) { + printk("test %d:\n", i + 1); + memset(result, 0, sizeof(result)); + + p = md4_tv[i].plaintext; + sg[0].page = virt_to_page(p); + sg[0].offset = ((long)p & ~PAGE_MASK); + sg[0].length = strlen(md4_tv[i].plaintext); + + crypto_digest_digest(tfm, sg, 1, result); + + hexdump(result, crypto_tfm_digestsize(tfm)); + printk("%s\n", memcmp(result, md4_tv[i].digest, crypto_tfm_digestsize(tfm)) ? "fail" : "pass"); + } + + crypto_free_tfm(tfm); +} + static void test_sha1(void) { char *p; @@ -239,7 +284,6 @@ static void test_sha1(void) memset(result, 0, sizeof(result)); crypto_digest_digest(tfm, sg, 2, result); hexdump(result, crypto_tfm_digestsize(tfm)); - printk("%s\n", memcmp(result, sha1_tv[1].digest, crypto_tfm_digestsize(tfm)) ? "fail" : "pass"); printk("\ntesting hmac_sha1\n"); @@ -1213,6 +1257,7 @@ static void do_test(void) test_sha1(); test_des(); test_des3_ede(); + test_md4(); break; case 1: @@ -1230,6 +1275,10 @@ static void do_test(void) case 4: test_des3_ede(); break; + + case 5: + test_md4(); + break; default: /* useful for debugging */ diff --git a/crypto/tcrypt.h b/crypto/tcrypt.h index dbdc542b9cbb9c..acc6b0b45d7634 100644 --- a/crypto/tcrypt.h +++ b/crypto/tcrypt.h @@ -17,9 +17,55 @@ #define _CRYPTO_TCRYPT_H #define MD5_DIGEST_SIZE 16 +#define MD4_DIGEST_SIZE 16 #define SHA1_DIGEST_SIZE 20 /* + * MD4 test vectors from RFC1320 + */ +#define MD4_TEST_VECTORS 7 + +struct md4_testvec { + char plaintext[128]; + char digest[MD4_DIGEST_SIZE]; +} md4_tv_template[] = { + { "", + { 0x31, 0xd6, 0xcf, 0xe0, 0xd1, 0x6a, 0xe9, 0x31, + 0xb7, 0x3c, 0x59, 0xd7, 0xe0, 0xc0, 0x89, 0xc0 } + }, + + { "a", + { 0xbd, 0xe5, 0x2c, 0xb3, 0x1d, 0xe3, 0x3e, 0x46, + 0x24, 0x5e, 0x05, 0xfb, 0xdb, 0xd6, 0xfb, 0x24 } + }, + + { "abc", + { 0xa4, 0x48, 0x01, 0x7a, 0xaf, 0x21, 0xd8, 0x52, + 0x5f, 0xc1, 0x0a, 0xe8, 0x7a, 0xa6, 0x72, 0x9d } + }, + + { "message digest", + { 0xd9, 0x13, 0x0a, 0x81, 0x64, 0x54, 0x9f, 0xe8, + 0x18, 0x87, 0x48, 0x06, 0xe1, 0xc7, 0x01, 0x4b } + }, + + { "abcdefghijklmnopqrstuvwxyz", + { 0xd7, 0x9e, 0x1c, 0x30, 0x8a, 0xa5, 0xbb, 0xcd, + 0xee, 0xa8, 0xed, 0x63, 0xdf, 0x41, 0x2d, 0xa9 } + }, + + { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", + { 0x04, 0x3f, 0x85, 0x82, 0xf2, 0x41, 0xdb, 0x35, + 0x1c, 0xe6, 0x27, 0xe1, 0x53, 0xe7, 0xf0, 0xe4 } + }, + + { "12345678901234567890123456789012345678901234567890123456789012345678901234567890", + { 0xe3, 0x3b, 0x4d, 0xdc, 0x9c, 0x38, 0xf2, 0x19, + 0x9c, 0x3e, 0x7b, 0x16, 0x4f, 0xcc, 0x05, 0x36 } + }, +}; + +/* * MD5 test vectors from RFC1321 */ #define MD5_TEST_VECTORS 7 |