From 3103a616dc6b3150eaec0000af767f268a647f6d Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Sun, 13 Oct 2019 14:44:54 +0200 Subject: [PATCH 1/1] Move MD2, MD4 and MD5 digests completely to the providers This leaves minimal implementations of EVP_md2, EVP_md4, EVP_md5 and EVP_mdc2, that are now only there to provide a name for implicit fetches. Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/10164) --- crypto/evp/build.info | 17 ++++++++++-- crypto/evp/legacy_md2.c | 35 +++++++++++++++++++++++++ crypto/evp/legacy_md4.c | 35 +++++++++++++++++++++++++ crypto/evp/legacy_md5.c | 35 +++++++++++++++++++++++++ crypto/evp/legacy_mdc2.c | 35 +++++++++++++++++++++++++ crypto/evp/m_md2.c | 56 ---------------------------------------- crypto/evp/m_md4.c | 55 --------------------------------------- crypto/evp/m_md5.c | 55 --------------------------------------- crypto/evp/m_mdc2.c | 55 --------------------------------------- 9 files changed, 155 insertions(+), 223 deletions(-) create mode 100644 crypto/evp/legacy_md2.c create mode 100644 crypto/evp/legacy_md4.c create mode 100644 crypto/evp/legacy_md5.c create mode 100644 crypto/evp/legacy_mdc2.c delete mode 100644 crypto/evp/m_md2.c delete mode 100644 crypto/evp/m_md4.c delete mode 100644 crypto/evp/m_md5.c delete mode 100644 crypto/evp/m_mdc2.c diff --git a/crypto/evp/build.info b/crypto/evp/build.info index aef0031d3d..f2c798b703 100644 --- a/crypto/evp/build.info +++ b/crypto/evp/build.info @@ -7,8 +7,7 @@ SOURCE[../../libcrypto]=$COMMON\ e_des.c e_bf.c e_idea.c e_des3.c e_camellia.c\ e_rc4.c e_aes.c names.c e_seed.c e_aria.c e_sm4.c \ e_xcbc_d.c e_rc2.c e_cast.c e_rc5.c \ - m_null.c m_md2.c m_md4.c m_md5.c m_wp.c \ - m_mdc2.c m_ripemd.c \ + m_null.c m_wp.c m_ripemd.c \ p_open.c p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c p_dec.c \ bio_md.c bio_b64.c bio_enc.c evp_err.c e_null.c \ c_allc.c c_alld.c bio_ok.c \ @@ -19,6 +18,20 @@ SOURCE[../../libcrypto]=$COMMON\ e_chacha20_poly1305.c \ pkey_mac.c exchange.c \ legacy_sha.c legacy_md5_sha1.c + +IF[{- !$disabled{md2} -}] + SOURCE[../../libcrypto]=legacy_md2.c +ENDIF +IF[{- !$disabled{md4} -}] + SOURCE[../../libcrypto]=legacy_md4.c +ENDIF +IF[{- !$disabled{md5} -}] + SOURCE[../../libcrypto]=legacy_md5.c +ENDIF +IF[{- !$disabled{mdc2} -}] + SOURCE[../../libcrypto]=legacy_mdc2.c +ENDIF + SOURCE[../../providers/libfips.a]=$COMMON INCLUDE[e_aes.o]=.. ../modes diff --git a/crypto/evp/legacy_md2.c b/crypto/evp/legacy_md2.c new file mode 100644 index 0000000000..d399095f47 --- /dev/null +++ b/crypto/evp/legacy_md2.c @@ -0,0 +1,35 @@ +/* + * Copyright 2015-2019 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 + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include + +#ifndef OPENSSL_NO_MD2 + +# include +# include "crypto/evp.h" + +static const EVP_MD md2_md = { + NID_md2, + NID_md2WithRSAEncryption, + MD2_DIGEST_LENGTH, + 0, + NULL, + NULL, + NULL, + NULL, + NULL, + MD2_BLOCK, +}; + +const EVP_MD *EVP_md2(void) +{ + return &md2_md; +} + +#endif /* OPENSSL_NO_MD2 */ diff --git a/crypto/evp/legacy_md4.c b/crypto/evp/legacy_md4.c new file mode 100644 index 0000000000..fa57e98b78 --- /dev/null +++ b/crypto/evp/legacy_md4.c @@ -0,0 +1,35 @@ +/* + * Copyright 2015-2019 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 + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include + +#ifndef OPENSSL_NO_MD4 + +# include +# include "crypto/evp.h" + +static const EVP_MD md4_md = { + NID_md4, + NID_md4WithRSAEncryption, + MD4_DIGEST_LENGTH, + 0, + NULL, + NULL, + NULL, + NULL, + NULL, + MD4_CBLOCK, +}; + +const EVP_MD *EVP_md4(void) +{ + return &md4_md; +} + +#endif /* OPENSSL_NO_MD4 */ diff --git a/crypto/evp/legacy_md5.c b/crypto/evp/legacy_md5.c new file mode 100644 index 0000000000..f125b33f91 --- /dev/null +++ b/crypto/evp/legacy_md5.c @@ -0,0 +1,35 @@ +/* + * Copyright 2015-2019 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 + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include + +#ifndef OPENSSL_NO_MD5 + +# include +# include "crypto/evp.h" + +static const EVP_MD md5_md = { + NID_md5, + NID_md5WithRSAEncryption, + MD5_DIGEST_LENGTH, + 0, + NULL, + NULL, + NULL, + NULL, + NULL, + MD5_CBLOCK, +}; + +const EVP_MD *EVP_md5(void) +{ + return &md5_md; +} + +#endif /* OPENSSL_NO_MD5 */ diff --git a/crypto/evp/legacy_mdc2.c b/crypto/evp/legacy_mdc2.c new file mode 100644 index 0000000000..5b51b015ea --- /dev/null +++ b/crypto/evp/legacy_mdc2.c @@ -0,0 +1,35 @@ +/* + * Copyright 2015-2019 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 + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include + +#ifndef OPENSSL_NO_MDC2 + +# include +# include "crypto/evp.h" + +static const EVP_MD mdc2_md = { + NID_mdc2, + NID_mdc2WithRSA, + MDC2_DIGEST_LENGTH, + 0, + NULL, + NULL, + NULL, + NULL, + NULL, + MDC2_BLOCK, +}; + +const EVP_MD *EVP_mdc2(void) +{ + return &mdc2_md; +} + +#endif /* OPENSSL_NO_MDC2 */ diff --git a/crypto/evp/m_md2.c b/crypto/evp/m_md2.c deleted file mode 100644 index a8a0af96aa..0000000000 --- a/crypto/evp/m_md2.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 1995-2016 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 - * in the file LICENSE in the source distribution or at - * https://www.openssl.org/source/license.html - */ - -#include -#include "internal/cryptlib.h" - -#ifndef OPENSSL_NO_MD2 - -# include -# include -# include -# include -# include - -#include "crypto/evp.h" - -static int init(EVP_MD_CTX *ctx) -{ - return MD2_Init(EVP_MD_CTX_md_data(ctx)); -} - -static int update(EVP_MD_CTX *ctx, const void *data, size_t count) -{ - return MD2_Update(EVP_MD_CTX_md_data(ctx), data, count); -} - -static int final(EVP_MD_CTX *ctx, unsigned char *md) -{ - return MD2_Final(md, EVP_MD_CTX_md_data(ctx)); -} - -static const EVP_MD md2_md = { - NID_md2, - NID_md2WithRSAEncryption, - MD2_DIGEST_LENGTH, - 0, - init, - update, - final, - NULL, - NULL, - MD2_BLOCK, - sizeof(EVP_MD *) + sizeof(MD2_CTX), -}; - -const EVP_MD *EVP_md2(void) -{ - return &md2_md; -} -#endif diff --git a/crypto/evp/m_md4.c b/crypto/evp/m_md4.c deleted file mode 100644 index 9638213de7..0000000000 --- a/crypto/evp/m_md4.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 1995-2016 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 - * in the file LICENSE in the source distribution or at - * https://www.openssl.org/source/license.html - */ - -#include -#include "internal/cryptlib.h" - -#ifndef OPENSSL_NO_MD4 - -# include -# include -# include -# include -# include -# include "crypto/evp.h" - -static int init(EVP_MD_CTX *ctx) -{ - return MD4_Init(EVP_MD_CTX_md_data(ctx)); -} - -static int update(EVP_MD_CTX *ctx, const void *data, size_t count) -{ - return MD4_Update(EVP_MD_CTX_md_data(ctx), data, count); -} - -static int final(EVP_MD_CTX *ctx, unsigned char *md) -{ - return MD4_Final(md, EVP_MD_CTX_md_data(ctx)); -} - -static const EVP_MD md4_md = { - NID_md4, - NID_md4WithRSAEncryption, - MD4_DIGEST_LENGTH, - 0, - init, - update, - final, - NULL, - NULL, - MD4_CBLOCK, - sizeof(EVP_MD *) + sizeof(MD4_CTX), -}; - -const EVP_MD *EVP_md4(void) -{ - return &md4_md; -} -#endif diff --git a/crypto/evp/m_md5.c b/crypto/evp/m_md5.c deleted file mode 100644 index d817982488..0000000000 --- a/crypto/evp/m_md5.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 1995-2016 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 - * in the file LICENSE in the source distribution or at - * https://www.openssl.org/source/license.html - */ - -#include -#include "internal/cryptlib.h" - -#ifndef OPENSSL_NO_MD5 - -# include -# include -# include -# include -# include -# include "crypto/evp.h" - -static int init(EVP_MD_CTX *ctx) -{ - return MD5_Init(EVP_MD_CTX_md_data(ctx)); -} - -static int update(EVP_MD_CTX *ctx, const void *data, size_t count) -{ - return MD5_Update(EVP_MD_CTX_md_data(ctx), data, count); -} - -static int final(EVP_MD_CTX *ctx, unsigned char *md) -{ - return MD5_Final(md, EVP_MD_CTX_md_data(ctx)); -} - -static const EVP_MD md5_md = { - NID_md5, - NID_md5WithRSAEncryption, - MD5_DIGEST_LENGTH, - 0, - init, - update, - final, - NULL, - NULL, - MD5_CBLOCK, - sizeof(EVP_MD *) + sizeof(MD5_CTX), -}; - -const EVP_MD *EVP_md5(void) -{ - return &md5_md; -} -#endif diff --git a/crypto/evp/m_mdc2.c b/crypto/evp/m_mdc2.c deleted file mode 100644 index fdc689e115..0000000000 --- a/crypto/evp/m_mdc2.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 1995-2016 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 - * in the file LICENSE in the source distribution or at - * https://www.openssl.org/source/license.html - */ - -#include -#include "internal/cryptlib.h" - -#ifndef OPENSSL_NO_MDC2 - -# include -# include -# include -# include -# include -# include "crypto/evp.h" - -static int init(EVP_MD_CTX *ctx) -{ - return MDC2_Init(EVP_MD_CTX_md_data(ctx)); -} - -static int update(EVP_MD_CTX *ctx, const void *data, size_t count) -{ - return MDC2_Update(EVP_MD_CTX_md_data(ctx), data, count); -} - -static int final(EVP_MD_CTX *ctx, unsigned char *md) -{ - return MDC2_Final(md, EVP_MD_CTX_md_data(ctx)); -} - -static const EVP_MD mdc2_md = { - NID_mdc2, - NID_mdc2WithRSA, - MDC2_DIGEST_LENGTH, - 0, - init, - update, - final, - NULL, - NULL, - MDC2_BLOCK, - sizeof(EVP_MD *) + sizeof(MDC2_CTX), -}; - -const EVP_MD *EVP_mdc2(void) -{ - return &mdc2_md; -} -#endif -- 2.34.1