evp/e_aes: Expose IV
authorBoris Pismenny <borisp@mellanox.com>
Thu, 1 Jun 2017 05:54:55 +0000 (08:54 +0300)
committerMatt Caswell <matt@openssl.org>
Fri, 7 Dec 2018 11:25:45 +0000 (11:25 +0000)
This commit exposes the cipher's IV to applications.

Signed-off-by: Boris Pismenny <borisp@mellanox.com>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Yang <yang.yang@baishancloud.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5253)

crypto/evp/e_aes.c
include/openssl/evp.h

index 7b35575f0ae5dfce7d9aff48fac130a4c88b38da..09f6598b6c96cc74e4b47f77cded8b036fe872e9 100644 (file)
@@ -2866,6 +2866,14 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
         memcpy(ptr, c->buf, arg);
         return 1;
 
         memcpy(ptr, c->buf, arg);
         return 1;
 
+    case EVP_CTRL_GET_IV:
+        if (gctx->iv_gen != 1)
+            return 0;
+        if (gctx->ivlen != arg)
+            return 0;
+        memcpy(ptr, gctx->iv, arg);
+        return 1;
+
     case EVP_CTRL_GCM_SET_IV_FIXED:
         /* Special case: -1 length restores whole IV */
         if (arg == -1) {
     case EVP_CTRL_GCM_SET_IV_FIXED:
         /* Special case: -1 length restores whole IV */
         if (arg == -1) {
index f381a5760f0782e7c7da42a2e7225fd0537c1e25..636ed1b680ac7da78eacfe4f3e8ffc4699e3d6d0 100644 (file)
@@ -350,6 +350,8 @@ int (*EVP_CIPHER_meth_get_ctrl(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
 # define         EVP_CTRL_SET_PIPELINE_INPUT_BUFS        0x23
 /* Set the input buffer lengths to use for a pipelined operation */
 # define         EVP_CTRL_SET_PIPELINE_INPUT_LENS        0x24
 # define         EVP_CTRL_SET_PIPELINE_INPUT_BUFS        0x23
 /* Set the input buffer lengths to use for a pipelined operation */
 # define         EVP_CTRL_SET_PIPELINE_INPUT_LENS        0x24
+/* Get the IV used by the cipher */
+# define         EVP_CTRL_GET_IV                         0x25
 
 /* Padding modes */
 #define EVP_PADDING_PKCS7       1
 
 /* Padding modes */
 #define EVP_PADDING_PKCS7       1