diff options
| author | Mattias Andrée <m@maandree.se> | 2026-05-16 12:11:02 +0200 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2026-05-16 12:11:02 +0200 |
| commit | 8ea4c3659a63fa4c5a1b85e2e6650ea2c3a4b91b (patch) | |
| tree | 827cd837787ad59964e9233b73629bb6c7c717a2 | |
| parent | m (diff) | |
| download | librecrypt-8ea4c3659a63fa4c5a1b85e2e6650ea2c3a4b91b.tar.gz librecrypt-8ea4c3659a63fa4c5a1b85e2e6650ea2c3a4b91b.tar.bz2 librecrypt-8ea4c3659a63fa4c5a1b85e2e6650ea2c3a4b91b.tar.xz | |
Add "reserved" parameter to a few more functions
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to '')
| -rw-r--r-- | librecrypt.h | 64 | ||||
| -rw-r--r-- | librecrypt_add_algorithm.c | 23 | ||||
| -rw-r--r-- | librecrypt_crypt.c | 2 | ||||
| -rw-r--r-- | librecrypt_get_encoding.3 | 14 | ||||
| -rw-r--r-- | librecrypt_get_encoding.c | 29 | ||||
| -rw-r--r-- | librecrypt_hash.c | 2 | ||||
| -rw-r--r-- | librecrypt_hash_.c | 7 | ||||
| -rw-r--r-- | librecrypt_hash_binary.c | 2 | ||||
| -rw-r--r-- | librecrypt_make_settings.3 | 13 | ||||
| -rw-r--r-- | librecrypt_make_settings.c | 53 | ||||
| -rw-r--r-- | librecrypt_realise_salts.3 | 13 | ||||
| -rw-r--r-- | librecrypt_realise_salts.c | 50 | ||||
| -rw-r--r-- | librecrypt_settings_prefix.3 | 7 | ||||
| -rw-r--r-- | librecrypt_settings_prefix.c | 16 | ||||
| -rw-r--r-- | librecrypt_test_supported.3 | 8 | ||||
| -rw-r--r-- | librecrypt_test_supported.c | 22 |
16 files changed, 217 insertions, 108 deletions
diff --git a/librecrypt.h b/librecrypt.h index 48d2ff7..ee94c40 100644 --- a/librecrypt.h +++ b/librecrypt.h @@ -81,6 +81,7 @@ * return `strlen(hash)` if `hash` is properly * formatted) the value 0 is stored, indicating * that a default hash size shall be used + * @param reserved Reserved for future use, should be `NULL` * @return The number of bytes, from the front of `hash`, * that make up the algorithm configuration; may be 0 * @@ -92,7 +93,7 @@ * @since 1.0 */ LIBRECRYPT_READ_STR__(1) LIBRECRYPT_NONNULL_1__ LIBRECRYPT_WUR__ LIBRECRYPT_PURE__ -size_t librecrypt_settings_prefix(const char *hash, size_t *hashsize_out); +size_t librecrypt_settings_prefix(const char *hash, size_t *hashsize_out, void *reserved); /** @@ -359,6 +360,7 @@ ssize_t librecrypt_decode(void *out_buffer, size_t size, const char *ascii, size * @param decoding 0 if the returned pointer should be useful for, * `librecrypt_encode`, otherwise it will be useful * for `librecrypt_decode` + * @param reserved Reserved for future use, should be `NULL` * @return If `decoding` is 0: * the encoding alphabet, consisting of 64 characters, * repeated 4 times; @@ -369,6 +371,8 @@ ssize_t librecrypt_decode(void *out_buffer, size_t size, const char *ascii, size * and any other character to the value `0xFF`; * but `NULL` on failure * + * @throws EINVAL `reserved` is non-`NULL` (this case will be removed + * once `reserved` as being used by the library) * @throws ENOSYS The last algorithm in `settings` is not recognised * or was disabled at compile-time * @@ -390,9 +394,10 @@ ssize_t librecrypt_decode(void *out_buffer, size_t size, const char *ascii, size * * @since 1.0 */ -LIBRECRYPT_READ_STR__(1) LIBRECRYPT_NONNULL__ LIBRECRYPT_WUR__ +LIBRECRYPT_READ_STR__(1) LIBRECRYPT_NONNULL_I__(1) LIBRECRYPT_NONNULL_I__(3) +LIBRECRYPT_NONNULL_I__(4) LIBRECRYPT_WUR__ const void *librecrypt_get_encoding(const char *settings, size_t len, char *pad_out, - int *strict_pad_out, int decoding); + int *strict_pad_out, int decoding, void *reserved); /** @@ -493,8 +498,11 @@ librecrypt_equal(const char *a, const char *b) * the number of generated bytes, or -1 on failure * @param user Passed as the third argument to `*rng` for user-defined * purposes, ignored if `rng` is `NULL` + * @param reserved Reserved for future use, should be `NULL` * @return The number of bytes that would have been written to `out_buffer`, * if `size` was sufficiently large, -1 on failure + * @throws EINVAL `reserved` is non-`NULL` (this case will be removed + * once `reserved` as being used by the library) * @throws ERANGE The expected return value is greater than {SSIZE_MAX} * @throws ENOSYS `settings` contain an algorithm that is not recognised * or was disabled at compile-time @@ -531,7 +539,8 @@ librecrypt_equal(const char *a, const char *b) */ LIBRECRYPT_WRITE_MEM__(1, 2) LIBRECRYPT_READ_STR__(3) LIBRECRYPT_WUR__ ssize_t librecrypt_realise_salts(char *restrict out_buffer, size_t size, const char *settings, - ssize_t (*rng)(void *out, size_t n, void *user), void *user); + ssize_t (*rng)(void *out, size_t n, void *user), void *user, + void *reserved); /** @@ -563,9 +572,12 @@ ssize_t librecrypt_realise_salts(char *restrict out_buffer, size_t size, const c * ignored if `gensalt` is zero * @param user Passed as the third argument to `*rng` for user-defined * purposes, ignored if `rng` is `NULL` or if `gensalt` is zero + * @param reserved Reserved for future use, should be `NULL` * @return The number of bytes that would have been written to * `out_buffer`, if `size` was sufficiently large, -1 on failure * + * @throws EINVAL `reserved` is non-`NULL` (this case will be removed + * once `reserved` as being used by the library) * @throws EINVAL `algorithm` represents a chain of algorithms * @throws ENOSYS `algorithm` represents an algorithm that is not * recognised or was disabled at compile-time @@ -599,7 +611,8 @@ ssize_t librecrypt_realise_salts(char *restrict out_buffer, size_t size, const c LIBRECRYPT_WRITE_MEM__(1, 2) LIBRECRYPT_READ_STR__(3) LIBRECRYPT_WUR__ ssize_t librecrypt_make_settings(char *out_buffer, size_t size, const char *algorithm, size_t memcost, uintmax_t timecost, int gensalt, - ssize_t (*rng)(void *out, size_t n, void *user), void *user); + ssize_t (*rng)(void *out, size_t n, void *user), void *user, + void *reserved); /** @@ -773,30 +786,31 @@ ssize_t librecrypt_crypt(char *restrict out_buffer, size_t size, const char *phr * for the given input, and that each algorithm * configuration is valid * - * @param phrase The password to hash, may contain NUL bytes; - * may be `NULL` even if `len` is non-zero - * @param len The number of bytes in `phrase`, if `phrase` is `NULL`, - * the function will check that the specified number of - * bytes is supported as well as any byte sequence unless - * `text` is non-zero - * @param text Assume the password is valid UTF-8 text (without NUL bytes) - * iff non-zero; ignored if `phrase` is non-`NULL` - * @param settings The password hash string; it is allowed for algorithm - * tuning parameters, and the hash result, to be omitted - * @return 1 if the configuration is supported, 0 otherwise, which - * means part of the string is invalid: the algorithm does - * not exist, supported was disabled at compile-time, or an - * algorithm it does not support the output of the previous - * algorithm in the chain as input; additionally a small - * number of legacy algorithms require the passphrase to - * be within a specific length range or be valid text, - * if the selected word does not match such constraints - * for the first algorithm in the chain, 0 is returned + * @param phrase The password to hash, may contain NUL bytes; + * may be `NULL` even if `len` is non-zero + * @param len The number of bytes in `phrase`, if `phrase` is `NULL`, + * the function will check that the specified number of + * bytes is supported as well as any byte sequence unless + * `text` is non-zero + * @param text Assume the password is valid UTF-8 text (without NUL bytes) + * iff non-zero; ignored if `phrase` is non-`NULL` + * @param settings The password hash string; it is allowed for algorithm + * tuning parameters, and the hash result, to be omitted + * @param reserved Reserved for future use, should be `NULL` + * @return 1 if the configuration is supported, 0 otherwise, which + * means part of the string is invalid: the algorithm does + * not exist, supported was disabled at compile-time, or an + * algorithm it does not support the output of the previous + * algorithm in the chain as input; additionally a small + * number of legacy algorithms require the passphrase to + * be within a specific length range or be valid text, + * if the selected word does not match such constraints + * for the first algorithm in the chain, 0 is returned * * This function is MT-Safe and AS-Safe */ LIBRECRYPT_READ_STR__(4) LIBRECRYPT_NONNULL_I__(4) LIBRECRYPT_WUR__ -int librecrypt_test_supported(const char *phrase, size_t len, int text, const char *settings); +int librecrypt_test_supported(const char *phrase, size_t len, int text, const char *settings, void *reserved); /** diff --git a/librecrypt_add_algorithm.c b/librecrypt_add_algorithm.c index ad21ec4..5501f8d 100644 --- a/librecrypt_add_algorithm.c +++ b/librecrypt_add_algorithm.c @@ -18,6 +18,12 @@ librecrypt_add_algorithm(char *out_buffer, size_t size, const char *augend, cons const unsigned char *lut; ssize_t r; + /* Ensure the reserved parameter is NULL */ + if (reserved != NULL) { + errno = EINVAL; + return -1; + } + /* Reserve space for NUL-termination */ if (size) { nul_term = 1; @@ -27,8 +33,8 @@ librecrypt_add_algorithm(char *out_buffer, size_t size, const char *augend, cons } /* Get the prefix and hash size in `augend` and `augment` */ - prefix1 = librecrypt_settings_prefix(augend, &hashsize1); - prefix2 = librecrypt_settings_prefix(augment, &hashsize2); + prefix1 = librecrypt_settings_prefix(augend, &hashsize1, reserved); + prefix2 = librecrypt_settings_prefix(augment, &hashsize2, reserved); /* If `augend` specifies a hash size rather than a hash, include it as the prefix */ if (augend[prefix1] == '*') { @@ -122,7 +128,7 @@ librecrypt_add_algorithm(char *out_buffer, size_t size, const char *augend, cons len = strlen(&augend[prefix1]); /* Get encoding information */ - lut = librecrypt_get_encoding(augend, prefix1 + len, &pad, &strict_pad, 1); + lut = librecrypt_get_encoding(augend, prefix1 + len, &pad, &strict_pad, 1, reserved); if (!lut) return -1; @@ -199,6 +205,7 @@ main(void) #define HASH1 "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTYVWXYZ/+" #define ASTRA "*48" + char reserved[1] = {0}; char buf[1024], phrase[sizeof(buf)], expected[sizeof(buf)], pad; size_t i, min, phraselen; int strict_pad; @@ -263,8 +270,16 @@ main(void) }\ } while (0) + errno = 0; + EXPECT(librecrypt_add_algorithm(NULL, 0u, "", "", reserved) == -1); + EXPECT(errno == EINVAL); + #if defined(SUPPORT_ARGON2I) && defined(SUPPORT_ARGON2D) + errno = 0; + EXPECT(librecrypt_add_algorithm(NULL, 0u, "$argon2d$v=16$m=8,t=1,p=1$*16$*40", "$argon2d$v=16$m=8,t=1,p=1$*16$*40", reserved) == -1); + EXPECT(errno == EINVAL); + CHECK("$argon2d$v=16$m=8,t=1,p=1$*16$*40", "$argon2i$v=19$m=16,t=4,p=2$*18$*50", "$argon2d$v=16$m=8,t=1,p=1$*16$*40>" "$argon2i$v=19$m=16,t=4,p=2$*18$*50"); @@ -321,7 +336,7 @@ main(void) EXPECT(librecrypt_add_algorithm(NULL, 0u, "$argon2d$m=8,t=1,p=1$"ASTRA"$"HASH1, "$argon2i$m=8,t=4,p=1$"SALT2"$", NULL) > -2); - lut = librecrypt_get_encoding("$argon2d$", sizeof("$argon2d$") - 1u, &pad, &strict_pad, 1); + lut = librecrypt_get_encoding("$argon2d$", sizeof("$argon2d$") - 1u, &pad, &strict_pad, 1, NULL); assert(lut); r = librecrypt_decode(phrase, sizeof(phrase), HASH1, strlen(HASH1), lut, pad, strict_pad); assert(r > 0 && (size_t)r <= sizeof(phrase)); diff --git a/librecrypt_crypt.c b/librecrypt_crypt.c index 893c96f..c3f441b 100644 --- a/librecrypt_crypt.c +++ b/librecrypt_crypt.c @@ -56,7 +56,7 @@ check(const char *phrase, const char *settings, const char *chain, size_t chain_ EXPECT(librecrypt_crypt(buf, 0u, phrase, len, settings, NULL) == (ssize_t)hashlen); EXPECT(librecrypt_crypt(NULL, 0u, phrase, len, settings, NULL) == (ssize_t)hashlen); - lut = librecrypt_get_encoding(settings, strlen(settings), &pad, &strict_pad, 1); + lut = librecrypt_get_encoding(settings, strlen(settings), &pad, &strict_pad, 1, NULL); assert(lut); r = librecrypt_decode(expected, sizeof(expected), &hash[hash_prefix], hashlen - hash_prefix, lut, pad, strict_pad); assert(r > 0 && (size_t)r <= sizeof(expected)); diff --git a/librecrypt_get_encoding.3 b/librecrypt_get_encoding.3 index e9f7e83..2c0b827 100644 --- a/librecrypt_get_encoding.3 +++ b/librecrypt_get_encoding.3 @@ -6,8 +6,8 @@ librecrypt_get_encoding - Get encoding alphabet for the last algorithm in a chai .nf #include <librecrypt.h> -const void *\fBlibrecrypt_get_encoding\fP(const char *\fIsettings\fP, size_t \fIlen\fP, - char *\fIpad_out\fP, int *\fIstrict_pad_out\fP, int \fIdecoding\fP); +const void *\fBlibrecrypt_get_encoding\fP(const char *\fIsettings\fP, size_t \fIlen\fP, char *\fIpad_out\fP, + int *\fIstrict_pad_out\fP, int \fIdecoding\fP, void *\fIreserved\fP); .fi .PP Link with @@ -44,6 +44,11 @@ character) to its value in the encoding alphabet and any other character to .BR 0xFFu . .PP +The +.I reserved +parameter is reserved for future use and should be +.IR NULL . +.PP On success, .IR *pad_out is set to the padding character, or to the @@ -77,6 +82,11 @@ The .BR librecrypt_get_encoding () function will fail if: .TP +.B EINVAL +.I reserved +is not +.IR NULL . +.TP .B ENOSYS The last algorithm in .I settings diff --git a/librecrypt_get_encoding.c b/librecrypt_get_encoding.c index 8dc1c0a..a977178 100644 --- a/librecrypt_get_encoding.c +++ b/librecrypt_get_encoding.c @@ -4,11 +4,17 @@ const void * -librecrypt_get_encoding(const char *settings, size_t len, char *pad_out, int *strict_pad_out, int decoding) +librecrypt_get_encoding(const char *settings, size_t len, char *pad_out, int *strict_pad_out, int decoding, void *reserved) { size_t i, start = 0u; const struct algorithm *algo; + /* Ensure the reserved parameter is NULL */ + if (reserved != NULL) { + errno = EINVAL; + return NULL; + } + /* Find last algorithm in the chain */ for (i = 0u; i < len; i++) if (settings[i] == LIBRECRYPT_ALGORITHM_LINK_DELIMITER) @@ -72,7 +78,7 @@ check_decoding_lut(const unsigned char *lut, const char *alpha) do {\ pad = (char)~(PAD);\ strict_pad = -1;\ - elut = librecrypt_get_encoding(PREFIX, sizeof(PREFIX) - 1u, &pad, &strict_pad, 0);\ + elut = librecrypt_get_encoding(PREFIX, sizeof(PREFIX) - 1u, &pad, &strict_pad, 0, NULL);\ EXPECT(elut != NULL);\ EXPECT(pad == (PAD));\ EXPECT(strict_pad == (STRICT_PAD));\ @@ -80,7 +86,7 @@ check_decoding_lut(const unsigned char *lut, const char *alpha) \ pad = (char)~(PAD);\ strict_pad = -1;\ - dlut = librecrypt_get_encoding(PREFIX, sizeof(PREFIX) - 1u, &pad, &strict_pad, 1);\ + dlut = librecrypt_get_encoding(PREFIX, sizeof(PREFIX) - 1u, &pad, &strict_pad, 1, NULL);\ EXPECT(dlut != NULL);\ EXPECT(pad == (PAD));\ EXPECT(strict_pad == (STRICT_PAD));\ @@ -88,7 +94,7 @@ check_decoding_lut(const unsigned char *lut, const char *alpha) \ pad = (char)~(PAD);\ strict_pad = -1;\ - elut = librecrypt_get_encoding(NSA">"PREFIX, sizeof(NSA">"PREFIX) - 1u, &pad, &strict_pad, 0);\ + elut = librecrypt_get_encoding(NSA">"PREFIX, sizeof(NSA">"PREFIX) - 1u, &pad, &strict_pad, 0, NULL);\ EXPECT(elut != NULL);\ EXPECT(pad == (PAD));\ EXPECT(strict_pad == (STRICT_PAD));\ @@ -104,6 +110,7 @@ check_decoding_lut(const unsigned char *lut, const char *alpha) int main(void) { + char reserved[1] = {0}; const char *elut; const unsigned char *dlut; char pad; @@ -113,19 +120,23 @@ main(void) INIT_RESOURCE_TEST(); errno = 0; - EXPECT(librecrypt_get_encoding(NSA, 1u, &pad, &strict_pad, 0) == NULL); + EXPECT(librecrypt_get_encoding("$argon2i$", sizeof("$argon2i$") - 1u, &pad, &strict_pad, 0, reserved) == NULL); + EXPECT(errno == EINVAL); + + errno = 0; + EXPECT(librecrypt_get_encoding(NSA, sizeof(NSA) - 1u, &pad, &strict_pad, 0, NULL) == NULL); EXPECT(errno == ENOSYS); errno = 0; - EXPECT(librecrypt_get_encoding(NSA, 1u, &pad, &strict_pad, 1) == NULL); + EXPECT(librecrypt_get_encoding(NSA, sizeof(NSA) - 1u, &pad, &strict_pad, 1, NULL) == NULL); EXPECT(errno == ENOSYS); errno = 0; - EXPECT(librecrypt_get_encoding(">"NSA, 1u, &pad, &strict_pad, 0) == NULL); + EXPECT(librecrypt_get_encoding(">"NSA, sizeof(">"NSA) - 1u, &pad, &strict_pad, 0, NULL) == NULL); EXPECT(errno == ENOSYS); errno = 0; - EXPECT(librecrypt_get_encoding(">"NSA, 1u, &pad, &strict_pad, 1) == NULL); + EXPECT(librecrypt_get_encoding(">"NSA, sizeof(">"NSA) - 1u, &pad, &strict_pad, 1, NULL) == NULL); EXPECT(errno == ENOSYS); IF__argon2i__SUPPORTED(CHECK("$argon2i$", UPPER LOWER DIGIT "+/", '=', 0);) @@ -155,7 +166,7 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) decoding = (int)data[0u] & 1; settings = (const void *)&data[1u]; size -= 1u; - discarded_return_value = librecrypt_get_encoding(settings, size, &(char){0}, &(int){0}, decoding); + discarded_return_value = librecrypt_get_encoding(settings, size, &(char){0}, &(int){0}, decoding, NULL); return 0; } diff --git a/librecrypt_hash.c b/librecrypt_hash.c index 050e0c1..e00c35b 100644 --- a/librecrypt_hash.c +++ b/librecrypt_hash.c @@ -58,7 +58,7 @@ check(const char *phrase, const char *settings, const char *chain, const char *h CANARY_X_CHECK(buf, 0u, 0u); EXPECT(librecrypt_hash(NULL, 0u, phrase, len, settings, NULL) == (ssize_t)hashlen); - lut = librecrypt_get_encoding(settings, strlen(settings), &pad, &strict_pad, 1); + lut = librecrypt_get_encoding(settings, strlen(settings), &pad, &strict_pad, 1, NULL); assert(lut); r = librecrypt_decode(expected, sizeof(expected), hash, strlen(hash), lut, pad, strict_pad); assert(r > 0 && (size_t)r <= sizeof(expected)); diff --git a/librecrypt_hash_.c b/librecrypt_hash_.c index cc1ae93..95d8aea 100644 --- a/librecrypt_hash_.c +++ b/librecrypt_hash_.c @@ -80,7 +80,7 @@ librecrypt_hash_(char *restrict out_buffer, size_t size, const char *phrase, siz rng = &zero_generator; /* Generate the salts */ - r_len = librecrypt_realise_salts(out_buffer, size, settings, rng, NULL); + r_len = librecrypt_realise_salts(out_buffer, size, settings, rng, NULL, reserved); if (r_len < 0) { if (errno == ERANGE) { errno = ENOMEM; @@ -91,7 +91,7 @@ librecrypt_hash_(char *restrict out_buffer, size_t size, const char *phrase, siz settings_scratch = malloc((size_t)r_len + 1u); if (!settings_scratch) return -1; - if (librecrypt_realise_salts(settings_scratch, (size_t)r_len + 1u, settings, rng, NULL) != r_len) + if (librecrypt_realise_salts(settings_scratch, (size_t)r_len + 1u, settings, rng, NULL, reserved) != r_len) abort(); /* $covered$ (impossible) */ settings = settings_scratch; } @@ -378,12 +378,13 @@ main(void) char sbuf[160]; size_t i, n; ssize_t r, r1, r1b, r1c, r2, r3; + char reserved[1] = {0}; SET_UP_ALARM(); INIT_RESOURCE_TEST(); errno = 0; - EXPECT(librecrypt_hash_(NULL, 0u, NULL, 0u, "$~no~such~algorithm~$", &(char){0}, ASCII_CRYPT) == -1); + EXPECT(librecrypt_hash_(NULL, 0u, NULL, 0u, "$~no~such~algorithm~$", reserved, ASCII_CRYPT) == -1); EXPECT(errno == EINVAL); errno = 0; diff --git a/librecrypt_hash_binary.c b/librecrypt_hash_binary.c index 9987758..7efb81e 100644 --- a/librecrypt_hash_binary.c +++ b/librecrypt_hash_binary.c @@ -25,7 +25,7 @@ check(const char *phrase, const char *settings, const char *chain, const char *h assert(hashlen <= sizeof(buf)); assert(hashlen <= sizeof(expected)); - lut = librecrypt_get_encoding(settings, strlen(settings), &pad, &strict_pad, 1); + lut = librecrypt_get_encoding(settings, strlen(settings), &pad, &strict_pad, 1, NULL); assert(lut); r = librecrypt_decode(expected, sizeof(expected), hash, strlen(hash), lut, pad, strict_pad); diff --git a/librecrypt_make_settings.3 b/librecrypt_make_settings.3 index f742df6..ca31417 100644 --- a/librecrypt_make_settings.3 +++ b/librecrypt_make_settings.3 @@ -8,7 +8,8 @@ librecrypt_make_settings - Generate a password hash settings string ssize_t \fBlibrecrypt_make_settings\fP(char *\fIout_buffer\fP, size_t \fIsize\fP, const char *\fIalgorithm\fP, size_t \fImemcost\fP, uintmax_t \fItimecost\fP, int \fIgensalt\fP, - ssize_t (*\fIrng\fP)(void *\fIout\fP, size_t \fIn\fP, void *\fIuser\fP), void *\fIuser\fP); + ssize_t (*\fIrng\fP)(void *\fIout\fP, size_t \fIn\fP, void *\fIuser\fP), + void *\fIuser\fP, void *\fIreserved\fP); .fi .PP Link with @@ -76,6 +77,11 @@ with the same name, as is and may be used by .IR *rng for user-defined purposes. .PP +The +.I reserved +parameter is reserved for future use and should be +.IR NULL . +.PP On successful completion, if .I size is positive, the output is null byte terminated @@ -114,6 +120,11 @@ The function will fail if: .TP .B EINVAL +.I reserved +is not +.IR NULL . +.TP +.B EINVAL .I algorithm represents a chain of algorithms. .TP diff --git a/librecrypt_make_settings.c b/librecrypt_make_settings.c index 5bdc6f5..dc068e7 100644 --- a/librecrypt_make_settings.c +++ b/librecrypt_make_settings.c @@ -5,10 +5,16 @@ ssize_t librecrypt_make_settings(char *out_buffer, size_t size, const char *algorithm, size_t memcost, uintmax_t timecost, - int gensalt, ssize_t (*rng)(void *out, size_t n, void *user), void *user) + int gensalt, ssize_t (*rng)(void *out, size_t n, void *user), void *user, void *reserved) { const struct algorithm *algo; + /* Ensure the reserved parameter is NULL */ + if (reserved != NULL) { + errno = EINVAL; + return -1; + } + /* Get algorithm */ if (!algorithm) { /* Select best algorithm if `NULL` is specified */ @@ -75,30 +81,35 @@ main(void) int any_supported = 0; int any_salted = 0; ssize_t r; + char reserved[1] = {0}; SET_UP_ALARM(); INIT_RESOURCE_TEST(); errno = 0; - EXPECT(librecrypt_make_settings(NULL, 0u, ">", 0u, 0u, 0, NULL, NULL) == -1); + EXPECT(librecrypt_make_settings(NULL, 0u, ">", 0u, 0u, 0, NULL, NULL, NULL) == -1); EXPECT(errno == EINVAL); errno = 0; - EXPECT(librecrypt_make_settings(NULL, 0u, "$argon2id$>", 0u, 0u, 0, NULL, NULL) == -1); + EXPECT(librecrypt_make_settings(NULL, 0u, "$argon2id$>", 0u, 0u, 0, NULL, NULL, NULL) == -1); EXPECT(errno == EINVAL); errno = 0; - EXPECT(librecrypt_make_settings(NULL, 0u, ">$argon2id$", 0u, 0u, 0, NULL, NULL) == -1); + EXPECT(librecrypt_make_settings(NULL, 0u, ">$argon2id$", 0u, 0u, 0, NULL, NULL, NULL) == -1); EXPECT(errno == EINVAL); errno = 0; - EXPECT(librecrypt_make_settings(NULL, 0u, "$argon2id$>$argon2id$", 0u, 0u, 0, NULL, NULL) == -1); + EXPECT(librecrypt_make_settings(NULL, 0u, "$argon2id$>$argon2id$", 0u, 0u, 0, NULL, NULL, NULL) == -1); EXPECT(errno == EINVAL); errno = 0; - EXPECT(librecrypt_make_settings(NULL, 0u, "$~no~such~algorithm~$", 0u, 0u, 0, NULL, NULL) == -1); + EXPECT(librecrypt_make_settings(NULL, 0u, "$~no~such~algorithm~$", 0u, 0u, 0, NULL, NULL, NULL) == -1); EXPECT(errno == ENOSYS); #if defined(SUPPORT_ARGON2I) + errno = 0; + EXPECT(librecrypt_make_settings(NULL, 0u, "$argon2id$", 0u, 0u, 0, NULL, NULL, reserved) == -1); + EXPECT(errno == EINVAL); + saltbyte = 0u; CANARY_FILL(buf); - r = librecrypt_make_settings(buf, sizeof(buf), "$argon2i$", 8192u << 10, (uintmax_t)81920u, 1, &saltgen, &saltbyte); + r = librecrypt_make_settings(buf, sizeof(buf), "$argon2i$", 8192u << 10, (uintmax_t)81920u, 1, &saltgen, &saltbyte, NULL); EXPECT(r > 0 && (size_t)r < sizeof(buf)); EXPECT(!buf[r] && (size_t)r == strlen(buf)); EXPECT(!strcmp(buf, "$argon2i$v=19$m=8192,t=10,p=1$AAAAAAAAAAAAAAAAAAAAAA$*32")); @@ -110,7 +121,7 @@ main(void) #if defined(SUPPORT_ARGON2D) saltbyte = 0u; CANARY_FILL(buf); - r = librecrypt_make_settings(buf, sizeof(buf), "$argon2d$", 8192u << 10, (uintmax_t)81920u, 1, &saltgen, &saltbyte); + r = librecrypt_make_settings(buf, sizeof(buf), "$argon2d$", 8192u << 10, (uintmax_t)81920u, 1, &saltgen, &saltbyte, NULL); EXPECT(r > 0 && (size_t)r < sizeof(buf)); EXPECT(!buf[r] && (size_t)r == strlen(buf)); EXPECT(!strcmp(buf, "$argon2d$v=19$m=8192,t=10,p=1$AAAAAAAAAAAAAAAAAAAAAA$*32")); @@ -122,7 +133,7 @@ main(void) #if defined(SUPPORT_ARGON2ID) saltbyte = 0u; CANARY_FILL(buf); - r = librecrypt_make_settings(buf, sizeof(buf), "$argon2id$", 8192u << 10, (uintmax_t)81920u, 1, &saltgen, &saltbyte); + r = librecrypt_make_settings(buf, sizeof(buf), "$argon2id$", 8192u << 10, (uintmax_t)81920u, 1, &saltgen, &saltbyte, NULL); EXPECT(r > 0 && (size_t)r < sizeof(buf)); EXPECT(!buf[r] && (size_t)r == strlen(buf)); EXPECT(!strcmp(buf, "$argon2id$v=19$m=8192,t=10,p=1$AAAAAAAAAAAAAAAAAAAAAA$*32")); @@ -134,7 +145,7 @@ main(void) #if defined(SUPPORT_ARGON2DS) saltbyte = 0u; CANARY_FILL(buf); - r = librecrypt_make_settings(buf, sizeof(buf), "$argon2ds$", 8192u << 10, (uintmax_t)81920u, 1, &saltgen, &saltbyte); + r = librecrypt_make_settings(buf, sizeof(buf), "$argon2ds$", 8192u << 10, (uintmax_t)81920u, 1, &saltgen, &saltbyte, NULL); EXPECT(r > 0 && (size_t)r < sizeof(buf)); EXPECT(!buf[r] && (size_t)r == strlen(buf)); EXPECT(!strcmp(buf, "$argon2ds$v=19$m=8192,t=10,p=1$AAAAAAAAAAAAAAAAAAAAAA$*32")); @@ -144,23 +155,23 @@ main(void) #endif if (any_supported) { - EXPECT(librecrypt_make_settings(NULL, 0u, NULL, 0u, 0u, 0, NULL, NULL) > 0); - EXPECT(librecrypt_make_settings(buf, sizeof(buf), NULL, 0u, 0u, 0, NULL, NULL) > 0); + EXPECT(librecrypt_make_settings(NULL, 0u, NULL, 0u, 0u, 0, NULL, NULL, NULL) > 0); + EXPECT(librecrypt_make_settings(buf, sizeof(buf), NULL, 0u, 0u, 0, NULL, NULL, NULL) > 0); if (any_salted) { errno = 0; - EXPECT(librecrypt_make_settings(buf, sizeof(buf), NULL, 0u, 0u, 1, &saltfail, NULL) == -1); + EXPECT(librecrypt_make_settings(buf, sizeof(buf), NULL, 0u, 0u, 1, &saltfail, NULL, NULL) == -1); EXPECT(errno == EDOM); } else { - EXPECT(librecrypt_make_settings(buf, sizeof(buf), NULL, 0u, 0u, 1, &saltfail, NULL) > 0); + EXPECT(librecrypt_make_settings(buf, sizeof(buf), NULL, 0u, 0u, 1, &saltfail, NULL, NULL) > 0); } CANARY_FILL(buf); CANARY_FILL(buf2); - r = librecrypt_make_settings(buf, sizeof(buf), NULL, 0u, 0u, 0, &saltfail, NULL); + r = librecrypt_make_settings(buf, sizeof(buf), NULL, 0u, 0u, 0, &saltfail, NULL, NULL); EXPECT(r > 0 && (size_t)r < sizeof(buf)); EXPECT(!buf[r] && (size_t)r == strlen(buf)); - EXPECT(librecrypt_make_settings(buf2, sizeof(buf2), NULL, 0u, 0u, 0, &saltfail, NULL) == r); + EXPECT(librecrypt_make_settings(buf2, sizeof(buf2), NULL, 0u, 0u, 0, &saltfail, NULL, NULL) == r); EXPECT(!buf2[r] && (size_t)r == strlen(buf2)); EXPECT(!strcmp(buf, buf2)); CANARY_CHECK(buf, (size_t)r + 1u); @@ -168,10 +179,10 @@ main(void) CANARY_FILL(buf); CANARY_FILL(buf2); - r = librecrypt_make_settings(buf, sizeof(buf), NULL, 0u, 0u, 0, NULL, NULL); + r = librecrypt_make_settings(buf, sizeof(buf), NULL, 0u, 0u, 0, NULL, NULL, NULL); EXPECT(r > 0 && (size_t)r < sizeof(buf)); EXPECT(!buf[r] && (size_t)r == strlen(buf)); - EXPECT(librecrypt_make_settings(buf2, sizeof(buf2), NULL, 0u, 0u, 0, NULL, NULL) == r); + EXPECT(librecrypt_make_settings(buf2, sizeof(buf2), NULL, 0u, 0u, 0, NULL, NULL, NULL) == r); EXPECT(!buf2[r] && (size_t)r == strlen(buf2)); EXPECT(!strcmp(buf, buf2)); CANARY_CHECK(buf, (size_t)r + 1u); @@ -179,17 +190,17 @@ main(void) CANARY_FILL(buf); CANARY_FILL(buf2); - r = librecrypt_make_settings(buf, sizeof(buf), NULL, 0u, 0u, 1, NULL, NULL); + r = librecrypt_make_settings(buf, sizeof(buf), NULL, 0u, 0u, 1, NULL, NULL, NULL); EXPECT(r > 0 && (size_t)r < sizeof(buf)); EXPECT(!buf[r] && (size_t)r == strlen(buf)); - EXPECT(librecrypt_make_settings(buf2, sizeof(buf2), NULL, 0u, 0u, 1, NULL, NULL) == r); + EXPECT(librecrypt_make_settings(buf2, sizeof(buf2), NULL, 0u, 0u, 1, NULL, NULL, NULL) == r); EXPECT(!buf2[r] && (size_t)r == strlen(buf2)); EXPECT(strcmp(buf, buf2)); CANARY_CHECK(buf, (size_t)r + 1u); CANARY_CHECK(buf2, (size_t)r + 1u); } else { errno = 0; - EXPECT(librecrypt_make_settings(NULL, 0u, NULL, 0u, 0u, 0, NULL, NULL) == -1); + EXPECT(librecrypt_make_settings(NULL, 0u, NULL, 0u, 0u, 0, NULL, NULL, NULL) == -1); EXPECT(errno == ENOSYS); } diff --git a/librecrypt_realise_salts.3 b/librecrypt_realise_salts.3 index 0e314e2..7900a4f 100644 --- a/librecrypt_realise_salts.3 +++ b/librecrypt_realise_salts.3 @@ -7,7 +7,8 @@ librecrypt_realise_salts - Realise asterisk-encoded random salts in a settings s #include <librecrypt.h> ssize_t \fBlibrecrypt_realise_salts\fP(char *restrict \fIout_buffer\fP, size_t \fIsize\fP, const char *\fIsettings\fP, - ssize_t (*\fIrng\fP)(void *\fIout\fP, size_t \fIn\fP, void *\fIuser\fP), void *\fIuser\fP); + ssize_t (*\fIrng\fP)(void *\fIout\fP, size_t \fIn\fP, void *\fIuser\fP), void *\fIuser\fP, + void *\fIreserved\fP); .fi .PP Link with @@ -63,6 +64,11 @@ bytes (inclusively), write them to the front of and return the number of generated bytes, or -1 on failure. .PP +The +.I reserved +parameter is reserved for future use and should be +.IR NULL . +.PP On successful completion, if .I size is positive, the output is @@ -103,6 +109,11 @@ The .BR librecrypt_realise_salts () function will fail if: .TP +.B EINVAL +.I reserved +is not +.IR NULL . +.TP .B ERANGE The expected return value is greater than {SSIZE_MAX}. .TP diff --git a/librecrypt_realise_salts.c b/librecrypt_realise_salts.c index 62bb2c3..eca3c4a 100644 --- a/librecrypt_realise_salts.c +++ b/librecrypt_realise_salts.c @@ -5,7 +5,7 @@ ssize_t librecrypt_realise_salts(char *restrict out_buffer, size_t size, const char *settings, - ssize_t (*rng)(void *out, size_t n, void *user), void *user) + ssize_t (*rng)(void *out, size_t n, void *user), void *user, void *reserved) { const char *lut; char pad; @@ -13,6 +13,12 @@ librecrypt_realise_salts(char *restrict out_buffer, size_t size, const char *set size_t i, min, nasterisks, prefix, ret = 0u; size_t count, digit, q, r, left, mid, right; + /* Ensure the reserved parameter is NULL */ + if (reserved != NULL) { + errno = EINVAL; + return -1; + } + /* If we are doing output, it should be NUL-terminated */ if (size) { nul_term = 1; @@ -40,7 +46,7 @@ librecrypt_realise_salts(char *restrict out_buffer, size_t size, const char *set } /* Get binary data encoding format */ - lut = librecrypt_get_encoding(settings, prefix, &pad, &strict_pad, 0); + lut = librecrypt_get_encoding(settings, prefix, &pad, &strict_pad, 0, reserved); if (!lut) return -1; pad = strict_pad ? pad : '\0'; @@ -203,15 +209,16 @@ main(void) char buf[1024], buf2[1024], conf[128]; size_t i; int r; + char reserved[1] = {0}; SET_UP_ALARM(); INIT_RESOURCE_TEST(); errno = 0; - EXPECT(librecrypt_realise_salts(NULL, 0u, "$~no~such~algorithm~$", NULL, NULL) == -1); + EXPECT(librecrypt_realise_salts(NULL, 0u, "$~no~such~algorithm~$", NULL, NULL, NULL) == -1); EXPECT(errno == ENOSYS); - EXPECT(librecrypt_realise_salts(NULL, 0u, "", NULL, NULL) == 0); + EXPECT(librecrypt_realise_salts(NULL, 0u, "", NULL, NULL, NULL) == 0); #if defined(SUPPORT_ARGON2ID) # define ALGO "$argon2id$" @@ -224,16 +231,21 @@ main(void) #endif #if defined(ALGO) + + errno = 0; + EXPECT(librecrypt_realise_salts(NULL, 0u, ALGO, NULL, NULL, reserved) == -1); + EXPECT(errno == EINVAL); + # define CHECK(IN, OUT)\ do {\ - EXPECT(librecrypt_realise_salts(NULL, 0u, (IN), NULL, NULL) == (ssize_t)sizeof(OUT) - 1);\ - EXPECT(librecrypt_realise_salts(buf, 0u, (IN), NULL, NULL) == (ssize_t)sizeof(OUT) - 1);\ + EXPECT(librecrypt_realise_salts(NULL, 0u, (IN), NULL, NULL, NULL) == (ssize_t)sizeof(OUT) - 1);\ + EXPECT(librecrypt_realise_salts(buf, 0u, (IN), NULL, NULL, NULL) == (ssize_t)sizeof(OUT) - 1);\ memset(buf, 99, sizeof(buf));\ - EXPECT(librecrypt_realise_salts(buf, sizeof(buf), (IN), &saltgen, &saltbyte) == (ssize_t)sizeof(OUT) - 1);\ + EXPECT(librecrypt_realise_salts(buf, sizeof(buf), (IN), &saltgen, &saltbyte, NULL) == (ssize_t)sizeof(OUT) - 1);\ EXPECT(!strcmp(buf, (OUT)));\ for (i = 0u; i < sizeof(OUT); i++) {\ memset(buf, 99, sizeof(buf));\ - EXPECT(librecrypt_realise_salts(buf, i + 1u, (IN), &saltgen, &saltbyte) == (ssize_t)sizeof(OUT) - 1);\ + EXPECT(librecrypt_realise_salts(buf, i + 1u, (IN), &saltgen, &saltbyte, NULL) == (ssize_t)sizeof(OUT) - 1);\ EXPECT(!memcmp(buf, (OUT), i));\ EXPECT(!buf[i]);\ }\ @@ -264,44 +276,44 @@ main(void) # undef CHECK errno = 0; - EXPECT(librecrypt_realise_salts(NULL, 0u, ALGO">$~no~such~algorithm~$", &saltgen, &saltbyte) == -1); + EXPECT(librecrypt_realise_salts(NULL, 0u, ALGO">$~no~such~algorithm~$", &saltgen, &saltbyte, NULL) == -1); EXPECT(errno == ENOSYS); errno = 0; - EXPECT(librecrypt_realise_salts(NULL, 0u, "$~no~such~algorithm~$>"ALGO, &saltgen, &saltbyte) == -1); + EXPECT(librecrypt_realise_salts(NULL, 0u, "$~no~such~algorithm~$>"ALGO, &saltgen, &saltbyte, NULL) == -1); EXPECT(errno == ENOSYS); errno = 0; - EXPECT(librecrypt_realise_salts(NULL, 0u, ALGO"*"LARGE"$", &saltgen, &saltbyte) == -1); + EXPECT(librecrypt_realise_salts(NULL, 0u, ALGO"*"LARGE"$", &saltgen, &saltbyte, NULL) == -1); EXPECT(errno == ERANGE); CANARY_FILL(buf); - EXPECT(librecrypt_realise_salts(buf, sizeof(ALGO) - 1u, ALGO"*3$", &saltfail, NULL) == (ssize_t)sizeof(ALGO"$") - 1 + 4); + EXPECT(librecrypt_realise_salts(buf, sizeof(ALGO) - 1u, ALGO"*3$", &saltfail, NULL, NULL) == (ssize_t)sizeof(ALGO"$") - 1 + 4); CANARY_CHECK(buf, sizeof(ALGO) - 1u); errno = 0; - EXPECT(librecrypt_realise_salts(buf, sizeof(buf), ALGO"*3$", &saltfail, NULL) == -1); + EXPECT(librecrypt_realise_salts(buf, sizeof(buf), ALGO"*3$", &saltfail, NULL, NULL) == -1); EXPECT(errno == EDOM); r = snprintf(conf, sizeof(conf), "%s*%zu$", ALGO, (size_t)SSIZE_MAX / 4u * 3u + 3u); assert(r > 0 && (size_t)r < sizeof(conf)); errno = 0; - EXPECT(librecrypt_realise_salts(NULL, 0u, conf, &saltgen, &saltbyte) == -1); + EXPECT(librecrypt_realise_salts(NULL, 0u, conf, &saltgen, &saltbyte, NULL) == -1); EXPECT(errno == ERANGE); r = snprintf(conf, sizeof(conf), "%s*%zu$", ALGO, (size_t)SSIZE_MAX / 4u * 3u); assert(r > 0 && (size_t)r < sizeof(conf)); errno = 0; - EXPECT(librecrypt_realise_salts(NULL, 0u, conf, &saltgen, &saltbyte) == -1); + EXPECT(librecrypt_realise_salts(NULL, 0u, conf, &saltgen, &saltbyte, NULL) == -1); EXPECT(errno == ERANGE); r = snprintf(conf, sizeof(conf), "%s*%zu$abcdef", ALGO, ((size_t)SSIZE_MAX - (sizeof(ALGO) - 1u)) / 4u * 3u); assert(r > 0 && (size_t)r < sizeof(conf)); errno = 0; - EXPECT(librecrypt_realise_salts(NULL, 0u, conf, &saltgen, &saltbyte) == -1); + EXPECT(librecrypt_realise_salts(NULL, 0u, conf, &saltgen, &saltbyte, NULL) == -1); EXPECT(errno == ERANGE); CANARY_FILL(buf); CANARY_FILL(buf2); - EXPECT(librecrypt_realise_salts(buf, sizeof(buf), ALGO"*30$", NULL, NULL) == (ssize_t)sizeof(ALGO"$") - 1 + 40); - EXPECT(librecrypt_realise_salts(buf2, sizeof(buf2), ALGO"*30$", NULL, NULL) == (ssize_t)sizeof(ALGO"$") - 1 + 40); + EXPECT(librecrypt_realise_salts(buf, sizeof(buf), ALGO"*30$", NULL, NULL, NULL) == (ssize_t)sizeof(ALGO"$") - 1 + 40); + EXPECT(librecrypt_realise_salts(buf2, sizeof(buf2), ALGO"*30$", NULL, NULL, NULL) == (ssize_t)sizeof(ALGO"$") - 1 + 40); EXPECT(!buf[sizeof(ALGO"$") - 1u + 40u]); EXPECT(!buf2[sizeof(ALGO"$") - 1u + 40u]); EXPECT(memcmp(buf, buf2, sizeof(ALGO"$") - 1u + 40u)); @@ -360,7 +372,7 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) memcpy(settings, data, size); settings[size] = '\0'; - r = librecrypt_realise_salts(out_buffer, out_size, settings, NULL, NULL); + r = librecrypt_realise_salts(out_buffer, out_size, settings, NULL, NULL, NULL); if (out_size && r >= 0) { assert(strlen(out_buffer) < out_size); assert((size_t)r >= strlen(out_buffer)); diff --git a/librecrypt_settings_prefix.3 b/librecrypt_settings_prefix.3 index 6420c3e..8981133 100644 --- a/librecrypt_settings_prefix.3 +++ b/librecrypt_settings_prefix.3 @@ -6,7 +6,7 @@ librecrypt_settings_prefix - Get length of settings prefix in a password hash st .nf #include <librecrypt.h> -size_t \fBlibrecrypt_settings_prefix\fP(const char *\fIhash\fP, size_t *\fIhashsize_out\fP); +size_t \fBlibrecrypt_settings_prefix\fP(const char *\fIhash\fP, size_t *\fIhashsize_out\fP, void *\fIreserved\fP); .fi .PP Link with @@ -44,6 +44,11 @@ See the .B EXTENDED DESCRIPTION section for more information. .PP +The +.I reserved +parameter is reserved for future use and should be +.IR NULL . +.PP .I hash must not be .IR NULL . diff --git a/librecrypt_settings_prefix.c b/librecrypt_settings_prefix.c index 0d78c23..df1c56a 100644 --- a/librecrypt_settings_prefix.c +++ b/librecrypt_settings_prefix.c @@ -4,13 +4,15 @@ size_t -librecrypt_settings_prefix(const char *hash, size_t *hashsize_out) +librecrypt_settings_prefix(const char *hash, size_t *hashsize_out, void *reserved) { size_t i, len, ret = 0u; size_t last_offset = 0u; const struct algorithm *algo; uintmax_t hashsize; + (void) reserved; + /* Find last algorithm, and beginning of result */ for (i = 0u; hash[i]; i++) { if (hash[i] == LIBRECRYPT_HASH_COMPOSITION_DELIMITER) @@ -60,21 +62,21 @@ out: #define CHECK_NULL(PREFIX, SUFFIX)\ do {\ - EXPECT(librecrypt_settings_prefix(PREFIX SUFFIX, NULL) == sizeof(PREFIX) - 1u);\ - EXPECT(librecrypt_settings_prefix(PREFIX, NULL) == sizeof(PREFIX) - 1u); \ + EXPECT(librecrypt_settings_prefix(PREFIX SUFFIX, NULL, NULL) == sizeof(PREFIX) - 1u);\ + EXPECT(librecrypt_settings_prefix(PREFIX, NULL, NULL) == sizeof(PREFIX) - 1u); \ } while (0) #define CHECK_ZERO(PREFIX, SUFFIX)\ do {\ size_t hashsize = 99999u;\ - EXPECT(librecrypt_settings_prefix(PREFIX SUFFIX, &hashsize) == sizeof(PREFIX) - 1u);\ + EXPECT(librecrypt_settings_prefix(PREFIX SUFFIX, &hashsize, NULL) == sizeof(PREFIX) - 1u);\ EXPECT(hashsize == 0u);\ } while (0) #define CHECK_HASH(PREFIX, SUFFIX, HASH)\ do {\ size_t hashsize = 99999u;\ - EXPECT(librecrypt_settings_prefix(PREFIX SUFFIX, &hashsize) == sizeof(PREFIX) - 1u);\ + EXPECT(librecrypt_settings_prefix(PREFIX SUFFIX, &hashsize, NULL) == sizeof(PREFIX) - 1u);\ EXPECT(hashsize == HASH##u);\ } while (0) @@ -167,8 +169,8 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) assert(hash); memcpy(hash, data, size); hash[size] = '\0'; - r = librecrypt_settings_prefix(hash, &(size_t){0u}); - EXPECT(librecrypt_settings_prefix(hash, NULL) == r); + r = librecrypt_settings_prefix(hash, &(size_t){0u}, NULL); + EXPECT(librecrypt_settings_prefix(hash, NULL, NULL) == r); free(hash); return 0; } diff --git a/librecrypt_test_supported.3 b/librecrypt_test_supported.3 index eb51e2d..6afb068 100644 --- a/librecrypt_test_supported.3 +++ b/librecrypt_test_supported.3 @@ -6,7 +6,8 @@ librecrypt_test_supported - Check whether an algorithm chain is supported .nf #include <librecrypt.h> -int \fBlibrecrypt_test_supported\fP(const char *\fIphrase\fP, size_t \fIlen\fP, int \fItext\fP, const char *\fIsettings\fP); +int \fBlibrecrypt_test_supported\fP(const char *\fIphrase\fP, size_t \fIlen\fP, int \fItext\fP, + const char *\fIsettings\fP, void *\fIreserved\fP); .fi .PP Link with @@ -45,6 +46,11 @@ is zero. If .I text is non-zero, UTF-8 without null bytes is assumed. .PP +The +.I reserved +parameter is reserved for future use and should be +.IR NULL . +.PP If .I phrase is not diff --git a/librecrypt_test_supported.c b/librecrypt_test_supported.c index 66ee4fb..db5ac7c 100644 --- a/librecrypt_test_supported.c +++ b/librecrypt_test_supported.c @@ -4,7 +4,7 @@ int -librecrypt_test_supported(const char *phrase, size_t len, int text, const char *settings) +librecrypt_test_supported(const char *phrase, size_t len, int text, const char *settings, void *reserved) { const struct algorithm *algo; size_t n; @@ -49,11 +49,11 @@ librecrypt_test_supported(const char *phrase, size_t len, int text, const char * #define CHECK(ALGO, VALID, INVALID)\ do {\ - EXPECT(librecrypt_test_supported(NULL, 4096u, 0, ALGO VALID) == 1);\ - EXPECT(librecrypt_test_supported(NULL, 4096u, 0, ALGO VALID">"NSA) == 0);\ - EXPECT(librecrypt_test_supported(NULL, 4096u, 0, NSA">"ALGO VALID) == 0);\ - EXPECT(librecrypt_test_supported(NULL, 4096u, 0, ALGO VALID">"ALGO VALID) == 1);\ - EXPECT(librecrypt_test_supported(NULL, 4096u, 0, ALGO INVALID) == 0);\ + EXPECT(librecrypt_test_supported(NULL, 4096u, 0, ALGO VALID, NULL) == 1);\ + EXPECT(librecrypt_test_supported(NULL, 4096u, 0, ALGO VALID">"NSA, NULL) == 0);\ + EXPECT(librecrypt_test_supported(NULL, 4096u, 0, NSA">"ALGO VALID, NULL) == 0);\ + EXPECT(librecrypt_test_supported(NULL, 4096u, 0, ALGO VALID">"ALGO VALID, NULL) == 1);\ + EXPECT(librecrypt_test_supported(NULL, 4096u, 0, ALGO INVALID, NULL) == 0);\ } while (0) @@ -63,10 +63,10 @@ main(void) SET_UP_ALARM(); INIT_RESOURCE_TEST(); - EXPECT(librecrypt_test_supported("abcdefgh", 8u, 1, NSA) == 0); - EXPECT(librecrypt_test_supported("abcdefgh", 8u, 1, NSA">") == 0); - EXPECT(librecrypt_test_supported("abcdefgh", 8u, 1, ">"NSA) == 0); - EXPECT(librecrypt_test_supported("abcdefgh", 8u, 1, NSA">"NSA) == 0); + EXPECT(librecrypt_test_supported("abcdefgh", 8u, 1, NSA, NULL) == 0); + EXPECT(librecrypt_test_supported("abcdefgh", 8u, 1, NSA">", NULL) == 0); + EXPECT(librecrypt_test_supported("abcdefgh", 8u, 1, ">"NSA, NULL) == 0); + EXPECT(librecrypt_test_supported("abcdefgh", 8u, 1, NSA">"NSA, NULL) == 0); IF__argon2i__SUPPORTED(CHECK("$argon2i$v=19$", "m=8,t=1,p=1$*16$*40", "m=0,t=0,p=0$*1$*1")); IF__argon2d__SUPPORTED(CHECK("$argon2d$v=19$", "m=8,t=1,p=1$*16$*40", "m=0,t=0,p=0$*1$*1")); @@ -107,7 +107,7 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) memcpy(settings, data, size); settings[size] = '\0'; - discarded_return_value = librecrypt_test_supported(phrase, len, text, settings); + discarded_return_value = librecrypt_test_supported(phrase, len, text, settings, NULL); free(settings); return 0; |
