1b0d17251Schristos /* 2b0d17251Schristos * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved. 3b0d17251Schristos * 4b0d17251Schristos * Licensed under the Apache License 2.0 (the "License"). You may not use 5b0d17251Schristos * this file except in compliance with the License. You can obtain a copy 6b0d17251Schristos * in the file LICENSE in the source distribution or at 7b0d17251Schristos * https://www.openssl.org/source/license.html 8b0d17251Schristos */ 9b0d17251Schristos 10b0d17251Schristos /* 11b0d17251Schristos * SHA low level APIs are deprecated for public use, but still ok for 12b0d17251Schristos * internal use. 13b0d17251Schristos */ 14b0d17251Schristos #include "internal/deprecated.h" 15b0d17251Schristos 16b0d17251Schristos #include <openssl/crypto.h> 17b0d17251Schristos #include <openssl/core_dispatch.h> 18b0d17251Schristos #include <openssl/evp.h> 19b0d17251Schristos #include <openssl/sha.h> 20b0d17251Schristos #include <openssl/evp.h> 21b0d17251Schristos #include <openssl/params.h> 22b0d17251Schristos #include <openssl/core_names.h> 23b0d17251Schristos #include "prov/digestcommon.h" 24b0d17251Schristos #include "prov/implementations.h" 25b0d17251Schristos #include "crypto/sha.h" 26b0d17251Schristos 27b0d17251Schristos #define SHA2_FLAGS PROV_DIGEST_FLAG_ALGID_ABSENT 28b0d17251Schristos 29b0d17251Schristos static OSSL_FUNC_digest_set_ctx_params_fn sha1_set_ctx_params; 30b0d17251Schristos static OSSL_FUNC_digest_settable_ctx_params_fn sha1_settable_ctx_params; 31b0d17251Schristos 32b0d17251Schristos static const OSSL_PARAM known_sha1_settable_ctx_params[] = { 33b0d17251Schristos {OSSL_DIGEST_PARAM_SSL3_MS, OSSL_PARAM_OCTET_STRING, NULL, 0, 0}, 34b0d17251Schristos OSSL_PARAM_END 35b0d17251Schristos }; 36b0d17251Schristos static const OSSL_PARAM *sha1_settable_ctx_params(ossl_unused void *ctx, 37b0d17251Schristos ossl_unused void *provctx) 38b0d17251Schristos { 39b0d17251Schristos return known_sha1_settable_ctx_params; 40b0d17251Schristos } 41b0d17251Schristos 42b0d17251Schristos /* Special set_params method for SSL3 */ 43b0d17251Schristos static int sha1_set_ctx_params(void *vctx, const OSSL_PARAM params[]) 44b0d17251Schristos { 45b0d17251Schristos const OSSL_PARAM *p; 46b0d17251Schristos SHA_CTX *ctx = (SHA_CTX *)vctx; 47b0d17251Schristos 48b0d17251Schristos if (ctx == NULL) 49b0d17251Schristos return 0; 50b0d17251Schristos if (params == NULL) 51b0d17251Schristos return 1; 52b0d17251Schristos 53b0d17251Schristos p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_SSL3_MS); 54b0d17251Schristos if (p != NULL && p->data_type == OSSL_PARAM_OCTET_STRING) 55b0d17251Schristos return ossl_sha1_ctrl(ctx, EVP_CTRL_SSL3_MASTER_SECRET, 56b0d17251Schristos p->data_size, p->data); 57b0d17251Schristos return 1; 58b0d17251Schristos } 59b0d17251Schristos 60b0d17251Schristos /* ossl_sha1_functions */ 61b0d17251Schristos IMPLEMENT_digest_functions_with_settable_ctx( 62b0d17251Schristos sha1, SHA_CTX, SHA_CBLOCK, SHA_DIGEST_LENGTH, SHA2_FLAGS, 63b0d17251Schristos SHA1_Init, SHA1_Update, SHA1_Final, 64b0d17251Schristos sha1_settable_ctx_params, sha1_set_ctx_params) 65b0d17251Schristos 66b0d17251Schristos /* ossl_sha224_functions */ 67b0d17251Schristos IMPLEMENT_digest_functions(sha224, SHA256_CTX, 68b0d17251Schristos SHA256_CBLOCK, SHA224_DIGEST_LENGTH, SHA2_FLAGS, 69b0d17251Schristos SHA224_Init, SHA224_Update, SHA224_Final) 70b0d17251Schristos 71b0d17251Schristos /* ossl_sha256_functions */ 72b0d17251Schristos IMPLEMENT_digest_functions(sha256, SHA256_CTX, 73b0d17251Schristos SHA256_CBLOCK, SHA256_DIGEST_LENGTH, SHA2_FLAGS, 74b0d17251Schristos SHA256_Init, SHA256_Update, SHA256_Final) 75b0d17251Schristos 76b0d17251Schristos /* ossl_sha384_functions */ 77b0d17251Schristos IMPLEMENT_digest_functions(sha384, SHA512_CTX, 78b0d17251Schristos SHA512_CBLOCK, SHA384_DIGEST_LENGTH, SHA2_FLAGS, 79b0d17251Schristos SHA384_Init, SHA384_Update, SHA384_Final) 80b0d17251Schristos 81b0d17251Schristos /* ossl_sha512_functions */ 82b0d17251Schristos IMPLEMENT_digest_functions(sha512, SHA512_CTX, 83b0d17251Schristos SHA512_CBLOCK, SHA512_DIGEST_LENGTH, SHA2_FLAGS, 84b0d17251Schristos SHA512_Init, SHA512_Update, SHA512_Final) 85b0d17251Schristos 86b0d17251Schristos /* ossl_sha512_224_functions */ 87b0d17251Schristos IMPLEMENT_digest_functions(sha512_224, SHA512_CTX, 88b0d17251Schristos SHA512_CBLOCK, SHA224_DIGEST_LENGTH, SHA2_FLAGS, 89*aa91064fSriastradh sha512_224_init, SHA512_Update, SHA512_Final) 90b0d17251Schristos 91b0d17251Schristos /* ossl_sha512_256_functions */ 92b0d17251Schristos IMPLEMENT_digest_functions(sha512_256, SHA512_CTX, 93b0d17251Schristos SHA512_CBLOCK, SHA256_DIGEST_LENGTH, SHA2_FLAGS, 94*aa91064fSriastradh sha512_256_init, SHA512_Update, SHA512_Final) 95b0d17251Schristos 96