Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/crypto/clu_encrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ int wolfCLU_encrypt(int alg, char* mode, byte* pwdKey, byte* key, int size,

if (ret != 0) {
XFCLOSE(inFile);
wc_FreeRng(&rng);
return ret;
}

Expand All @@ -137,6 +138,7 @@ int wolfCLU_encrypt(int alg, char* mode, byte* pwdKey, byte* key, int size,
if (ret != WOLFCLU_SUCCESS) {
wolfCLU_LogError("failed to set pwdKey.");
XFCLOSE(inFile);
wc_FreeRng(&rng);
return ret;
}
/* move the generated pwdKey to "key" for encrypting */
Expand All @@ -150,6 +152,7 @@ int wolfCLU_encrypt(int alg, char* mode, byte* pwdKey, byte* key, int size,
if (outFile == NULL) {
wolfCLU_LogError("unable to open output file %s", out);
XFCLOSE(inFile);
wc_FreeRng(&rng);
return WOLFCLU_FATAL_ERROR;
}
XFWRITE(salt, 1, SALT_SIZE, outFile);
Expand All @@ -160,12 +163,14 @@ int wolfCLU_encrypt(int alg, char* mode, byte* pwdKey, byte* key, int size,
input = (byte*) XMALLOC(MAX_LEN, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (input == NULL) {
XFCLOSE(inFile);
wc_FreeRng(&rng);
return MEMORY_E;
}
output = (byte*) XMALLOC(MAX_LEN, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (output == NULL) {
XFCLOSE(inFile);
wolfCLU_freeBins(input, NULL, NULL, NULL, NULL);
wc_FreeRng(&rng);
return MEMORY_E;
}
Comment on lines 163 to 175

Expand Down Expand Up @@ -197,6 +202,7 @@ int wolfCLU_encrypt(int alg, char* mode, byte* pwdKey, byte* key, int size,
wolfCLU_LogError("failed during conversion of input,"
" ret = %d", hexRet);
XFCLOSE(inFile);
wc_FreeRng(&rng);
return hexRet;
Comment on lines 202 to 206
}
}/* end hex or ascii */
Expand All @@ -211,6 +217,7 @@ int wolfCLU_encrypt(int alg, char* mode, byte* pwdKey, byte* key, int size,
else { /* otherwise we got a file read error */
wolfCLU_freeBins(input, output, NULL, NULL, NULL);
XFCLOSE(inFile);
wc_FreeRng(&rng);
return FREAD_ERROR;
}/* End feof check */
}/* End fread check */
Expand All @@ -223,6 +230,7 @@ int wolfCLU_encrypt(int alg, char* mode, byte* pwdKey, byte* key, int size,
XFCLOSE(inFile);
wolfCLU_LogError("CamelliaSetKey failed.");
wolfCLU_freeBins(input, output, NULL, NULL, NULL);
wc_FreeRng(&rng);
return ret;
}
if (XSTRNCMP(mode, "cbc", 3) == 0) {
Expand All @@ -232,6 +240,7 @@ int wolfCLU_encrypt(int alg, char* mode, byte* pwdKey, byte* key, int size,
XFCLOSE(inFile);
wolfCLU_LogError("Incompatible mode while using Camellia.");
wolfCLU_freeBins(input, output, NULL, NULL, NULL);
wc_FreeRng(&rng);
return FATAL_ERROR;
}
}
Expand Down Expand Up @@ -259,6 +268,7 @@ int wolfCLU_encrypt(int alg, char* mode, byte* pwdKey, byte* key, int size,
XFCLOSE(inFile);
wolfCLU_LogError("failed to open file.");
wolfCLU_freeBins(input, output, NULL, NULL, NULL);
wc_FreeRng(&rng);
return FWRITE_ERROR;
}

Expand All @@ -269,13 +279,15 @@ int wolfCLU_encrypt(int alg, char* mode, byte* pwdKey, byte* key, int size,
XFCLOSE(inFile);
wolfCLU_LogError("failed to write to file.");
wolfCLU_freeBins(input, output, NULL, NULL, NULL);
wc_FreeRng(&rng);
return FWRITE_ERROR;
}
if (ret > MAX_LEN) {
XFCLOSE(outFile);
XFCLOSE(inFile);
wolfCLU_LogError("Wrote too much to file.");
wolfCLU_freeBins(input, output, NULL, NULL, NULL);
wc_FreeRng(&rng);
return FWRITE_ERROR;
}
/* close the outFile */
Expand Down
Loading