Skip to content

Commit 9620003

Browse files
committed
Add missing wc_AesInit calls.
1 parent d091791 commit 9620003

4 files changed

Lines changed: 67 additions & 6 deletions

File tree

crypto/aes/aes-file-encrypt.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,19 @@ int AesEncrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
119119
if (ret != 0)
120120
return -1040;
121121

122+
/* inits aes structure */
123+
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
124+
if (ret != 0) {
125+
printf("AesInit returned: %d\n", ret);
126+
return -1001;
127+
}
128+
122129
/* sets key */
123130
ret = wc_AesSetKey(aes, key, size, iv, AES_ENCRYPTION);
124-
if (ret != 0)
131+
if (ret != 0) {
132+
printf("SetKey returned: %d\n", ret);
125133
return -1001;
134+
}
126135

127136
/* encrypts the message to the output based on input length + padding */
128137
ret = wc_AesCbcEncrypt(aes, output, input, length);
@@ -195,10 +204,19 @@ int AesDecrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
195204
if (ret != 0)
196205
return -1050;
197206

207+
/* inits aes structure */
208+
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
209+
if (ret != 0) {
210+
printf("AesInit returned: %d\n", ret);
211+
return -1001;
212+
}
213+
198214
/* sets key */
199215
ret = wc_AesSetKey(aes, key, size, iv, AES_DECRYPTION);
200-
if (ret != 0)
216+
if (ret != 0) {
217+
printf("SetKey returned: %d\n", ret);
201218
return -1002;
219+
}
202220

203221
/* change length to remove salt/iv block from being decrypted */
204222
length -= (AES_BLOCK_SIZE + SALT_SIZE);

crypto/aes/aescfb-file-encrypt.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,19 @@ int AesEncrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
112112
if (ret != 0)
113113
return -1040;
114114

115+
/* inits aes structure */
116+
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
117+
if (ret != 0) {
118+
printf("AesInit returned: %d\n", ret);
119+
return -1001;
120+
}
121+
115122
/* sets key */
116123
ret = wc_AesSetKey(aes, key, size, iv, AES_ENCRYPTION);
117-
if (ret != 0)
124+
if (ret != 0) {
125+
printf("SetKey returned: %d\n", ret);
118126
return -1001;
127+
}
119128

120129
/* encrypts the message to the output based on input length + padding */
121130
ret = wc_AesCfbEncrypt(aes, output, input, length);
@@ -188,11 +197,20 @@ int AesDecrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
188197
if (ret != 0)
189198
return -1050;
190199

200+
/* inits aes structure */
201+
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
202+
if (ret != 0) {
203+
printf("AesInit returned: %d\n", ret);
204+
return -1002;
205+
}
206+
191207
/* sets key */
192208
/* decrypt uses AES_ENCRYPTION */
193209
ret = wc_AesSetKey(aes, key, size, iv, AES_ENCRYPTION);
194-
if (ret != 0)
210+
if (ret != 0) {
211+
printf("SetKey returned: %d\n", ret);
195212
return -1002;
213+
}
196214

197215
/* change length to remove salt/iv block from being decrypted */
198216
length -= (AES_BLOCK_SIZE + SALT_SIZE);

crypto/aes/aesctr-file-encrypt.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,19 @@ int AesCtrEncrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
9595
if (ret != 0)
9696
return -1040;
9797

98+
/* inits aes structure */
99+
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
100+
if (ret != 0) {
101+
printf("AesInit returned: %d\n", ret);
102+
return -1001;
103+
}
104+
98105
/* sets key */
99106
ret = wc_AesSetKey(aes, key, size, iv, AES_ENCRYPTION);
100-
if (ret != 0)
107+
if (ret != 0) {
108+
printf("SetKey returned: %d\n", ret);
101109
return -1001;
110+
}
102111

103112
/* encrypts the message to the output based on input length + padding */
104113
ret = wc_AesCtrEncrypt(aes, output, input, length);
@@ -164,11 +173,20 @@ int AesCtrDecrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
164173
if (ret != 0)
165174
return -1050;
166175

176+
/* inits aes structure */
177+
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
178+
if (ret != 0) {
179+
printf("AesInit returned: %d\n", ret);
180+
return -1002;
181+
}
182+
167183
/* sets key */
168184
/* decrypt uses AES_ENCRYPTION */
169185
ret = wc_AesSetKey(aes, key, size, iv, AES_ENCRYPTION);
170-
if (ret != 0)
186+
if (ret != 0) {
187+
printf("SetKey returned: %d\n", ret);
171188
return -1002;
189+
}
172190

173191
ret = wc_AesCtrEncrypt(aes, output, c, cSz);
174192
if (ret != 0)

crypto/aes/aesgcm-file-encrypt.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,13 @@ int encrypt_file_AesGCM(const char *in_file, const char *out_file,
235235
strncpy((char *)iv, iv_str, AES_IV_SIZE);
236236
strncpy((char *)key, key_str, AES_KEY_SIZE);
237237

238+
/* inits aes structure */
239+
ret = wc_AesInit(&gcm, NULL, INVALID_DEVID);
240+
if (ret != 0) {
241+
printf("AesInit returned: %d\n", ret);
242+
goto exit;
243+
}
244+
238245
ret = wc_AesGcmEncryptInit(&gcm, key, AES_KEY_SIZE, iv, AES_IV_SIZE);
239246
if (ret == 0) {
240247
/* Write magic label in the beginning of the cipher file */

0 commit comments

Comments
 (0)