xref: /freebsd/crypto/openssl/providers/implementations/digests/sha2_prov.c (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1*b077aed3SPierre Pronchery /*
2*b077aed3SPierre Pronchery  * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
3*b077aed3SPierre Pronchery  *
4*b077aed3SPierre Pronchery  * Licensed under the Apache License 2.0 (the "License").  You may not use
5*b077aed3SPierre Pronchery  * this file except in compliance with the License.  You can obtain a copy
6*b077aed3SPierre Pronchery  * in the file LICENSE in the source distribution or at
7*b077aed3SPierre Pronchery  * https://www.openssl.org/source/license.html
8*b077aed3SPierre Pronchery  */
9*b077aed3SPierre Pronchery 
10*b077aed3SPierre Pronchery /*
11*b077aed3SPierre Pronchery  * SHA low level APIs are deprecated for public use, but still ok for
12*b077aed3SPierre Pronchery  * internal use.
13*b077aed3SPierre Pronchery  */
14*b077aed3SPierre Pronchery #include "internal/deprecated.h"
15*b077aed3SPierre Pronchery 
16*b077aed3SPierre Pronchery #include <openssl/crypto.h>
17*b077aed3SPierre Pronchery #include <openssl/core_dispatch.h>
18*b077aed3SPierre Pronchery #include <openssl/evp.h>
19*b077aed3SPierre Pronchery #include <openssl/sha.h>
20*b077aed3SPierre Pronchery #include <openssl/evp.h>
21*b077aed3SPierre Pronchery #include <openssl/params.h>
22*b077aed3SPierre Pronchery #include <openssl/core_names.h>
23*b077aed3SPierre Pronchery #include "prov/digestcommon.h"
24*b077aed3SPierre Pronchery #include "prov/implementations.h"
25*b077aed3SPierre Pronchery #include "crypto/sha.h"
26*b077aed3SPierre Pronchery 
27*b077aed3SPierre Pronchery #define SHA2_FLAGS PROV_DIGEST_FLAG_ALGID_ABSENT
28*b077aed3SPierre Pronchery 
29*b077aed3SPierre Pronchery static OSSL_FUNC_digest_set_ctx_params_fn sha1_set_ctx_params;
30*b077aed3SPierre Pronchery static OSSL_FUNC_digest_settable_ctx_params_fn sha1_settable_ctx_params;
31*b077aed3SPierre Pronchery 
32*b077aed3SPierre Pronchery static const OSSL_PARAM known_sha1_settable_ctx_params[] = {
33*b077aed3SPierre Pronchery     {OSSL_DIGEST_PARAM_SSL3_MS, OSSL_PARAM_OCTET_STRING, NULL, 0, 0},
34*b077aed3SPierre Pronchery     OSSL_PARAM_END
35*b077aed3SPierre Pronchery };
sha1_settable_ctx_params(ossl_unused void * ctx,ossl_unused void * provctx)36*b077aed3SPierre Pronchery static const OSSL_PARAM *sha1_settable_ctx_params(ossl_unused void *ctx,
37*b077aed3SPierre Pronchery                                                   ossl_unused void *provctx)
38*b077aed3SPierre Pronchery {
39*b077aed3SPierre Pronchery     return known_sha1_settable_ctx_params;
40*b077aed3SPierre Pronchery }
41*b077aed3SPierre Pronchery 
42*b077aed3SPierre Pronchery /* Special set_params method for SSL3 */
sha1_set_ctx_params(void * vctx,const OSSL_PARAM params[])43*b077aed3SPierre Pronchery static int sha1_set_ctx_params(void *vctx, const OSSL_PARAM params[])
44*b077aed3SPierre Pronchery {
45*b077aed3SPierre Pronchery     const OSSL_PARAM *p;
46*b077aed3SPierre Pronchery     SHA_CTX *ctx = (SHA_CTX *)vctx;
47*b077aed3SPierre Pronchery 
48*b077aed3SPierre Pronchery     if (ctx == NULL)
49*b077aed3SPierre Pronchery         return 0;
50*b077aed3SPierre Pronchery     if (params == NULL)
51*b077aed3SPierre Pronchery         return 1;
52*b077aed3SPierre Pronchery 
53*b077aed3SPierre Pronchery     p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_SSL3_MS);
54*b077aed3SPierre Pronchery     if (p != NULL && p->data_type == OSSL_PARAM_OCTET_STRING)
55*b077aed3SPierre Pronchery         return ossl_sha1_ctrl(ctx, EVP_CTRL_SSL3_MASTER_SECRET,
56*b077aed3SPierre Pronchery                               p->data_size, p->data);
57*b077aed3SPierre Pronchery     return 1;
58*b077aed3SPierre Pronchery }
59*b077aed3SPierre Pronchery 
60*b077aed3SPierre Pronchery /* ossl_sha1_functions */
61*b077aed3SPierre Pronchery IMPLEMENT_digest_functions_with_settable_ctx(
62*b077aed3SPierre Pronchery     sha1, SHA_CTX, SHA_CBLOCK, SHA_DIGEST_LENGTH, SHA2_FLAGS,
63*b077aed3SPierre Pronchery     SHA1_Init, SHA1_Update, SHA1_Final,
64*b077aed3SPierre Pronchery     sha1_settable_ctx_params, sha1_set_ctx_params)
65*b077aed3SPierre Pronchery 
66*b077aed3SPierre Pronchery /* ossl_sha224_functions */
67*b077aed3SPierre Pronchery IMPLEMENT_digest_functions(sha224, SHA256_CTX,
68*b077aed3SPierre Pronchery                            SHA256_CBLOCK, SHA224_DIGEST_LENGTH, SHA2_FLAGS,
69*b077aed3SPierre Pronchery                            SHA224_Init, SHA224_Update, SHA224_Final)
70*b077aed3SPierre Pronchery 
71*b077aed3SPierre Pronchery /* ossl_sha256_functions */
72*b077aed3SPierre Pronchery IMPLEMENT_digest_functions(sha256, SHA256_CTX,
73*b077aed3SPierre Pronchery                            SHA256_CBLOCK, SHA256_DIGEST_LENGTH, SHA2_FLAGS,
74*b077aed3SPierre Pronchery                            SHA256_Init, SHA256_Update, SHA256_Final)
75*b077aed3SPierre Pronchery 
76*b077aed3SPierre Pronchery /* ossl_sha384_functions */
77*b077aed3SPierre Pronchery IMPLEMENT_digest_functions(sha384, SHA512_CTX,
78*b077aed3SPierre Pronchery                            SHA512_CBLOCK, SHA384_DIGEST_LENGTH, SHA2_FLAGS,
79*b077aed3SPierre Pronchery                            SHA384_Init, SHA384_Update, SHA384_Final)
80*b077aed3SPierre Pronchery 
81*b077aed3SPierre Pronchery /* ossl_sha512_functions */
82*b077aed3SPierre Pronchery IMPLEMENT_digest_functions(sha512, SHA512_CTX,
83*b077aed3SPierre Pronchery                            SHA512_CBLOCK, SHA512_DIGEST_LENGTH, SHA2_FLAGS,
84*b077aed3SPierre Pronchery                            SHA512_Init, SHA512_Update, SHA512_Final)
85*b077aed3SPierre Pronchery 
86*b077aed3SPierre Pronchery /* ossl_sha512_224_functions */
87*b077aed3SPierre Pronchery IMPLEMENT_digest_functions(sha512_224, SHA512_CTX,
88*b077aed3SPierre Pronchery                            SHA512_CBLOCK, SHA224_DIGEST_LENGTH, SHA2_FLAGS,
89*b077aed3SPierre Pronchery                            sha512_224_init, SHA512_Update, SHA512_Final)
90*b077aed3SPierre Pronchery 
91*b077aed3SPierre Pronchery /* ossl_sha512_256_functions */
92*b077aed3SPierre Pronchery IMPLEMENT_digest_functions(sha512_256, SHA512_CTX,
93*b077aed3SPierre Pronchery                            SHA512_CBLOCK, SHA256_DIGEST_LENGTH, SHA2_FLAGS,
94*b077aed3SPierre Pronchery                            sha512_256_init, SHA512_Update, SHA512_Final)
95*b077aed3SPierre Pronchery 
96