diff options
author | Tomas Mraz <tomas@openssl.org> | 2021-11-12 16:31:35 +0100 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2021-11-15 09:26:03 +0100 |
commit | cf9a84a12dc4f3b314347e44f5c51b473a504926 (patch) | |
tree | cafb60e7cbe10d6f6bd0ab8f284cbcb992907a99 /providers | |
parent | 487934081d87a0d02bbb9afd6bd650d5d1afe8ea (diff) |
Add null digest implementation to the default provider
This is necessary to keep compatibility with 1.1.1.
Fixes #16660
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17016)
(cherry picked from commit bef9b48e5071cdd2b41a4f486d1bcb5e14b2a5c3)
Diffstat (limited to 'providers')
-rw-r--r-- | providers/defltprov.c | 1 | ||||
-rw-r--r-- | providers/implementations/digests/build.info | 3 | ||||
-rw-r--r-- | providers/implementations/digests/null_prov.c | 52 | ||||
-rw-r--r-- | providers/implementations/include/prov/digestcommon.h | 23 | ||||
-rw-r--r-- | providers/implementations/include/prov/implementations.h | 1 |
5 files changed, 70 insertions, 10 deletions
diff --git a/providers/defltprov.c b/providers/defltprov.c index 62258da723..6e669fbdfb 100644 --- a/providers/defltprov.c +++ b/providers/defltprov.c @@ -148,6 +148,7 @@ static const OSSL_ALGORITHM deflt_digests[] = { { PROV_NAMES_MD5_SHA1, "provider=default", ossl_md5_sha1_functions }, #endif /* OPENSSL_NO_MD5 */ + { PROV_NAMES_NULL, "provider=default", ossl_nullmd_functions }, { NULL, NULL, NULL } }; diff --git a/providers/implementations/digests/build.info b/providers/implementations/digests/build.info index 2c2b0c3db0..c6508b6e85 100644 --- a/providers/implementations/digests/build.info +++ b/providers/implementations/digests/build.info @@ -9,6 +9,7 @@ $SHA3_GOAL=../../libdefault.a ../../libfips.a $BLAKE2_GOAL=../../libdefault.a $SM3_GOAL=../../libdefault.a $MD5_GOAL=../../libdefault.a +$NULL_GOAL=../../libdefault.a $MD2_GOAL=../../liblegacy.a $MD4_GOAL=../../liblegacy.a @@ -22,6 +23,8 @@ SOURCE[$COMMON_GOAL]=digestcommon.c SOURCE[$SHA2_GOAL]=sha2_prov.c SOURCE[$SHA3_GOAL]=sha3_prov.c +SOURCE[$NULL_GOAL]=null_prov.c + IF[{- !$disabled{blake2} -}] SOURCE[$BLAKE2_GOAL]=blake2_prov.c blake2b_prov.c blake2s_prov.c ENDIF diff --git a/providers/implementations/digests/null_prov.c b/providers/implementations/digests/null_prov.c new file mode 100644 index 0000000000..b220a1966f --- /dev/null +++ b/providers/implementations/digests/null_prov.c @@ -0,0 +1,52 @@ +/* + * Copyright 2021 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 <openssl/crypto.h> +#include "prov/digestcommon.h" +#include "prov/implementations.h" + +typedef struct { + unsigned char nothing; +} NULLMD_CTX; + +static int null_init(NULLMD_CTX *ctx) +{ + return 1; +} + +static int null_update(NULLMD_CTX *ctx, const void *data, size_t datalen) +{ + return 1; +} + +static int null_final(unsigned char *md, NULLMD_CTX *ctx) +{ + return 1; +} + +/* + * We must override the PROV_FUNC_DIGEST_FINAL as dgstsize == 0 + * and that would cause compilation warnings with the default implementation. + */ +#undef PROV_FUNC_DIGEST_FINAL +#define PROV_FUNC_DIGEST_FINAL(name, dgstsize, fin) \ +static OSSL_FUNC_digest_final_fn name##_internal_final; \ +static int name##_internal_final(void *ctx, unsigned char *out, size_t *outl, \ + size_t outsz) \ +{ \ + if (ossl_prov_is_running() && fin(out, ctx)) { \ + *outl = dgstsize; \ + return 1; \ + } \ + return 0; \ +} + +IMPLEMENT_digest_functions(nullmd, NULLMD_CTX, + 0, 0, 0, + null_init, null_update, null_final) diff --git a/providers/implementations/include/prov/digestcommon.h b/providers/implementations/include/prov/digestcommon.h index b0ed83648d..abdb8bb2ad 100644 --- a/providers/implementations/include/prov/digestcommon.h +++ b/providers/implementations/include/prov/digestcommon.h @@ -35,6 +35,18 @@ static int name##_get_params(OSSL_PARAM params[]) \ { OSSL_FUNC_DIGEST_GETTABLE_PARAMS, \ (void (*)(void))ossl_digest_default_gettable_params } +# define PROV_FUNC_DIGEST_FINAL(name, dgstsize, fin) \ +static OSSL_FUNC_digest_final_fn name##_internal_final; \ +static int name##_internal_final(void *ctx, unsigned char *out, size_t *outl, \ + size_t outsz) \ +{ \ + if (ossl_prov_is_running() && outsz >= dgstsize && fin(out, ctx)) { \ + *outl = dgstsize; \ + return 1; \ + } \ + return 0; \ +} + # define PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START( \ name, CTX, blksize, dgstsize, flags, upd, fin) \ static OSSL_FUNC_digest_newctx_fn name##_newctx; \ @@ -58,16 +70,7 @@ static void *name##_dupctx(void *ctx) \ *ret = *in; \ return ret; \ } \ -static OSSL_FUNC_digest_final_fn name##_internal_final; \ -static int name##_internal_final(void *ctx, unsigned char *out, size_t *outl, \ - size_t outsz) \ -{ \ - if (ossl_prov_is_running() && outsz >= dgstsize && fin(out, ctx)) { \ - *outl = dgstsize; \ - return 1; \ - } \ - return 0; \ -} \ +PROV_FUNC_DIGEST_FINAL(name, dgstsize, fin) \ PROV_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags) \ const OSSL_DISPATCH ossl_##name##_functions[] = { \ { OSSL_FUNC_DIGEST_NEWCTX, (void (*)(void))name##_newctx }, \ diff --git a/providers/implementations/include/prov/implementations.h b/providers/implementations/include/prov/implementations.h index 73e1823742..30e5e4cd77 100644 --- a/providers/implementations/include/prov/implementations.h +++ b/providers/implementations/include/prov/implementations.h @@ -36,6 +36,7 @@ extern const OSSL_DISPATCH ossl_md4_functions[]; extern const OSSL_DISPATCH ossl_mdc2_functions[]; extern const OSSL_DISPATCH ossl_wp_functions[]; extern const OSSL_DISPATCH ossl_ripemd160_functions[]; +extern const OSSL_DISPATCH ossl_nullmd_functions[]; /* Ciphers */ extern const OSSL_DISPATCH ossl_null_functions[]; |