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