aboutsummaryrefslogtreecommitdiffstats
path: root/libhashsum_init_hasher_from_string.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libhashsum_init_hasher_from_string.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/libhashsum_init_hasher_from_string.c b/libhashsum_init_hasher_from_string.c
index e7a26d0..8ff5e44 100644
--- a/libhashsum_init_hasher_from_string.c
+++ b/libhashsum_init_hasher_from_string.c
@@ -51,31 +51,37 @@ einval:
static int
-with_rcnz(int (*initfunc)(struct libhashsum_hasher *, size_t, size_t, size_t, size_t),
+keccak(int (*initfunc)(struct libhashsum_hasher *, const struct libhashsum_keccak_params *params),
struct libhashsum_hasher *this, const char *algorithm)
{
+ struct libhashsum_keccak_params params = {0};
const char *p;
- size_t r = 0, c = 0, n = 0, z = 0;
p = strchr(algorithm, '[');
if (!p || *++p == ']') {
if (p && *++p)
goto einval;
- return initfunc(this, 0, 0, 0, 0);
+ return initfunc(this, &params);
}
for (;;) {
if (*p == 'r' || *p == 'R') {
- if (parse_value(&r, &p[1], &p))
+ if (parse_value(&params.ratebits, &p[1], &p))
goto einval;
} else if (*p == 'c' || *p == 'C') {
- if (parse_value(&c, &p[1], &p))
+ if (parse_value(&params.capbits, &p[1], &p))
goto einval;
- } else if (*p == 'n' || *p == 'N') {
- if (parse_value(&n, &p[1], &p))
+ } else if (*p == 'n' || *p == 'N' || *p == 'o' || *p == 'O') {
+ if (parse_value(&params.hashbits, &p[1], &p))
+ goto einval;
+ } else if (*p == 's' || *p == 'S' || *p == 'b' || *p == 'B') {
+ if (parse_value(&params.statebits, &p[1], &p))
+ goto einval;
+ } else if (*p == 'w' || *p == 'W') {
+ if (parse_value(&params.wordbits, &p[1], &p))
goto einval;
} else if (*p == 'z' || *p == 'Z') {
- if (parse_value(&z, &p[1], &p))
+ if (parse_value(&params.squeezes, &p[1], &p))
goto einval;
} else if (*p == ']') {
break;
@@ -90,7 +96,7 @@ with_rcnz(int (*initfunc)(struct libhashsum_hasher *, size_t, size_t, size_t, si
if (p[1])
goto einval;
- return initfunc(this, r, c, n, z);
+ return initfunc(this, &params);
einval:
errno = EINVAL;
@@ -309,7 +315,7 @@ libhashsum_init_hasher_from_string(struct libhashsum_hasher *this, const char *a
case LIBHASHSUM_RAWSHAKE128: return with_n(&libhashsum_init_rawshake128_hasher, this, algorithm);
case LIBHASHSUM_RAWSHAKE256: return with_n(&libhashsum_init_rawshake256_hasher, this, algorithm);
case LIBHASHSUM_RAWSHAKE512: return with_n(&libhashsum_init_rawshake512_hasher, this, algorithm);
- case LIBHASHSUM_KECCAK: return with_rcnz(&libhashsum_init_keccak_hasher, this, algorithm);
+ case LIBHASHSUM_KECCAK: return keccak(&libhashsum_init_keccak_hasher2, this, algorithm);
case LIBHASHSUM_BLAKE224: return with_salt(&libhashsum_init_blake224_hasher, this, algorithm, 16U);
case LIBHASHSUM_BLAKE256: return with_salt(&libhashsum_init_blake256_hasher, this, algorithm, 16U);
case LIBHASHSUM_BLAKE384: return with_salt(&libhashsum_init_blake384_hasher, this, algorithm, 32U);