2016-05-18 02:24:46 +08:00
|
|
|
/*
|
2021-04-22 21:38:44 +08:00
|
|
|
* Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 18:52:47 +08:00
|
|
|
*
|
2018-12-06 20:40:06 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:24:46 +08:00
|
|
|
* 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
|
1998-12-21 18:52:47 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-05-14 22:56:48 +08:00
|
|
|
#include "internal/cryptlib.h"
|
1999-04-24 06:13:45 +08:00
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/objects.h>
|
2019-09-28 06:45:33 +08:00
|
|
|
#include "crypto/evp.h"
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2000-06-03 22:13:58 +08:00
|
|
|
static int null_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
2015-01-22 11:40:55 +08:00
|
|
|
const unsigned char *iv, int enc);
|
2000-05-27 20:38:43 +08:00
|
|
|
static int null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
2015-01-22 11:40:55 +08:00
|
|
|
const unsigned char *in, size_t inl);
|
|
|
|
static const EVP_CIPHER n_cipher = {
|
|
|
|
NID_undef,
|
|
|
|
1, 0, 0, 0,
|
Add "origin" field to EVP_CIPHER, EVP_MD
Add a "where did this EVP_{CIPHER,MD} come from" flag: global, via fetch,
or via EVP_{CIPHER,MD}_meth_new. Update EVP_{CIPHER,MD}_free to handle all
three origins. The flag is deliberately right before some function pointers,
so that compile-time failures (int/pointer) will occur, as opposed to
taking a bit in the existing "flags" field. The "global variable" flag
is non-zero, so the default case of using OPENSSL_zalloc (for provider
ciphers), will do the right thing. Ref-counting is a no-op for
Make up_ref no-op for global MD and CIPHER objects
Deprecate EVP_MD_CTX_md(). Added EVP_MD_CTX_get0_md() (same semantics as
the deprecated function) and EVP_MD_CTX_get1_md(). Likewise, deprecate
EVP_CIPHER_CTX_cipher() in favor of EVP_CIPHER_CTX_get0_cipher(), and add
EVP_CIPHER_CTX_get1_CIPHER().
Refactor EVP_MD_free() and EVP_MD_meth_free() to call new common
evp_md_free_int() function.
Refactor EVP_CIPHER_free() and EVP_CIPHER_meth_free() to call new common
evp_cipher_free_int() function.
Also change some flags tests to explicit test == or != zero. E.g.,
if (flags & x) --> if ((flags & x) != 0)
if (!(flags & x)) --> if ((flags & x) == 0)
Only done for those lines where "get0_cipher" calls were made.
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14193)
2021-02-17 06:51:56 +08:00
|
|
|
EVP_ORIG_GLOBAL,
|
2015-01-22 11:40:55 +08:00
|
|
|
null_init_key,
|
|
|
|
null_cipher,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2001-03-09 10:51:02 +08:00
|
|
|
const EVP_CIPHER *EVP_enc_null(void)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2017-10-17 22:04:09 +08:00
|
|
|
return &n_cipher;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2000-06-03 22:13:58 +08:00
|
|
|
static int null_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
2015-01-22 11:40:55 +08:00
|
|
|
const unsigned char *iv, int enc)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2000-05-27 20:38:43 +08:00
|
|
|
static int null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
2015-01-22 11:40:55 +08:00
|
|
|
const unsigned char *in, size_t inl)
|
|
|
|
{
|
|
|
|
if (in != out)
|
2015-05-05 06:00:15 +08:00
|
|
|
memcpy(out, in, inl);
|
2015-01-22 11:40:55 +08:00
|
|
|
return 1;
|
|
|
|
}
|