Commit dd26a14c authored by James Morris's avatar James Morris

[CRYPTO]: Add MD4.

parent f8b20525
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
CONFIG_CRYPTO CONFIG_CRYPTO
This option provides the core Cryptographic API. This option provides the core Cryptographic API.
CONFIG_CRYPTO_MD4
MD4 message digest algorithm (RFC1320), including HMAC (RFC2104).
CONFIG_CRYPTO_MD5 CONFIG_CRYPTO_MD5
MD5 message digest algorithm (RFC1321), including HMAC (RFC2104, RFC2403). MD5 message digest algorithm (RFC1321), including HMAC (RFC2104, RFC2403).
......
...@@ -6,6 +6,7 @@ comment 'Cryptographic options' ...@@ -6,6 +6,7 @@ comment 'Cryptographic options'
bool 'Cryptographic API' CONFIG_CRYPTO bool 'Cryptographic API' CONFIG_CRYPTO
if [ "$CONFIG_CRYPTO" = "y" ]; then if [ "$CONFIG_CRYPTO" = "y" ]; then
tristate ' MD4 digest algorithm' CONFIG_CRYPTO_MD4
tristate ' MD5 digest algorithm' CONFIG_CRYPTO_MD5 tristate ' MD5 digest algorithm' CONFIG_CRYPTO_MD5
tristate ' SHA-1 digest algorithm' CONFIG_CRYPTO_SHA1 tristate ' SHA-1 digest algorithm' CONFIG_CRYPTO_SHA1
tristate ' DES and Triple DES EDE cipher algorithms' CONFIG_CRYPTO_DES tristate ' DES and Triple DES EDE cipher algorithms' CONFIG_CRYPTO_DES
......
...@@ -7,6 +7,7 @@ export-objs := api.o ...@@ -7,6 +7,7 @@ export-objs := api.o
obj-$(CONFIG_CRYPTO) += api.o cipher.o digest.o compress.o obj-$(CONFIG_CRYPTO) += api.o cipher.o digest.o compress.o
obj-$(CONFIG_KMOD) += autoload.o obj-$(CONFIG_KMOD) += autoload.o
obj-$(CONFIG_CRYPTO_MD4) += md4.o
obj-$(CONFIG_CRYPTO_MD5) += md5.o obj-$(CONFIG_CRYPTO_MD5) += md5.o
obj-$(CONFIG_CRYPTO_SHA1) += sha1.o obj-$(CONFIG_CRYPTO_SHA1) += sha1.o
obj-$(CONFIG_CRYPTO_DES) += des.o obj-$(CONFIG_CRYPTO_DES) += des.o
......
...@@ -25,10 +25,11 @@ static struct { ...@@ -25,10 +25,11 @@ static struct {
} alg_modmap[] = { } alg_modmap[] = {
{ CRYPTO_ALG_DES, "des" }, { CRYPTO_ALG_DES, "des" },
{ CRYPTO_ALG_DES3_EDE, "des" }, { CRYPTO_ALG_DES3_EDE, "des" },
{ CRYPTO_ALG_MD4, "md4" },
{ CRYPTO_ALG_MD5, "md5" }, { CRYPTO_ALG_MD5, "md5" },
{ CRYPTO_ALG_SHA1, "sha1" }, { CRYPTO_ALG_SHA1, "sha1" },
}; };
#define ALG_MAX_MODMAP 4 #define ALG_MAX_MODMAP 5
void crypto_alg_autoload(u32 algid) void crypto_alg_autoload(u32 algid)
{ {
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/crypto.h> #include <linux/crypto.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
#define MD5_DIGEST_SIZE 16 #define MD5_DIGEST_SIZE 16
...@@ -43,7 +42,7 @@ struct md5_ctx { ...@@ -43,7 +42,7 @@ struct md5_ctx {
static inline void md5_transform(u32 *hash, u32 const *in) static inline void md5_transform(u32 *hash, u32 const *in)
{ {
register u32 a, b, c, d; u32 a, b, c, d;
a = hash[0]; a = hash[0];
b = hash[1]; b = hash[1];
......
...@@ -174,6 +174,51 @@ static void test_md5(void) ...@@ -174,6 +174,51 @@ static void test_md5(void)
crypto_free_tfm(tfm); 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) static void test_sha1(void)
{ {
char *p; char *p;
...@@ -239,7 +284,6 @@ static void test_sha1(void) ...@@ -239,7 +284,6 @@ static void test_sha1(void)
memset(result, 0, sizeof(result)); memset(result, 0, sizeof(result));
crypto_digest_digest(tfm, sg, 2, result); crypto_digest_digest(tfm, sg, 2, result);
hexdump(result, crypto_tfm_digestsize(tfm)); hexdump(result, crypto_tfm_digestsize(tfm));
printk("%s\n", memcmp(result, sha1_tv[1].digest, crypto_tfm_digestsize(tfm)) ? "fail" : "pass"); printk("%s\n", memcmp(result, sha1_tv[1].digest, crypto_tfm_digestsize(tfm)) ? "fail" : "pass");
printk("\ntesting hmac_sha1\n"); printk("\ntesting hmac_sha1\n");
...@@ -1213,6 +1257,7 @@ static void do_test(void) ...@@ -1213,6 +1257,7 @@ static void do_test(void)
test_sha1(); test_sha1();
test_des(); test_des();
test_des3_ede(); test_des3_ede();
test_md4();
break; break;
case 1: case 1:
...@@ -1231,6 +1276,10 @@ static void do_test(void) ...@@ -1231,6 +1276,10 @@ static void do_test(void)
test_des3_ede(); test_des3_ede();
break; break;
case 5:
test_md4();
break;
default: default:
/* useful for debugging */ /* useful for debugging */
printk("not testing anything\n"); printk("not testing anything\n");
......
...@@ -17,8 +17,54 @@ ...@@ -17,8 +17,54 @@
#define _CRYPTO_TCRYPT_H #define _CRYPTO_TCRYPT_H
#define MD5_DIGEST_SIZE 16 #define MD5_DIGEST_SIZE 16
#define MD4_DIGEST_SIZE 16
#define SHA1_DIGEST_SIZE 20 #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 * MD5 test vectors from RFC1321
*/ */
......
...@@ -56,8 +56,9 @@ ...@@ -56,8 +56,9 @@
#define CRYPTO_ALG_DES3_EDE_ECB (CRYPTO_ALG_DES3_EDE|CRYPTO_MODE_ECB) #define CRYPTO_ALG_DES3_EDE_ECB (CRYPTO_ALG_DES3_EDE|CRYPTO_MODE_ECB)
#define CRYPTO_ALG_DES3_EDE_CBC (CRYPTO_ALG_DES3_EDE|CRYPTO_MODE_CBC) #define CRYPTO_ALG_DES3_EDE_CBC (CRYPTO_ALG_DES3_EDE|CRYPTO_MODE_CBC)
#define CRYPTO_ALG_MD5 (0x00000f00|CRYPTO_TYPE_DIGEST) #define CRYPTO_ALG_MD4 (0x00000f00|CRYPTO_TYPE_DIGEST)
#define CRYPTO_ALG_SHA1 (0x00000f01|CRYPTO_TYPE_DIGEST) #define CRYPTO_ALG_MD5 (0x00000f01|CRYPTO_TYPE_DIGEST)
#define CRYPTO_ALG_SHA1 (0x00000f02|CRYPTO_TYPE_DIGEST)
#define CRYPTO_UNSPEC 0 #define CRYPTO_UNSPEC 0
#define CRYPTO_MAX_ALG_NAME 64 #define CRYPTO_MAX_ALG_NAME 64
......
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