aboutsummaryrefslogtreecommitdiffstats
path: root/librecrypt_add_algorithm.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--librecrypt_add_algorithm.c23
1 files changed, 19 insertions, 4 deletions
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));