diff options
author | Mattias Andrée <maandree@kth.se> | 2024-08-30 19:58:07 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-08-30 19:58:07 +0200 |
commit | 2c15891937c6fb9f3b5e70ae0f0d0d906e4c03ed (patch) | |
tree | d3d3cc3784207210fc7c63cca267257b20153b67 /libhashsum | |
parent | m + add man pages (diff) | |
download | libhashsum-2c15891937c6fb9f3b5e70ae0f0d0d906e4c03ed.tar.gz libhashsum-2c15891937c6fb9f3b5e70ae0f0d0d906e4c03ed.tar.bz2 libhashsum-2c15891937c6fb9f3b5e70ae0f0d0d906e4c03ed.tar.xz |
Add more tests + m fixes
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | libhashsum.h | 12 | ||||
-rw-r--r-- | libhashsum_get_algorithm_from_string.3 | 8 | ||||
-rw-r--r-- | libhashsum_get_algorithm_from_string.c | 4 | ||||
-rw-r--r-- | libhashsum_init_hasher_from_string.c | 28 |
4 files changed, 35 insertions, 17 deletions
diff --git a/libhashsum.h b/libhashsum.h index d1a9f64..b10f2f4 100644 --- a/libhashsum.h +++ b/libhashsum.h @@ -478,7 +478,7 @@ struct libhashsum_hasher { * @since 1.0 */ LIBHASHSUM_1_NONNULL_ -int libhashsum_init_hasher(struct libhashsum_hasher *this, enum libhashsum_algorithm algorithm); /* TODO test */ +int libhashsum_init_hasher(struct libhashsum_hasher *this, enum libhashsum_algorithm algorithm); /** * Inspect a hashing algorithm string to identify @@ -492,7 +492,7 @@ int libhashsum_init_hasher(struct libhashsum_hasher *this, enum libhashsum_algor * @since 1.0 */ LIBHASHSUM_NONNULL_ -int libhashsum_get_algorithm_from_string(enum libhashsum_algorithm *algorithm_out, const char *algorithm); /* TODO test */ +int libhashsum_get_algorithm_from_string(enum libhashsum_algorithm *algorithm_out, const char *algorithm); /** * Create an initialised state for a hash algorithm @@ -516,7 +516,7 @@ int libhashsum_get_algorithm_from_string(enum libhashsum_algorithm *algorithm_ou * @since 1.0 */ LIBHASHSUM_NONNULL_ -int libhashsum_init_hasher_from_string(struct libhashsum_hasher *this, const char *algorithm); /* TODO test */ +int libhashsum_init_hasher_from_string(struct libhashsum_hasher *this, const char *algorithm); /** * Create an initialised state for MD2 @@ -1097,7 +1097,7 @@ int libhashsum_init_blake256_hasher(struct libhashsum_hasher *this, const void * * @since 1.0 */ LIBHASHSUM_1_NONNULL_ -int libhashsum_init_blakes_hasher(struct libhashsum_hasher *this, size_t hashbits, const void *salt); /* TODO test */ +int libhashsum_init_blakes_hasher(struct libhashsum_hasher *this, size_t hashbits, const void *salt); /** * Create an initialised state for BLAKE384 (BLAKE, BLAKEb) @@ -1144,7 +1144,7 @@ int libhashsum_init_blake512_hasher(struct libhashsum_hasher *this, const void * * @since 1.0 */ LIBHASHSUM_1_NONNULL_ -int libhashsum_init_blakeb_hasher(struct libhashsum_hasher *this, size_t hashbits, const void *salt); /* TODO test */ +int libhashsum_init_blakeb_hasher(struct libhashsum_hasher *this, size_t hashbits, const void *salt); /** * Create an initialised state for BLAKE @@ -1166,7 +1166,7 @@ int libhashsum_init_blakeb_hasher(struct libhashsum_hasher *this, size_t hashbit * @since 1.0 */ LIBHASHSUM_1_NONNULL_ -int libhashsum_init_blake_hasher(struct libhashsum_hasher *this, size_t hashbits, const void *salt, size_t saltbytes); /* TODO test */ +int libhashsum_init_blake_hasher(struct libhashsum_hasher *this, size_t hashbits, const void *salt, size_t saltbytes); #endif diff --git a/libhashsum_get_algorithm_from_string.3 b/libhashsum_get_algorithm_from_string.3 index d7f338f..c039da6 100644 --- a/libhashsum_get_algorithm_from_string.3 +++ b/libhashsum_get_algorithm_from_string.3 @@ -315,7 +315,13 @@ The function validate the parameters for the hash function that may be places inside square brackets at the end of -.IR algorithm . +.IR algorithm , +now will it check anything in +.I algorithm +after the opening bracket, +however it will not recognise the hash function +if brackets are used but the hash function does +not have any parameters. .PP .I algorithm_out and diff --git a/libhashsum_get_algorithm_from_string.c b/libhashsum_get_algorithm_from_string.c index 96892e1..9740510 100644 --- a/libhashsum_get_algorithm_from_string.c +++ b/libhashsum_get_algorithm_from_string.c @@ -20,7 +20,9 @@ equiv(const char *a, const char *b) } if (!strncasecmp(a, "sum", 3)) a = &a[3]; - return !*a && (!*b || *b == '['); + if (*b == '[') + return *a == '[' || !*a; + return !*a && !*b; } diff --git a/libhashsum_init_hasher_from_string.c b/libhashsum_init_hasher_from_string.c index c4bf441..a1ee827 100644 --- a/libhashsum_init_hasher_from_string.c +++ b/libhashsum_init_hasher_from_string.c @@ -12,8 +12,9 @@ with_n(int (*initfunc)(struct libhashsum_hasher *, size_t), struct libhashsum_ha if (!p || *++p == ']') return initfunc(this, 0); - if (*p++ != 'n' && *p++ != 'N') + if (*p != 'n' && *p != 'N') goto einval; + p++; if (*p++ != '=' || !('1' <= *p && *p <= '9')) goto einval; @@ -62,8 +63,11 @@ with_rcnz(int (*initfunc)(struct libhashsum_hasher *, size_t, size_t, size_t, si size_t r = 0, c = 0, n = 0, z = 0; p = strchr(algorithm, '['); - if (!p || *++p == ']') + if (!p || *++p == ']') { + if (p && *p) + goto einval; return initfunc(this, 0, 0, 0, 0); + } for (;;) { if (*p == 'r' || *p == 'R') { @@ -111,16 +115,21 @@ with_salt(int (*initfunc)(struct libhashsum_hasher *, const void *), if (!p || *++p == ']') return initfunc(this, NULL); - if (*p++ != 's' && *p++ != 'S') + if (*p != 's' && *p != 'S') goto einval; - if (*p++ != 'a' && *p++ != 'A') + p++; + if (*p != 'a' && *p != 'A') goto einval; - if (*p++ != 'l' && *p++ != 'L') + p++; + if (*p != 'l' && *p != 'L') goto einval; - if (*p++ != 't' && *p++ != 'T') + p++; + if (*p != 't' && *p != 'T') goto einval; - if (*p++ != '=') + p++; + if (*p != '=') goto einval; + p++; if (p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) p = &p[2]; @@ -138,9 +147,10 @@ with_salt(int (*initfunc)(struct libhashsum_hasher *, const void *), break; } - a = (uint8_t)(((*p & 15) + (*p > '9' ? 9 : 0)) << 4); - b = (uint8_t)(((*p & 15) + (*p > '9' ? 9 : 0)) << 0); + a = (uint8_t)(((p[0] & 15) + (p[0] > '9' ? 9 : 0)) << 4); + b = (uint8_t)(((p[1] & 15) + (p[1] > '9' ? 9 : 0)) << 0); salt[salti++] = (uint8_t)(a | b); + p = &p[2]; } if (*p++ != ']' || *p) |