Lines Matching +full:sha +full:- +full:1

1 // SPDX-License-Identifier: GPL-2.0+
20 * blocksize of the used hashing sha2-algorithm function codes. The param block
21 * contains the hash chaining value (cv), the input message bit-length (imbl)
22 * and the hmac-secret (key). To prevent code duplication, the sizes of all
25 * param-block:
26 * +-------+
28 * +-------+
30 * +-------+
32 * +-------+
35 * part | sh2-alg | calculation | size | type
36 * -----+---------+-------------+------+--------
49 #define SHA2_CV_SIZE(bs) ((bs) >> 1)
63 unsigned long ikp : 1;
64 unsigned long iimp : 1;
65 unsigned long ccup : 1;
79 * kmac_sha2_set_imbl - sets the input message bit-length based on the blocksize
114 param.sha##x.h[0] = SHA##y ## _H0; \ in hash_key()
115 param.sha##x.h[1] = SHA##y ## _H1; \ in hash_key()
116 param.sha##x.h[2] = SHA##y ## _H2; \ in hash_key()
117 param.sha##x.h[3] = SHA##y ## _H3; \ in hash_key()
118 param.sha##x.h[4] = SHA##y ## _H4; \ in hash_key()
119 param.sha##x.h[5] = SHA##y ## _H5; \ in hash_key()
120 param.sha##x.h[6] = SHA##y ## _H6; \ in hash_key()
121 param.sha##x.h[7] = SHA##y ## _H7; \ in hash_key()
122 param.sha##x.mbl = (z) in hash_key()
142 return -EINVAL; in hash_key()
164 return hash_key(key, keylen, tfm_ctx->key, ds); in s390_hmac_sha2_setkey()
166 memcpy(tfm_ctx->key, key, keylen); in s390_hmac_sha2_setkey()
172 struct s390_hmac_ctx *tfm_ctx = crypto_shash_ctx(desc->tfm); in s390_hmac_sha2_init()
174 unsigned int bs = crypto_shash_blocksize(desc->tfm); in s390_hmac_sha2_init()
176 memcpy(ctx->param + SHA2_KEY_OFFSET(bs), in s390_hmac_sha2_init()
177 tfm_ctx->key, bs); in s390_hmac_sha2_init()
179 ctx->buflen = 0; in s390_hmac_sha2_init()
180 ctx->gr0.reg = 0; in s390_hmac_sha2_init()
181 switch (crypto_shash_digestsize(desc->tfm)) { in s390_hmac_sha2_init()
183 ctx->gr0.fc = CPACF_KMAC_HMAC_SHA_224; in s390_hmac_sha2_init()
186 ctx->gr0.fc = CPACF_KMAC_HMAC_SHA_256; in s390_hmac_sha2_init()
189 ctx->gr0.fc = CPACF_KMAC_HMAC_SHA_384; in s390_hmac_sha2_init()
192 ctx->gr0.fc = CPACF_KMAC_HMAC_SHA_512; in s390_hmac_sha2_init()
195 return -EINVAL; in s390_hmac_sha2_init()
205 unsigned int bs = crypto_shash_blocksize(desc->tfm); in s390_hmac_sha2_update()
209 offset = ctx->buflen % bs; in s390_hmac_sha2_update()
210 ctx->buflen += len; in s390_hmac_sha2_update()
216 n = bs - offset; in s390_hmac_sha2_update()
217 memcpy(ctx->buf + offset, data, n); in s390_hmac_sha2_update()
218 ctx->gr0.iimp = 1; in s390_hmac_sha2_update()
219 _cpacf_kmac(&ctx->gr0.reg, ctx->param, ctx->buf, bs); in s390_hmac_sha2_update()
221 len -= n; 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()
230 len -= n; in s390_hmac_sha2_update()
235 memcpy(ctx->buf + offset, data, len); in s390_hmac_sha2_update()
243 unsigned int bs = crypto_shash_blocksize(desc->tfm); in s390_hmac_sha2_final()
245 ctx->gr0.iimp = 0; in s390_hmac_sha2_final()
246 kmac_sha2_set_imbl(ctx->param, ctx->buflen, bs); in s390_hmac_sha2_final()
247 _cpacf_kmac(&ctx->gr0.reg, ctx->param, ctx->buf, ctx->buflen % bs); in s390_hmac_sha2_final()
248 memcpy(out, ctx->param, crypto_shash_digestsize(desc->tfm)); in s390_hmac_sha2_final()
257 unsigned int ds = crypto_shash_digestsize(desc->tfm); in s390_hmac_sha2_digest()
264 ctx->gr0.iimp = 0; in s390_hmac_sha2_digest()
265 kmac_sha2_set_imbl(ctx->param, len, in s390_hmac_sha2_digest()
266 crypto_shash_blocksize(desc->tfm)); in s390_hmac_sha2_digest()
267 _cpacf_kmac(&ctx->gr0.reg, ctx->param, data, len); in s390_hmac_sha2_digest()
268 memcpy(out, ctx->param, ds); in s390_hmac_sha2_digest()
283 .digestsize = SHA##x##_DIGEST_SIZE, \
285 .cra_name = "hmac(sha" #x ")", \
287 .cra_blocksize = SHA##x##_BLOCK_SIZE, \
312 for (i = ARRAY_SIZE(s390_hmac_algs) - 1; i >= 0; i--) { in _s390_hmac_algs_unregister()
314 if (!hmac->registered) in _s390_hmac_algs_unregister()
316 crypto_unregister_shash(&hmac->alg); in _s390_hmac_algs_unregister()
323 int i, rc = -ENODEV; in hmac_s390_init()
326 return -ENODEV; in hmac_s390_init()
328 return -ENODEV; in hmac_s390_init()
332 if (!cpacf_query_func(CPACF_KMAC, hmac->fc)) in hmac_s390_init()
335 rc = crypto_register_shash(&hmac->alg); in hmac_s390_init()
338 hmac->alg.halg.base.cra_name); in hmac_s390_init()
341 hmac->registered = true; in hmac_s390_init()
342 pr_debug("registered %s\n", hmac->alg.halg.base.cra_name); in hmac_s390_init()