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