1950e5c84SEric Biggers // SPDX-License-Identifier: GPL-2.0-or-later
2950e5c84SEric Biggers /*
3e0cd3716SEric Biggers * Crypto API support for SHA-224, SHA-256, HMAC-SHA224, and HMAC-SHA256
4950e5c84SEric Biggers *
5950e5c84SEric Biggers * Copyright (c) Jean-Luc Cooke <jlcooke@certainkey.com>
6950e5c84SEric Biggers * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
7950e5c84SEric Biggers * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
8950e5c84SEric Biggers * SHA224 Support Copyright 2007 Intel Corporation <jonathan.lynch@intel.com>
9e0cd3716SEric Biggers * Copyright 2025 Google LLC
10950e5c84SEric Biggers */
11950e5c84SEric Biggers #include <crypto/internal/hash.h>
12e0cd3716SEric Biggers #include <crypto/sha2.h>
13950e5c84SEric Biggers #include <linux/kernel.h>
14950e5c84SEric Biggers #include <linux/module.h>
15950e5c84SEric Biggers
1607f09095SEric Biggers /*
1707f09095SEric Biggers * Export and import functions. crypto_shash wants a particular format that
1807f09095SEric Biggers * matches that used by some legacy drivers. It currently is the same as the
1907f09095SEric Biggers * library SHA context, except the value in bytecount must be block-aligned and
2007f09095SEric Biggers * the remainder must be stored in an extra u8 appended to the struct.
2107f09095SEric Biggers */
2207f09095SEric Biggers
2307f09095SEric Biggers #define SHA256_SHASH_STATE_SIZE 105
2407f09095SEric Biggers static_assert(offsetof(struct __sha256_ctx, state) == 0);
2507f09095SEric Biggers static_assert(offsetof(struct __sha256_ctx, bytecount) == 32);
2607f09095SEric Biggers static_assert(offsetof(struct __sha256_ctx, buf) == 40);
2707f09095SEric Biggers static_assert(sizeof(struct __sha256_ctx) + 1 == SHA256_SHASH_STATE_SIZE);
2807f09095SEric Biggers
__crypto_sha256_export(const struct __sha256_ctx * ctx0,void * out)2907f09095SEric Biggers static int __crypto_sha256_export(const struct __sha256_ctx *ctx0, void *out)
3007f09095SEric Biggers {
3107f09095SEric Biggers struct __sha256_ctx ctx = *ctx0;
3207f09095SEric Biggers unsigned int partial;
3307f09095SEric Biggers u8 *p = out;
3407f09095SEric Biggers
3507f09095SEric Biggers partial = ctx.bytecount % SHA256_BLOCK_SIZE;
3607f09095SEric Biggers ctx.bytecount -= partial;
3707f09095SEric Biggers memcpy(p, &ctx, sizeof(ctx));
3807f09095SEric Biggers p += sizeof(ctx);
3907f09095SEric Biggers *p = partial;
4007f09095SEric Biggers return 0;
4107f09095SEric Biggers }
4207f09095SEric Biggers
__crypto_sha256_import(struct __sha256_ctx * ctx,const void * in)4307f09095SEric Biggers static int __crypto_sha256_import(struct __sha256_ctx *ctx, const void *in)
4407f09095SEric Biggers {
4507f09095SEric Biggers const u8 *p = in;
4607f09095SEric Biggers
4707f09095SEric Biggers memcpy(ctx, p, sizeof(*ctx));
4807f09095SEric Biggers p += sizeof(*ctx);
4907f09095SEric Biggers ctx->bytecount += *p;
5007f09095SEric Biggers return 0;
5107f09095SEric Biggers }
5207f09095SEric Biggers
__crypto_sha256_export_core(const struct __sha256_ctx * ctx,void * out)53*30b2a8c4SEric Biggers static int __crypto_sha256_export_core(const struct __sha256_ctx *ctx,
54*30b2a8c4SEric Biggers void *out)
55*30b2a8c4SEric Biggers {
56*30b2a8c4SEric Biggers memcpy(out, ctx, offsetof(struct __sha256_ctx, buf));
57*30b2a8c4SEric Biggers return 0;
58*30b2a8c4SEric Biggers }
59*30b2a8c4SEric Biggers
__crypto_sha256_import_core(struct __sha256_ctx * ctx,const void * in)60*30b2a8c4SEric Biggers static int __crypto_sha256_import_core(struct __sha256_ctx *ctx, const void *in)
61*30b2a8c4SEric Biggers {
62*30b2a8c4SEric Biggers memcpy(ctx, in, offsetof(struct __sha256_ctx, buf));
63*30b2a8c4SEric Biggers return 0;
64*30b2a8c4SEric Biggers }
65*30b2a8c4SEric Biggers
66e0cd3716SEric Biggers /* SHA-224 */
67e0cd3716SEric Biggers
68950e5c84SEric Biggers const u8 sha224_zero_message_hash[SHA224_DIGEST_SIZE] = {
69950e5c84SEric Biggers 0xd1, 0x4a, 0x02, 0x8c, 0x2a, 0x3a, 0x2b, 0xc9, 0x47,
70950e5c84SEric Biggers 0x61, 0x02, 0xbb, 0x28, 0x82, 0x34, 0xc4, 0x15, 0xa2,
71950e5c84SEric Biggers 0xb0, 0x1f, 0x82, 0x8e, 0xa6, 0x2a, 0xc5, 0xb3, 0xe4,
72950e5c84SEric Biggers 0x2f
73950e5c84SEric Biggers };
74950e5c84SEric Biggers EXPORT_SYMBOL_GPL(sha224_zero_message_hash);
75950e5c84SEric Biggers
76e0cd3716SEric Biggers #define SHA224_CTX(desc) ((struct sha224_ctx *)shash_desc_ctx(desc))
77e0cd3716SEric Biggers
crypto_sha224_init(struct shash_desc * desc)78e0cd3716SEric Biggers static int crypto_sha224_init(struct shash_desc *desc)
79e0cd3716SEric Biggers {
80e0cd3716SEric Biggers sha224_init(SHA224_CTX(desc));
81e0cd3716SEric Biggers return 0;
82e0cd3716SEric Biggers }
83e0cd3716SEric Biggers
crypto_sha224_update(struct shash_desc * desc,const u8 * data,unsigned int len)84e0cd3716SEric Biggers static int crypto_sha224_update(struct shash_desc *desc,
85e0cd3716SEric Biggers const u8 *data, unsigned int len)
86e0cd3716SEric Biggers {
87e0cd3716SEric Biggers sha224_update(SHA224_CTX(desc), data, len);
88e0cd3716SEric Biggers return 0;
89e0cd3716SEric Biggers }
90e0cd3716SEric Biggers
crypto_sha224_final(struct shash_desc * desc,u8 * out)91e0cd3716SEric Biggers static int crypto_sha224_final(struct shash_desc *desc, u8 *out)
92e0cd3716SEric Biggers {
93e0cd3716SEric Biggers sha224_final(SHA224_CTX(desc), out);
94e0cd3716SEric Biggers return 0;
95e0cd3716SEric Biggers }
96e0cd3716SEric Biggers
crypto_sha224_digest(struct shash_desc * desc,const u8 * data,unsigned int len,u8 * out)97e0cd3716SEric Biggers static int crypto_sha224_digest(struct shash_desc *desc,
98e0cd3716SEric Biggers const u8 *data, unsigned int len, u8 *out)
99e0cd3716SEric Biggers {
100e0cd3716SEric Biggers sha224(data, len, out);
101e0cd3716SEric Biggers return 0;
102e0cd3716SEric Biggers }
103e0cd3716SEric Biggers
crypto_sha224_export(struct shash_desc * desc,void * out)10407f09095SEric Biggers static int crypto_sha224_export(struct shash_desc *desc, void *out)
10507f09095SEric Biggers {
10607f09095SEric Biggers return __crypto_sha256_export(&SHA224_CTX(desc)->ctx, out);
10707f09095SEric Biggers }
10807f09095SEric Biggers
crypto_sha224_import(struct shash_desc * desc,const void * in)10907f09095SEric Biggers static int crypto_sha224_import(struct shash_desc *desc, const void *in)
11007f09095SEric Biggers {
11107f09095SEric Biggers return __crypto_sha256_import(&SHA224_CTX(desc)->ctx, in);
11207f09095SEric Biggers }
11307f09095SEric Biggers
crypto_sha224_export_core(struct shash_desc * desc,void * out)114*30b2a8c4SEric Biggers static int crypto_sha224_export_core(struct shash_desc *desc, void *out)
115*30b2a8c4SEric Biggers {
116*30b2a8c4SEric Biggers return __crypto_sha256_export_core(&SHA224_CTX(desc)->ctx, out);
117*30b2a8c4SEric Biggers }
118*30b2a8c4SEric Biggers
crypto_sha224_import_core(struct shash_desc * desc,const void * in)119*30b2a8c4SEric Biggers static int crypto_sha224_import_core(struct shash_desc *desc, const void *in)
120*30b2a8c4SEric Biggers {
121*30b2a8c4SEric Biggers return __crypto_sha256_import_core(&SHA224_CTX(desc)->ctx, in);
122*30b2a8c4SEric Biggers }
123*30b2a8c4SEric Biggers
124e0cd3716SEric Biggers /* SHA-256 */
125e0cd3716SEric Biggers
126950e5c84SEric Biggers const u8 sha256_zero_message_hash[SHA256_DIGEST_SIZE] = {
127950e5c84SEric Biggers 0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14,
128950e5c84SEric Biggers 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24,
129950e5c84SEric Biggers 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c,
130950e5c84SEric Biggers 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55
131950e5c84SEric Biggers };
132950e5c84SEric Biggers EXPORT_SYMBOL_GPL(sha256_zero_message_hash);
133950e5c84SEric Biggers
134e0cd3716SEric Biggers #define SHA256_CTX(desc) ((struct sha256_ctx *)shash_desc_ctx(desc))
135e0cd3716SEric Biggers
crypto_sha256_init(struct shash_desc * desc)136950e5c84SEric Biggers static int crypto_sha256_init(struct shash_desc *desc)
137950e5c84SEric Biggers {
138e0cd3716SEric Biggers sha256_init(SHA256_CTX(desc));
139950e5c84SEric Biggers return 0;
140950e5c84SEric Biggers }
141950e5c84SEric Biggers
crypto_sha256_update(struct shash_desc * desc,const u8 * data,unsigned int len)142e0cd3716SEric Biggers static int crypto_sha256_update(struct shash_desc *desc,
143e0cd3716SEric Biggers const u8 *data, unsigned int len)
144ff8f037dSHerbert Xu {
145e0cd3716SEric Biggers sha256_update(SHA256_CTX(desc), data, len);
146950e5c84SEric Biggers return 0;
147950e5c84SEric Biggers }
148950e5c84SEric Biggers
crypto_sha256_final(struct shash_desc * desc,u8 * out)149e0cd3716SEric Biggers static int crypto_sha256_final(struct shash_desc *desc, u8 *out)
1503bf53378SHerbert Xu {
151e0cd3716SEric Biggers sha256_final(SHA256_CTX(desc), out);
152950e5c84SEric Biggers return 0;
153950e5c84SEric Biggers }
154950e5c84SEric Biggers
crypto_sha256_digest(struct shash_desc * desc,const u8 * data,unsigned int len,u8 * out)155e0cd3716SEric Biggers static int crypto_sha256_digest(struct shash_desc *desc,
156e0cd3716SEric Biggers const u8 *data, unsigned int len, u8 *out)
157950e5c84SEric Biggers {
158950e5c84SEric Biggers sha256(data, len, out);
159950e5c84SEric Biggers return 0;
160950e5c84SEric Biggers }
161950e5c84SEric Biggers
crypto_sha256_export(struct shash_desc * desc,void * out)16207f09095SEric Biggers static int crypto_sha256_export(struct shash_desc *desc, void *out)
16307f09095SEric Biggers {
16407f09095SEric Biggers return __crypto_sha256_export(&SHA256_CTX(desc)->ctx, out);
16507f09095SEric Biggers }
16607f09095SEric Biggers
crypto_sha256_import(struct shash_desc * desc,const void * in)16707f09095SEric Biggers static int crypto_sha256_import(struct shash_desc *desc, const void *in)
16807f09095SEric Biggers {
16907f09095SEric Biggers return __crypto_sha256_import(&SHA256_CTX(desc)->ctx, in);
17007f09095SEric Biggers }
17107f09095SEric Biggers
crypto_sha256_export_core(struct shash_desc * desc,void * out)172*30b2a8c4SEric Biggers static int crypto_sha256_export_core(struct shash_desc *desc, void *out)
173*30b2a8c4SEric Biggers {
174*30b2a8c4SEric Biggers return __crypto_sha256_export_core(&SHA256_CTX(desc)->ctx, out);
175*30b2a8c4SEric Biggers }
176*30b2a8c4SEric Biggers
crypto_sha256_import_core(struct shash_desc * desc,const void * in)177*30b2a8c4SEric Biggers static int crypto_sha256_import_core(struct shash_desc *desc, const void *in)
178*30b2a8c4SEric Biggers {
179*30b2a8c4SEric Biggers return __crypto_sha256_import_core(&SHA256_CTX(desc)->ctx, in);
180*30b2a8c4SEric Biggers }
181*30b2a8c4SEric Biggers
182e0cd3716SEric Biggers /* HMAC-SHA224 */
1833bf53378SHerbert Xu
184e0cd3716SEric Biggers #define HMAC_SHA224_KEY(tfm) ((struct hmac_sha224_key *)crypto_shash_ctx(tfm))
185e0cd3716SEric Biggers #define HMAC_SHA224_CTX(desc) ((struct hmac_sha224_ctx *)shash_desc_ctx(desc))
186e0cd3716SEric Biggers
crypto_hmac_sha224_setkey(struct crypto_shash * tfm,const u8 * raw_key,unsigned int keylen)187e0cd3716SEric Biggers static int crypto_hmac_sha224_setkey(struct crypto_shash *tfm,
188e0cd3716SEric Biggers const u8 *raw_key, unsigned int keylen)
189950e5c84SEric Biggers {
190e0cd3716SEric Biggers hmac_sha224_preparekey(HMAC_SHA224_KEY(tfm), raw_key, keylen);
191950e5c84SEric Biggers return 0;
192950e5c84SEric Biggers }
193950e5c84SEric Biggers
crypto_hmac_sha224_init(struct shash_desc * desc)194e0cd3716SEric Biggers static int crypto_hmac_sha224_init(struct shash_desc *desc)
195950e5c84SEric Biggers {
196e0cd3716SEric Biggers hmac_sha224_init(HMAC_SHA224_CTX(desc), HMAC_SHA224_KEY(desc->tfm));
197950e5c84SEric Biggers return 0;
198950e5c84SEric Biggers }
199950e5c84SEric Biggers
crypto_hmac_sha224_update(struct shash_desc * desc,const u8 * data,unsigned int len)200e0cd3716SEric Biggers static int crypto_hmac_sha224_update(struct shash_desc *desc,
201e0cd3716SEric Biggers const u8 *data, unsigned int len)
202950e5c84SEric Biggers {
203e0cd3716SEric Biggers hmac_sha224_update(HMAC_SHA224_CTX(desc), data, len);
204950e5c84SEric Biggers return 0;
205950e5c84SEric Biggers }
206950e5c84SEric Biggers
crypto_hmac_sha224_final(struct shash_desc * desc,u8 * out)207e0cd3716SEric Biggers static int crypto_hmac_sha224_final(struct shash_desc *desc, u8 *out)
208950e5c84SEric Biggers {
209e0cd3716SEric Biggers hmac_sha224_final(HMAC_SHA224_CTX(desc), out);
210950e5c84SEric Biggers return 0;
211950e5c84SEric Biggers }
212950e5c84SEric Biggers
crypto_hmac_sha224_digest(struct shash_desc * desc,const u8 * data,unsigned int len,u8 * out)213e0cd3716SEric Biggers static int crypto_hmac_sha224_digest(struct shash_desc *desc,
214e0cd3716SEric Biggers const u8 *data, unsigned int len,
215e0cd3716SEric Biggers u8 *out)
216e0cd3716SEric Biggers {
217e0cd3716SEric Biggers hmac_sha224(HMAC_SHA224_KEY(desc->tfm), data, len, out);
218e0cd3716SEric Biggers return 0;
219e0cd3716SEric Biggers }
220e0cd3716SEric Biggers
crypto_hmac_sha224_export(struct shash_desc * desc,void * out)22107f09095SEric Biggers static int crypto_hmac_sha224_export(struct shash_desc *desc, void *out)
22207f09095SEric Biggers {
22307f09095SEric Biggers return __crypto_sha256_export(&HMAC_SHA224_CTX(desc)->ctx.sha_ctx, out);
22407f09095SEric Biggers }
22507f09095SEric Biggers
crypto_hmac_sha224_import(struct shash_desc * desc,const void * in)22607f09095SEric Biggers static int crypto_hmac_sha224_import(struct shash_desc *desc, const void *in)
22707f09095SEric Biggers {
22807f09095SEric Biggers struct hmac_sha224_ctx *ctx = HMAC_SHA224_CTX(desc);
22907f09095SEric Biggers
23007f09095SEric Biggers ctx->ctx.ostate = HMAC_SHA224_KEY(desc->tfm)->key.ostate;
23107f09095SEric Biggers return __crypto_sha256_import(&ctx->ctx.sha_ctx, in);
23207f09095SEric Biggers }
23307f09095SEric Biggers
crypto_hmac_sha224_export_core(struct shash_desc * desc,void * out)234*30b2a8c4SEric Biggers static int crypto_hmac_sha224_export_core(struct shash_desc *desc, void *out)
235*30b2a8c4SEric Biggers {
236*30b2a8c4SEric Biggers return __crypto_sha256_export_core(&HMAC_SHA224_CTX(desc)->ctx.sha_ctx,
237*30b2a8c4SEric Biggers out);
238*30b2a8c4SEric Biggers }
239*30b2a8c4SEric Biggers
crypto_hmac_sha224_import_core(struct shash_desc * desc,const void * in)240*30b2a8c4SEric Biggers static int crypto_hmac_sha224_import_core(struct shash_desc *desc,
241*30b2a8c4SEric Biggers const void *in)
242*30b2a8c4SEric Biggers {
243*30b2a8c4SEric Biggers struct hmac_sha224_ctx *ctx = HMAC_SHA224_CTX(desc);
244*30b2a8c4SEric Biggers
245*30b2a8c4SEric Biggers ctx->ctx.ostate = HMAC_SHA224_KEY(desc->tfm)->key.ostate;
246*30b2a8c4SEric Biggers return __crypto_sha256_import_core(&ctx->ctx.sha_ctx, in);
247*30b2a8c4SEric Biggers }
248*30b2a8c4SEric Biggers
249e0cd3716SEric Biggers /* HMAC-SHA256 */
250e0cd3716SEric Biggers
251e0cd3716SEric Biggers #define HMAC_SHA256_KEY(tfm) ((struct hmac_sha256_key *)crypto_shash_ctx(tfm))
252e0cd3716SEric Biggers #define HMAC_SHA256_CTX(desc) ((struct hmac_sha256_ctx *)shash_desc_ctx(desc))
253e0cd3716SEric Biggers
crypto_hmac_sha256_setkey(struct crypto_shash * tfm,const u8 * raw_key,unsigned int keylen)254e0cd3716SEric Biggers static int crypto_hmac_sha256_setkey(struct crypto_shash *tfm,
255e0cd3716SEric Biggers const u8 *raw_key, unsigned int keylen)
256e0cd3716SEric Biggers {
257e0cd3716SEric Biggers hmac_sha256_preparekey(HMAC_SHA256_KEY(tfm), raw_key, keylen);
258e0cd3716SEric Biggers return 0;
259e0cd3716SEric Biggers }
260e0cd3716SEric Biggers
crypto_hmac_sha256_init(struct shash_desc * desc)261e0cd3716SEric Biggers static int crypto_hmac_sha256_init(struct shash_desc *desc)
262e0cd3716SEric Biggers {
263e0cd3716SEric Biggers hmac_sha256_init(HMAC_SHA256_CTX(desc), HMAC_SHA256_KEY(desc->tfm));
264e0cd3716SEric Biggers return 0;
265e0cd3716SEric Biggers }
266e0cd3716SEric Biggers
crypto_hmac_sha256_update(struct shash_desc * desc,const u8 * data,unsigned int len)267e0cd3716SEric Biggers static int crypto_hmac_sha256_update(struct shash_desc *desc,
268e0cd3716SEric Biggers const u8 *data, unsigned int len)
269e0cd3716SEric Biggers {
270e0cd3716SEric Biggers hmac_sha256_update(HMAC_SHA256_CTX(desc), data, len);
271e0cd3716SEric Biggers return 0;
272e0cd3716SEric Biggers }
273e0cd3716SEric Biggers
crypto_hmac_sha256_final(struct shash_desc * desc,u8 * out)274e0cd3716SEric Biggers static int crypto_hmac_sha256_final(struct shash_desc *desc, u8 *out)
275e0cd3716SEric Biggers {
276e0cd3716SEric Biggers hmac_sha256_final(HMAC_SHA256_CTX(desc), out);
277e0cd3716SEric Biggers return 0;
278e0cd3716SEric Biggers }
279e0cd3716SEric Biggers
crypto_hmac_sha256_digest(struct shash_desc * desc,const u8 * data,unsigned int len,u8 * out)280e0cd3716SEric Biggers static int crypto_hmac_sha256_digest(struct shash_desc *desc,
281e0cd3716SEric Biggers const u8 *data, unsigned int len,
282e0cd3716SEric Biggers u8 *out)
283e0cd3716SEric Biggers {
284e0cd3716SEric Biggers hmac_sha256(HMAC_SHA256_KEY(desc->tfm), data, len, out);
285e0cd3716SEric Biggers return 0;
286e0cd3716SEric Biggers }
287e0cd3716SEric Biggers
crypto_hmac_sha256_export(struct shash_desc * desc,void * out)28807f09095SEric Biggers static int crypto_hmac_sha256_export(struct shash_desc *desc, void *out)
28907f09095SEric Biggers {
29007f09095SEric Biggers return __crypto_sha256_export(&HMAC_SHA256_CTX(desc)->ctx.sha_ctx, out);
29107f09095SEric Biggers }
29207f09095SEric Biggers
crypto_hmac_sha256_import(struct shash_desc * desc,const void * in)29307f09095SEric Biggers static int crypto_hmac_sha256_import(struct shash_desc *desc, const void *in)
29407f09095SEric Biggers {
29507f09095SEric Biggers struct hmac_sha256_ctx *ctx = HMAC_SHA256_CTX(desc);
29607f09095SEric Biggers
29707f09095SEric Biggers ctx->ctx.ostate = HMAC_SHA256_KEY(desc->tfm)->key.ostate;
29807f09095SEric Biggers return __crypto_sha256_import(&ctx->ctx.sha_ctx, in);
29907f09095SEric Biggers }
30007f09095SEric Biggers
crypto_hmac_sha256_export_core(struct shash_desc * desc,void * out)301*30b2a8c4SEric Biggers static int crypto_hmac_sha256_export_core(struct shash_desc *desc, void *out)
302*30b2a8c4SEric Biggers {
303*30b2a8c4SEric Biggers return __crypto_sha256_export_core(&HMAC_SHA256_CTX(desc)->ctx.sha_ctx,
304*30b2a8c4SEric Biggers out);
305*30b2a8c4SEric Biggers }
306*30b2a8c4SEric Biggers
crypto_hmac_sha256_import_core(struct shash_desc * desc,const void * in)307*30b2a8c4SEric Biggers static int crypto_hmac_sha256_import_core(struct shash_desc *desc,
308*30b2a8c4SEric Biggers const void *in)
309*30b2a8c4SEric Biggers {
310*30b2a8c4SEric Biggers struct hmac_sha256_ctx *ctx = HMAC_SHA256_CTX(desc);
311*30b2a8c4SEric Biggers
312*30b2a8c4SEric Biggers ctx->ctx.ostate = HMAC_SHA256_KEY(desc->tfm)->key.ostate;
313*30b2a8c4SEric Biggers return __crypto_sha256_import_core(&ctx->ctx.sha_ctx, in);
314*30b2a8c4SEric Biggers }
315*30b2a8c4SEric Biggers
316e0cd3716SEric Biggers /* Algorithm definitions */
317e0cd3716SEric Biggers
318950e5c84SEric Biggers static struct shash_alg algs[] = {
319950e5c84SEric Biggers {
320950e5c84SEric Biggers .base.cra_name = "sha224",
321e0cd3716SEric Biggers .base.cra_driver_name = "sha224-lib",
322e0cd3716SEric Biggers .base.cra_priority = 300,
323950e5c84SEric Biggers .base.cra_blocksize = SHA224_BLOCK_SIZE,
324950e5c84SEric Biggers .base.cra_module = THIS_MODULE,
325950e5c84SEric Biggers .digestsize = SHA224_DIGEST_SIZE,
326950e5c84SEric Biggers .init = crypto_sha224_init,
327e0cd3716SEric Biggers .update = crypto_sha224_update,
328e0cd3716SEric Biggers .final = crypto_sha224_final,
329e0cd3716SEric Biggers .digest = crypto_sha224_digest,
33007f09095SEric Biggers .export = crypto_sha224_export,
33107f09095SEric Biggers .import = crypto_sha224_import,
332*30b2a8c4SEric Biggers .export_core = crypto_sha224_export_core,
333*30b2a8c4SEric Biggers .import_core = crypto_sha224_import_core,
334e0cd3716SEric Biggers .descsize = sizeof(struct sha224_ctx),
33507f09095SEric Biggers .statesize = SHA256_SHASH_STATE_SIZE,
336950e5c84SEric Biggers },
337950e5c84SEric Biggers {
338950e5c84SEric Biggers .base.cra_name = "sha256",
3393bf53378SHerbert Xu .base.cra_driver_name = "sha256-lib",
340e0cd3716SEric Biggers .base.cra_priority = 300,
341950e5c84SEric Biggers .base.cra_blocksize = SHA256_BLOCK_SIZE,
342950e5c84SEric Biggers .base.cra_module = THIS_MODULE,
343950e5c84SEric Biggers .digestsize = SHA256_DIGEST_SIZE,
344950e5c84SEric Biggers .init = crypto_sha256_init,
345e0cd3716SEric Biggers .update = crypto_sha256_update,
346e0cd3716SEric Biggers .final = crypto_sha256_final,
347e0cd3716SEric Biggers .digest = crypto_sha256_digest,
34807f09095SEric Biggers .export = crypto_sha256_export,
34907f09095SEric Biggers .import = crypto_sha256_import,
350*30b2a8c4SEric Biggers .export_core = crypto_sha256_export_core,
351*30b2a8c4SEric Biggers .import_core = crypto_sha256_import_core,
352b86ced88SEric Biggers .descsize = sizeof(struct sha256_ctx),
35307f09095SEric Biggers .statesize = SHA256_SHASH_STATE_SIZE,
354950e5c84SEric Biggers },
355950e5c84SEric Biggers {
356e0cd3716SEric Biggers .base.cra_name = "hmac(sha224)",
357e0cd3716SEric Biggers .base.cra_driver_name = "hmac-sha224-lib",
358e0cd3716SEric Biggers .base.cra_priority = 300,
359950e5c84SEric Biggers .base.cra_blocksize = SHA224_BLOCK_SIZE,
360e0cd3716SEric Biggers .base.cra_ctxsize = sizeof(struct hmac_sha224_key),
361950e5c84SEric Biggers .base.cra_module = THIS_MODULE,
362950e5c84SEric Biggers .digestsize = SHA224_DIGEST_SIZE,
363e0cd3716SEric Biggers .setkey = crypto_hmac_sha224_setkey,
364e0cd3716SEric Biggers .init = crypto_hmac_sha224_init,
365e0cd3716SEric Biggers .update = crypto_hmac_sha224_update,
366e0cd3716SEric Biggers .final = crypto_hmac_sha224_final,
367e0cd3716SEric Biggers .digest = crypto_hmac_sha224_digest,
36807f09095SEric Biggers .export = crypto_hmac_sha224_export,
36907f09095SEric Biggers .import = crypto_hmac_sha224_import,
370*30b2a8c4SEric Biggers .export_core = crypto_hmac_sha224_export_core,
371*30b2a8c4SEric Biggers .import_core = crypto_hmac_sha224_import_core,
372e0cd3716SEric Biggers .descsize = sizeof(struct hmac_sha224_ctx),
37307f09095SEric Biggers .statesize = SHA256_SHASH_STATE_SIZE,
374950e5c84SEric Biggers },
3753bf53378SHerbert Xu {
376e0cd3716SEric Biggers .base.cra_name = "hmac(sha256)",
377e0cd3716SEric Biggers .base.cra_driver_name = "hmac-sha256-lib",
3783bf53378SHerbert Xu .base.cra_priority = 300,
3793bf53378SHerbert Xu .base.cra_blocksize = SHA256_BLOCK_SIZE,
380e0cd3716SEric Biggers .base.cra_ctxsize = sizeof(struct hmac_sha256_key),
3813bf53378SHerbert Xu .base.cra_module = THIS_MODULE,
3823bf53378SHerbert Xu .digestsize = SHA256_DIGEST_SIZE,
383e0cd3716SEric Biggers .setkey = crypto_hmac_sha256_setkey,
384e0cd3716SEric Biggers .init = crypto_hmac_sha256_init,
385e0cd3716SEric Biggers .update = crypto_hmac_sha256_update,
386e0cd3716SEric Biggers .final = crypto_hmac_sha256_final,
387e0cd3716SEric Biggers .digest = crypto_hmac_sha256_digest,
38807f09095SEric Biggers .export = crypto_hmac_sha256_export,
38907f09095SEric Biggers .import = crypto_hmac_sha256_import,
390*30b2a8c4SEric Biggers .export_core = crypto_hmac_sha256_export_core,
391*30b2a8c4SEric Biggers .import_core = crypto_hmac_sha256_import_core,
392e0cd3716SEric Biggers .descsize = sizeof(struct hmac_sha256_ctx),
39307f09095SEric Biggers .statesize = SHA256_SHASH_STATE_SIZE,
3943bf53378SHerbert Xu },
395950e5c84SEric Biggers };
396950e5c84SEric Biggers
crypto_sha256_mod_init(void)397950e5c84SEric Biggers static int __init crypto_sha256_mod_init(void)
398950e5c84SEric Biggers {
399950e5c84SEric Biggers return crypto_register_shashes(algs, ARRAY_SIZE(algs));
400950e5c84SEric Biggers }
401ef93f156SHerbert Xu module_init(crypto_sha256_mod_init);
402950e5c84SEric Biggers
crypto_sha256_mod_exit(void)403950e5c84SEric Biggers static void __exit crypto_sha256_mod_exit(void)
404950e5c84SEric Biggers {
405e0cd3716SEric Biggers crypto_unregister_shashes(algs, ARRAY_SIZE(algs));
406950e5c84SEric Biggers }
407950e5c84SEric Biggers module_exit(crypto_sha256_mod_exit);
408950e5c84SEric Biggers
409950e5c84SEric Biggers MODULE_LICENSE("GPL");
410e0cd3716SEric Biggers MODULE_DESCRIPTION("Crypto API support for SHA-224, SHA-256, HMAC-SHA224, and HMAC-SHA256");
411950e5c84SEric Biggers
412950e5c84SEric Biggers MODULE_ALIAS_CRYPTO("sha224");
413e0cd3716SEric Biggers MODULE_ALIAS_CRYPTO("sha224-lib");
414e0cd3716SEric Biggers MODULE_ALIAS_CRYPTO("sha256");
415e0cd3716SEric Biggers MODULE_ALIAS_CRYPTO("sha256-lib");
416e0cd3716SEric Biggers MODULE_ALIAS_CRYPTO("hmac(sha224)");
417e0cd3716SEric Biggers MODULE_ALIAS_CRYPTO("hmac-sha224-lib");
418e0cd3716SEric Biggers MODULE_ALIAS_CRYPTO("hmac(sha256)");
419e0cd3716SEric Biggers MODULE_ALIAS_CRYPTO("hmac-sha256-lib");
420