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