1*e1644613SEric Biggers // SPDX-License-Identifier: GPL-2.0-or-later
2*e1644613SEric Biggers /*
3*e1644613SEric Biggers * MD5 and HMAC-MD5 library functions
4*e1644613SEric Biggers *
5*e1644613SEric Biggers * md5_block_generic() is derived from cryptoapi implementation, originally
6*e1644613SEric Biggers * based on the public domain implementation written by Colin Plumb in 1993.
7*e1644613SEric Biggers *
8*e1644613SEric Biggers * Copyright (c) Cryptoapi developers.
9*e1644613SEric Biggers * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
10*e1644613SEric Biggers * Copyright 2025 Google LLC
11*e1644613SEric Biggers */
12*e1644613SEric Biggers
13*e1644613SEric Biggers #include <crypto/hmac.h>
14*e1644613SEric Biggers #include <crypto/md5.h>
15*e1644613SEric Biggers #include <linux/export.h>
16*e1644613SEric Biggers #include <linux/kernel.h>
17*e1644613SEric Biggers #include <linux/module.h>
18*e1644613SEric Biggers #include <linux/string.h>
19*e1644613SEric Biggers #include <linux/unaligned.h>
20*e1644613SEric Biggers #include <linux/wordpart.h>
21*e1644613SEric Biggers
22*e1644613SEric Biggers static const struct md5_block_state md5_iv = {
23*e1644613SEric Biggers .h = { MD5_H0, MD5_H1, MD5_H2, MD5_H3 },
24*e1644613SEric Biggers };
25*e1644613SEric Biggers
26*e1644613SEric Biggers #define F1(x, y, z) (z ^ (x & (y ^ z)))
27*e1644613SEric Biggers #define F2(x, y, z) F1(z, x, y)
28*e1644613SEric Biggers #define F3(x, y, z) (x ^ y ^ z)
29*e1644613SEric Biggers #define F4(x, y, z) (y ^ (x | ~z))
30*e1644613SEric Biggers
31*e1644613SEric Biggers #define MD5STEP(f, w, x, y, z, in, s) \
32*e1644613SEric Biggers (w += f(x, y, z) + in, w = (w << s | w >> (32 - s)) + x)
33*e1644613SEric Biggers
md5_block_generic(struct md5_block_state * state,const u8 data[MD5_BLOCK_SIZE])34*e1644613SEric Biggers static void md5_block_generic(struct md5_block_state *state,
35*e1644613SEric Biggers const u8 data[MD5_BLOCK_SIZE])
36*e1644613SEric Biggers {
37*e1644613SEric Biggers u32 in[MD5_BLOCK_WORDS];
38*e1644613SEric Biggers u32 a, b, c, d;
39*e1644613SEric Biggers
40*e1644613SEric Biggers memcpy(in, data, MD5_BLOCK_SIZE);
41*e1644613SEric Biggers le32_to_cpu_array(in, ARRAY_SIZE(in));
42*e1644613SEric Biggers
43*e1644613SEric Biggers a = state->h[0];
44*e1644613SEric Biggers b = state->h[1];
45*e1644613SEric Biggers c = state->h[2];
46*e1644613SEric Biggers d = state->h[3];
47*e1644613SEric Biggers
48*e1644613SEric Biggers MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
49*e1644613SEric Biggers MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
50*e1644613SEric Biggers MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
51*e1644613SEric Biggers MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
52*e1644613SEric Biggers MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
53*e1644613SEric Biggers MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
54*e1644613SEric Biggers MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
55*e1644613SEric Biggers MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
56*e1644613SEric Biggers MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
57*e1644613SEric Biggers MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
58*e1644613SEric Biggers MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
59*e1644613SEric Biggers MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
60*e1644613SEric Biggers MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
61*e1644613SEric Biggers MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
62*e1644613SEric Biggers MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
63*e1644613SEric Biggers MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
64*e1644613SEric Biggers
65*e1644613SEric Biggers MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
66*e1644613SEric Biggers MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
67*e1644613SEric Biggers MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
68*e1644613SEric Biggers MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
69*e1644613SEric Biggers MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
70*e1644613SEric Biggers MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
71*e1644613SEric Biggers MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
72*e1644613SEric Biggers MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
73*e1644613SEric Biggers MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
74*e1644613SEric Biggers MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
75*e1644613SEric Biggers MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
76*e1644613SEric Biggers MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
77*e1644613SEric Biggers MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
78*e1644613SEric Biggers MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
79*e1644613SEric Biggers MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
80*e1644613SEric Biggers MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
81*e1644613SEric Biggers
82*e1644613SEric Biggers MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
83*e1644613SEric Biggers MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
84*e1644613SEric Biggers MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
85*e1644613SEric Biggers MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
86*e1644613SEric Biggers MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
87*e1644613SEric Biggers MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
88*e1644613SEric Biggers MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
89*e1644613SEric Biggers MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
90*e1644613SEric Biggers MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
91*e1644613SEric Biggers MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
92*e1644613SEric Biggers MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
93*e1644613SEric Biggers MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
94*e1644613SEric Biggers MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
95*e1644613SEric Biggers MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
96*e1644613SEric Biggers MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
97*e1644613SEric Biggers MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
98*e1644613SEric Biggers
99*e1644613SEric Biggers MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
100*e1644613SEric Biggers MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
101*e1644613SEric Biggers MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
102*e1644613SEric Biggers MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
103*e1644613SEric Biggers MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
104*e1644613SEric Biggers MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
105*e1644613SEric Biggers MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
106*e1644613SEric Biggers MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
107*e1644613SEric Biggers MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
108*e1644613SEric Biggers MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
109*e1644613SEric Biggers MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
110*e1644613SEric Biggers MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
111*e1644613SEric Biggers MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
112*e1644613SEric Biggers MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
113*e1644613SEric Biggers MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
114*e1644613SEric Biggers MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
115*e1644613SEric Biggers
116*e1644613SEric Biggers state->h[0] += a;
117*e1644613SEric Biggers state->h[1] += b;
118*e1644613SEric Biggers state->h[2] += c;
119*e1644613SEric Biggers state->h[3] += d;
120*e1644613SEric Biggers }
121*e1644613SEric Biggers
md5_blocks_generic(struct md5_block_state * state,const u8 * data,size_t nblocks)122*e1644613SEric Biggers static void __maybe_unused md5_blocks_generic(struct md5_block_state *state,
123*e1644613SEric Biggers const u8 *data, size_t nblocks)
124*e1644613SEric Biggers {
125*e1644613SEric Biggers do {
126*e1644613SEric Biggers md5_block_generic(state, data);
127*e1644613SEric Biggers data += MD5_BLOCK_SIZE;
128*e1644613SEric Biggers } while (--nblocks);
129*e1644613SEric Biggers }
130*e1644613SEric Biggers
131*e1644613SEric Biggers #ifdef CONFIG_CRYPTO_LIB_MD5_ARCH
132*e1644613SEric Biggers #include "md5.h" /* $(SRCARCH)/md5.h */
133*e1644613SEric Biggers #else
134*e1644613SEric Biggers #define md5_blocks md5_blocks_generic
135*e1644613SEric Biggers #endif
136*e1644613SEric Biggers
md5_init(struct md5_ctx * ctx)137*e1644613SEric Biggers void md5_init(struct md5_ctx *ctx)
138*e1644613SEric Biggers {
139*e1644613SEric Biggers ctx->state = md5_iv;
140*e1644613SEric Biggers ctx->bytecount = 0;
141*e1644613SEric Biggers }
142*e1644613SEric Biggers EXPORT_SYMBOL_GPL(md5_init);
143*e1644613SEric Biggers
md5_update(struct md5_ctx * ctx,const u8 * data,size_t len)144*e1644613SEric Biggers void md5_update(struct md5_ctx *ctx, const u8 *data, size_t len)
145*e1644613SEric Biggers {
146*e1644613SEric Biggers size_t partial = ctx->bytecount % MD5_BLOCK_SIZE;
147*e1644613SEric Biggers
148*e1644613SEric Biggers ctx->bytecount += len;
149*e1644613SEric Biggers
150*e1644613SEric Biggers if (partial + len >= MD5_BLOCK_SIZE) {
151*e1644613SEric Biggers size_t nblocks;
152*e1644613SEric Biggers
153*e1644613SEric Biggers if (partial) {
154*e1644613SEric Biggers size_t l = MD5_BLOCK_SIZE - partial;
155*e1644613SEric Biggers
156*e1644613SEric Biggers memcpy(&ctx->buf[partial], data, l);
157*e1644613SEric Biggers data += l;
158*e1644613SEric Biggers len -= l;
159*e1644613SEric Biggers
160*e1644613SEric Biggers md5_blocks(&ctx->state, ctx->buf, 1);
161*e1644613SEric Biggers }
162*e1644613SEric Biggers
163*e1644613SEric Biggers nblocks = len / MD5_BLOCK_SIZE;
164*e1644613SEric Biggers len %= MD5_BLOCK_SIZE;
165*e1644613SEric Biggers
166*e1644613SEric Biggers if (nblocks) {
167*e1644613SEric Biggers md5_blocks(&ctx->state, data, nblocks);
168*e1644613SEric Biggers data += nblocks * MD5_BLOCK_SIZE;
169*e1644613SEric Biggers }
170*e1644613SEric Biggers partial = 0;
171*e1644613SEric Biggers }
172*e1644613SEric Biggers if (len)
173*e1644613SEric Biggers memcpy(&ctx->buf[partial], data, len);
174*e1644613SEric Biggers }
175*e1644613SEric Biggers EXPORT_SYMBOL_GPL(md5_update);
176*e1644613SEric Biggers
__md5_final(struct md5_ctx * ctx,u8 out[MD5_DIGEST_SIZE])177*e1644613SEric Biggers static void __md5_final(struct md5_ctx *ctx, u8 out[MD5_DIGEST_SIZE])
178*e1644613SEric Biggers {
179*e1644613SEric Biggers u64 bitcount = ctx->bytecount << 3;
180*e1644613SEric Biggers size_t partial = ctx->bytecount % MD5_BLOCK_SIZE;
181*e1644613SEric Biggers
182*e1644613SEric Biggers ctx->buf[partial++] = 0x80;
183*e1644613SEric Biggers if (partial > MD5_BLOCK_SIZE - 8) {
184*e1644613SEric Biggers memset(&ctx->buf[partial], 0, MD5_BLOCK_SIZE - partial);
185*e1644613SEric Biggers md5_blocks(&ctx->state, ctx->buf, 1);
186*e1644613SEric Biggers partial = 0;
187*e1644613SEric Biggers }
188*e1644613SEric Biggers memset(&ctx->buf[partial], 0, MD5_BLOCK_SIZE - 8 - partial);
189*e1644613SEric Biggers *(__le64 *)&ctx->buf[MD5_BLOCK_SIZE - 8] = cpu_to_le64(bitcount);
190*e1644613SEric Biggers md5_blocks(&ctx->state, ctx->buf, 1);
191*e1644613SEric Biggers
192*e1644613SEric Biggers cpu_to_le32_array(ctx->state.h, ARRAY_SIZE(ctx->state.h));
193*e1644613SEric Biggers memcpy(out, ctx->state.h, MD5_DIGEST_SIZE);
194*e1644613SEric Biggers }
195*e1644613SEric Biggers
md5_final(struct md5_ctx * ctx,u8 out[MD5_DIGEST_SIZE])196*e1644613SEric Biggers void md5_final(struct md5_ctx *ctx, u8 out[MD5_DIGEST_SIZE])
197*e1644613SEric Biggers {
198*e1644613SEric Biggers __md5_final(ctx, out);
199*e1644613SEric Biggers memzero_explicit(ctx, sizeof(*ctx));
200*e1644613SEric Biggers }
201*e1644613SEric Biggers EXPORT_SYMBOL_GPL(md5_final);
202*e1644613SEric Biggers
md5(const u8 * data,size_t len,u8 out[MD5_DIGEST_SIZE])203*e1644613SEric Biggers void md5(const u8 *data, size_t len, u8 out[MD5_DIGEST_SIZE])
204*e1644613SEric Biggers {
205*e1644613SEric Biggers struct md5_ctx ctx;
206*e1644613SEric Biggers
207*e1644613SEric Biggers md5_init(&ctx);
208*e1644613SEric Biggers md5_update(&ctx, data, len);
209*e1644613SEric Biggers md5_final(&ctx, out);
210*e1644613SEric Biggers }
211*e1644613SEric Biggers EXPORT_SYMBOL_GPL(md5);
212*e1644613SEric Biggers
__hmac_md5_preparekey(struct md5_block_state * istate,struct md5_block_state * ostate,const u8 * raw_key,size_t raw_key_len)213*e1644613SEric Biggers static void __hmac_md5_preparekey(struct md5_block_state *istate,
214*e1644613SEric Biggers struct md5_block_state *ostate,
215*e1644613SEric Biggers const u8 *raw_key, size_t raw_key_len)
216*e1644613SEric Biggers {
217*e1644613SEric Biggers union {
218*e1644613SEric Biggers u8 b[MD5_BLOCK_SIZE];
219*e1644613SEric Biggers unsigned long w[MD5_BLOCK_SIZE / sizeof(unsigned long)];
220*e1644613SEric Biggers } derived_key = { 0 };
221*e1644613SEric Biggers
222*e1644613SEric Biggers if (unlikely(raw_key_len > MD5_BLOCK_SIZE))
223*e1644613SEric Biggers md5(raw_key, raw_key_len, derived_key.b);
224*e1644613SEric Biggers else
225*e1644613SEric Biggers memcpy(derived_key.b, raw_key, raw_key_len);
226*e1644613SEric Biggers
227*e1644613SEric Biggers for (size_t i = 0; i < ARRAY_SIZE(derived_key.w); i++)
228*e1644613SEric Biggers derived_key.w[i] ^= REPEAT_BYTE(HMAC_IPAD_VALUE);
229*e1644613SEric Biggers *istate = md5_iv;
230*e1644613SEric Biggers md5_blocks(istate, derived_key.b, 1);
231*e1644613SEric Biggers
232*e1644613SEric Biggers for (size_t i = 0; i < ARRAY_SIZE(derived_key.w); i++)
233*e1644613SEric Biggers derived_key.w[i] ^= REPEAT_BYTE(HMAC_OPAD_VALUE ^
234*e1644613SEric Biggers HMAC_IPAD_VALUE);
235*e1644613SEric Biggers *ostate = md5_iv;
236*e1644613SEric Biggers md5_blocks(ostate, derived_key.b, 1);
237*e1644613SEric Biggers
238*e1644613SEric Biggers memzero_explicit(&derived_key, sizeof(derived_key));
239*e1644613SEric Biggers }
240*e1644613SEric Biggers
hmac_md5_preparekey(struct hmac_md5_key * key,const u8 * raw_key,size_t raw_key_len)241*e1644613SEric Biggers void hmac_md5_preparekey(struct hmac_md5_key *key,
242*e1644613SEric Biggers const u8 *raw_key, size_t raw_key_len)
243*e1644613SEric Biggers {
244*e1644613SEric Biggers __hmac_md5_preparekey(&key->istate, &key->ostate, raw_key, raw_key_len);
245*e1644613SEric Biggers }
246*e1644613SEric Biggers EXPORT_SYMBOL_GPL(hmac_md5_preparekey);
247*e1644613SEric Biggers
hmac_md5_init(struct hmac_md5_ctx * ctx,const struct hmac_md5_key * key)248*e1644613SEric Biggers void hmac_md5_init(struct hmac_md5_ctx *ctx, const struct hmac_md5_key *key)
249*e1644613SEric Biggers {
250*e1644613SEric Biggers ctx->hash_ctx.state = key->istate;
251*e1644613SEric Biggers ctx->hash_ctx.bytecount = MD5_BLOCK_SIZE;
252*e1644613SEric Biggers ctx->ostate = key->ostate;
253*e1644613SEric Biggers }
254*e1644613SEric Biggers EXPORT_SYMBOL_GPL(hmac_md5_init);
255*e1644613SEric Biggers
hmac_md5_init_usingrawkey(struct hmac_md5_ctx * ctx,const u8 * raw_key,size_t raw_key_len)256*e1644613SEric Biggers void hmac_md5_init_usingrawkey(struct hmac_md5_ctx *ctx,
257*e1644613SEric Biggers const u8 *raw_key, size_t raw_key_len)
258*e1644613SEric Biggers {
259*e1644613SEric Biggers __hmac_md5_preparekey(&ctx->hash_ctx.state, &ctx->ostate,
260*e1644613SEric Biggers raw_key, raw_key_len);
261*e1644613SEric Biggers ctx->hash_ctx.bytecount = MD5_BLOCK_SIZE;
262*e1644613SEric Biggers }
263*e1644613SEric Biggers EXPORT_SYMBOL_GPL(hmac_md5_init_usingrawkey);
264*e1644613SEric Biggers
hmac_md5_final(struct hmac_md5_ctx * ctx,u8 out[MD5_DIGEST_SIZE])265*e1644613SEric Biggers void hmac_md5_final(struct hmac_md5_ctx *ctx, u8 out[MD5_DIGEST_SIZE])
266*e1644613SEric Biggers {
267*e1644613SEric Biggers /* Generate the padded input for the outer hash in ctx->hash_ctx.buf. */
268*e1644613SEric Biggers __md5_final(&ctx->hash_ctx, ctx->hash_ctx.buf);
269*e1644613SEric Biggers memset(&ctx->hash_ctx.buf[MD5_DIGEST_SIZE], 0,
270*e1644613SEric Biggers MD5_BLOCK_SIZE - MD5_DIGEST_SIZE);
271*e1644613SEric Biggers ctx->hash_ctx.buf[MD5_DIGEST_SIZE] = 0x80;
272*e1644613SEric Biggers *(__le64 *)&ctx->hash_ctx.buf[MD5_BLOCK_SIZE - 8] =
273*e1644613SEric Biggers cpu_to_le64(8 * (MD5_BLOCK_SIZE + MD5_DIGEST_SIZE));
274*e1644613SEric Biggers
275*e1644613SEric Biggers /* Compute the outer hash, which gives the HMAC value. */
276*e1644613SEric Biggers md5_blocks(&ctx->ostate, ctx->hash_ctx.buf, 1);
277*e1644613SEric Biggers cpu_to_le32_array(ctx->ostate.h, ARRAY_SIZE(ctx->ostate.h));
278*e1644613SEric Biggers memcpy(out, ctx->ostate.h, MD5_DIGEST_SIZE);
279*e1644613SEric Biggers
280*e1644613SEric Biggers memzero_explicit(ctx, sizeof(*ctx));
281*e1644613SEric Biggers }
282*e1644613SEric Biggers EXPORT_SYMBOL_GPL(hmac_md5_final);
283*e1644613SEric Biggers
hmac_md5(const struct hmac_md5_key * key,const u8 * data,size_t data_len,u8 out[MD5_DIGEST_SIZE])284*e1644613SEric Biggers void hmac_md5(const struct hmac_md5_key *key,
285*e1644613SEric Biggers const u8 *data, size_t data_len, u8 out[MD5_DIGEST_SIZE])
286*e1644613SEric Biggers {
287*e1644613SEric Biggers struct hmac_md5_ctx ctx;
288*e1644613SEric Biggers
289*e1644613SEric Biggers hmac_md5_init(&ctx, key);
290*e1644613SEric Biggers hmac_md5_update(&ctx, data, data_len);
291*e1644613SEric Biggers hmac_md5_final(&ctx, out);
292*e1644613SEric Biggers }
293*e1644613SEric Biggers EXPORT_SYMBOL_GPL(hmac_md5);
294*e1644613SEric Biggers
hmac_md5_usingrawkey(const u8 * raw_key,size_t raw_key_len,const u8 * data,size_t data_len,u8 out[MD5_DIGEST_SIZE])295*e1644613SEric Biggers void hmac_md5_usingrawkey(const u8 *raw_key, size_t raw_key_len,
296*e1644613SEric Biggers const u8 *data, size_t data_len,
297*e1644613SEric Biggers u8 out[MD5_DIGEST_SIZE])
298*e1644613SEric Biggers {
299*e1644613SEric Biggers struct hmac_md5_ctx ctx;
300*e1644613SEric Biggers
301*e1644613SEric Biggers hmac_md5_init_usingrawkey(&ctx, raw_key, raw_key_len);
302*e1644613SEric Biggers hmac_md5_update(&ctx, data, data_len);
303*e1644613SEric Biggers hmac_md5_final(&ctx, out);
304*e1644613SEric Biggers }
305*e1644613SEric Biggers EXPORT_SYMBOL_GPL(hmac_md5_usingrawkey);
306*e1644613SEric Biggers
307*e1644613SEric Biggers #ifdef md5_mod_init_arch
md5_mod_init(void)308*e1644613SEric Biggers static int __init md5_mod_init(void)
309*e1644613SEric Biggers {
310*e1644613SEric Biggers md5_mod_init_arch();
311*e1644613SEric Biggers return 0;
312*e1644613SEric Biggers }
313*e1644613SEric Biggers subsys_initcall(md5_mod_init);
314*e1644613SEric Biggers
md5_mod_exit(void)315*e1644613SEric Biggers static void __exit md5_mod_exit(void)
316*e1644613SEric Biggers {
317*e1644613SEric Biggers }
318*e1644613SEric Biggers module_exit(md5_mod_exit);
319*e1644613SEric Biggers #endif
320*e1644613SEric Biggers
321*e1644613SEric Biggers MODULE_DESCRIPTION("MD5 and HMAC-MD5 library functions");
322*e1644613SEric Biggers MODULE_LICENSE("GPL");
323