Lines Matching +full:sha +full:- +full:512
1 // SPDX-License-Identifier: GPL-2.0+
24 * blocksize of the used hashing sha2-algorithm function codes. The param block
25 * contains the hash chaining value (cv), the input message bit-length (imbl)
26 * and the hmac-secret (key). To prevent code duplication, the sizes of all
29 * param-block:
30 * +-------+
32 * +-------+
34 * +-------+
36 * +-------+
39 * part | sh2-alg | calculation | size | type
40 * -----+---------+-------------+------+--------
42 * | 384/512 | | 64 | u128[8]
44 * | 384/512 | | 16 | u128
46 * | 384/512 | | 128 | u8[128]
82 * kmac_sha2_set_imbl - sets the input message bit-length based on the blocksize
117 param.sha##x.h[0] = SHA##y ## _H0; \ in hash_data()
118 param.sha##x.h[1] = SHA##y ## _H1; \ in hash_data()
119 param.sha##x.h[2] = SHA##y ## _H2; \ in hash_data()
120 param.sha##x.h[3] = SHA##y ## _H3; \ in hash_data()
121 param.sha##x.h[4] = SHA##y ## _H4; \ in hash_data()
122 param.sha##x.h[5] = SHA##y ## _H5; \ in hash_data()
123 param.sha##x.h[6] = SHA##y ## _H6; \ in hash_data()
124 param.sha##x.h[7] = SHA##y ## _H7; \ in hash_data()
125 param.sha##x.mbl = (z) in hash_data()
140 PARAM_INIT(512, 384, inlen * 8); in hash_data()
146 PARAM_INIT(512, 512, inlen * 8); in hash_data()
149 return -EINVAL; in hash_data()
177 return hash_key(key, keylen, tfm_ctx->key, ds); in s390_hmac_sha2_setkey()
179 memcpy(tfm_ctx->key, key, keylen); in s390_hmac_sha2_setkey()
185 struct s390_hmac_ctx *tfm_ctx = crypto_shash_ctx(desc->tfm); in s390_hmac_sha2_init()
187 unsigned int bs = crypto_shash_blocksize(desc->tfm); in s390_hmac_sha2_init()
189 memcpy(ctx->param + SHA2_KEY_OFFSET(bs), in s390_hmac_sha2_init()
190 tfm_ctx->key, bs); in s390_hmac_sha2_init()
192 ctx->buflen[0] = 0; in s390_hmac_sha2_init()
193 ctx->buflen[1] = 0; in s390_hmac_sha2_init()
194 ctx->gr0.reg = 0; in s390_hmac_sha2_init()
195 switch (crypto_shash_digestsize(desc->tfm)) { in s390_hmac_sha2_init()
197 ctx->gr0.fc = CPACF_KMAC_HMAC_SHA_224; in s390_hmac_sha2_init()
200 ctx->gr0.fc = CPACF_KMAC_HMAC_SHA_256; in s390_hmac_sha2_init()
203 ctx->gr0.fc = CPACF_KMAC_HMAC_SHA_384; in s390_hmac_sha2_init()
206 ctx->gr0.fc = CPACF_KMAC_HMAC_SHA_512; in s390_hmac_sha2_init()
209 return -EINVAL; in s390_hmac_sha2_init()
219 unsigned int bs = crypto_shash_blocksize(desc->tfm); in s390_hmac_sha2_update()
222 ctx->buflen[0] += n; in s390_hmac_sha2_update()
223 if (ctx->buflen[0] < n) in s390_hmac_sha2_update()
224 ctx->buflen[1]++; in s390_hmac_sha2_update()
227 ctx->gr0.iimp = 1; in s390_hmac_sha2_update()
228 _cpacf_kmac(&ctx->gr0.reg, ctx->param, data, n); in s390_hmac_sha2_update()
229 return len - n; in s390_hmac_sha2_update()
236 unsigned int bs = crypto_shash_blocksize(desc->tfm); in s390_hmac_sha2_finup()
238 ctx->buflen[0] += len; in s390_hmac_sha2_finup()
239 if (ctx->buflen[0] < len) in s390_hmac_sha2_finup()
240 ctx->buflen[1]++; in s390_hmac_sha2_finup()
242 ctx->gr0.iimp = 0; in s390_hmac_sha2_finup()
243 kmac_sha2_set_imbl(ctx->param, ctx->buflen[0], ctx->buflen[1], bs); in s390_hmac_sha2_finup()
244 _cpacf_kmac(&ctx->gr0.reg, ctx->param, src, len); in s390_hmac_sha2_finup()
245 memcpy(out, ctx->param, crypto_shash_digestsize(desc->tfm)); in s390_hmac_sha2_finup()
254 unsigned int ds = crypto_shash_digestsize(desc->tfm); in s390_hmac_sha2_digest()
261 ctx->gr0.iimp = 0; in s390_hmac_sha2_digest()
262 kmac_sha2_set_imbl(ctx->param, len, 0, in s390_hmac_sha2_digest()
263 crypto_shash_blocksize(desc->tfm)); in s390_hmac_sha2_digest()
264 _cpacf_kmac(&ctx->gr0.reg, ctx->param, data, len); in s390_hmac_sha2_digest()
265 memcpy(out, ctx->param, ds); in s390_hmac_sha2_digest()
272 struct crypto_shash *tfm = desc->tfm; in s390_hmac_export_zero()
281 ipad[i] = ctx->key[i] ^ HMAC_IPAD_VALUE; in s390_hmac_export_zero()
291 unsigned int bs = crypto_shash_blocksize(desc->tfm); in s390_hmac_export()
293 u64 lo = ctx->buflen[0]; in s390_hmac_export()
300 if (!ctx->gr0.ikp) in s390_hmac_export()
303 memcpy(p.u8, ctx->param, ds); in s390_hmac_export()
308 put_unaligned(ctx->buflen[1] + (lo < bs), p.u64); in s390_hmac_export()
315 unsigned int bs = crypto_shash_blocksize(desc->tfm); in s390_hmac_import()
325 memcpy(ctx->param, p.u8, ds); in s390_hmac_import()
328 ctx->buflen[0] = lo - bs; in s390_hmac_import()
330 ctx->buflen[1] = get_unaligned(p.u64) - (lo < bs); in s390_hmac_import()
331 if (ctx->buflen[0] | ctx->buflen[1]) in s390_hmac_import()
332 ctx->gr0.ikp = 1; in s390_hmac_import()
349 .digestsize = SHA##x##_DIGEST_SIZE, \
351 .cra_name = "hmac(sha" #x ")", \
353 .cra_blocksize = SHA##x##_BLOCK_SIZE, \
372 S390_HMAC_SHA2_ALG(512, SHA512_STATE_SIZE),
380 for (i = ARRAY_SIZE(s390_hmac_algs) - 1; i >= 0; i--) { in _s390_hmac_algs_unregister()
382 if (!hmac->registered) in _s390_hmac_algs_unregister()
384 crypto_unregister_shash(&hmac->alg); in _s390_hmac_algs_unregister()
391 int i, rc = -ENODEV; in hmac_s390_init()
394 return -ENODEV; in hmac_s390_init()
396 return -ENODEV; in hmac_s390_init()
400 if (!cpacf_query_func(CPACF_KMAC, hmac->fc)) in hmac_s390_init()
403 rc = crypto_register_shash(&hmac->alg); in hmac_s390_init()
406 hmac->alg.halg.base.cra_name); in hmac_s390_init()
409 hmac->registered = true; in hmac_s390_init()
410 pr_debug("registered %s\n", hmac->alg.halg.base.cra_name); in hmac_s390_init()