diff options
author | Samuel Fadel <samuel@nihil.ws> | 2023-04-12 08:37:44 +0200 |
---|---|---|
committer | Samuel Fadel <samuel@nihil.ws> | 2023-04-12 08:37:44 +0200 |
commit | 8e5cf60500792f1f96e36cbe5faa856c12797f3b (patch) | |
tree | 1862365bd137a1f5b241e9796b87300cae1e80f9 /lpass.c | |
parent | b4c67148a2d780bcbd59a97fb967b8625913e3e4 (diff) |
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.
Diffstat (limited to 'lpass.c')
-rw-r--r-- | lpass.c | 22 |
1 files changed, 10 insertions, 12 deletions
@@ -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 |