prov: prefix all OSSL_DISPATCH tables names with ossl_
[openssl.git] / providers / implementations / ciphers / cipher_tdes_wrap.c
index a6f4e4efe420ee74ca1697d424054895775a21d9..9007e403a4ce671679109ee1e63eb0a92fbbb22a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1995-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
@@ -8,24 +8,25 @@
  */
 
 /*
- * SHA-1 low level APIs are deprecated for public use, but still ok for
+ * DES and SHA-1 low level APIs are deprecated for public use, but still ok for
  * internal use.
  */
 #include "internal/deprecated.h"
 
 #include <openssl/sha.h>
+#include <openssl/rand.h>
 #include "cipher_tdes_default.h"
 #include "crypto/evp.h"
-#include "crypto/rand.h"
 #include "prov/implementations.h"
+#include "prov/providercommon.h"
 #include "prov/providercommonerr.h"
 
 /* TODO (3.0) Figure out what flags are required */
 #define TDES_WRAP_FLAGS (EVP_CIPH_WRAP_MODE | EVP_CIPH_CUSTOM_IV)
 
 
-static OSSL_OP_cipher_update_fn tdes_wrap_update;
-static OSSL_OP_cipher_cipher_fn tdes_wrap_cipher;
+static OSSL_FUNC_cipher_update_fn tdes_wrap_update;
+static OSSL_FUNC_cipher_cipher_fn tdes_wrap_cipher;
 
 static const unsigned char wrap_iv[8] =
 {
@@ -98,7 +99,7 @@ static int des_ede3_wrap(PROV_CIPHER_CTX *ctx, unsigned char *out,
     memcpy(out + inl + ivlen, sha1tmp, icvlen);
     OPENSSL_cleanse(sha1tmp, SHA_DIGEST_LENGTH);
     /* Generate random IV */
-    if (rand_bytes_ex(ctx->libctx, ctx->iv, ivlen) <= 0)
+    if (RAND_bytes_ex(ctx->libctx, ctx->iv, ivlen) <= 0)
         return 0;
     memcpy(out, ctx->iv, ivlen);
     /* Encrypt everything after IV in place */
@@ -133,6 +134,9 @@ static int tdes_wrap_cipher(void *vctx,
     int ret;
 
     *outl = 0;
+    if (!ossl_prov_is_running())
+        return 0;
+
     if (outsize < inl) {
         PROVerr(0, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
         return 0;
@@ -167,19 +171,19 @@ static int tdes_wrap_update(void *vctx, unsigned char *out, size_t *outl,
 
 
 # define IMPLEMENT_WRAP_CIPHER(flags, kbits, blkbits, ivbits)                  \
-static OSSL_OP_cipher_newctx_fn tdes_wrap_newctx;                              \
+static OSSL_FUNC_cipher_newctx_fn tdes_wrap_newctx;                            \
 static void *tdes_wrap_newctx(void *provctx)                                   \
 {                                                                              \
     return tdes_newctx(provctx, EVP_CIPH_WRAP_MODE, kbits, blkbits, ivbits,    \
                        flags, PROV_CIPHER_HW_tdes_wrap_cbc());                 \
 }                                                                              \
-static OSSL_OP_cipher_get_params_fn tdes_wrap_get_params;                      \
+static OSSL_FUNC_cipher_get_params_fn tdes_wrap_get_params;                    \
 static int tdes_wrap_get_params(OSSL_PARAM params[])                           \
 {                                                                              \
     return cipher_generic_get_params(params, EVP_CIPH_WRAP_MODE, flags,        \
                                      kbits, blkbits, ivbits);                  \
 }                                                                              \
-const OSSL_DISPATCH tdes_wrap_cbc_functions[] =                                \
+const OSSL_DISPATCH ossl_tdes_wrap_cbc_functions[] =                           \
 {                                                                              \
     { OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void)) tdes_einit },            \
     { OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void)) tdes_dinit },            \
@@ -201,5 +205,5 @@ const OSSL_DISPATCH tdes_wrap_cbc_functions[] =                                \
     { 0, NULL }                                                                \
 }
 
-/* tdes_wrap_cbc_functions */
+/* ossl_tdes_wrap_cbc_functions */
 IMPLEMENT_WRAP_CIPHER(TDES_WRAP_FLAGS, 64*3, 64, 0);