]> git.ipfire.org Git - thirdparty/openssl.git/blob - providers/implementations/digests/sha2_prov.c
prov: prefix all OSSL_DISPATCH tables names with ossl_
[thirdparty/openssl.git] / providers / implementations / digests / sha2_prov.c
1 /*
2 * Copyright 2019-2020 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 /*
11 * SHA low level APIs are deprecated for public use, but still ok for
12 * internal use.
13 */
14 #include "internal/deprecated.h"
15
16 #include <openssl/crypto.h>
17 #include <openssl/core_dispatch.h>
18 #include <openssl/evp.h>
19 #include <openssl/sha.h>
20 #include <openssl/evp.h>
21 #include <openssl/params.h>
22 #include <openssl/core_names.h>
23 #include "prov/digestcommon.h"
24 #include "prov/implementations.h"
25 #include "crypto/sha.h"
26
27 static OSSL_FUNC_digest_set_ctx_params_fn sha1_set_ctx_params;
28 static OSSL_FUNC_digest_settable_ctx_params_fn sha1_settable_ctx_params;
29
30 static const OSSL_PARAM known_sha1_settable_ctx_params[] = {
31 {OSSL_DIGEST_PARAM_SSL3_MS, OSSL_PARAM_OCTET_STRING, NULL, 0, 0},
32 OSSL_PARAM_END
33 };
34 static const OSSL_PARAM *sha1_settable_ctx_params(ossl_unused void *provctx)
35 {
36 return known_sha1_settable_ctx_params;
37 }
38
39 /* Special set_params method for SSL3 */
40 static int sha1_set_ctx_params(void *vctx, const OSSL_PARAM params[])
41 {
42 const OSSL_PARAM *p;
43 SHA_CTX *ctx = (SHA_CTX *)vctx;
44
45 if (ctx != NULL && params != NULL) {
46 p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_SSL3_MS);
47 if (p != NULL && p->data_type == OSSL_PARAM_OCTET_STRING)
48 return sha1_ctrl(ctx, EVP_CTRL_SSL3_MASTER_SECRET, p->data_size,
49 p->data);
50 }
51 return 0;
52 }
53
54 /* ossl_sha1_functions */
55 IMPLEMENT_digest_functions_with_settable_ctx(
56 sha1, SHA_CTX, SHA_CBLOCK, SHA_DIGEST_LENGTH, EVP_MD_FLAG_DIGALGID_ABSENT,
57 SHA1_Init, SHA1_Update, SHA1_Final,
58 sha1_settable_ctx_params, sha1_set_ctx_params)
59
60 /* ossl_sha224_functions */
61 IMPLEMENT_digest_functions(sha224, SHA256_CTX,
62 SHA256_CBLOCK, SHA224_DIGEST_LENGTH,
63 EVP_MD_FLAG_DIGALGID_ABSENT,
64 SHA224_Init, SHA224_Update, SHA224_Final)
65
66 /* ossl_sha256_functions */
67 IMPLEMENT_digest_functions(sha256, SHA256_CTX,
68 SHA256_CBLOCK, SHA256_DIGEST_LENGTH,
69 EVP_MD_FLAG_DIGALGID_ABSENT,
70 SHA256_Init, SHA256_Update, SHA256_Final)
71
72 /* ossl_sha384_functions */
73 IMPLEMENT_digest_functions(sha384, SHA512_CTX,
74 SHA512_CBLOCK, SHA384_DIGEST_LENGTH,
75 EVP_MD_FLAG_DIGALGID_ABSENT,
76 SHA384_Init, SHA384_Update, SHA384_Final)
77
78 /* ossl_sha512_functions */
79 IMPLEMENT_digest_functions(sha512, SHA512_CTX,
80 SHA512_CBLOCK, SHA512_DIGEST_LENGTH,
81 EVP_MD_FLAG_DIGALGID_ABSENT,
82 SHA512_Init, SHA512_Update, SHA512_Final)
83
84 /* ossl_sha512_224_functions */
85 IMPLEMENT_digest_functions(sha512_224, SHA512_CTX,
86 SHA512_CBLOCK, SHA224_DIGEST_LENGTH,
87 EVP_MD_FLAG_DIGALGID_ABSENT,
88 sha512_224_init, SHA512_Update, SHA512_Final)
89
90 /* ossl_sha512_256_functions */
91 IMPLEMENT_digest_functions(sha512_256, SHA512_CTX,
92 SHA512_CBLOCK, SHA256_DIGEST_LENGTH,
93 EVP_MD_FLAG_DIGALGID_ABSENT,
94 sha512_256_init, SHA512_Update, SHA512_Final)
95