Add missing wc_AesInit calls.

pull/412/head
philljj 2023-11-30 15:14:05 -06:00
parent d091791f42
commit 96200032eb
4 changed files with 67 additions and 6 deletions

View File

@ -119,10 +119,19 @@ int AesEncrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
if (ret != 0)
return -1040;
/* inits aes structure */
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
if (ret != 0) {
printf("AesInit returned: %d\n", ret);
return -1001;
}
/* sets key */
ret = wc_AesSetKey(aes, key, size, iv, AES_ENCRYPTION);
if (ret != 0)
if (ret != 0) {
printf("SetKey returned: %d\n", ret);
return -1001;
}
/* encrypts the message to the output based on input length + padding */
ret = wc_AesCbcEncrypt(aes, output, input, length);
@ -195,10 +204,19 @@ int AesDecrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
if (ret != 0)
return -1050;
/* inits aes structure */
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
if (ret != 0) {
printf("AesInit returned: %d\n", ret);
return -1001;
}
/* sets key */
ret = wc_AesSetKey(aes, key, size, iv, AES_DECRYPTION);
if (ret != 0)
if (ret != 0) {
printf("SetKey returned: %d\n", ret);
return -1002;
}
/* change length to remove salt/iv block from being decrypted */
length -= (AES_BLOCK_SIZE + SALT_SIZE);

View File

@ -112,10 +112,19 @@ int AesEncrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
if (ret != 0)
return -1040;
/* inits aes structure */
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
if (ret != 0) {
printf("AesInit returned: %d\n", ret);
return -1001;
}
/* sets key */
ret = wc_AesSetKey(aes, key, size, iv, AES_ENCRYPTION);
if (ret != 0)
if (ret != 0) {
printf("SetKey returned: %d\n", ret);
return -1001;
}
/* encrypts the message to the output based on input length + padding */
ret = wc_AesCfbEncrypt(aes, output, input, length);
@ -188,11 +197,20 @@ int AesDecrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
if (ret != 0)
return -1050;
/* inits aes structure */
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
if (ret != 0) {
printf("AesInit returned: %d\n", ret);
return -1002;
}
/* sets key */
/* decrypt uses AES_ENCRYPTION */
ret = wc_AesSetKey(aes, key, size, iv, AES_ENCRYPTION);
if (ret != 0)
if (ret != 0) {
printf("SetKey returned: %d\n", ret);
return -1002;
}
/* change length to remove salt/iv block from being decrypted */
length -= (AES_BLOCK_SIZE + SALT_SIZE);

View File

@ -95,10 +95,19 @@ int AesCtrEncrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
if (ret != 0)
return -1040;
/* inits aes structure */
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
if (ret != 0) {
printf("AesInit returned: %d\n", ret);
return -1001;
}
/* sets key */
ret = wc_AesSetKey(aes, key, size, iv, AES_ENCRYPTION);
if (ret != 0)
if (ret != 0) {
printf("SetKey returned: %d\n", ret);
return -1001;
}
/* encrypts the message to the output based on input length + padding */
ret = wc_AesCtrEncrypt(aes, output, input, length);
@ -164,11 +173,20 @@ int AesCtrDecrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
if (ret != 0)
return -1050;
/* inits aes structure */
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
if (ret != 0) {
printf("AesInit returned: %d\n", ret);
return -1002;
}
/* sets key */
/* decrypt uses AES_ENCRYPTION */
ret = wc_AesSetKey(aes, key, size, iv, AES_ENCRYPTION);
if (ret != 0)
if (ret != 0) {
printf("SetKey returned: %d\n", ret);
return -1002;
}
ret = wc_AesCtrEncrypt(aes, output, c, cSz);
if (ret != 0)

View File

@ -235,6 +235,13 @@ int encrypt_file_AesGCM(const char *in_file, const char *out_file,
strncpy((char *)iv, iv_str, AES_IV_SIZE);
strncpy((char *)key, key_str, AES_KEY_SIZE);
/* inits aes structure */
ret = wc_AesInit(&gcm, NULL, INVALID_DEVID);
if (ret != 0) {
printf("AesInit returned: %d\n", ret);
goto exit;
}
ret = wc_AesGcmEncryptInit(&gcm, key, AES_KEY_SIZE, iv, AES_IV_SIZE);
if (ret == 0) {
/* Write magic label in the beginning of the cipher file */