diff options
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/Kconfig | 2 | ||||
-rw-r--r-- | crypto/digest.c | 3 | ||||
-rw-r--r-- | crypto/hmac.c | 101 | ||||
-rw-r--r-- | crypto/internal.h | 13 |
4 files changed, 2 insertions, 117 deletions
diff --git a/crypto/Kconfig b/crypto/Kconfig index f07d9237950f..1e2f39c21180 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig | |||
@@ -33,7 +33,7 @@ config CRYPTO_MANAGER | |||
33 | cbc(aes). | 33 | cbc(aes). |
34 | 34 | ||
35 | config CRYPTO_HMAC | 35 | config CRYPTO_HMAC |
36 | bool "HMAC support" | 36 | tristate "HMAC support" |
37 | select CRYPTO_HASH | 37 | select CRYPTO_HASH |
38 | help | 38 | help |
39 | HMAC: Keyed-Hashing for Message Authentication (RFC2104). | 39 | HMAC: Keyed-Hashing for Message Authentication (RFC2104). |
diff --git a/crypto/digest.c b/crypto/digest.c index 5873063db840..0155a94e4b15 100644 --- a/crypto/digest.c +++ b/crypto/digest.c | |||
@@ -191,10 +191,9 @@ int crypto_init_digest_ops(struct crypto_tfm *tfm) | |||
191 | ops->setkey = dalg->dia_setkey ? setkey : nosetkey; | 191 | ops->setkey = dalg->dia_setkey ? setkey : nosetkey; |
192 | ops->digestsize = dalg->dia_digestsize; | 192 | ops->digestsize = dalg->dia_digestsize; |
193 | 193 | ||
194 | return crypto_alloc_hmac_block(tfm); | 194 | return 0; |
195 | } | 195 | } |
196 | 196 | ||
197 | void crypto_exit_digest_ops(struct crypto_tfm *tfm) | 197 | void crypto_exit_digest_ops(struct crypto_tfm *tfm) |
198 | { | 198 | { |
199 | crypto_free_hmac_block(tfm); | ||
200 | } | 199 | } |
diff --git a/crypto/hmac.c b/crypto/hmac.c index eac77e294740..f403b6946047 100644 --- a/crypto/hmac.c +++ b/crypto/hmac.c | |||
@@ -29,107 +29,6 @@ struct hmac_ctx { | |||
29 | struct crypto_hash *child; | 29 | struct crypto_hash *child; |
30 | }; | 30 | }; |
31 | 31 | ||
32 | static void hash_key(struct crypto_tfm *tfm, u8 *key, unsigned int keylen) | ||
33 | { | ||
34 | struct scatterlist tmp; | ||
35 | |||
36 | sg_set_buf(&tmp, key, keylen); | ||
37 | crypto_digest_digest(tfm, &tmp, 1, key); | ||
38 | } | ||
39 | |||
40 | int crypto_alloc_hmac_block(struct crypto_tfm *tfm) | ||
41 | { | ||
42 | int ret = 0; | ||
43 | |||
44 | BUG_ON(!crypto_tfm_alg_blocksize(tfm)); | ||
45 | |||
46 | tfm->crt_hash.hmac_block = kmalloc(crypto_tfm_alg_blocksize(tfm), | ||
47 | GFP_KERNEL); | ||
48 | if (tfm->crt_hash.hmac_block == NULL) | ||
49 | ret = -ENOMEM; | ||
50 | |||
51 | return ret; | ||
52 | |||
53 | } | ||
54 | |||
55 | void crypto_free_hmac_block(struct crypto_tfm *tfm) | ||
56 | { | ||
57 | kfree(tfm->crt_hash.hmac_block); | ||
58 | } | ||
59 | |||
60 | void crypto_hmac_init(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen) | ||
61 | { | ||
62 | unsigned int i; | ||
63 | struct scatterlist tmp; | ||
64 | char *ipad = tfm->crt_hash.hmac_block; | ||
65 | |||
66 | if (*keylen > crypto_tfm_alg_blocksize(tfm)) { | ||
67 | hash_key(tfm, key, *keylen); | ||
68 | *keylen = crypto_tfm_alg_digestsize(tfm); | ||
69 | } | ||
70 | |||
71 | memset(ipad, 0, crypto_tfm_alg_blocksize(tfm)); | ||
72 | memcpy(ipad, key, *keylen); | ||
73 | |||
74 | for (i = 0; i < crypto_tfm_alg_blocksize(tfm); i++) | ||
75 | ipad[i] ^= 0x36; | ||
76 | |||
77 | sg_set_buf(&tmp, ipad, crypto_tfm_alg_blocksize(tfm)); | ||
78 | |||
79 | crypto_digest_init(tfm); | ||
80 | crypto_digest_update(tfm, &tmp, 1); | ||
81 | } | ||
82 | |||
83 | void crypto_hmac_update(struct crypto_tfm *tfm, | ||
84 | struct scatterlist *sg, unsigned int nsg) | ||
85 | { | ||
86 | crypto_digest_update(tfm, sg, nsg); | ||
87 | } | ||
88 | |||
89 | void crypto_hmac_final(struct crypto_tfm *tfm, u8 *key, | ||
90 | unsigned int *keylen, u8 *out) | ||
91 | { | ||
92 | unsigned int i; | ||
93 | struct scatterlist tmp; | ||
94 | char *opad = tfm->crt_hash.hmac_block; | ||
95 | |||
96 | if (*keylen > crypto_tfm_alg_blocksize(tfm)) { | ||
97 | hash_key(tfm, key, *keylen); | ||
98 | *keylen = crypto_tfm_alg_digestsize(tfm); | ||
99 | } | ||
100 | |||
101 | crypto_digest_final(tfm, out); | ||
102 | |||
103 | memset(opad, 0, crypto_tfm_alg_blocksize(tfm)); | ||
104 | memcpy(opad, key, *keylen); | ||
105 | |||
106 | for (i = 0; i < crypto_tfm_alg_blocksize(tfm); i++) | ||
107 | opad[i] ^= 0x5c; | ||
108 | |||
109 | sg_set_buf(&tmp, opad, crypto_tfm_alg_blocksize(tfm)); | ||
110 | |||
111 | crypto_digest_init(tfm); | ||
112 | crypto_digest_update(tfm, &tmp, 1); | ||
113 | |||
114 | sg_set_buf(&tmp, out, crypto_tfm_alg_digestsize(tfm)); | ||
115 | |||
116 | crypto_digest_update(tfm, &tmp, 1); | ||
117 | crypto_digest_final(tfm, out); | ||
118 | } | ||
119 | |||
120 | void crypto_hmac(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen, | ||
121 | struct scatterlist *sg, unsigned int nsg, u8 *out) | ||
122 | { | ||
123 | crypto_hmac_init(tfm, key, keylen); | ||
124 | crypto_hmac_update(tfm, sg, nsg); | ||
125 | crypto_hmac_final(tfm, key, keylen, out); | ||
126 | } | ||
127 | |||
128 | EXPORT_SYMBOL_GPL(crypto_hmac_init); | ||
129 | EXPORT_SYMBOL_GPL(crypto_hmac_update); | ||
130 | EXPORT_SYMBOL_GPL(crypto_hmac_final); | ||
131 | EXPORT_SYMBOL_GPL(crypto_hmac); | ||
132 | |||
133 | static inline void *align_ptr(void *p, unsigned int align) | 32 | static inline void *align_ptr(void *p, unsigned int align) |
134 | { | 33 | { |
135 | return (void *)ALIGN((unsigned long)p, align); | 34 | return (void *)ALIGN((unsigned long)p, align); |
diff --git a/crypto/internal.h b/crypto/internal.h index 93d9b10ff914..2da6ad4f3593 100644 --- a/crypto/internal.h +++ b/crypto/internal.h | |||
@@ -73,19 +73,6 @@ static inline void crypto_yield(u32 flags) | |||
73 | cond_resched(); | 73 | cond_resched(); |
74 | } | 74 | } |
75 | 75 | ||
76 | #ifdef CONFIG_CRYPTO_HMAC | ||
77 | int crypto_alloc_hmac_block(struct crypto_tfm *tfm); | ||
78 | void crypto_free_hmac_block(struct crypto_tfm *tfm); | ||
79 | #else | ||
80 | static inline int crypto_alloc_hmac_block(struct crypto_tfm *tfm) | ||
81 | { | ||
82 | return 0; | ||
83 | } | ||
84 | |||
85 | static inline void crypto_free_hmac_block(struct crypto_tfm *tfm) | ||
86 | { } | ||
87 | #endif | ||
88 | |||
89 | #ifdef CONFIG_PROC_FS | 76 | #ifdef CONFIG_PROC_FS |
90 | void __init crypto_init_proc(void); | 77 | void __init crypto_init_proc(void); |
91 | void __exit crypto_exit_proc(void); | 78 | void __exit crypto_exit_proc(void); |