diff --git a/src/libsodium/crypto_pwhash/argon2/argon2-core.c b/src/libsodium/crypto_pwhash/argon2/argon2-core.c index 2f1ebbfd..fbf286cc 100644 --- a/src/libsodium/crypto_pwhash/argon2/argon2-core.c +++ b/src/libsodium/crypto_pwhash/argon2/argon2-core.c @@ -175,8 +175,8 @@ free_memory(block_region *region) free(region); } -void -free_instance(argon2_instance_t *instance, int flags) +static void +argon2_free_instance(argon2_instance_t *instance, int flags) { /* Clear memory */ clear_memory(instance, flags & ARGON2_FLAG_CLEAR_MEMORY); @@ -189,7 +189,7 @@ free_instance(argon2_instance_t *instance, int flags) } void -finalize(const argon2_context *context, argon2_instance_t *instance) +argon2_finalize(const argon2_context *context, argon2_instance_t *instance) { if (context != NULL && instance != NULL) { block blockhash; @@ -218,7 +218,7 @@ finalize(const argon2_context *context, argon2_instance_t *instance) ARGON2_BLOCK_SIZE); /* clear blockhash_bytes */ } - free_instance(instance, context->flags); + argon2_free_instance(instance, context->flags); } } @@ -245,7 +245,7 @@ fill_memory_blocks(argon2_instance_t *instance, uint32_t pass) } int -validate_inputs(const argon2_context *context) +argon2_validate_inputs(const argon2_context *context) { /* LCOV_EXCL_START */ if (NULL == context) { @@ -393,8 +393,9 @@ fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance) sodium_memzero(blockhash_bytes, ARGON2_BLOCK_SIZE); } -void -initial_hash(uint8_t *blockhash, argon2_context *context, argon2_type type) +static void +argon2_initial_hash(uint8_t *blockhash, argon2_context *context, + argon2_type type) { crypto_generichash_blake2b_state BlakeHash; uint8_t value[4U /* sizeof(uint32_t) */]; @@ -477,7 +478,7 @@ initial_hash(uint8_t *blockhash, argon2_context *context, argon2_type type) } int -initialize(argon2_instance_t *instance, argon2_context *context) +argon2_initialize(argon2_instance_t *instance, argon2_context *context) { uint8_t blockhash[ARGON2_PREHASH_SEED_LENGTH]; int result = ARGON2_OK; @@ -495,7 +496,7 @@ initialize(argon2_instance_t *instance, argon2_context *context) result = allocate_memory(&(instance->region), instance->memory_blocks); if (ARGON2_OK != result) { - free_instance(instance, context->flags); + argon2_free_instance(instance, context->flags); return result; } @@ -503,7 +504,7 @@ initialize(argon2_instance_t *instance, argon2_context *context) /* H_0 + 8 extra bytes to produce the first blocks */ /* uint8_t blockhash[ARGON2_PREHASH_SEED_LENGTH]; */ /* Hashing all inputs */ - initial_hash(blockhash, context, instance->type); + argon2_initial_hash(blockhash, context, instance->type); /* Zeroing 8 extra bytes */ sodium_memzero(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, ARGON2_PREHASH_SEED_LENGTH - ARGON2_PREHASH_DIGEST_LENGTH); diff --git a/src/libsodium/crypto_pwhash/argon2/argon2-core.h b/src/libsodium/crypto_pwhash/argon2/argon2-core.h index caab1038..a5779041 100644 --- a/src/libsodium/crypto_pwhash/argon2/argon2-core.h +++ b/src/libsodium/crypto_pwhash/argon2/argon2-core.h @@ -214,20 +214,7 @@ static uint32_t index_alpha(const argon2_instance_t *instance, * @return ARGON2_OK if everything is all right, otherwise one of error codes * (all defined in */ -int validate_inputs(const argon2_context *context); - -/* - * Hashes all the inputs into @a blockhash[PREHASH_DIGEST_LENGTH], clears - * password and secret if needed - * @param context Pointer to the Argon2 internal structure containing memory - * pointer, and parameters for time and space requirements. - * @param blockhash Buffer for pre-hashing digest - * @param type Argon2 type - * @pre @a blockhash must have at least @a PREHASH_DIGEST_LENGTH bytes - * allocated - */ -void initial_hash(uint8_t *blockhash, argon2_context *context, - argon2_type type); +int argon2_validate_inputs(const argon2_context *context); /* * Function creates first 2 blocks per lane @@ -247,12 +234,7 @@ void fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance); * @return Zero if successful, -1 if memory failed to allocate. @context->state * will be modified if successful. */ -int initialize(argon2_instance_t *instance, argon2_context *context); - -/* - * Deallocates memory. Used on error path. - */ -void free_instance(argon2_instance_t *instance, int flags); +int argon2_initialize(argon2_instance_t *instance, argon2_context *context); /* * XORing the last block of each lane, hashing it, making the tag. Deallocates @@ -265,7 +247,8 @@ void free_instance(argon2_instance_t *instance, int flags); * @pre if context->free_cbk is not NULL, it should point to a function that * deallocates memory */ -void finalize(const argon2_context *context, argon2_instance_t *instance); +void argon2_finalize(const argon2_context *context, + argon2_instance_t *instance); /* * Function that fills the segment using previous segments also from other diff --git a/src/libsodium/crypto_pwhash/argon2/argon2-encoding.c b/src/libsodium/crypto_pwhash/argon2/argon2-encoding.c index a08acdda..6a80afe0 100644 --- a/src/libsodium/crypto_pwhash/argon2/argon2-encoding.c +++ b/src/libsodium/crypto_pwhash/argon2/argon2-encoding.c @@ -83,7 +83,7 @@ decode_decimal(const char *str, unsigned long *v) * output length must be in the allowed ranges defined in argon2.h. * * The ctx struct must contain buffers large enough to hold the salt and pwd - * when it is fed into decode_string. + * when it is fed into argon2_decode_string. */ /* @@ -91,7 +91,7 @@ decode_decimal(const char *str, unsigned long *v) * Returned value is ARGON2_OK on success. */ int -decode_string(argon2_context *ctx, const char *str, argon2_type type) +argon2_decode_string(argon2_context *ctx, const char *str, argon2_type type) { /* Prefix checking */ #define CC(prefix) \ @@ -193,7 +193,7 @@ decode_string(argon2_context *ctx, const char *str, argon2_type type) BIN(ctx->salt, maxsaltlen, ctx->saltlen); CC("$"); BIN(ctx->out, maxoutlen, ctx->outlen); - validation_result = validate_inputs(ctx); + validation_result = argon2_validate_inputs(ctx); if (validation_result != ARGON2_OK) { return validation_result; } @@ -238,7 +238,8 @@ u32_to_string(char *str, uint32_t x) * On success, ARGON2_OK is returned. */ int -encode_string(char *dst, size_t dst_len, argon2_context *ctx, argon2_type type) +argon2_encode_string(char *dst, size_t dst_len, argon2_context *ctx, + argon2_type type) { #define SS(str) \ do { \ @@ -280,7 +281,7 @@ encode_string(char *dst, size_t dst_len, argon2_context *ctx, argon2_type type) default: return ARGON2_ENCODING_FAIL; } - validation_result = validate_inputs(ctx); + validation_result = argon2_validate_inputs(ctx); if (validation_result != ARGON2_OK) { return validation_result; } diff --git a/src/libsodium/crypto_pwhash/argon2/argon2-encoding.h b/src/libsodium/crypto_pwhash/argon2/argon2-encoding.h index e929b31d..c35fbf42 100644 --- a/src/libsodium/crypto_pwhash/argon2/argon2-encoding.h +++ b/src/libsodium/crypto_pwhash/argon2/argon2-encoding.h @@ -17,8 +17,8 @@ * * No other parameters are checked */ -int encode_string(char *dst, size_t dst_len, argon2_context *ctx, - argon2_type type); +int argon2_encode_string(char *dst, size_t dst_len, argon2_context *ctx, + argon2_type type); /* * Decodes an Argon2 hash string into the provided structure 'ctx'. @@ -28,6 +28,7 @@ int encode_string(char *dst, size_t dst_len, argon2_context *ctx, * * Returned value is ARGON2_OK on success. */ -int decode_string(argon2_context *ctx, const char *str, argon2_type type); +int argon2_decode_string(argon2_context *ctx, const char *str, + argon2_type type); #endif diff --git a/src/libsodium/crypto_pwhash/argon2/argon2.c b/src/libsodium/crypto_pwhash/argon2/argon2.c index ac1628c9..ba075a28 100644 --- a/src/libsodium/crypto_pwhash/argon2/argon2.c +++ b/src/libsodium/crypto_pwhash/argon2/argon2.c @@ -27,7 +27,7 @@ int argon2_ctx(argon2_context *context, argon2_type type) { /* 1. Validate all inputs */ - int result = validate_inputs(context); + int result = argon2_validate_inputs(context); uint32_t memory_blocks, segment_length; uint32_t pass; argon2_instance_t instance; @@ -65,7 +65,7 @@ argon2_ctx(argon2_context *context, argon2_type type) /* 3. Initialization: Hashing inputs, allocating memory, filling first * blocks */ - result = initialize(&instance, context); + result = argon2_initialize(&instance, context); if (ARGON2_OK != result) { return result; @@ -77,7 +77,7 @@ argon2_ctx(argon2_context *context, argon2_type type) } /* 5. Finalization */ - finalize(context, &instance); + argon2_finalize(context, &instance); return ARGON2_OK; } @@ -141,7 +141,8 @@ argon2_hash(const uint32_t t_cost, const uint32_t m_cost, /* if encoding requested, write it */ if (encoded && encodedlen) { - if (encode_string(encoded, encodedlen, &context, type) != ARGON2_OK) { + if (argon2_encode_string(encoded, encodedlen, + &context, type) != ARGON2_OK) { sodium_memzero(out, hashlen); sodium_memzero(encoded, encodedlen); free(out); @@ -214,7 +215,7 @@ argon2_verify(const char *encoded, const void *pwd, const size_t pwdlen, ctx.secret = NULL; ctx.secretlen = 0; - /* max values, to be updated in decode_string */ + /* max values, to be updated in argon2_decode_string */ encoded_len = strlen(encoded); if (encoded_len > UINT32_MAX) { return ARGON2_DECODING_LENGTH_FAIL; @@ -240,7 +241,7 @@ argon2_verify(const char *encoded, const void *pwd, const size_t pwdlen, return ARGON2_MEMORY_ALLOCATION_ERROR; } - decode_result = decode_string(&ctx, encoded, type); + decode_result = argon2_decode_string(&ctx, encoded, type); if (decode_result != ARGON2_OK) { free(ctx.ad); free(ctx.salt); diff --git a/src/libsodium/crypto_pwhash/argon2/argon2.h b/src/libsodium/crypto_pwhash/argon2/argon2.h index 85ca4dd3..3b05daac 100644 --- a/src/libsodium/crypto_pwhash/argon2/argon2.h +++ b/src/libsodium/crypto_pwhash/argon2/argon2.h @@ -283,7 +283,7 @@ int argon2_hash(const uint32_t t_cost, const uint32_t m_cost, /** * Verifies a password against an encoded string - * Encoded string is restricted as in validate_inputs() + * Encoded string is restricted as in argon2_validate_inputs() * @param encoded String encoding parameters, salt, hash * @param pwd Pointer to password * @pre Returns ARGON2_OK if successful @@ -292,7 +292,7 @@ int argon2i_verify(const char *encoded, const void *pwd, const size_t pwdlen); /** * Verifies a password against an encoded string - * Encoded string is restricted as in validate_inputs() + * Encoded string is restricted as in argon2_validate_inputs() * @param encoded String encoding parameters, salt, hash * @param pwd Pointer to password * @pre Returns ARGON2_OK if successful diff --git a/src/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c b/src/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c index 0515bd61..685fa03a 100644 --- a/src/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c +++ b/src/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c @@ -261,7 +261,7 @@ _needs_rehash(const char *str, unsigned long long opslimit, size_t memlimit, ctx.outlen = ctx.pwdlen = ctx.saltlen = (uint32_t) fodder_len; ctx.ad = ctx.secret = NULL; ctx.adlen = ctx.secretlen = 0U; - if (decode_string(&ctx, str, type) != 0) { + if (argon2_decode_string(&ctx, str, type) != 0) { errno = EINVAL; ret = -1; } else if (ctx.t_cost != (uint32_t) opslimit || diff --git a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt.h b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt.h index 83101967..f966fe4a 100644 --- a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt.h +++ b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt.h @@ -65,8 +65,8 @@ extern int escrypt_init_local(escrypt_local_t *__local); extern int escrypt_free_local(escrypt_local_t *__local); -extern void *alloc_region(escrypt_region_t *region, size_t size); -extern int free_region(escrypt_region_t *region); +extern void *escrypt_alloc_region(escrypt_region_t *region, size_t size); +extern int escrypt_free_region(escrypt_region_t *region); typedef int (*escrypt_kdf_t)(escrypt_local_t *__local, const uint8_t *__passwd, size_t __passwdlen, const uint8_t *__salt, diff --git a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c index d7bf18d2..a4db8818 100644 --- a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c +++ b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c @@ -351,10 +351,10 @@ escrypt_kdf_nosse(escrypt_local_t *local, const uint8_t *passwd, return -1; } if (local->size < need) { - if (free_region(local)) { + if (escrypt_free_region(local)) { return -1; } - if (!alloc_region(local, need)) { + if (!escrypt_alloc_region(local, need)) { return -1; } } diff --git a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/scrypt_platform.c b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/scrypt_platform.c index a7d94107..890517f7 100644 --- a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/scrypt_platform.c +++ b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/scrypt_platform.c @@ -42,7 +42,7 @@ #endif void * -alloc_region(escrypt_region_t *region, size_t size) +escrypt_alloc_region(escrypt_region_t *region, size_t size) { uint8_t *base, *aligned; #if defined(MAP_ANON) && defined(HAVE_MMAP) @@ -81,7 +81,7 @@ init_region(escrypt_region_t *region) } int -free_region(escrypt_region_t *region) +escrypt_free_region(escrypt_region_t *region) { if (region->base) { #if defined(MAP_ANON) && defined(HAVE_MMAP) @@ -108,5 +108,5 @@ escrypt_init_local(escrypt_local_t *local) int escrypt_free_local(escrypt_local_t *local) { - return free_region(local); + return escrypt_free_region(local); } diff --git a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c index 79dbb87a..8c6c54ab 100644 --- a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +++ b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c @@ -371,10 +371,10 @@ escrypt_kdf_sse(escrypt_local_t *local, const uint8_t *passwd, size_t passwdlen, } /* LCOV_EXCL_END */ if (local->size < need) { - if (free_region(local)) { + if (escrypt_free_region(local)) { return -1; /* LCOV_EXCL_LINE */ } - if (!alloc_region(local, need)) { + if (!escrypt_alloc_region(local, need)) { return -1; /* LCOV_EXCL_LINE */ } }