aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
Diffstat (limited to 'crypto')
-rw-r--r--crypto/Kconfig2
-rw-r--r--crypto/md4.c52
2 files changed, 30 insertions, 24 deletions
diff --git a/crypto/Kconfig b/crypto/Kconfig
index 5386beb503e3..96f8154147a2 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -276,7 +276,7 @@ config CRYPTO_CRC32C_INTEL
276 276
277config CRYPTO_MD4 277config CRYPTO_MD4
278 tristate "MD4 digest algorithm" 278 tristate "MD4 digest algorithm"
279 select CRYPTO_ALGAPI 279 select CRYPTO_HASH
280 help 280 help
281 MD4 message digest algorithm (RFC1320). 281 MD4 message digest algorithm (RFC1320).
282 282
diff --git a/crypto/md4.c b/crypto/md4.c
index a143c4aaa398..7fca1f59a4f5 100644
--- a/crypto/md4.c
+++ b/crypto/md4.c
@@ -20,8 +20,8 @@
20 * (at your option) any later version. 20 * (at your option) any later version.
21 * 21 *
22 */ 22 */
23#include <crypto/internal/hash.h>
23#include <linux/init.h> 24#include <linux/init.h>
24#include <linux/crypto.h>
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/string.h> 26#include <linux/string.h>
27#include <linux/types.h> 27#include <linux/types.h>
@@ -58,7 +58,7 @@ static inline u32 H(u32 x, u32 y, u32 z)
58{ 58{
59 return x ^ y ^ z; 59 return x ^ y ^ z;
60} 60}
61 61
62#define ROUND1(a,b,c,d,k,s) (a = lshift(a + F(b,c,d) + k, s)) 62#define ROUND1(a,b,c,d,k,s) (a = lshift(a + F(b,c,d) + k, s))
63#define ROUND2(a,b,c,d,k,s) (a = lshift(a + G(b,c,d) + k + (u32)0x5A827999,s)) 63#define ROUND2(a,b,c,d,k,s) (a = lshift(a + G(b,c,d) + k + (u32)0x5A827999,s))
64#define ROUND3(a,b,c,d,k,s) (a = lshift(a + H(b,c,d) + k + (u32)0x6ED9EBA1,s)) 64#define ROUND3(a,b,c,d,k,s) (a = lshift(a + H(b,c,d) + k + (u32)0x6ED9EBA1,s))
@@ -152,20 +152,22 @@ static inline void md4_transform_helper(struct md4_ctx *ctx)
152 md4_transform(ctx->hash, ctx->block); 152 md4_transform(ctx->hash, ctx->block);
153} 153}
154 154
155static void md4_init(struct crypto_tfm *tfm) 155static int md4_init(struct shash_desc *desc)
156{ 156{
157 struct md4_ctx *mctx = crypto_tfm_ctx(tfm); 157 struct md4_ctx *mctx = shash_desc_ctx(desc);
158 158
159 mctx->hash[0] = 0x67452301; 159 mctx->hash[0] = 0x67452301;
160 mctx->hash[1] = 0xefcdab89; 160 mctx->hash[1] = 0xefcdab89;
161 mctx->hash[2] = 0x98badcfe; 161 mctx->hash[2] = 0x98badcfe;
162 mctx->hash[3] = 0x10325476; 162 mctx->hash[3] = 0x10325476;
163 mctx->byte_count = 0; 163 mctx->byte_count = 0;
164
165 return 0;
164} 166}
165 167
166static void md4_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len) 168static int md4_update(struct shash_desc *desc, const u8 *data, unsigned int len)
167{ 169{
168 struct md4_ctx *mctx = crypto_tfm_ctx(tfm); 170 struct md4_ctx *mctx = shash_desc_ctx(desc);
169 const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f); 171 const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f);
170 172
171 mctx->byte_count += len; 173 mctx->byte_count += len;
@@ -173,7 +175,7 @@ static void md4_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
173 if (avail > len) { 175 if (avail > len) {
174 memcpy((char *)mctx->block + (sizeof(mctx->block) - avail), 176 memcpy((char *)mctx->block + (sizeof(mctx->block) - avail),
175 data, len); 177 data, len);
176 return; 178 return 0;
177 } 179 }
178 180
179 memcpy((char *)mctx->block + (sizeof(mctx->block) - avail), 181 memcpy((char *)mctx->block + (sizeof(mctx->block) - avail),
@@ -191,11 +193,13 @@ static void md4_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
191 } 193 }
192 194
193 memcpy(mctx->block, data, len); 195 memcpy(mctx->block, data, len);
196
197 return 0;
194} 198}
195 199
196static void md4_final(struct crypto_tfm *tfm, u8 *out) 200static int md4_final(struct shash_desc *desc, u8 *out)
197{ 201{
198 struct md4_ctx *mctx = crypto_tfm_ctx(tfm); 202 struct md4_ctx *mctx = shash_desc_ctx(desc);
199 const unsigned int offset = mctx->byte_count & 0x3f; 203 const unsigned int offset = mctx->byte_count & 0x3f;
200 char *p = (char *)mctx->block + offset; 204 char *p = (char *)mctx->block + offset;
201 int padding = 56 - (offset + 1); 205 int padding = 56 - (offset + 1);
@@ -217,30 +221,32 @@ static void md4_final(struct crypto_tfm *tfm, u8 *out)
217 cpu_to_le32_array(mctx->hash, ARRAY_SIZE(mctx->hash)); 221 cpu_to_le32_array(mctx->hash, ARRAY_SIZE(mctx->hash));
218 memcpy(out, mctx->hash, sizeof(mctx->hash)); 222 memcpy(out, mctx->hash, sizeof(mctx->hash));
219 memset(mctx, 0, sizeof(*mctx)); 223 memset(mctx, 0, sizeof(*mctx));
224
225 return 0;
220} 226}
221 227
222static struct crypto_alg alg = { 228static struct shash_alg alg = {
223 .cra_name = "md4", 229 .digestsize = MD4_DIGEST_SIZE,
224 .cra_flags = CRYPTO_ALG_TYPE_DIGEST, 230 .init = md4_init,
225 .cra_blocksize = MD4_HMAC_BLOCK_SIZE, 231 .update = md4_update,
226 .cra_ctxsize = sizeof(struct md4_ctx), 232 .final = md4_final,
227 .cra_module = THIS_MODULE, 233 .descsize = sizeof(struct md4_ctx),
228 .cra_list = LIST_HEAD_INIT(alg.cra_list), 234 .base = {
229 .cra_u = { .digest = { 235 .cra_name = "md4",
230 .dia_digestsize = MD4_DIGEST_SIZE, 236 .cra_flags = CRYPTO_ALG_TYPE_SHASH,
231 .dia_init = md4_init, 237 .cra_blocksize = MD4_HMAC_BLOCK_SIZE,
232 .dia_update = md4_update, 238 .cra_module = THIS_MODULE,
233 .dia_final = md4_final } } 239 }
234}; 240};
235 241
236static int __init md4_mod_init(void) 242static int __init md4_mod_init(void)
237{ 243{
238 return crypto_register_alg(&alg); 244 return crypto_register_shash(&alg);
239} 245}
240 246
241static void __exit md4_mod_fini(void) 247static void __exit md4_mod_fini(void)
242{ 248{
243 crypto_unregister_alg(&alg); 249 crypto_unregister_shash(&alg);
244} 250}
245 251
246module_init(md4_mod_init); 252module_init(md4_mod_init);