From: Andy Polyakov Date: Tue, 8 Dec 2015 18:46:28 +0000 (+0100) Subject: evp/e_aes.c: wire hardware-assisted block function to OCB. X-Git-Tag: OpenSSL_1_1_0-pre1~7 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=02dc0b82ab19c32bf072213feff746b5b35f8ef6;p=oweals%2Fopenssl.git evp/e_aes.c: wire hardware-assisted block function to OCB. Reviewed-by: Richard Levitte --- diff --git a/crypto/evp/e_aes.c b/crypto/evp/e_aes.c index c356c9a035..b067dcfdff 100644 --- a/crypto/evp/e_aes.c +++ b/crypto/evp/e_aes.c @@ -886,7 +886,8 @@ static int aes_t4_ocb_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, if (!CRYPTO_ocb128_init(&octx->ocb, &octx->ksenc.ks, &octx->ksdec.ks, (block128_f) aes_t4_encrypt, - (block128_f) aes_t4_decrypt)) + (block128_f) aes_t4_decrypt, + NULL)) return 0; } while (0); @@ -2343,6 +2344,29 @@ static int aes_ocb_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) } } +# ifdef HWAES_CAPABLE +# ifdef HWAES_ocb_encrypt +void HWAES_ocb_encrypt(const unsigned char *in, unsigned char *out, + size_t blocks, const void *key, + size_t start_block_num, + unsigned char offset_i[16], + const unsigned char L_[][16], + unsigned char checksum[16]); +# else +# define HWAES_ocb_encrypt NULL +# endif +# ifdef HWAES_ocb_decrypt +void HWAES_ocb_decrypt(const unsigned char *in, unsigned char *out, + size_t blocks, const void *key, + size_t start_block_num, + unsigned char offset_i[16], + const unsigned char L_[][16], + unsigned char checksum[16]); +# else +# define HWAES_ocb_decrypt NULL +# endif +# endif + static int aes_ocb_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc) { @@ -2356,6 +2380,20 @@ static int aes_ocb_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, * needs both. We could possibly optimise to remove setting the * decrypt for an encryption operation. */ +# ifdef HWAES_CAPABLE + if (HWAES_CAPABLE) { + HWAES_set_encrypt_key(key, ctx->key_len * 8, &octx->ksenc.ks); + HWAES_set_decrypt_key(key, ctx->key_len * 8, &octx->ksdec.ks); + if (!CRYPTO_ocb128_init(&octx->ocb, + &octx->ksenc.ks, &octx->ksdec.ks, + (block128_f) HWAES_encrypt, + (block128_f) HWAES_decrypt, + enc ? HWAES_ocb_encrypt + : HWAES_ocb_decrypt)) + return 0; + break; + } +# endif # ifdef VPAES_CAPABLE if (VPAES_CAPABLE) { vpaes_set_encrypt_key(key, ctx->key_len * 8, &octx->ksenc.ks);