From b4c67148a2d780bcbd59a97fb967b8625913e3e4 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Tue, 11 Apr 2023 11:25:15 +0200 Subject: Use size_t for lengths and complete Makefile. * lpass.c: Use size_t for all lengths * Makefile: Proper targets (clean, install, uninstall) added and more strict compilation flags * LICENSE: Actually add file... --- lpass.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'lpass.c') diff --git a/lpass.c b/lpass.c index ef94412..ad9ab93 100644 --- a/lpass.c +++ b/lpass.c @@ -75,7 +75,7 @@ calc_entropy(const char *site, } static int -consume_entropy(char *generated_pass, BIGNUM *entropy, const char *charset, int maxlen) +consume_entropy(char *generated_pass, BIGNUM *entropy, const char *charset, size_t maxlen) { int retval = 1; BN_CTX *ctx = BN_CTX_new(); @@ -86,12 +86,12 @@ consume_entropy(char *generated_pass, BIGNUM *entropy, const char *charset, int goto consume_entropy_cleanup; } - int charsetlen = strlen(charset); + size_t charsetlen = strlen(charset); if (BN_set_word(bn_charsetlen, charsetlen) == 0) { retval = 0; goto consume_entropy_cleanup; } - for (int passlen = strlen(generated_pass); + for (size_t passlen = strlen(generated_pass); passlen < maxlen; passlen++) { BN_div(entropy, bn_remainder, entropy, bn_charsetlen, ctx); @@ -174,10 +174,10 @@ charsets_has_set(uint8_t charsets, enum CharSet set) return (charsets & set) != 0; } -static int +static size_t build_charset(char *charset, uint8_t allowed_charsets) { - int c = 0; + size_t c = 0; charset[0] = '\0'; if (charsets_has_set(allowed_charsets, CHARSET_LOWER)) { strcat(charset, CHAR_SUBSET_LOWER); @@ -199,10 +199,10 @@ build_charset(char *charset, uint8_t allowed_charsets) } int -render_pass(BIGNUM *entropy, uint8_t allowed_charsets, char *out, int length) +render_pass(BIGNUM *entropy, uint8_t allowed_charsets, char *out, size_t length) { char charset[MAX_BUF + 1]; - int num_charsets = build_charset(charset, allowed_charsets); + size_t num_charsets = build_charset(charset, allowed_charsets); if (consume_entropy(out, entropy, charset, length - num_charsets) == 0) { return 0; } @@ -213,7 +213,7 @@ render_pass(BIGNUM *entropy, uint8_t allowed_charsets, char *out, int length) */ char str_to_add[num_charsets + 1]; memset(str_to_add, 0, sizeof(str_to_add)); - int c = 0; + size_t c = 0; if (charsets_has_set(allowed_charsets, CHARSET_LOWER) && consume_entropy(&str_to_add[c++], entropy, CHAR_SUBSET_LOWER, 1) == 0) { return 0; @@ -264,7 +264,7 @@ int main(int argc, char *argv[]) { int c; - int length = DEFAULT_LENGTH; + size_t length = DEFAULT_LENGTH; uint8_t allowed_charsets = CHARSET_LOWER | CHARSET_UPPER | CHARSET_DIGITS @@ -303,7 +303,7 @@ main(int argc, char *argv[]) exit(EXIT_SUCCESS); case 'L': if (!optarg - || sscanf(optarg, "%d", &length) == 0 + || sscanf(optarg, "%zu", &length) == 0 || length < 1 || length >= MAX_BUF) { usage(); @@ -332,7 +332,7 @@ main(int argc, char *argv[]) const char *site = argv[optind++]; const char *login = argv[optind++]; - int passlen = strlen(master_pass); + size_t passlen = strlen(master_pass); uint64_t counter = 1; BIGNUM *entropy = calc_entropy(site, login, counter, master_pass, passlen); if (entropy == NULL) { -- cgit v1.2.3