diff options
author | Jakob Unterwurzacher | 2021-09-03 17:11:57 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2021-09-07 18:14:05 +0200 |
commit | 69d626b26f5a3f55c752b59af44710b992e2ab76 (patch) | |
tree | 030d8b65aedb4a6d8e40c3f9c3552775a38d0669 /internal/stupidgcm/chacha.c | |
parent | a3f5a8492a8bc62d8e2a639bd449b425efa66ce2 (diff) |
stupidgcm: replace chacha20poly1305_seal with generic aead_seal
Diffstat (limited to 'internal/stupidgcm/chacha.c')
-rw-r--r-- | internal/stupidgcm/chacha.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/internal/stupidgcm/chacha.c b/internal/stupidgcm/chacha.c index c85cf78..e188bfc 100644 --- a/internal/stupidgcm/chacha.c +++ b/internal/stupidgcm/chacha.c @@ -1,9 +1,8 @@ +#include "chacha.h" #include <openssl/evp.h> #include <stdio.h> //#cgo pkg-config: libcrypto -extern void panic1(void); - static void panic(const char* const msg) { fprintf(stderr, "panic in C code: %s\n", msg); @@ -11,7 +10,8 @@ static void panic(const char* const msg) } // https://wiki.openssl.org/index.php/EVP_Authenticated_Encryption_and_Decryption#Authenticated_Encryption_using_GCM_mode -int chacha20poly1305_seal( +int aead_seal( + const enum aeadType cipherId, const unsigned char* const plaintext, const int plaintextLen, const unsigned char* const authData, @@ -23,6 +23,18 @@ int chacha20poly1305_seal( unsigned char* const ciphertext, const int ciphertextBufLen) { + const EVP_CIPHER* evpCipher = NULL; + switch (cipherId) { + case aeadTypeChacha: + evpCipher = EVP_chacha20_poly1305(); + break; + case aeadTypeGcm: + evpCipher = EVP_aes_256_gcm(); + break; + default: + panic("unknown cipherId"); + } + // Create scratch space "context" EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new(); if (!ctx) { @@ -30,7 +42,7 @@ int chacha20poly1305_seal( } // Set cipher - if (EVP_EncryptInit_ex(ctx, EVP_chacha20_poly1305(), NULL, NULL, NULL) != 1) { + if (EVP_EncryptInit_ex(ctx, evpCipher, NULL, NULL, NULL) != 1) { panic("EVP_EncryptInit_ex set cipher failed"); } |