]> git.ipfire.org Git - thirdparty/openssl.git/blob - providers/implementations/digests/sha2_prov.c
Providers: move all digests
[thirdparty/openssl.git] / providers / implementations / 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 "prov/digestcommon.h"
18 #include "internal/provider_algs.h"
19 #include "crypto/sha.h"
20
21 static OSSL_OP_digest_set_ctx_params_fn sha1_set_ctx_params;
22 static OSSL_OP_digest_settable_ctx_params_fn sha1_settable_ctx_params;
23
24 static const OSSL_PARAM known_sha1_settable_ctx_params[] = {
25 {OSSL_DIGEST_PARAM_SSL3_MS, OSSL_PARAM_OCTET_STRING, NULL, 0, 0},
26 OSSL_PARAM_END
27 };
28 static const OSSL_PARAM *sha1_settable_ctx_params(void)
29 {
30 return known_sha1_settable_ctx_params;
31 }
32
33 /* Special set_params method for SSL3 */
34 static int sha1_set_ctx_params(void *vctx, const OSSL_PARAM params[])
35 {
36 const OSSL_PARAM *p;
37 SHA_CTX *ctx = (SHA_CTX *)vctx;
38
39 if (ctx != NULL && params != NULL) {
40 p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_SSL3_MS);
41 if (p != NULL && p->data_type == OSSL_PARAM_OCTET_STRING)
42 return sha1_ctrl(ctx, EVP_CTRL_SSL3_MASTER_SECRET, p->data_size,
43 p->data);
44 }
45 return 0;
46 }
47
48 /* sha1_functions */
49 IMPLEMENT_digest_functions_with_settable_ctx(
50 sha1, SHA_CTX, SHA_CBLOCK, SHA_DIGEST_LENGTH, EVP_MD_FLAG_DIGALGID_ABSENT,
51 SHA1_Init, SHA1_Update, SHA1_Final,
52 sha1_settable_ctx_params, sha1_set_ctx_params)
53
54 /* sha224_functions */
55 IMPLEMENT_digest_functions(sha224, SHA256_CTX,
56 SHA256_CBLOCK, SHA224_DIGEST_LENGTH,
57 EVP_MD_FLAG_DIGALGID_ABSENT,
58 SHA224_Init, SHA224_Update, SHA224_Final)
59
60 /* sha256_functions */
61 IMPLEMENT_digest_functions(sha256, SHA256_CTX,
62 SHA256_CBLOCK, SHA256_DIGEST_LENGTH,
63 EVP_MD_FLAG_DIGALGID_ABSENT,
64 SHA256_Init, SHA256_Update, SHA256_Final)
65
66 /* sha384_functions */
67 IMPLEMENT_digest_functions(sha384, SHA512_CTX,
68 SHA512_CBLOCK, SHA384_DIGEST_LENGTH,
69 EVP_MD_FLAG_DIGALGID_ABSENT,
70 SHA384_Init, SHA384_Update, SHA384_Final)
71
72 /* sha512_functions */
73 IMPLEMENT_digest_functions(sha512, SHA512_CTX,
74 SHA512_CBLOCK, SHA512_DIGEST_LENGTH,
75 EVP_MD_FLAG_DIGALGID_ABSENT,
76 SHA512_Init, SHA512_Update, SHA512_Final)
77
78 /* sha512_224_functions */
79 IMPLEMENT_digest_functions(sha512_224, SHA512_CTX,
80 SHA512_CBLOCK, SHA224_DIGEST_LENGTH,
81 EVP_MD_FLAG_DIGALGID_ABSENT,
82 sha512_224_init, SHA512_Update, SHA512_Final)
83
84 /* sha512_256_functions */
85 IMPLEMENT_digest_functions(sha512_256, SHA512_CTX,
86 SHA512_CBLOCK, SHA256_DIGEST_LENGTH,
87 EVP_MD_FLAG_DIGALGID_ABSENT,
88 sha512_256_init, SHA512_Update, SHA512_Final)
89