diff options
author | Mattias Andrée <maandree@kth.se> | 2024-09-12 20:18:55 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-09-12 20:18:55 +0200 |
commit | a17e0d582aaf91c6be55a5adbd5d8d38a09db222 (patch) | |
tree | 202a201357907ffd9dc72f586e19a99ac661365c /libhashsum_init_hasher_from_string.c | |
parent | m (diff) | |
download | libhashsum-a17e0d582aaf91c6be55a5adbd5d8d38a09db222.tar.gz libhashsum-a17e0d582aaf91c6be55a5adbd5d8d38a09db222.tar.bz2 libhashsum-a17e0d582aaf91c6be55a5adbd5d8d38a09db222.tar.xz |
Add libhashsum_init_keccak_hasher2
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | libhashsum_init_hasher_from_string.c | 26 |
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, ¶ms); } for (;;) { if (*p == 'r' || *p == 'R') { - if (parse_value(&r, &p[1], &p)) + if (parse_value(¶ms.ratebits, &p[1], &p)) goto einval; } else if (*p == 'c' || *p == 'C') { - if (parse_value(&c, &p[1], &p)) + if (parse_value(¶ms.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(¶ms.hashbits, &p[1], &p)) + goto einval; + } else if (*p == 's' || *p == 'S' || *p == 'b' || *p == 'B') { + if (parse_value(¶ms.statebits, &p[1], &p)) + goto einval; + } else if (*p == 'w' || *p == 'W') { + if (parse_value(¶ms.wordbits, &p[1], &p)) goto einval; } else if (*p == 'z' || *p == 'Z') { - if (parse_value(&z, &p[1], &p)) + if (parse_value(¶ms.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, ¶ms); 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); |