diff options
author | Mattias Andrée <maandree@kth.se> | 2023-07-06 07:20:03 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-07-06 07:20:03 +0200 |
commit | 0c3cf7819ceb7fe970f0fc240fa177b4e6dd5506 (patch) | |
tree | 29dbd39a897dbef2e391a095d39fe03b07b22d94 /common.c | |
parent | Remove -Wall -O3 from CFLAGS (unportable) and -s from LDFLAGS (diff) | |
download | blakesum-0c3cf7819ceb7fe970f0fc240fa177b4e6dd5506.tar.gz blakesum-0c3cf7819ceb7fe970f0fc240fa177b4e6dd5506.tar.bz2 blakesum-0c3cf7819ceb7fe970f0fc240fa177b4e6dd5506.tar.xz |
Add -S (salt) to bsum
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | common.c | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -226,3 +226,39 @@ hash_and_print(const char *path, size_t hashlen, int decode_hex, char newline, i free(hex); return 0; } + + +void +parse_salt(uint_least8_t *salt, const char *s, size_t required_length) +{ + size_t i; + + for (i = 0; i < required_length; i++, s = &s[2]) { + if (!s[0] || !s[1]) + goto too_short; + if (!isxdigit(s[0]) || !isxdigit(s[1])) + goto not_hexadecimal; + + salt[i] = (uint_least8_t)((((s[0] & 15) + (s[0] > '9' ? 9 : 0)) << 4) | + (s[1] & 15) + (s[1] > '9' ? 9 : 0)); + } + + if (*s) + goto too_long; + + return; + +not_hexadecimal: + fprintf(stderr, "%s: specified salt contains non-hexadecimal-digit character\n", argv0); + exit(2); + +too_short: + fprintf(stderr, "%s: specified salt is shorter than expected, should be %zu hexadecimal digits\n", + argv0, required_length * 2); + exit(2); + +too_long: + fprintf(stderr, "%s: specified salt is longer than expected, should be %zu hexadecimal digits\n", + argv0, required_length * 2); + exit(2); +} |