]> git.ipfire.org Git - thirdparty/openssl.git/blame - providers/common/digests/sha2_prov.c
Add {get,set}table_params() functions for provider digests
[thirdparty/openssl.git] / providers / common / digests / sha2_prov.c
CommitLineData
de29ff17
MC
1/*
2 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
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
de29ff17
MC
10#include <openssl/crypto.h>
11#include <openssl/core_numbers.h>
f1d3df3e 12#include <openssl/evp.h>
d5e5e2ff 13#include <openssl/sha.h>
83b4a243 14#include <openssl/evp.h>
d5e5e2ff
SL
15#include <openssl/params.h>
16#include <openssl/core_names.h>
17#include "internal/core_mkdigest.h"
861b8f87 18#include "internal/provider_algs.h"
d5e5e2ff 19#include "internal/sha.h"
de29ff17 20
f1d3df3e 21static OSSL_OP_digest_ctx_set_params_fn sha1_set_params;
ec02412b
RL
22static OSSL_OP_digest_settable_ctx_params_fn sha1_settable_params;
23
24static const OSSL_PARAM known_sha1_ctx_params[] = {
25 {OSSL_DIGEST_PARAM_SSL3_MS, OSSL_PARAM_OCTET_STRING, NULL, 0, 0},
26 OSSL_PARAM_END
27};
28
29static const OSSL_PARAM *sha1_settable_params(void)
30{
31 return known_sha1_ctx_params;
32}
f2dbb71c 33
d5e5e2ff
SL
34/* Special set_params method for SSL3 */
35static int sha1_set_params(void *vctx, const OSSL_PARAM params[])
de29ff17 36{
d5e5e2ff
SL
37 const OSSL_PARAM *p;
38 SHA_CTX *ctx = (SHA_CTX *)vctx;
de29ff17 39
d5e5e2ff 40 if (ctx != NULL && params != NULL) {
4e7991b4 41 p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_SSL3_MS);
83b4a243
SL
42 if (p != NULL && p->data_type == OSSL_PARAM_OCTET_STRING)
43 return sha1_ctrl(ctx, EVP_CTRL_SSL3_MASTER_SECRET, p->data_size,
44 p->data);
d5e5e2ff 45 }
de29ff17
MC
46 return 0;
47}
48
d5e5e2ff
SL
49OSSL_FUNC_DIGEST_CONSTRUCT_PARAMS(sha1, SHA_CTX,
50 SHA_CBLOCK, SHA_DIGEST_LENGTH,
f1d3df3e 51 EVP_MD_FLAG_DIGALGID_ABSENT,
d5e5e2ff 52 SHA1_Init, SHA1_Update, SHA1_Final,
ec02412b 53 sha1_settable_params, sha1_set_params)
de29ff17 54
d5e5e2ff
SL
55OSSL_FUNC_DIGEST_CONSTRUCT(sha224, SHA256_CTX,
56 SHA256_CBLOCK, SHA224_DIGEST_LENGTH,
f1d3df3e 57 EVP_MD_FLAG_DIGALGID_ABSENT,
d5e5e2ff 58 SHA224_Init, SHA224_Update, SHA224_Final)
de29ff17 59
d5e5e2ff
SL
60OSSL_FUNC_DIGEST_CONSTRUCT(sha256, SHA256_CTX,
61 SHA256_CBLOCK, SHA256_DIGEST_LENGTH,
f1d3df3e 62 EVP_MD_FLAG_DIGALGID_ABSENT,
d5e5e2ff 63 SHA256_Init, SHA256_Update, SHA256_Final)
de29ff17 64
d5e5e2ff
SL
65OSSL_FUNC_DIGEST_CONSTRUCT(sha384, SHA512_CTX,
66 SHA512_CBLOCK, SHA384_DIGEST_LENGTH,
f1d3df3e 67 EVP_MD_FLAG_DIGALGID_ABSENT,
d5e5e2ff 68 SHA384_Init, SHA384_Update, SHA384_Final)
de29ff17 69
d5e5e2ff
SL
70OSSL_FUNC_DIGEST_CONSTRUCT(sha512, SHA512_CTX,
71 SHA512_CBLOCK, SHA512_DIGEST_LENGTH,
f1d3df3e 72 EVP_MD_FLAG_DIGALGID_ABSENT,
d5e5e2ff 73 SHA512_Init, SHA512_Update, SHA512_Final)
de29ff17 74
d5e5e2ff
SL
75OSSL_FUNC_DIGEST_CONSTRUCT(sha512_224, SHA512_CTX,
76 SHA512_CBLOCK, SHA224_DIGEST_LENGTH,
f1d3df3e 77 EVP_MD_FLAG_DIGALGID_ABSENT,
d5e5e2ff 78 sha512_224_init, SHA512_Update, SHA512_Final)
de29ff17 79
d5e5e2ff
SL
80OSSL_FUNC_DIGEST_CONSTRUCT(sha512_256, SHA512_CTX,
81 SHA512_CBLOCK, SHA256_DIGEST_LENGTH,
f1d3df3e 82 EVP_MD_FLAG_DIGALGID_ABSENT,
d5e5e2ff 83 sha512_256_init, SHA512_Update, SHA512_Final)
7556b9df 84