@@ -50,6 +50,19 @@ static int __crypto_sha256_import(struct __sha256_ctx *ctx, const void *in)
50
50
return 0 ;
51
51
}
52
52
53
+ static int __crypto_sha256_export_core (const struct __sha256_ctx * ctx ,
54
+ void * out )
55
+ {
56
+ memcpy (out , ctx , offsetof(struct __sha256_ctx , buf ));
57
+ return 0 ;
58
+ }
59
+
60
+ static int __crypto_sha256_import_core (struct __sha256_ctx * ctx , const void * in )
61
+ {
62
+ memcpy (ctx , in , offsetof(struct __sha256_ctx , buf ));
63
+ return 0 ;
64
+ }
65
+
53
66
/* SHA-224 */
54
67
55
68
const u8 sha224_zero_message_hash [SHA224_DIGEST_SIZE ] = {
@@ -98,6 +111,16 @@ static int crypto_sha224_import(struct shash_desc *desc, const void *in)
98
111
return __crypto_sha256_import (& SHA224_CTX (desc )-> ctx , in );
99
112
}
100
113
114
+ static int crypto_sha224_export_core (struct shash_desc * desc , void * out )
115
+ {
116
+ return __crypto_sha256_export_core (& SHA224_CTX (desc )-> ctx , out );
117
+ }
118
+
119
+ static int crypto_sha224_import_core (struct shash_desc * desc , const void * in )
120
+ {
121
+ return __crypto_sha256_import_core (& SHA224_CTX (desc )-> ctx , in );
122
+ }
123
+
101
124
/* SHA-256 */
102
125
103
126
const u8 sha256_zero_message_hash [SHA256_DIGEST_SIZE ] = {
@@ -146,6 +169,16 @@ static int crypto_sha256_import(struct shash_desc *desc, const void *in)
146
169
return __crypto_sha256_import (& SHA256_CTX (desc )-> ctx , in );
147
170
}
148
171
172
+ static int crypto_sha256_export_core (struct shash_desc * desc , void * out )
173
+ {
174
+ return __crypto_sha256_export_core (& SHA256_CTX (desc )-> ctx , out );
175
+ }
176
+
177
+ static int crypto_sha256_import_core (struct shash_desc * desc , const void * in )
178
+ {
179
+ return __crypto_sha256_import_core (& SHA256_CTX (desc )-> ctx , in );
180
+ }
181
+
149
182
/* HMAC-SHA224 */
150
183
151
184
#define HMAC_SHA224_KEY (tfm ) ((struct hmac_sha224_key *)crypto_shash_ctx(tfm))
@@ -198,6 +231,21 @@ static int crypto_hmac_sha224_import(struct shash_desc *desc, const void *in)
198
231
return __crypto_sha256_import (& ctx -> ctx .sha_ctx , in );
199
232
}
200
233
234
+ static int crypto_hmac_sha224_export_core (struct shash_desc * desc , void * out )
235
+ {
236
+ return __crypto_sha256_export_core (& HMAC_SHA224_CTX (desc )-> ctx .sha_ctx ,
237
+ out );
238
+ }
239
+
240
+ static int crypto_hmac_sha224_import_core (struct shash_desc * desc ,
241
+ const void * in )
242
+ {
243
+ struct hmac_sha224_ctx * ctx = HMAC_SHA224_CTX (desc );
244
+
245
+ ctx -> ctx .ostate = HMAC_SHA224_KEY (desc -> tfm )-> key .ostate ;
246
+ return __crypto_sha256_import_core (& ctx -> ctx .sha_ctx , in );
247
+ }
248
+
201
249
/* HMAC-SHA256 */
202
250
203
251
#define HMAC_SHA256_KEY (tfm ) ((struct hmac_sha256_key *)crypto_shash_ctx(tfm))
@@ -250,6 +298,21 @@ static int crypto_hmac_sha256_import(struct shash_desc *desc, const void *in)
250
298
return __crypto_sha256_import (& ctx -> ctx .sha_ctx , in );
251
299
}
252
300
301
+ static int crypto_hmac_sha256_export_core (struct shash_desc * desc , void * out )
302
+ {
303
+ return __crypto_sha256_export_core (& HMAC_SHA256_CTX (desc )-> ctx .sha_ctx ,
304
+ out );
305
+ }
306
+
307
+ static int crypto_hmac_sha256_import_core (struct shash_desc * desc ,
308
+ const void * in )
309
+ {
310
+ struct hmac_sha256_ctx * ctx = HMAC_SHA256_CTX (desc );
311
+
312
+ ctx -> ctx .ostate = HMAC_SHA256_KEY (desc -> tfm )-> key .ostate ;
313
+ return __crypto_sha256_import_core (& ctx -> ctx .sha_ctx , in );
314
+ }
315
+
253
316
/* Algorithm definitions */
254
317
255
318
static struct shash_alg algs [] = {
@@ -266,6 +329,8 @@ static struct shash_alg algs[] = {
266
329
.digest = crypto_sha224_digest ,
267
330
.export = crypto_sha224_export ,
268
331
.import = crypto_sha224_import ,
332
+ .export_core = crypto_sha224_export_core ,
333
+ .import_core = crypto_sha224_import_core ,
269
334
.descsize = sizeof (struct sha224_ctx ),
270
335
.statesize = SHA256_SHASH_STATE_SIZE ,
271
336
},
@@ -282,6 +347,8 @@ static struct shash_alg algs[] = {
282
347
.digest = crypto_sha256_digest ,
283
348
.export = crypto_sha256_export ,
284
349
.import = crypto_sha256_import ,
350
+ .export_core = crypto_sha256_export_core ,
351
+ .import_core = crypto_sha256_import_core ,
285
352
.descsize = sizeof (struct sha256_ctx ),
286
353
.statesize = SHA256_SHASH_STATE_SIZE ,
287
354
},
@@ -300,6 +367,8 @@ static struct shash_alg algs[] = {
300
367
.digest = crypto_hmac_sha224_digest ,
301
368
.export = crypto_hmac_sha224_export ,
302
369
.import = crypto_hmac_sha224_import ,
370
+ .export_core = crypto_hmac_sha224_export_core ,
371
+ .import_core = crypto_hmac_sha224_import_core ,
303
372
.descsize = sizeof (struct hmac_sha224_ctx ),
304
373
.statesize = SHA256_SHASH_STATE_SIZE ,
305
374
},
@@ -318,6 +387,8 @@ static struct shash_alg algs[] = {
318
387
.digest = crypto_hmac_sha256_digest ,
319
388
.export = crypto_hmac_sha256_export ,
320
389
.import = crypto_hmac_sha256_import ,
390
+ .export_core = crypto_hmac_sha256_export_core ,
391
+ .import_core = crypto_hmac_sha256_import_core ,
321
392
.descsize = sizeof (struct hmac_sha256_ctx ),
322
393
.statesize = SHA256_SHASH_STATE_SIZE ,
323
394
},
0 commit comments