/src/libressl/crypto/evp/m_sm3.c
Line | Count | Source |
1 | | /* $OpenBSD: m_sm3.c,v 1.7 2024/04/09 13:52:41 beck Exp $ */ |
2 | | /* |
3 | | * Copyright (c) 2018, Ribose Inc |
4 | | * |
5 | | * Permission to use, copy, modify, and/or distribute this software for any |
6 | | * purpose with or without fee is hereby granted, provided that the above |
7 | | * copyright notice and this permission notice appear in all copies. |
8 | | * |
9 | | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
10 | | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
11 | | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
12 | | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
13 | | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
14 | | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
15 | | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
16 | | */ |
17 | | |
18 | | #include <openssl/opensslconf.h> |
19 | | |
20 | | #ifndef OPENSSL_NO_SM3 |
21 | | #include <openssl/evp.h> |
22 | | #include <openssl/sm3.h> |
23 | | |
24 | | #ifndef OPENSSL_NO_RSA |
25 | | #include <openssl/rsa.h> |
26 | | #endif |
27 | | |
28 | | #include "evp_local.h" |
29 | | |
30 | | static int |
31 | | sm3_init(EVP_MD_CTX *ctx) |
32 | 246 | { |
33 | 246 | return SM3_Init(ctx->md_data); |
34 | 246 | } |
35 | | |
36 | | static int |
37 | | sm3_update(EVP_MD_CTX *ctx, const void *data, size_t count) |
38 | 2.88k | { |
39 | 2.88k | return SM3_Update(ctx->md_data, data, count); |
40 | 2.88k | } |
41 | | |
42 | | static int |
43 | | sm3_final(EVP_MD_CTX *ctx, unsigned char *md) |
44 | 246 | { |
45 | 246 | return SM3_Final(md, ctx->md_data); |
46 | 246 | } |
47 | | |
48 | | static const EVP_MD sm3_md = { |
49 | | .type = NID_sm3, |
50 | | .pkey_type = NID_sm3WithRSAEncryption, |
51 | | .md_size = SM3_DIGEST_LENGTH, |
52 | | .flags = EVP_MD_FLAG_DIGALGID_ABSENT, |
53 | | .init = sm3_init, |
54 | | .update = sm3_update, |
55 | | .final = sm3_final, |
56 | | .copy = NULL, |
57 | | .cleanup = NULL, |
58 | | .block_size = SM3_CBLOCK, |
59 | | .ctx_size = sizeof(EVP_MD *) + sizeof(SM3_CTX), |
60 | | }; |
61 | | |
62 | | const EVP_MD * |
63 | | EVP_sm3(void) |
64 | 1 | { |
65 | 1 | return &sm3_md; |
66 | 1 | } |
67 | | LCRYPTO_ALIAS(EVP_sm3); |
68 | | |
69 | | #endif /* OPENSSL_NO_SM3 */ |