|
@@ -58,7 +58,6 @@ int aes_gcm_128(int enc, unsigned char *key, unsigned char *iv, unsigned char* p
|
|
|
{
|
|
|
int len;
|
|
|
int ciphertext_len;
|
|
|
- int reset_return;
|
|
|
if(ctx == NULL)
|
|
|
{
|
|
|
/* Create and initialise the context */
|
|
@@ -68,10 +67,8 @@ int aes_gcm_128(int enc, unsigned char *key, unsigned char *iv, unsigned char* p
|
|
|
/* Initialise the encryption operation. */
|
|
|
if(1 != EVP_CipherInit_ex(ctx, EVP_aes_128_gcm(), NULL, key, iv, enc))
|
|
|
{
|
|
|
- reset_return = EVP_CIPHER_CTX_reset(ctx);
|
|
|
+ EVP_CIPHER_CTX_init(ctx);
|
|
|
ERR_print_errors_fp(stderr);
|
|
|
- if(reset_return != 1)
|
|
|
- return 0xf2;
|
|
|
return 0x2;
|
|
|
}
|
|
|
/* Provide the message to be encrypted, and obtain the encrypted output.
|
|
@@ -79,10 +76,8 @@ int aes_gcm_128(int enc, unsigned char *key, unsigned char *iv, unsigned char* p
|
|
|
*/
|
|
|
if(1 != EVP_CipherUpdate(ctx, ciphertext, &len, plaintext, plaintext_len))
|
|
|
{
|
|
|
- reset_return = EVP_CIPHER_CTX_reset(ctx);
|
|
|
+ EVP_CIPHER_CTX_init(ctx);
|
|
|
ERR_print_errors_fp(stderr);
|
|
|
- if(1 != reset_return)
|
|
|
- return 0xF3;
|
|
|
return 0x3;
|
|
|
}
|
|
|
ciphertext_len = len;
|
|
@@ -91,10 +86,8 @@ int aes_gcm_128(int enc, unsigned char *key, unsigned char *iv, unsigned char* p
|
|
|
{
|
|
|
if(1 != EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, 16, tag))
|
|
|
{
|
|
|
- reset_return = EVP_CIPHER_CTX_reset(ctx);
|
|
|
+ EVP_CIPHER_CTX_init(ctx);
|
|
|
ERR_print_errors_fp(stderr); fflush(stderr);
|
|
|
- if(1 != reset_return)
|
|
|
- return 0xF5;
|
|
|
return 0x5;
|
|
|
}
|
|
|
}
|
|
@@ -106,10 +99,8 @@ int aes_gcm_128(int enc, unsigned char *key, unsigned char *iv, unsigned char* p
|
|
|
// TODO: ^^^ Why the heck does it not occur in GCM mode ?
|
|
|
if(1 != EVP_CipherFinal_ex(ctx, ciphertext + len, &len))
|
|
|
{
|
|
|
- reset_return = EVP_CIPHER_CTX_reset(ctx);
|
|
|
+ EVP_CIPHER_CTX_init(ctx);
|
|
|
ERR_print_errors_fp(stderr); fflush(stderr);
|
|
|
- if(1 != reset_return)
|
|
|
- return 0xF4;
|
|
|
return 0x4;
|
|
|
}
|
|
|
ciphertext_len += len;
|
|
@@ -119,20 +110,14 @@ int aes_gcm_128(int enc, unsigned char *key, unsigned char *iv, unsigned char* p
|
|
|
{
|
|
|
if(1 != EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, 16, tag))
|
|
|
{
|
|
|
- reset_return = EVP_CIPHER_CTX_reset(ctx);
|
|
|
+ EVP_CIPHER_CTX_init(ctx);
|
|
|
ERR_print_errors_fp(stderr); fflush(stderr);
|
|
|
- if(1 != reset_return)
|
|
|
- return 0xF5;
|
|
|
return 0x5;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/* Clean up */
|
|
|
- if(1 != EVP_CIPHER_CTX_reset(ctx))
|
|
|
- {
|
|
|
- ERR_print_errors_fp(stderr); fflush(stderr);
|
|
|
- return 0xF0;
|
|
|
- }
|
|
|
+ EVP_CIPHER_CTX_init(ctx);
|
|
|
|
|
|
*op_ciphertext_len=ciphertext_len;
|
|
|
return 0;
|