/*
- * 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
* https://www.openssl.org/source/license.html
*/
+/*
+ * 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 "internal/provider_algs.h"
-#include "internal/providercommonerr.h"
+#include "prov/implementations.h"
+#include "prov/providercommon.h"
+#include "prov/providercommonerr.h"
-/* TODO (3.0) Figure out what flags are requred */
-#define TDES_WRAP_FLAGS (EVP_CIPH_WRAP_MODE \
- | EVP_CIPH_CUSTOM_IV \
- | EVP_CIPH_FLAG_CUSTOM_CIPHER)
+/* 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] =
{
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 */
int ret;
*outl = 0;
+ if (!ossl_prov_is_running())
+ return 0;
+
if (outsize < inl) {
- PROVerr(0, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
- return -1;
+ ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
+ return 0;
}
ret = tdes_wrap_cipher_internal(ctx, out, in, inl);
size_t inl)
{
*outl = 0;
+ if (inl == 0)
+ return 1;
if (outsize < inl) {
- PROVerr(0, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
+ ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
return 0;
}
if (!tdes_wrap_cipher(vctx, out, outl, outsize, in, inl)) {
- PROVerr(0, PROV_R_CIPHER_OPERATION_FAILED);
+ ERR_raise(ERR_LIB_PROV, PROV_R_CIPHER_OPERATION_FAILED);
return 0;
}
return 1;
# 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()); \
+ flags, ossl_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); \
+ return ossl_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 }, \
{ OSSL_FUNC_CIPHER_NEWCTX, (void (*)(void))tdes_wrap_newctx }, \
{ OSSL_FUNC_CIPHER_FREECTX, (void (*)(void))tdes_freectx }, \
{ OSSL_FUNC_CIPHER_UPDATE, (void (*)(void))tdes_wrap_update }, \
- { OSSL_FUNC_CIPHER_FINAL, (void (*)(void))cipher_generic_stream_final }, \
+ { OSSL_FUNC_CIPHER_FINAL, (void (*)(void))ossl_cipher_generic_stream_final },\
{ OSSL_FUNC_CIPHER_GET_PARAMS, (void (*)(void))tdes_wrap_get_params }, \
{ OSSL_FUNC_CIPHER_GETTABLE_PARAMS, \
- (void (*)(void))cipher_generic_gettable_params }, \
+ (void (*)(void))ossl_cipher_generic_gettable_params }, \
{ OSSL_FUNC_CIPHER_GET_CTX_PARAMS, (void (*)(void))tdes_get_ctx_params }, \
{ OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS, \
(void (*)(void))tdes_gettable_ctx_params }, \
{ OSSL_FUNC_CIPHER_SET_CTX_PARAMS, \
- (void (*)(void))cipher_generic_set_ctx_params }, \
+ (void (*)(void))ossl_cipher_generic_set_ctx_params }, \
{ OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS, \
- (void (*)(void))cipher_generic_settable_ctx_params }, \
+ (void (*)(void))ossl_cipher_generic_settable_ctx_params }, \
{ 0, NULL } \
}
-/* tdes_wrap_cbc_functions */
+/* ossl_tdes_wrap_cbc_functions */
IMPLEMENT_WRAP_CIPHER(TDES_WRAP_FLAGS, 64*3, 64, 0);