Make EVP_MD_CTX_ctrl() work for legacy use cases (ssl3).
[openssl.git] / providers / common / digests / sha2_prov.c
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
10 #include <openssl/crypto.h>
11 #include <openssl/core_numbers.h>
12 #include <openssl/sha.h>
13 #include <openssl/evp.h>
14 #include <openssl/params.h>
15 #include <openssl/core_names.h>
16 #include "internal/core_mkdigest.h"
17 #include "internal/provider_algs.h"
18 #include "internal/sha.h"
19
20 static OSSL_OP_digest_set_params_fn sha1_set_params;
21
22 /* Special set_params method for SSL3 */
23 static int sha1_set_params(void *vctx, const OSSL_PARAM params[])
24 {
25     const OSSL_PARAM *p;
26     SHA_CTX *ctx = (SHA_CTX *)vctx;
27
28     if (ctx != NULL && params != NULL) {
29         p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_SSL3_MS);
30         if (p != NULL && p->data_type == OSSL_PARAM_OCTET_STRING)
31             return sha1_ctrl(ctx, EVP_CTRL_SSL3_MASTER_SECRET, p->data_size,
32                              p->data);
33     }
34     return 0;
35 }
36
37 OSSL_FUNC_DIGEST_CONSTRUCT_PARAMS(sha1, SHA_CTX,
38                            SHA_CBLOCK, SHA_DIGEST_LENGTH,
39                            SHA1_Init, SHA1_Update, SHA1_Final,
40                            sha1_set_params)
41
42 OSSL_FUNC_DIGEST_CONSTRUCT(sha224, SHA256_CTX,
43                            SHA256_CBLOCK, SHA224_DIGEST_LENGTH,
44                            SHA224_Init, SHA224_Update, SHA224_Final)
45
46 OSSL_FUNC_DIGEST_CONSTRUCT(sha256, SHA256_CTX,
47                            SHA256_CBLOCK, SHA256_DIGEST_LENGTH,
48                            SHA256_Init, SHA256_Update, SHA256_Final)
49
50 OSSL_FUNC_DIGEST_CONSTRUCT(sha384, SHA512_CTX,
51                            SHA512_CBLOCK, SHA384_DIGEST_LENGTH,
52                            SHA384_Init, SHA384_Update, SHA384_Final)
53
54 OSSL_FUNC_DIGEST_CONSTRUCT(sha512, SHA512_CTX,
55                            SHA512_CBLOCK, SHA512_DIGEST_LENGTH,
56                            SHA512_Init, SHA512_Update, SHA512_Final)
57
58 OSSL_FUNC_DIGEST_CONSTRUCT(sha512_224, SHA512_CTX,
59                            SHA512_CBLOCK, SHA224_DIGEST_LENGTH,
60                            sha512_224_init, SHA512_Update, SHA512_Final)
61
62 OSSL_FUNC_DIGEST_CONSTRUCT(sha512_256, SHA512_CTX,
63                            SHA512_CBLOCK, SHA256_DIGEST_LENGTH,
64                            sha512_256_init, SHA512_Update, SHA512_Final)
65