diff options
Diffstat (limited to '')
-rw-r--r-- | libhashsum_init_hasher_from_string.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/libhashsum_init_hasher_from_string.c b/libhashsum_init_hasher_from_string.c index 55fe882..0eaa12e 100644 --- a/libhashsum_init_hasher_from_string.c +++ b/libhashsum_init_hasher_from_string.c @@ -41,7 +41,6 @@ parse_value(size_t *valp, const char *p, const char **end_out) size_t digit; if (*valp) return -1; - p++; if (*p++ != '=' || !('1' <= *p && *p <= '9')) return -1; while (isdigit(*p)) { @@ -56,25 +55,28 @@ parse_value(size_t *valp, const char *p, const char **end_out) static int -with_rcn(int (*initfunc)(struct libhashsum_hasher *, size_t, size_t, size_t), +with_rcnz(int (*initfunc)(struct libhashsum_hasher *, size_t, size_t, size_t, size_t), struct libhashsum_hasher *this, const char *algorithm) { const char *p; - size_t r = 0, c = 0, n = 0; + size_t r = 0, c = 0, n = 0, z = 0; p = strchr(algorithm, '['); if (!p || *++p == ']') - return initfunc(this, 0, 0, 0); + return initfunc(this, 0, 0, 0, 0); for (;;) { if (*p == 'r' || *p == 'R') { - if (parse_value(&r, p, &p)) + if (parse_value(&r, &p[1], &p)) goto einval; } else if (*p == 'c' || *p == 'C') { - if (parse_value(&c, p, &p)) + if (parse_value(&c, &p[1], &p)) goto einval; } else if (*p == 'n' || *p == 'N') { - if (parse_value(&n, p, &p)) + if (parse_value(&n, &p[1], &p)) + goto einval; + } else if (*p == 'z' || *p == 'Z') { + if (parse_value(&z, &p[1], &p)) goto einval; } else if (*p == ']') { break; @@ -89,7 +91,7 @@ with_rcn(int (*initfunc)(struct libhashsum_hasher *, size_t, size_t, size_t), if (p[1]) goto einval; - return initfunc(this, r, c, n); + return initfunc(this, r, c, n, z); einval: errno = EINVAL; @@ -190,7 +192,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_rcn(&libhashsum_init_keccak_hasher, this, algorithm); + case LIBHASHSUM_KECCAK: return with_rcnz(&libhashsum_init_keccak_hasher, 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); |