Skip to content

Commit 1b39bc4

Browse files
committed
crypto: s390/hmac - Fix counter in export state
The hmac export state needs to be one block-size bigger to account for the ipad. Reported-by: Ingo Franzki <ifranzki@linux.ibm.com> Fixes: 0881116 ("crypto: s390/hmac - Use API partial block handling") Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 442134a commit 1b39bc4

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

arch/s390/crypto/hmac_s390.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ static int s390_hmac_export(struct shash_desc *desc, void *out)
290290
struct s390_kmac_sha2_ctx *ctx = shash_desc_ctx(desc);
291291
unsigned int bs = crypto_shash_blocksize(desc->tfm);
292292
unsigned int ds = bs / 2;
293+
u64 lo = ctx->buflen[0];
293294
union {
294295
u8 *u8;
295296
u64 *u64;
@@ -301,9 +302,10 @@ static int s390_hmac_export(struct shash_desc *desc, void *out)
301302
else
302303
memcpy(p.u8, ctx->param, ds);
303304
p.u8 += ds;
304-
put_unaligned(ctx->buflen[0], p.u64++);
305+
lo += bs;
306+
put_unaligned(lo, p.u64++);
305307
if (ds == SHA512_DIGEST_SIZE)
306-
put_unaligned(ctx->buflen[1], p.u64);
308+
put_unaligned(ctx->buflen[1] + (lo < bs), p.u64);
307309
return err;
308310
}
309311

@@ -316,14 +318,16 @@ static int s390_hmac_import(struct shash_desc *desc, const void *in)
316318
const u8 *u8;
317319
const u64 *u64;
318320
} p = { .u8 = in };
321+
u64 lo;
319322
int err;
320323

321324
err = s390_hmac_sha2_init(desc);
322325
memcpy(ctx->param, p.u8, ds);
323326
p.u8 += ds;
324-
ctx->buflen[0] = get_unaligned(p.u64++);
327+
lo = get_unaligned(p.u64++);
328+
ctx->buflen[0] = lo - bs;
325329
if (ds == SHA512_DIGEST_SIZE)
326-
ctx->buflen[1] = get_unaligned(p.u64);
330+
ctx->buflen[1] = get_unaligned(p.u64) - (lo < bs);
327331
if (ctx->buflen[0] | ctx->buflen[1])
328332
ctx->gr0.ikp = 1;
329333
return err;

0 commit comments

Comments
 (0)