summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorjsing <>2023-04-16 15:32:16 +0000
committerjsing <>2023-04-16 15:32:16 +0000
commit50bbf7a93efba8cdbac043586d793a869d8ef88c (patch)
treedf5fefb5cd95af04b95938b79c1e5e3567b5c2b2 /src/lib
parent874d79def147f2f8205b36074dc89b1a0ad64ea4 (diff)
downloadopenbsd-50bbf7a93efba8cdbac043586d793a869d8ef88c.tar.gz
openbsd-50bbf7a93efba8cdbac043586d793a869d8ef88c.tar.bz2
openbsd-50bbf7a93efba8cdbac043586d793a869d8ef88c.zip
Bounds check mdlen that is passed to sha3_init().
While here, use KECCAK_BYTE_WIDTH instead of hardcoding the value.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/sha/sha3.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/lib/libcrypto/sha/sha3.c b/src/lib/libcrypto/sha/sha3.c
index d406241f8a..b070d715ca 100644
--- a/src/lib/libcrypto/sha/sha3.c
+++ b/src/lib/libcrypto/sha/sha3.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sha3.c,v 1.14 2023/04/15 20:00:24 jsing Exp $ */ 1/* $OpenBSD: sha3.c,v 1.15 2023/04/16 15:32:16 jsing Exp $ */
2/* 2/*
3 * The MIT License (MIT) 3 * The MIT License (MIT)
4 * 4 *
@@ -121,10 +121,13 @@ sha3_keccakf(uint64_t st[25])
121int 121int
122sha3_init(sha3_ctx *c, int mdlen) 122sha3_init(sha3_ctx *c, int mdlen)
123{ 123{
124 if (mdlen < 0 || mdlen >= KECCAK_BYTE_WIDTH / 2)
125 return 0;
126
124 memset(c, 0, sizeof(*c)); 127 memset(c, 0, sizeof(*c));
125 128
126 c->mdlen = mdlen; 129 c->mdlen = mdlen;
127 c->rsize = 200 - 2 * mdlen; 130 c->rsize = KECCAK_BYTE_WIDTH - 2 * mdlen;
128 131
129 return 1; 132 return 1;
130} 133}