aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Fadel <samuel@nihil.ws>2023-04-14 23:32:33 +0200
committerSamuel Fadel <samuel@nihil.ws>2023-04-14 23:32:33 +0200
commitbd625917ceda9c824f2ce609846fd484d207f934 (patch)
tree87154050c5d5bf18f87b8d1bd649c7619329b29b
parent0f37586e2ee34dc5c844b2d1bd89316b6f3adcdc (diff)
Minor formatting and refactoring.0.9.1
* lpass.c: Changed the order of some arguments, renamed variables/args where necessary to make them clearer.
-rw-r--r--lpass.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/lpass.c b/lpass.c
index 4323a35..fbdc673 100644
--- a/lpass.c
+++ b/lpass.c
@@ -57,22 +57,25 @@ calc_entropy(const char *site,
}
unsigned char key[ENTROPY_KEY_LENGTH];
- int status = PKCS5_PBKDF2_HMAC(master_pass, strlen(master_pass),
- (const unsigned char *) salt, saltlen,
- ENTROPY_ITERATIONS,
- EVP_sha256(),
- ENTROPY_KEY_LENGTH,
- key);
+ int status = PKCS5_PBKDF2_HMAC(
+ master_pass,
+ strlen(master_pass),
+ (const unsigned char *) salt,
+ saltlen,
+ ENTROPY_ITERATIONS,
+ EVP_sha256(),
+ ENTROPY_KEY_LENGTH,
+ key);
if (status == 0) {
return NULL;
}
- /* NULL as last arg to allocate a new BIGNUM */
+ /* NULL as last arg allocates a new BIGNUM */
return BN_bin2bn(key, ENTROPY_KEY_LENGTH, NULL);
}
static int
-consume_entropy(char *pass, BIGNUM *entropy, const char *charset, size_t maxlen)
+consume_entropy(BIGNUM *entropy, const char *charset, char *pass, size_t num_iter)
{
int retval = 1;
BN_CTX *ctx = BN_CTX_new();
@@ -88,7 +91,7 @@ consume_entropy(char *pass, BIGNUM *entropy, const char *charset, size_t maxlen)
retval = 0;
goto consume_entropy_cleanup;
}
- while (maxlen-- > 0) {
+ while (num_iter-- > 0) {
BN_div(entropy, bn_remainder, entropy, bn_charsetlen, ctx);
/*
@@ -113,7 +116,7 @@ consume_entropy_cleanup:
}
static int
-insert_str_pseudo_randomly(char *pass, BIGNUM *entropy, const char *s)
+insert_str_pseudo_randomly(BIGNUM *entropy, const char *s, char *pass)
{
int retval = 1;
char buf[MAX_BUF + 1];
@@ -149,7 +152,6 @@ insert_str_pseudo_randomly(char *pass, BIGNUM *entropy, const char *s)
* `pass`. 1. Copy the part that would need to be shifted into
* `buf`.
*/
- memset(buf, 0, sizeof(buf));
strncpy(buf, &pass[remainder], passlen - remainder);
/*
* 2. Add new character, then copy `buf` back into `pass`.
@@ -201,7 +203,7 @@ render_pass(BIGNUM *entropy, uint8_t allowed_charsets, char *out, size_t length)
{
char charset[MAX_BUF + 1];
size_t num_charsets = build_charset(charset, allowed_charsets);
- if (consume_entropy(out, entropy, charset, length - num_charsets) == 0) {
+ if (consume_entropy(entropy, charset, out, length - num_charsets) == 0) {
return 0;
}
@@ -213,22 +215,22 @@ render_pass(BIGNUM *entropy, uint8_t allowed_charsets, char *out, size_t length)
memset(str_to_add, 0, sizeof(str_to_add));
size_t count = 0;
if (charsets_has_set(allowed_charsets, CHARSET_LOWER)
- && consume_entropy(&str_to_add[count++], entropy, CHAR_SUBSET_LOWER, 1) == 0) {
+ && consume_entropy(entropy, CHAR_SUBSET_LOWER, &str_to_add[count++], 1) == 0) {
return 0;
}
if (charsets_has_set(allowed_charsets, CHARSET_UPPER)
- && consume_entropy(&str_to_add[count++], entropy, CHAR_SUBSET_UPPER, 1) == 0) {
+ && consume_entropy(entropy, CHAR_SUBSET_UPPER, &str_to_add[count++], 1) == 0) {
return 0;
}
if (charsets_has_set(allowed_charsets, CHARSET_DIGITS)
- && consume_entropy(&str_to_add[count++], entropy, CHAR_SUBSET_DIGITS, 1) == 0) {
+ && consume_entropy(entropy, CHAR_SUBSET_DIGITS, &str_to_add[count++], 1) == 0) {
return 0;
}
if (charsets_has_set(allowed_charsets, CHARSET_SYMBOLS)
- && consume_entropy(&str_to_add[count++], entropy, CHAR_SUBSET_SYMBOLS, 1) == 0) {
+ && consume_entropy(entropy, CHAR_SUBSET_SYMBOLS, &str_to_add[count++], 1) == 0) {
return 0;
}
- return insert_str_pseudo_randomly(out, entropy, str_to_add);
+ return insert_str_pseudo_randomly(entropy, str_to_add, out);
}
static void