[c] Changed itersize to 80000 and removed some prints
This commit is contained in:
parent
b9dac186ab
commit
ca19746259
1 changed files with 11 additions and 28 deletions
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#define KEY_SIZE 32
|
#define KEY_SIZE 32
|
||||||
#define SALT_SIZE 16
|
#define SALT_SIZE 16
|
||||||
#define ITERATIONS 10000
|
#define ITERATIONS 80000
|
||||||
|
|
||||||
int aes_ctr(const char *input_file, const char *output_file, const unsigned char *key, int enc) {
|
int aes_ctr(const char *input_file, const char *output_file, const unsigned char *key, int enc) {
|
||||||
|
|
||||||
|
@ -142,6 +142,7 @@ int encrypt(char *input_file, const char *passphrase) {
|
||||||
}
|
}
|
||||||
if (fwrite(salt, 1, 16, foutput) != 16) {
|
if (fwrite(salt, 1, 16, foutput) != 16) {
|
||||||
fprintf(stderr, "Error writing salt to file\n");
|
fprintf(stderr, "Error writing salt to file\n");
|
||||||
|
fclose(foutput);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
fclose(foutput);
|
fclose(foutput);
|
||||||
|
@ -152,18 +153,6 @@ int encrypt(char *input_file, const char *passphrase) {
|
||||||
fprintf(stderr, "Error deriving key from passphrase\n");
|
fprintf(stderr, "Error deriving key from passphrase\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print salt and key
|
|
||||||
printf("Salt: ");
|
|
||||||
for (int i = 0; i < SALT_SIZE; i++) {
|
|
||||||
printf("%02x", salt[i]);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
printf("Key: ");
|
|
||||||
for (int i = 0; i < KEY_SIZE; i++) {
|
|
||||||
printf("%02x", key[i]);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
aes_ctr(input_file, output_file, key, 1);
|
aes_ctr(input_file, output_file, key, 1);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -184,6 +173,7 @@ int decrypt(char *input_file, const char *passphrase) {
|
||||||
}
|
}
|
||||||
if (fread(salt, 1, 16, finput) != 16) {
|
if (fread(salt, 1, 16, finput) != 16) {
|
||||||
fprintf(stderr, "Error reading salt from file\n");
|
fprintf(stderr, "Error reading salt from file\n");
|
||||||
|
fclose(finput);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
fclose(finput);
|
fclose(finput);
|
||||||
|
@ -195,18 +185,6 @@ int decrypt(char *input_file, const char *passphrase) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print salt and key
|
|
||||||
printf("Salt: ");
|
|
||||||
for (int i = 0; i < SALT_SIZE; i++) {
|
|
||||||
printf("%02x", salt[i]);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
printf("Key: ");
|
|
||||||
for (int i = 0; i < KEY_SIZE; i++) {
|
|
||||||
printf("%02x", key[i]);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
aes_ctr(input_file, output_file, key, 0);
|
aes_ctr(input_file, output_file, key, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -237,11 +215,16 @@ int main(int argc, char *argv[]) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
passphrase[strcspn(passphrase, "\n")] = '\0'; // Remove trailing newline
|
passphrase[strcspn(passphrase, "\n")] = '\0'; // Remove trailing newline
|
||||||
|
int suc = 0;
|
||||||
if (strcmp(mode, "enc") == 0) {
|
if (strcmp(mode, "enc") == 0) {
|
||||||
encrypt(input_file, passphrase);
|
suc = encrypt(input_file, passphrase);
|
||||||
} else {
|
} else {
|
||||||
decrypt(input_file, passphrase);
|
suc = decrypt(input_file, passphrase);
|
||||||
}
|
}
|
||||||
|
if (suc == 0) {
|
||||||
|
printf("Operation completed successfully\n");
|
||||||
|
}else{
|
||||||
|
printf("Operation failed\n");
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue