pit
Owner: IIIlllIIIllI URL: git@github.com:nyangkosense/pit.git
use memlimit min for low memory systems
Commit fe583c04c447f2070fdc34377d4e01b604388ac3 by SM <seb.michalk@gmail.com> on 2025-03-26 08:56:27 +0100
diff --git a/pit.c b/pit.c
index 34b53e8..deea272 100644
--- a/pit.c
+++ b/pit.c
@@ -359,7 +359,16 @@ generate_key(const char *keyfile)
crypto_pwhash_OPSLIMIT_MODERATE,
crypto_pwhash_MEMLIMIT_MODERATE,
crypto_pwhash_ALG_DEFAULT) != 0) {
- fprintf(stderr, "pit: key derivation failed\n");
+ fprintf(stderr, "pit: key derivation failed - trying with minimal settings\n");
+ if (crypto_pwhash(
+ encrypted + SALT_SIZE, KEY_SIZE,
+ password, pwlen,
+ salt,
+ crypto_pwhash_OPSLIMIT_MIN,
+ crypto_pwhash_MEMLIMIT_MIN,
+ crypto_pwhash_ALG_DEFAULT) != 0) {
+ fprintf(stderr, "pit: key derivation failed - insufficient memory\n");
+ }
goto cleanup;
}
@@ -466,16 +475,30 @@ read_key_file(const char *path, char **key)
if (pwlen > 0 && password[pwlen-1] == '\n')
password[--pwlen] = 0;
- if (crypto_pwhash(
+ int r = crypto_pwhash(
+ decrypted, KEY_SIZE,
+ password, pwlen,
+ encrypted,
+ crypto_pwhash_OPSLIMIT_MODERATE,
+ crypto_pwhash_MEMLIMIT_MODERATE,
+ crypto_pwhash_ALG_DEFAULT);
+
+ if (r != 0) {
+ fprintf(stderr, "pit: trying with minimal memory settings .. \n");
+ r = crypto_pwhash(
decrypted, KEY_SIZE,
password, pwlen,
- encrypted, /* first SALT_SIZE bytes are the salt */
- crypto_pwhash_OPSLIMIT_SENSITIVE,
- crypto_pwhash_MEMLIMIT_SENSITIVE,
- crypto_pwhash_ALG_DEFAULT) != 0) {
- fprintf(stderr, "pit: key derivation failed\n");
+ encrypted,
+ crypto_pwhash_OPSLIMIT_MIN,
+ crypto_pwhash_MEMLIMIT_MIN,
+ crypto_pwhash_ALG_DEFAULT);
+ }
+
+ if (r !=0) {
+ fprintf(stderr, "pit: key derivation faield - insufficient memory or wrong password\n");
goto cleanup;
}
+
*key = (char*)decrypted;
decrypted = NULL;