|
@@ -132,8 +132,8 @@ void crypto_cleanup()
|
|
|
EVP_CIPHER_CTX_free(ctx);
|
|
|
}
|
|
|
|
|
|
-// Code adapted from here: https://wiki.openssl.org/index.php/EVP_Authenticated_Encryption_and_Decryption
|
|
|
-int aes_cipher(int enc, unsigned char *key, unsigned char *iv, unsigned char* plaintext, int plaintext_len, unsigned char *ciphertext, int* op_ciphertext_len, unsigned char* tag)
|
|
|
+// Code adapted from here: https://wiki.openssl.org/index.php/EVP_Authenticated_Encryption_and_Decryption
|
|
|
+int aes_gcm_128(int enc, unsigned char *key, unsigned char *iv, unsigned char* plaintext, int plaintext_len, unsigned char *ciphertext, int* op_ciphertext_len, unsigned char* tag)
|
|
|
{
|
|
|
int len;
|
|
|
int ciphertext_len;
|
|
@@ -172,7 +172,7 @@ int aes_cipher(int enc, unsigned char *key, unsigned char *iv, unsigned char* pl
|
|
|
{
|
|
|
reset_return = EVP_CIPHER_CTX_reset(ctx);
|
|
|
ERR_print_errors_fp(stderr); fflush(stderr);
|
|
|
- if(1 != reset_return)
|
|
|
+ if(1 != reset_return)
|
|
|
return 0xF5;
|
|
|
return 0x5;
|
|
|
}
|
|
@@ -182,8 +182,8 @@ int aes_cipher(int enc, unsigned char *key, unsigned char *iv, unsigned char* pl
|
|
|
/* Finalise the encryption. Normally ciphertext bytes may be written at
|
|
|
* this stage, but this does not occur in GCM mode
|
|
|
*/
|
|
|
- // TODO: ^^^ Why the heck does it not occur in GCM mode ?
|
|
|
- if(1 != EVP_CipherFinal_ex(ctx, ciphertext + len, &len))
|
|
|
+ // 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);
|
|
|
ERR_print_errors_fp(stderr); fflush(stderr);
|
|
@@ -200,7 +200,7 @@ int aes_cipher(int enc, unsigned char *key, unsigned char *iv, unsigned char* pl
|
|
|
{
|
|
|
reset_return = EVP_CIPHER_CTX_reset(ctx);
|
|
|
ERR_print_errors_fp(stderr); fflush(stderr);
|
|
|
- if(1 != reset_return)
|
|
|
+ if(1 != reset_return)
|
|
|
return 0xF5;
|
|
|
return 0x5;
|
|
|
}
|
|
@@ -210,10 +210,10 @@ int aes_cipher(int enc, unsigned char *key, unsigned char *iv, unsigned char* pl
|
|
|
if(1 != EVP_CIPHER_CTX_reset(ctx))
|
|
|
{
|
|
|
ERR_print_errors_fp(stderr); fflush(stderr);
|
|
|
- return 0xF0;
|
|
|
+ return 0xF0;
|
|
|
}
|
|
|
|
|
|
- *op_ciphertext_len=ciphertext_len;
|
|
|
+ *op_ciphertext_len=ciphertext_len;
|
|
|
return 0;
|
|
|
}
|
|
|
|