Make the naming scheme for dispatched functions more consistent
[openssl.git] / providers / implementations / ciphers / cipher_des.c
index 74539d3da4dd7c1b6b84e6b26d81dfb364c7c07c..7a7f16e45429f865bde41f9d5366b208150ba2f7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
  *
  * Licensed under the Apache License 2.0 (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
@@ -7,6 +7,12 @@
  * https://www.openssl.org/source/license.html
  */
 
+/*
+ * DES low level APIs are deprecated for public use, but still ok for internal
+ * use.
+ */
+#include "internal/deprecated.h"
+
 #include "prov/ciphercommon.h"
 #include "cipher_des.h"
 #include <openssl/rand.h>
 /* TODO(3.0) Figure out what flags need to be here */
 #define DES_FLAGS (EVP_CIPH_RAND_KEY)
 
-static OSSL_OP_cipher_freectx_fn des_freectx;
-static OSSL_OP_cipher_encrypt_init_fn des_einit;
-static OSSL_OP_cipher_decrypt_init_fn des_dinit;
-static OSSL_OP_cipher_get_ctx_params_fn des_get_ctx_params;
-static OSSL_OP_cipher_gettable_ctx_params_fn des_gettable_ctx_params;
+static OSSL_FUNC_cipher_freectx_fn des_freectx;
+static OSSL_FUNC_cipher_encrypt_init_fn des_einit;
+static OSSL_FUNC_cipher_decrypt_init_fn des_dinit;
+static OSSL_FUNC_cipher_get_ctx_params_fn des_get_ctx_params;
+static OSSL_FUNC_cipher_gettable_ctx_params_fn des_gettable_ctx_params;
 
 static void *des_newctx(void *provctx, size_t kbits, size_t blkbits,
                         size_t ivbits, unsigned int mode, uint64_t flags,
@@ -34,6 +40,20 @@ static void *des_newctx(void *provctx, size_t kbits, size_t blkbits,
     return ctx;
 }
 
+static void *des_dupctx(void *ctx)
+{
+    PROV_DES_CTX *in = (PROV_DES_CTX *)ctx;
+    PROV_DES_CTX *ret = OPENSSL_malloc(sizeof(*ret));
+
+    if (ret == NULL) {
+        ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
+        return NULL;
+    }
+    in->base.hw->copyctx(&ret->base, &in->base);
+
+    return ret;
+}
+
 static void des_freectx(void *vctx)
 {
     PROV_DES_CTX *ctx = (PROV_DES_CTX *)vctx;
@@ -109,14 +129,14 @@ static int des_get_ctx_params(void *vctx, OSSL_PARAM params[])
 
 #define IMPLEMENT_des_cipher(type, lcmode, UCMODE, flags,                      \
                              kbits, blkbits, ivbits, block)                    \
-static OSSL_OP_cipher_newctx_fn type##_##lcmode##_newctx;                      \
+static OSSL_FUNC_cipher_newctx_fn type##_##lcmode##_newctx;                    \
 static void *des_##lcmode##_newctx(void *provctx)                              \
 {                                                                              \
     return des_newctx(provctx, kbits, blkbits, ivbits,                         \
                       EVP_CIPH_##UCMODE##_MODE, flags,                         \
                       PROV_CIPHER_HW_des_##lcmode());                          \
 }                                                                              \
-static OSSL_OP_cipher_get_params_fn des_##lcmode##_get_params;                 \
+static OSSL_FUNC_cipher_get_params_fn des_##lcmode##_get_params;               \
 static int des_##lcmode##_get_params(OSSL_PARAM params[])                      \
 {                                                                              \
     return cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE, flags,  \
@@ -131,6 +151,7 @@ const OSSL_DISPATCH des_##lcmode##_functions[] = {                             \
     { OSSL_FUNC_CIPHER_CIPHER, (void (*)(void))cipher_generic_cipher },        \
     { OSSL_FUNC_CIPHER_NEWCTX,                                                 \
       (void (*)(void))des_##lcmode##_newctx },                                 \
+    { OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void))des_dupctx },                   \
     { OSSL_FUNC_CIPHER_FREECTX, (void (*)(void))des_freectx },                 \
     { OSSL_FUNC_CIPHER_GET_PARAMS,                                             \
       (void (*)(void))des_##lcmode##_get_params },                             \