From 8e5cf60500792f1f96e36cbe5faa856c12797f3b Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Wed, 12 Apr 2023 08:37:44 +0200 Subject: Remove uneeded init, improve comments, var names. * lpass.c: calc_entropy: salt and key are directly filled with data after init, do not need to be initialized beforehand. --- lpass.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lpass.c b/lpass.c index ad9ab93..6006a82 100644 --- a/lpass.c +++ b/lpass.c @@ -52,14 +52,12 @@ calc_entropy(const char *site, int passlen) { char salt[MAX_BUF + 1]; - memset(salt, 0, sizeof(salt)); int saltlen = snprintf(salt, MAX_BUF, "%s%s%lx", site, login, counter); if (saltlen > MAX_BUF) { return NULL; } unsigned char key[ENTROPY_KEY_LENGTH]; - memset(key, 0, sizeof(key)); int status = PKCS5_PBKDF2_HMAC(master_pass, passlen, (const unsigned char *) salt, saltlen, ENTROPY_ITERATIONS, @@ -99,8 +97,8 @@ consume_entropy(char *generated_pass, BIGNUM *entropy, const char *charset, size /* * If `remainder` cannot store the value in `bn_remainder`, it * will contain a very large number. Abort by checking if the - * remainder is too larger according to `passlen`, since that - * is also a failure case anyway. + * remainder is too large, since that is also a failure case + * anyway. */ uint64_t remainder = BN_get_word(bn_remainder); if (remainder >= charsetlen) { @@ -139,8 +137,8 @@ insert_str_pseudo_randomly(char *generated_pass, BIGNUM *entropy, const char *s) /* * If `remainder` cannot store the value in `bn_remainder`, it * will contain a very large number. Abort by checking if the - * remainder is too larger according to `passlen`, since that - * is also a failure case anyway. + * remainder is too large, since that is also a failure case + * anyway. */ uint64_t remainder = BN_get_word(bn_remainder); if (remainder >= passlen) { @@ -177,25 +175,25 @@ charsets_has_set(uint8_t charsets, enum CharSet set) static size_t build_charset(char *charset, uint8_t allowed_charsets) { - size_t c = 0; + size_t count = 0; charset[0] = '\0'; if (charsets_has_set(allowed_charsets, CHARSET_LOWER)) { strcat(charset, CHAR_SUBSET_LOWER); - c++; + count++; } if (charsets_has_set(allowed_charsets, CHARSET_UPPER)) { strcat(charset, CHAR_SUBSET_UPPER); - c++; + count++; } if (charsets_has_set(allowed_charsets, CHARSET_DIGITS)) { strcat(charset, CHAR_SUBSET_DIGITS); - c++; + count++; } if (charsets_has_set(allowed_charsets, CHARSET_SYMBOLS)) { strcat(charset, CHAR_SUBSET_SYMBOLS); - c++; + count++; } - return c; + return count; } int -- cgit v1.2.3