diff options
| author | Mattias Andrée <m@maandree.se> | 2026-05-19 20:09:27 +0200 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2026-05-19 20:09:27 +0200 |
| commit | 43ae14745c588f31c9ceb058645577cf2a5ce810 (patch) | |
| tree | 7ecade8d4e57d6d346123121731da3ef1c305fff /librecrypt_verify.c | |
| parent | Fix typo (diff) | |
| download | librecrypt-43ae14745c588f31c9ceb058645577cf2a5ce810.tar.gz librecrypt-43ae14745c588f31c9ceb058645577cf2a5ce810.tar.bz2 librecrypt-43ae14745c588f31c9ceb058645577cf2a5ce810.tar.xz | |
Add librecrypt_verify
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'librecrypt_verify.c')
| -rw-r--r-- | librecrypt_verify.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/librecrypt_verify.c b/librecrypt_verify.c new file mode 100644 index 0000000..18d8cd8 --- /dev/null +++ b/librecrypt_verify.c @@ -0,0 +1,71 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +int +librecrypt_verify(const char *phrase, size_t len, const char *settings, void *reserved) +{ + char *hash = NULL; + size_t size = 0u; + size_t off; + ssize_t n; + int ret, err; + + n = librecrypt_hash_(NULL, 0u, phrase, len, settings, reserved, ASCII_HASH); + if (n < 0) { + if (errno == EOVERFLOW) + errno = ENOMEM; + return -1; + } + + off = librecrypt_settings_prefix(hash, NULL, reserved); + if (hash[off] == '*') { + if ('0'> hash[off + 1u] || hash[off + 1u] > '9') { + errno = EINVAL; + return -1; + } + } + + size = (size_t)n + 128u; /* a little extra so the hasher don't need to allocate output scratch */ + hash = malloc(size); + if (!hash) + return -1; + + n = librecrypt_hash_(hash, size, phrase, len, settings, reserved, ASCII_HASH); + if (n < 0) { + err = errno; + librecrypt_wipe(hash, size); + free(hash); + if (err == EOVERFLOW) + err = ENOMEM; + errno = err; + return -1; + } + if ((size_t)n > size) + abort(); + + ret = librecrypt_equal(hash, &settings[off]); + librecrypt_wipe(hash, size); + free(hash); + return ret; +} + + +#else + + +int +main(void) +{ + SET_UP_ALARM(); + INIT_RESOURCE_TEST(); + + /* TODO test */ + + STOP_RESOURCE_TEST(); + return 0; +} + + +#endif |
