add multiline option and fix fread params

This commit is contained in:
Night Kaly 2024-04-10 17:00:59 +01:00
parent 57ffcff2f1
commit f418fec045
Signed by: night0721
GPG key ID: 957D67B8DB7A119B
2 changed files with 19 additions and 5 deletions

View file

@ -24,7 +24,7 @@ $ make
# Usage
```
Usage: ./argon [-vheRIQLG] [-v] [-h] [-e <password>] [-R <password>] [-I <password>] [-Q <password>] [-L] [-G <password> <length>]
Usage: argon [-vhL] [[-e | -R | -I | -Q] <password>] [-M <file>] [-G <password> <length>]
```
# Contributions

22
argon.c
View file

@ -33,7 +33,7 @@ char *get_master_key();
void usage()
{
printf("Usage: %s [-vhL] [[-e | -R | -I | -Q] <password>] [-G <password> <length>]\n", argv0);
printf("Usage: %s [-vhL] [[-e | -R | -I | -Q] <password>] [-M <file>] [-G <password> <length>]\n", argv0);
exit(EXIT_SUCCESS);
}
@ -214,15 +214,15 @@ void decrypt_password(const char *name, int open)
}
/* get salt and nonce from file */
fread(salt, sizeof(salt), 1, file);
fread(nonce, sizeof(nonce), 1, file);
fread(salt, sizeof(char), sizeof(salt), file);
fread(nonce, sizeof(char), sizeof(nonce), file);
fseek(file, 0, SEEK_END);
size_t ciphered_len = ftell(file) - sizeof(salt) - sizeof(nonce);
fseek(file, sizeof(salt) + sizeof(nonce), SEEK_SET);
char ciphered[ciphered_len];
fread(ciphered, 1, ciphered_len, file);
fread(ciphered, sizeof(char), ciphered_len, file);
if (crypto_pwhash(key, sizeof(key), m_key, strlen(m_key), salt,
crypto_pwhash_OPSLIMIT_INTERACTIVE,
crypto_pwhash_MEMLIMIT_INTERACTIVE,
@ -371,6 +371,20 @@ int main(int argc, char *argv[])
free(argon);
exit(EXIT_SUCCESS);
break;
case 'M':;
char *filename = EARGF(usage());
FILE *file = fopen(filename, "r");
if (file == NULL) {
die("Cannot open file to read");
}
fseek(file, 0, SEEK_END);
long file_size = ftell(file);
fseek(file, 0, SEEK_SET);
char *content = memalloc(file_size * sizeof(char));
fread(content, sizeof(char), file_size, file);
encrypt_password(basename(filename), content);
exit(EXIT_SUCCESS);
break;
case 'G':;
if (argc > 0)
--argc, ++argv;