1*9bac3682Sbeck /* $OpenBSD: m_sm3.c,v 1.7 2024/04/09 13:52:41 beck Exp $ */
243f50545Stb /*
343f50545Stb * Copyright (c) 2018, Ribose Inc
443f50545Stb *
543f50545Stb * Permission to use, copy, modify, and/or distribute this software for any
643f50545Stb * purpose with or without fee is hereby granted, provided that the above
743f50545Stb * copyright notice and this permission notice appear in all copies.
843f50545Stb *
943f50545Stb * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1043f50545Stb * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1143f50545Stb * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1243f50545Stb * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1343f50545Stb * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1443f50545Stb * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1543f50545Stb * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1643f50545Stb */
1743f50545Stb
1843f50545Stb #include <openssl/opensslconf.h>
1943f50545Stb
2043f50545Stb #ifndef OPENSSL_NO_SM3
2143f50545Stb #include <openssl/evp.h>
2243f50545Stb #include <openssl/sm3.h>
2343f50545Stb
2443f50545Stb #ifndef OPENSSL_NO_RSA
2543f50545Stb #include <openssl/rsa.h>
2643f50545Stb #endif
2743f50545Stb
28c9675a23Stb #include "evp_local.h"
29bc366ef8Stb
3043f50545Stb static int
sm3_init(EVP_MD_CTX * ctx)3143f50545Stb sm3_init(EVP_MD_CTX *ctx)
3243f50545Stb {
3343f50545Stb return SM3_Init(ctx->md_data);
3443f50545Stb }
3543f50545Stb
3643f50545Stb static int
sm3_update(EVP_MD_CTX * ctx,const void * data,size_t count)3743f50545Stb sm3_update(EVP_MD_CTX *ctx, const void *data, size_t count)
3843f50545Stb {
3943f50545Stb return SM3_Update(ctx->md_data, data, count);
4043f50545Stb }
4143f50545Stb
4243f50545Stb static int
sm3_final(EVP_MD_CTX * ctx,unsigned char * md)4343f50545Stb sm3_final(EVP_MD_CTX *ctx, unsigned char *md)
4443f50545Stb {
4543f50545Stb return SM3_Final(md, ctx->md_data);
4643f50545Stb }
4743f50545Stb
4843f50545Stb static const EVP_MD sm3_md = {
4943f50545Stb .type = NID_sm3,
5043f50545Stb .pkey_type = NID_sm3WithRSAEncryption,
5143f50545Stb .md_size = SM3_DIGEST_LENGTH,
5266c3bd61Stb .flags = EVP_MD_FLAG_DIGALGID_ABSENT,
5343f50545Stb .init = sm3_init,
5443f50545Stb .update = sm3_update,
5543f50545Stb .final = sm3_final,
5643f50545Stb .copy = NULL,
5743f50545Stb .cleanup = NULL,
5843f50545Stb .block_size = SM3_CBLOCK,
5943f50545Stb .ctx_size = sizeof(EVP_MD *) + sizeof(SM3_CTX),
6043f50545Stb };
6143f50545Stb
6243f50545Stb const EVP_MD *
EVP_sm3(void)6343f50545Stb EVP_sm3(void)
6443f50545Stb {
6543f50545Stb return &sm3_md;
6643f50545Stb }
67*9bac3682Sbeck LCRYPTO_ALIAS(EVP_sm3);
6843f50545Stb
6943f50545Stb #endif /* OPENSSL_NO_SM3 */
70