/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
+ * 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
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
#ifndef OPENSSL_NO_DES
# include <openssl/evp.h>
# include <openssl/objects.h>
-# include "internal/evp_int.h"
+# include "crypto/evp.h"
# include <openssl/des.h>
# include <openssl/rand.h>
-# include <openssl/rand_drbg.h>
-# include "evp_locl.h"
+# include "evp_local.h"
typedef struct {
union {
- double align;
+ OSSL_UNION_ALIGN;
DES_key_schedule ks[3];
} ks;
union {
{
DES_cblock *deskey = ptr;
+ int kl;
switch (type) {
case EVP_CTRL_RAND_KEY:
- if (ctx->drbg != NULL) {
- if (RAND_DRBG_bytes(ctx->drbg, ptr, EVP_CIPHER_CTX_key_length(ctx)) == 0)
- return 0;
- } else if (RAND_bytes(ptr, EVP_CIPHER_CTX_key_length(ctx)) <= 0) {
+ kl = EVP_CIPHER_CTX_key_length(ctx);
+ if (kl < 0 || RAND_priv_bytes(ptr, kl) <= 0)
return 0;
- }
DES_set_odd_parity(deskey);
- if (EVP_CIPHER_CTX_key_length(ctx) >= 16)
+ if (kl >= 16)
DES_set_odd_parity(deskey + 1);
- if (EVP_CIPHER_CTX_key_length(ctx) >= 24)
+ if (kl >= 24)
DES_set_odd_parity(deskey + 2);
return 1;
memcpy(out + inl + 8, sha1tmp, 8);
OPENSSL_cleanse(sha1tmp, SHA_DIGEST_LENGTH);
/* Generate random IV */
- if (ctx->drbg != NULL) {
- if (RAND_DRBG_bytes(ctx->drbg, EVP_CIPHER_CTX_iv_noconst(ctx), 8) == 0)
- return -1;
- } else if (RAND_bytes(EVP_CIPHER_CTX_iv_noconst(ctx), 8) <= 0) {
+ if (RAND_bytes(EVP_CIPHER_CTX_iv_noconst(ctx), 8) <= 0)
return -1;
- }
memcpy(out, EVP_CIPHER_CTX_iv_noconst(ctx), 8);
/* Encrypt everything after IV in place */
des_ede_cbc_cipher(ctx, out + 8, out + 8, inl + 8);