diff options
author | tb <> | 2018-11-11 06:53:31 +0000 |
---|---|---|
committer | tb <> | 2018-11-11 06:53:31 +0000 |
commit | 1d52a77751bd718c4bc8afa60ff78c4306636cd9 (patch) | |
tree | c825763485b682e2b4d62f2c543f52d67260398e /src/lib/libcrypto/evp | |
parent | 02538eda2e860ce41169bbc6f0d2519d31eda733 (diff) | |
download | openbsd-1d52a77751bd718c4bc8afa60ff78c4306636cd9.tar.gz openbsd-1d52a77751bd718c4bc8afa60ff78c4306636cd9.tar.bz2 openbsd-1d52a77751bd718c4bc8afa60ff78c4306636cd9.zip |
Add Ribose Inc's implementation of the SM3 hashing function with
tweaks from jsing and myself. The SM2/SM3/SM4 algorithms are mandatory
for legal use of cryptography within China and [are] widely applied in
the country, covering identification/financial cards, contactless,
TPM 2.0 and PKI.
ok beck inoguchi jsing
Diffstat (limited to 'src/lib/libcrypto/evp')
-rw-r--r-- | src/lib/libcrypto/evp/evp.h | 5 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/m_sm3.c | 73 |
2 files changed, 77 insertions, 1 deletions
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h index c09e2c046a..04e0455623 100644 --- a/src/lib/libcrypto/evp/evp.h +++ b/src/lib/libcrypto/evp/evp.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: evp.h,v 1.69 2018/09/12 06:35:38 djm Exp $ */ | 1 | /* $OpenBSD: evp.h,v 1.70 2018/11/11 06:53:31 tb Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -686,6 +686,9 @@ const EVP_MD *EVP_sha256(void); | |||
686 | const EVP_MD *EVP_sha384(void); | 686 | const EVP_MD *EVP_sha384(void); |
687 | const EVP_MD *EVP_sha512(void); | 687 | const EVP_MD *EVP_sha512(void); |
688 | #endif | 688 | #endif |
689 | #ifndef OPENSSL_NO_SM3 | ||
690 | const EVP_MD *EVP_sm3(void); | ||
691 | #endif | ||
689 | #ifndef OPENSSL_NO_RIPEMD | 692 | #ifndef OPENSSL_NO_RIPEMD |
690 | const EVP_MD *EVP_ripemd160(void); | 693 | const EVP_MD *EVP_ripemd160(void); |
691 | #endif | 694 | #endif |
diff --git a/src/lib/libcrypto/evp/m_sm3.c b/src/lib/libcrypto/evp/m_sm3.c new file mode 100644 index 0000000000..66582b8e4a --- /dev/null +++ b/src/lib/libcrypto/evp/m_sm3.c | |||
@@ -0,0 +1,73 @@ | |||
1 | /* $OpenBSD: m_sm3.c,v 1.1 2018/11/11 06:53:31 tb 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 | static int | ||
29 | sm3_init(EVP_MD_CTX *ctx) | ||
30 | { | ||
31 | return SM3_Init(ctx->md_data); | ||
32 | } | ||
33 | |||
34 | static int | ||
35 | sm3_update(EVP_MD_CTX *ctx, const void *data, size_t count) | ||
36 | { | ||
37 | return SM3_Update(ctx->md_data, data, count); | ||
38 | } | ||
39 | |||
40 | static int | ||
41 | sm3_final(EVP_MD_CTX *ctx, unsigned char *md) | ||
42 | { | ||
43 | return SM3_Final(md, ctx->md_data); | ||
44 | } | ||
45 | |||
46 | static const EVP_MD sm3_md = { | ||
47 | .type = NID_sm3, | ||
48 | .pkey_type = NID_sm3WithRSAEncryption, | ||
49 | .md_size = SM3_DIGEST_LENGTH, | ||
50 | .flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE|EVP_MD_FLAG_DIGALGID_ABSENT, | ||
51 | .init = sm3_init, | ||
52 | .update = sm3_update, | ||
53 | .final = sm3_final, | ||
54 | .copy = NULL, | ||
55 | .cleanup = NULL, | ||
56 | #ifndef OPENSSL_NO_RSA | ||
57 | .sign = (evp_sign_method *)RSA_sign, | ||
58 | .verify = (evp_verify_method *)RSA_verify, | ||
59 | .required_pkey_type = { | ||
60 | EVP_PKEY_RSA, EVP_PKEY_RSA2, 0, 0, | ||
61 | }, | ||
62 | #endif | ||
63 | .block_size = SM3_CBLOCK, | ||
64 | .ctx_size = sizeof(EVP_MD *) + sizeof(SM3_CTX), | ||
65 | }; | ||
66 | |||
67 | const EVP_MD * | ||
68 | EVP_sm3(void) | ||
69 | { | ||
70 | return &sm3_md; | ||
71 | } | ||
72 | |||
73 | #endif /* OPENSSL_NO_SM3 */ | ||