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