From 4e494342099225979115c59897e6f6f6dcee55ca Mon Sep 17 00:00:00 2001 From: Zhi Guan Date: Tue, 14 Feb 2017 17:16:13 +0800 Subject: [PATCH] add sm3 module --- Configure | 3 +- apps/progs.h | 1 + apps/progs.pl | 2 +- crypto/evp/build.info | 3 +- crypto/evp/c_alld.c | 3 + crypto/evp/m_sm3.c | 105 ++++++++ crypto/objects/obj_dat.h | 438 +++++++++++++++++++++++++++++++++- crypto/objects/obj_mac.num | 86 +++++++ crypto/sm3/asm/sm3-586.pl | 1 + crypto/sm3/asm/sm3-x86_64.pl | 1 + crypto/sm3/build.info | 2 + crypto/sm3/sm3.c | 214 +++++++++++++++++ crypto/sm3/sm3_hmac.c | 125 ++++++++++ include/openssl/evp.h | 51 ++++ include/openssl/obj_mac.h | 387 ++++++++++++++++++++++++++++++ include/openssl/sm3.h | 99 ++++++++ test/build.info | 7 +- test/recipes/03-test_ui.t | 2 +- test/recipes/05-test_sm3.t | 12 + test/recipes/15-test_rsa.t | 2 +- test/recipes/20-test_passwd.t | 12 +- test/recipes/25-test_req.t | 6 +- test/recipes/25-test_verify.t | 2 +- test/recipes/tconversion.pl | 2 +- test/sm3test.c | 239 +++++++++++++++++++ util/libcrypto.num | 1 + 26 files changed, 1784 insertions(+), 22 deletions(-) create mode 100644 crypto/evp/m_sm3.c create mode 100644 crypto/sm3/asm/sm3-586.pl create mode 100755 crypto/sm3/asm/sm3-x86_64.pl create mode 100644 crypto/sm3/build.info create mode 100644 crypto/sm3/sm3.c create mode 100644 crypto/sm3/sm3_hmac.c create mode 100644 include/openssl/sm3.h create mode 100644 test/recipes/05-test_sm3.t create mode 100644 test/sm3test.c diff --git a/Configure b/Configure index aee7cc3f..348122db 100755 --- a/Configure +++ b/Configure @@ -310,7 +310,8 @@ $config{sdirs} = [ "bn", "ec", "rsa", "dsa", "dh", "dso", "engine", "buffer", "bio", "stack", "lhash", "rand", "err", "evp", "asn1", "pem", "x509", "x509v3", "conf", "txt_db", "pkcs7", "pkcs12", "comp", "ocsp", "ui", - "cms", "ts", "srp", "cmac", "ct", "async", "kdf" + "cms", "ts", "srp", "cmac", "ct", "async", "kdf", + "sm3" ]; # Known TLS and DTLS protocols diff --git a/apps/progs.h b/apps/progs.h index 5f6f07f8..82b250c7 100644 --- a/apps/progs.h +++ b/apps/progs.h @@ -218,6 +218,7 @@ static FUNCTION functions[] = { #ifndef OPENSSL_NO_GOST { FT_md, "gost", dgst_main}, #endif + { FT_md, "sm3", dgst_main}, { FT_md, "sha1", dgst_main}, { FT_md, "sha224", dgst_main}, { FT_md, "sha256", dgst_main}, diff --git a/apps/progs.pl b/apps/progs.pl index 21baf173..ec3c1232 100644 --- a/apps/progs.pl +++ b/apps/progs.pl @@ -98,7 +98,7 @@ my %md_disabler = ( ); foreach my $cmd ( "md2", "md4", "md5", - "gost", + "gost", "sm3", "sha1", "sha224", "sha256", "sha384", "sha512", "mdc2", "rmd160", "blake2b512", "blake2s256" ) { diff --git a/crypto/evp/build.info b/crypto/evp/build.info index bf633dc7..e443d234 100644 --- a/crypto/evp/build.info +++ b/crypto/evp/build.info @@ -12,7 +12,8 @@ SOURCE[../../libcrypto]=\ evp_pkey.c evp_pbe.c p5_crpt.c p5_crpt2.c scrypt.c \ e_old.c pmeth_lib.c pmeth_fn.c pmeth_gn.c m_sigver.c \ e_aes_cbc_hmac_sha1.c e_aes_cbc_hmac_sha256.c e_rc4_hmac_md5.c \ - e_chacha20_poly1305.c cmeth_lib.c + e_chacha20_poly1305.c cmeth_lib.c \ + m_sm3.c INCLUDE[e_aes.o]=.. ../modes INCLUDE[e_aes_cbc_hmac_sha1.o]=../modes diff --git a/crypto/evp/c_alld.c b/crypto/evp/c_alld.c index ec79734e..a66dae25 100644 --- a/crypto/evp/c_alld.c +++ b/crypto/evp/c_alld.c @@ -46,4 +46,7 @@ void openssl_add_all_digests_int(void) EVP_add_digest(EVP_blake2b512()); EVP_add_digest(EVP_blake2s256()); #endif +#ifndef OPENSSL_NO_SM3 + EVP_add_digest(EVP_sm3()); +#endif } diff --git a/crypto/evp/m_sm3.c b/crypto/evp/m_sm3.c new file mode 100644 index 00000000..e88cef64 --- /dev/null +++ b/crypto/evp/m_sm3.c @@ -0,0 +1,105 @@ +/* ==================================================================== + * Copyright (c) 2014 - 2016 The GmSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the GmSSL Project. + * (http://gmssl.org/)" + * + * 4. The name "GmSSL Project" must not be used to endorse or promote + * products derived from this software without prior written + * permission. For written permission, please contact + * guanzhi1980@gmail.com. + * + * 5. Products derived from this software may not be called "GmSSL" + * nor may "GmSSL" appear in their names without prior written + * permission of the GmSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the GmSSL Project + * (http://gmssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ + +#include +#include +#include +#include +#include "internal/cryptlib.h" +#include "internal/evp_int.h" + +#ifndef OPENSSL_NO_SM3 +# include + +static int init(EVP_MD_CTX *ctx) +{ + if (!ctx || !EVP_MD_CTX_md_data(ctx)) { + return 0; + } + sm3_init(EVP_MD_CTX_md_data(ctx)); + return 1; +} + +static int update(EVP_MD_CTX *ctx, const void *in, size_t inlen) +{ + if (!ctx || !EVP_MD_CTX_md_data(ctx) || !in) { + return 0; + } + sm3_update(EVP_MD_CTX_md_data(ctx), in, inlen); + return 1; +} + +static int final(EVP_MD_CTX *ctx, unsigned char *md) +{ + if (!ctx || !EVP_MD_CTX_md_data(ctx) || !md) { + return 0; + } + sm3_final(EVP_MD_CTX_md_data(ctx), md); + return 1; +} + +static const EVP_MD sm3_md = { + NID_sm3, + NID_sm2sign_with_sm3, + SM3_DIGEST_LENGTH, + 0, /* flags */ + init, + update, + final, + NULL, + NULL, + SM3_BLOCK_SIZE, + sizeof(EVP_MD *) + sizeof(sm3_ctx_t), +}; + +const EVP_MD *EVP_sm3(void) +{ + return &sm3_md; +} +#endif /* OPENSSL_NO_SM3 */ diff --git a/crypto/objects/obj_dat.h b/crypto/objects/obj_dat.h index e1fc64f7..627abca1 100644 --- a/crypto/objects/obj_dat.h +++ b/crypto/objects/obj_dat.h @@ -10,7 +10,7 @@ */ /* Serialized OID's */ -static const unsigned char so[6765] = { +static const unsigned char so[7417] = { 0x2A,0x86,0x48,0x86,0xF7,0x0D, /* [ 0] OBJ_rsadsi */ 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01, /* [ 6] OBJ_pkcs */ 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x02, /* [ 13] OBJ_md2 */ @@ -961,9 +961,94 @@ static const unsigned char so[6765] = { 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x01,0x13, /* [ 6731] OBJ_id_smime_ct_contentCollection */ 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x01,0x17, /* [ 6742] OBJ_id_smime_ct_authEnvelopedData */ 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x01,0x1C, /* [ 6753] OBJ_id_ct_xml */ + 0x2A,0x86,0x48,0xCE,0x3D,0x04, /* [ 6764] OBJ_X9_62_id_ecSigType */ + 0x2B,0x81,0x04,0x01, /* [ 6770] OBJ_secg_scheme */ + 0x2B,0x81,0x04,0x01,0x07, /* [ 6774] OBJ_ecies_recommendedParameters */ + 0x2B,0x81,0x04,0x01,0x08, /* [ 6779] OBJ_ecies_specifiedParameters */ + 0x2B,0x81,0x04,0x01,0x11,0x00, /* [ 6784] OBJ_x9_63_kdf */ + 0x2B,0x81,0x04,0x01,0x11,0x01, /* [ 6790] OBJ_nist_concatenation_kdf */ + 0x2B,0x81,0x04,0x01,0x11,0x02, /* [ 6796] OBJ_tls_kdf */ + 0x2B,0x81,0x04,0x01,0x11,0x03, /* [ 6802] OBJ_ikev2_kdf */ + 0x2B,0x81,0x04,0x01,0x12, /* [ 6808] OBJ_xor_in_ecies */ + 0x2B,0x81,0x04,0x01,0x13, /* [ 6813] OBJ_tdes_cbc_in_ecies */ + 0x2B,0x81,0x04,0x01,0x14,0x00, /* [ 6818] OBJ_aes128_cbc_in_ecies */ + 0x2B,0x81,0x04,0x01,0x14,0x01, /* [ 6824] OBJ_aes192_cbc_in_ecies */ + 0x2B,0x81,0x04,0x01,0x14,0x02, /* [ 6830] OBJ_aes256_cbc_in_ecies */ + 0x2B,0x81,0x04,0x01,0x15,0x00, /* [ 6836] OBJ_aes128_ctr_in_ecies */ + 0x2B,0x81,0x04,0x01,0x15,0x01, /* [ 6842] OBJ_aes192_ctr_in_ecies */ + 0x2B,0x81,0x04,0x01,0x15,0x02, /* [ 6848] OBJ_aes256_ctr_in_ecies */ + 0x2B,0x81,0x04,0x01,0x16, /* [ 6854] OBJ_hmac_full_ecies */ + 0x2B,0x81,0x04,0x01,0x17, /* [ 6859] OBJ_hmac_half_ecies */ + 0x2B,0x81,0x04,0x01,0x18,0x00, /* [ 6864] OBJ_cmac_aes128_ecies */ + 0x2B,0x81,0x04,0x01,0x18,0x01, /* [ 6870] OBJ_cmac_aes192_ecies */ + 0x2B,0x81,0x04,0x01,0x18,0x02, /* [ 6876] OBJ_cmac_aes256_ecies */ + 0x2A,0x81,0x1C, /* [ 6882] OBJ_ISO_CN */ + 0x2A,0x81,0x1C,0xCF,0x55, /* [ 6885] OBJ_oscca */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01, /* [ 6890] OBJ_sm_scheme */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x65,0x01, /* [ 6896] OBJ_sm6_ecb */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x65,0x02, /* [ 6904] OBJ_sm6_cbc */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x65,0x03, /* [ 6912] OBJ_sm6_ofb128 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x65,0x04, /* [ 6920] OBJ_sm6_cfb128 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x66,0x01, /* [ 6928] OBJ_sm1_ecb */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x66,0x02, /* [ 6936] OBJ_sm1_cbc */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x66,0x03, /* [ 6944] OBJ_sm1_ofb128 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x66,0x04, /* [ 6952] OBJ_sm1_cfb128 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x66,0x05, /* [ 6960] OBJ_sm1_cfb1 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x66,0x06, /* [ 6968] OBJ_sm1_cfb8 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x67,0x01, /* [ 6976] OBJ_ssf33_ecb */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x67,0x02, /* [ 6984] OBJ_ssf33_cbc */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x67,0x03, /* [ 6992] OBJ_ssf33_ofb128 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x67,0x04, /* [ 7000] OBJ_ssf33_cfb128 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x67,0x05, /* [ 7008] OBJ_ssf33_cfb1 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x67,0x06, /* [ 7016] OBJ_ssf33_cfb8 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x68,0x01, /* [ 7024] OBJ_sms4_ecb */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x68,0x02, /* [ 7032] OBJ_sms4_cbc */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x68,0x03, /* [ 7040] OBJ_sms4_ofb128 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x68,0x04, /* [ 7048] OBJ_sms4_cfb128 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x68,0x05, /* [ 7056] OBJ_sms4_cfb1 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x68,0x06, /* [ 7064] OBJ_sms4_cfb8 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x68,0x07, /* [ 7072] OBJ_sms4_ctr */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x68,0x08, /* [ 7080] OBJ_sms4_gcm */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x68,0x09, /* [ 7088] OBJ_sms4_ccm */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x68,0x0A, /* [ 7096] OBJ_sms4_xts */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x68,0x0B, /* [ 7104] OBJ_sms4_wrap */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x68,0x0C, /* [ 7112] OBJ_sms4_wrap_pad */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x68,0x64, /* [ 7120] OBJ_sms4_ocb */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x81,0x49, /* [ 7128] OBJ_sm5 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x82,0x2D, /* [ 7136] OBJ_sm2p256v1 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x82,0x2D,0x01, /* [ 7144] OBJ_sm2sign */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x82,0x2D,0x02, /* [ 7153] OBJ_sm2keyagreement */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x82,0x2D,0x03, /* [ 7162] OBJ_sm2encrypt */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x82,0x2D,0x03,0x01, /* [ 7171] OBJ_sm2encrypt_recommendedParameters */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x82,0x2D,0x03,0x02, /* [ 7181] OBJ_sm2encrypt_specifiedParameters */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x82,0x2E, /* [ 7191] OBJ_id_sm9PublicKey */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x82,0x2E,0x01, /* [ 7199] OBJ_sm9sign */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x82,0x2E,0x02, /* [ 7208] OBJ_sm9keyagreement */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x82,0x2E,0x03, /* [ 7217] OBJ_sm9encrypt */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x83,0x11, /* [ 7226] OBJ_sm3 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x83,0x11,0x02, /* [ 7234] OBJ_hmac_sm3 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x83,0x75, /* [ 7243] OBJ_sm2sign_with_sm3 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x83,0x76, /* [ 7251] OBJ_sm2sign_with_sha1 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x83,0x77, /* [ 7259] OBJ_sm2sign_with_sha256 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x83,0x78, /* [ 7267] OBJ_sm2sign_with_sha512 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x83,0x79, /* [ 7275] OBJ_sm2sign_with_sha224 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x83,0x7A, /* [ 7283] OBJ_sm2sign_with_sha384 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x83,0x7B, /* [ 7291] OBJ_sm2sign_with_rmd160 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x82,0x2D,0x65, /* [ 7299] OBJ_wapip192v1 */ + 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x86,0x20, /* [ 7308] OBJ_zuc */ + 0x2A,0x86,0x48,0x01,0x86,0xFD,0x1E,0x01,0x02,0x01, /* [ 7316] OBJ_bfibe */ + 0x2A,0x86,0x48,0x01,0x86,0xFD,0x1E,0x01,0x02,0x02, /* [ 7326] OBJ_bb1 */ + 0x2A,0x86,0x48,0x01,0x86,0xFD,0x1E,0x01,0x01,0x01, /* [ 7336] OBJ_type1curve */ + 0x2A,0x86,0x48,0x01,0x86,0xFD,0x1E,0x01,0x01,0x02, /* [ 7346] OBJ_type2curve */ + 0x2A,0x86,0x48,0x01,0x86,0xFD,0x1E,0x01,0x01,0x03, /* [ 7356] OBJ_type3curve */ + 0x2A,0x86,0x48,0x01,0x86,0xFD,0x1E,0x01,0x01,0x04, /* [ 7366] OBJ_type4curve */ + 0x2A,0x86,0x48,0x01,0x86,0xFD,0x1E,0x01,0x03,0x01, /* [ 7376] OBJ_tate_pairing */ + 0x2A,0x86,0x48,0x01,0x86,0xFD,0x1E,0x01,0x03,0x02, /* [ 7386] OBJ_weil_pairing */ + 0x2A,0x86,0x48,0x01,0x86,0xFD,0x1E,0x01,0x03,0x03, /* [ 7396] OBJ_ate_pairing */ + 0x2A,0x86,0x48,0x01,0x86,0xFD,0x1E,0x01,0x03,0x04, /* [ 7406] OBJ_r_ate_pairing */ }; -#define NUM_NID 1061 +#define NUM_NID 1147 static const ASN1_OBJECT nid_objs[NUM_NID] = { {"UNDEF", "undefined", NID_undef}, {"rsadsi", "RSA Data Security, Inc.", NID_rsadsi, 6, &so[0]}, @@ -2026,9 +2111,95 @@ static const ASN1_OBJECT nid_objs[NUM_NID] = { {"id-smime-ct-contentCollection", "id-smime-ct-contentCollection", NID_id_smime_ct_contentCollection, 11, &so[6731]}, {"id-smime-ct-authEnvelopedData", "id-smime-ct-authEnvelopedData", NID_id_smime_ct_authEnvelopedData, 11, &so[6742]}, {"id-ct-xml", "id-ct-xml", NID_id_ct_xml, 11, &so[6753]}, + {"id-ecSigType", "id-ecSigType", NID_X9_62_id_ecSigType, 6, &so[6764]}, + {"secg-scheme", "secg-scheme", NID_secg_scheme, 4, &so[6770]}, + {"ecies-recommendedParameters", "ecies-recommendedParameters", NID_ecies_recommendedParameters, 5, &so[6774]}, + {"ecies-specifiedParameters", "ecies-specifiedParameters", NID_ecies_specifiedParameters, 5, &so[6779]}, + {"x9-63-kdf", "x9-63-kdf", NID_x9_63_kdf, 6, &so[6784]}, + {"nist-concatenation-kdf", "nist-concatenation-kdf", NID_nist_concatenation_kdf, 6, &so[6790]}, + {"tls-kdf", "tls-kdf", NID_tls_kdf, 6, &so[6796]}, + {"ikev2-kdf", "ikev2-kdf", NID_ikev2_kdf, 6, &so[6802]}, + {"xor-in-ecies", "xor-in-ecies", NID_xor_in_ecies, 5, &so[6808]}, + {"tdes-cbc-in-ecies", "tdes-cbc-in-ecies", NID_tdes_cbc_in_ecies, 5, &so[6813]}, + {"aes128-cbc-in-ecies", "aes128-cbc-in-ecies", NID_aes128_cbc_in_ecies, 6, &so[6818]}, + {"aes192-cbc-in-ecies", "aes192-cbc-in-ecies", NID_aes192_cbc_in_ecies, 6, &so[6824]}, + {"aes256-cbc-in-ecies", "aes256-cbc-in-ecies", NID_aes256_cbc_in_ecies, 6, &so[6830]}, + {"aes128-ctr-in-ecies", "aes128-ctr-in-ecies", NID_aes128_ctr_in_ecies, 6, &so[6836]}, + {"aes192-ctr-in-ecies", "aes192-ctr-in-ecies", NID_aes192_ctr_in_ecies, 6, &so[6842]}, + {"aes256-ctr-in-ecies", "aes256-ctr-in-ecies", NID_aes256_ctr_in_ecies, 6, &so[6848]}, + {"hmac-full-ecies", "hmac-full-ecies", NID_hmac_full_ecies, 5, &so[6854]}, + {"hmac-half-ecies", "hmac-half-ecies", NID_hmac_half_ecies, 5, &so[6859]}, + {"cmac-aes128-ecies", "cmac-aes128-ecies", NID_cmac_aes128_ecies, 6, &so[6864]}, + {"cmac-aes192-ecies", "cmac-aes192-ecies", NID_cmac_aes192_ecies, 6, &so[6870]}, + {"cmac-aes256-ecies", "cmac-aes256-ecies", NID_cmac_aes256_ecies, 6, &so[6876]}, + {"CBC-MAC", "cbc-mac", NID_cbc_mac}, + {"ISO-CN", "ISO CN Member Body", NID_ISO_CN, 3, &so[6882]}, + {"oscca", "oscca", NID_oscca, 5, &so[6885]}, + {"sm-scheme", "sm-scheme", NID_sm_scheme, 6, &so[6890]}, + {"SM6-ECB", "sm6-ecb", NID_sm6_ecb, 8, &so[6896]}, + {"SM6-CBC", "sm6-cbc", NID_sm6_cbc, 8, &so[6904]}, + {"SM6-OFB", "sm6-ofb", NID_sm6_ofb128, 8, &so[6912]}, + {"SM6-CFB", "sm6-cfb", NID_sm6_cfb128, 8, &so[6920]}, + {"SM1-ECB", "sm1-ecb", NID_sm1_ecb, 8, &so[6928]}, + {"SM1-CBC", "sm1-cbc", NID_sm1_cbc, 8, &so[6936]}, + {"SM1-OFB", "sm1-ofb", NID_sm1_ofb128, 8, &so[6944]}, + {"SM1-CFB", "sm1-cfb", NID_sm1_cfb128, 8, &so[6952]}, + {"SM1-CFB1", "sm1-cfb1", NID_sm1_cfb1, 8, &so[6960]}, + {"SM1-CFB8", "sm1-cfb8", NID_sm1_cfb8, 8, &so[6968]}, + {"SSF33-ECB", "ssf33-ecb", NID_ssf33_ecb, 8, &so[6976]}, + {"SSF33-CBC", "ssf33-cbc", NID_ssf33_cbc, 8, &so[6984]}, + {"SSF33-OFB", "ssf33-ofb", NID_ssf33_ofb128, 8, &so[6992]}, + {"SSF33-CFB", "ssf33-cfb", NID_ssf33_cfb128, 8, &so[7000]}, + {"SSF33-CFB1", "ssf33-cfb1", NID_ssf33_cfb1, 8, &so[7008]}, + {"SSF33-CFB8", "ssf33-cfb8", NID_ssf33_cfb8, 8, &so[7016]}, + {"SMS4-ECB", "sms4-ecb", NID_sms4_ecb, 8, &so[7024]}, + {"SMS4-CBC", "sms4-cbc", NID_sms4_cbc, 8, &so[7032]}, + {"SMS4-OFB", "sms4-ofb", NID_sms4_ofb128, 8, &so[7040]}, + {"SMS4-CFB", "sms4-cfb", NID_sms4_cfb128, 8, &so[7048]}, + {"SMS4-CFB1", "sms4-cfb1", NID_sms4_cfb1, 8, &so[7056]}, + {"SMS4-CFB8", "sms4-cfb8", NID_sms4_cfb8, 8, &so[7064]}, + {"SMS4-CTR", "sms4-ctr", NID_sms4_ctr, 8, &so[7072]}, + {"SMS4-GCM", "sms4-gcm", NID_sms4_gcm, 8, &so[7080]}, + {"SMS4-CCM", "sms4-ccm", NID_sms4_ccm, 8, &so[7088]}, + {"SMS4-XTS", "sms4-xts", NID_sms4_xts, 8, &so[7096]}, + {"SMS4-WRAP", "sms4-wrap", NID_sms4_wrap, 8, &so[7104]}, + {"SMS4-WRAP-PAD", "sms4-wrap-pad", NID_sms4_wrap_pad, 8, &so[7112]}, + {"SMS4-OCB", "sms4-ocb", NID_sms4_ocb, 8, &so[7120]}, + {"SM5", "sm5", NID_sm5, 8, &so[7128]}, + {"sm2p256v1", "sm2p256v1", NID_sm2p256v1, 8, &so[7136]}, + {"sm2sign", "sm2sign", NID_sm2sign, 9, &so[7144]}, + {"sm2keyagreement", "sm2keyagreement", NID_sm2keyagreement, 9, &so[7153]}, + {"sm2encrypt", "sm2encrypt", NID_sm2encrypt, 9, &so[7162]}, + {"sm2encrypt-recommendedParameters", "sm2encrypt-recommendedParameters", NID_sm2encrypt_recommendedParameters, 10, &so[7171]}, + {"sm2encrypt-specifiedParameters", "sm2encrypt-specifiedParameters", NID_sm2encrypt_specifiedParameters, 10, &so[7181]}, + {"id-sm9PublicKey", "id-sm9PublicKey", NID_id_sm9PublicKey, 8, &so[7191]}, + {"sm9sign", "sm9sign", NID_sm9sign, 9, &so[7199]}, + {"sm9keyagreement", "sm9keyagreement", NID_sm9keyagreement, 9, &so[7208]}, + {"sm9encrypt", "sm9encrypt", NID_sm9encrypt, 9, &so[7217]}, + {"SM3", "sm3", NID_sm3, 8, &so[7226]}, + {"HMAC-SM3", "hmac-sm3", NID_hmac_sm3, 9, &so[7234]}, + {"SM2Sign-with-SM3", "sm2sign-with-sm3", NID_sm2sign_with_sm3, 8, &so[7243]}, + {"SM2Sign-with-SHA1", "sm2sign-with-sha1", NID_sm2sign_with_sha1, 8, &so[7251]}, + {"SM2Sign-with-SHA256", "sm2sign-with-sha256", NID_sm2sign_with_sha256, 8, &so[7259]}, + {"SM2Sign-with-SHA511", "sm2sign-with-sha512", NID_sm2sign_with_sha512, 8, &so[7267]}, + {"SM2Sign-with-SHA224", "sm2sign-with-sha224", NID_sm2sign_with_sha224, 8, &so[7275]}, + {"SM2Sign-with-SHA384", "sm2sign-with-sha384", NID_sm2sign_with_sha384, 8, &so[7283]}, + {"SM2Sign-with-RMD160", "sm2sign-with-rmd160", NID_sm2sign_with_rmd160, 8, &so[7291]}, + {"wapip192v1", "wapip192v1", NID_wapip192v1, 9, &so[7299]}, + {"ZUC", "zuc", NID_zuc, 8, &so[7308]}, + {"bfibe", "bfibe", NID_bfibe, 10, &so[7316]}, + {"bb1", "bb1", NID_bb1, 10, &so[7326]}, + {"type1curve", "type1curve", NID_type1curve, 10, &so[7336]}, + {"type2curve", "type2curve", NID_type2curve, 10, &so[7346]}, + {"type3curve", "type3curve", NID_type3curve, 10, &so[7356]}, + {"type4curve", "type4curve", NID_type4curve, 10, &so[7366]}, + {"tate-pairing", "tate-pairing", NID_tate_pairing, 10, &so[7376]}, + {"weil-pairing", "weil-pairing", NID_weil_pairing, 10, &so[7386]}, + {"ate-pairing", "ate-pairing", NID_ate_pairing, 10, &so[7396]}, + {"r-ate-pairing", "r-ate-pairing", NID_r_ate_pairing, 10, &so[7406]}, }; -#define NUM_SN 1052 +#define NUM_SN 1138 static const unsigned int sn_objs[NUM_SN] = { 364, /* "AD_DVCS" */ 419, /* "AES-128-CBC" */ @@ -2112,6 +2283,7 @@ static const unsigned int sn_objs[NUM_SN] = { 110, /* "CAST5-CFB" */ 109, /* "CAST5-ECB" */ 111, /* "CAST5-OFB" */ + 1082, /* "CBC-MAC" */ 894, /* "CMAC" */ 13, /* "CN" */ 141, /* "CRLReason" */ @@ -2150,6 +2322,7 @@ static const unsigned int sn_objs[NUM_SN] = { 855, /* "HMAC" */ 780, /* "HMAC-MD5" */ 781, /* "HMAC-SHA1" */ + 1127, /* "HMAC-SM3" */ 381, /* "IANA" */ 34, /* "IDEA-CBC" */ 35, /* "IDEA-CFB" */ @@ -2157,6 +2330,7 @@ static const unsigned int sn_objs[NUM_SN] = { 46, /* "IDEA-OFB" */ 1004, /* "INN" */ 181, /* "ISO" */ + 1083, /* "ISO-CN" */ 183, /* "ISO-US" */ 645, /* "ITU-T" */ 646, /* "JOINT-ISO-ITU-T" */ @@ -2248,10 +2422,48 @@ static const unsigned int sn_objs[NUM_SN] = { 672, /* "SHA256" */ 673, /* "SHA384" */ 674, /* "SHA512" */ + 1091, /* "SM1-CBC" */ + 1093, /* "SM1-CFB" */ + 1094, /* "SM1-CFB1" */ + 1095, /* "SM1-CFB8" */ + 1090, /* "SM1-ECB" */ + 1092, /* "SM1-OFB" */ + 1134, /* "SM2Sign-with-RMD160" */ + 1129, /* "SM2Sign-with-SHA1" */ + 1132, /* "SM2Sign-with-SHA224" */ + 1130, /* "SM2Sign-with-SHA256" */ + 1133, /* "SM2Sign-with-SHA384" */ + 1131, /* "SM2Sign-with-SHA511" */ + 1128, /* "SM2Sign-with-SM3" */ + 1126, /* "SM3" */ + 1115, /* "SM5" */ + 1087, /* "SM6-CBC" */ + 1089, /* "SM6-CFB" */ + 1086, /* "SM6-ECB" */ + 1088, /* "SM6-OFB" */ 188, /* "SMIME" */ 167, /* "SMIME-CAPS" */ + 1103, /* "SMS4-CBC" */ + 1110, /* "SMS4-CCM" */ + 1105, /* "SMS4-CFB" */ + 1106, /* "SMS4-CFB1" */ + 1107, /* "SMS4-CFB8" */ + 1108, /* "SMS4-CTR" */ + 1102, /* "SMS4-ECB" */ + 1109, /* "SMS4-GCM" */ + 1114, /* "SMS4-OCB" */ + 1104, /* "SMS4-OFB" */ + 1112, /* "SMS4-WRAP" */ + 1113, /* "SMS4-WRAP-PAD" */ + 1111, /* "SMS4-XTS" */ 100, /* "SN" */ 1006, /* "SNILS" */ + 1097, /* "SSF33-CBC" */ + 1099, /* "SSF33-CFB" */ + 1100, /* "SSF33-CFB1" */ + 1101, /* "SSF33-CFB8" */ + 1096, /* "SSF33-ECB" */ + 1098, /* "SSF33-OFB" */ 16, /* "ST" */ 143, /* "SXNetID" */ 1021, /* "TLS1-PRF" */ @@ -2265,6 +2477,7 @@ static const unsigned int sn_objs[NUM_SN] = { 184, /* "X9-57" */ 185, /* "X9cm" */ 125, /* "ZLIB" */ + 1136, /* "ZUC" */ 478, /* "aRecord" */ 289, /* "aaControls" */ 287, /* "ac-auditEntity" */ @@ -2273,6 +2486,12 @@ static const unsigned int sn_objs[NUM_SN] = { 368, /* "acceptableResponses" */ 446, /* "account" */ 363, /* "ad_timestamping" */ + 1071, /* "aes128-cbc-in-ecies" */ + 1074, /* "aes128-ctr-in-ecies" */ + 1072, /* "aes192-cbc-in-ecies" */ + 1075, /* "aes192-ctr-in-ecies" */ + 1073, /* "aes256-cbc-in-ecies" */ + 1076, /* "aes256-ctr-in-ecies" */ 376, /* "algorithm" */ 405, /* "ansi-X9-62" */ 910, /* "anyExtendedKeyUsage" */ @@ -2280,12 +2499,15 @@ static const unsigned int sn_objs[NUM_SN] = { 370, /* "archiveCutoff" */ 484, /* "associatedDomain" */ 485, /* "associatedName" */ + 1145, /* "ate-pairing" */ 501, /* "audio" */ 177, /* "authorityInfoAccess" */ 90, /* "authorityKeyIdentifier" */ 882, /* "authorityRevocationList" */ 87, /* "basicConstraints" */ 365, /* "basicOCSPResponse" */ + 1138, /* "bb1" */ + 1137, /* "bfibe" */ 285, /* "biometricInfo" */ 921, /* "brainpoolP160r1" */ 922, /* "brainpoolP160t1" */ @@ -2339,6 +2561,9 @@ static const unsigned int sn_objs[NUM_SN] = { 407, /* "characteristic-two-field" */ 395, /* "clearance" */ 130, /* "clientAuth" */ + 1079, /* "cmac-aes128-ecies" */ + 1080, /* "cmac-aes192-ecies" */ + 1081, /* "cmac-aes256-ecies" */ 131, /* "codeSigning" */ 50, /* "contentType" */ 53, /* "countersignature" */ @@ -2398,6 +2623,8 @@ static const unsigned int sn_objs[NUM_SN] = { 795, /* "ecdsa-with-SHA384" */ 796, /* "ecdsa-with-SHA512" */ 792, /* "ecdsa-with-Specified" */ + 1063, /* "ecies-recommendedParameters" */ + 1064, /* "ecies-specifiedParameters" */ 48, /* "emailAddress" */ 132, /* "emailProtection" */ 885, /* "enhancedSearchGuide" */ @@ -2434,6 +2661,8 @@ static const unsigned int sn_objs[NUM_SN] = { 1012, /* "grasshopper-ecb" */ 1017, /* "grasshopper-mac" */ 1014, /* "grasshopper-ofb" */ + 1077, /* "hmac-full-ecies" */ + 1078, /* "hmac-half-ecies" */ 797, /* "hmacWithMD5" */ 163, /* "hmacWithSHA1" */ 798, /* "hmacWithSHA224" */ @@ -2549,6 +2778,7 @@ static const unsigned int sn_objs[NUM_SN] = { 787, /* "id-ct-asciiTextWithCRLF" */ 1060, /* "id-ct-xml" */ 408, /* "id-ecPublicKey" */ + 1061, /* "id-ecSigType" */ 508, /* "id-hex-multipart-message" */ 507, /* "id-hex-partial-message" */ 260, /* "id-it" */ @@ -2619,6 +2849,7 @@ static const unsigned int sn_objs[NUM_SN] = { 321, /* "id-regInfo-utf8Pairs" */ 973, /* "id-scrypt" */ 512, /* "id-set" */ + 1122, /* "id-sm9PublicKey" */ 191, /* "id-smime-aa" */ 215, /* "id-smime-aa-contentHint" */ 218, /* "id-smime-aa-contentIdentifier" */ @@ -2715,6 +2946,7 @@ static const unsigned int sn_objs[NUM_SN] = { 985, /* "id-tc26-signwithdigest-gost3410-2012-256" */ 986, /* "id-tc26-signwithdigest-gost3410-2012-512" */ 676, /* "identified-organization" */ + 1068, /* "ikev2-kdf" */ 461, /* "info" */ 748, /* "inhibitAnyPolicy" */ 101, /* "initials" */ @@ -2763,6 +2995,7 @@ static const unsigned int sn_objs[NUM_SN] = { 481, /* "nSRecord" */ 173, /* "name" */ 666, /* "nameConstraints" */ + 1066, /* "nist-concatenation-kdf" */ 369, /* "noCheck" */ 403, /* "noRevAvail" */ 72, /* "nsBaseUrl" */ @@ -2779,6 +3012,7 @@ static const unsigned int sn_objs[NUM_SN] = { 77, /* "nsSslServerName" */ 681, /* "onBasis" */ 491, /* "organizationalStatus" */ + 1084, /* "oscca" */ 475, /* "otherMailbox" */ 876, /* "owner" */ 489, /* "pagerTelephoneNumber" */ @@ -2838,6 +3072,7 @@ static const unsigned int sn_objs[NUM_SN] = { 435, /* "pss" */ 286, /* "qcStatements" */ 457, /* "qualityLabelledData" */ + 1146, /* "r-ate-pairing" */ 450, /* "rFC822localPart" */ 870, /* "registeredAddress" */ 400, /* "role" */ @@ -2855,6 +3090,7 @@ static const unsigned int sn_objs[NUM_SN] = { 292, /* "sbgp-routerIdentifier" */ 159, /* "sdsiCertificate" */ 859, /* "searchGuide" */ + 1062, /* "secg-scheme" */ 704, /* "secp112r1" */ 705, /* "secp112r2" */ 706, /* "secp128r1" */ @@ -3033,6 +3269,16 @@ static const unsigned int sn_objs[NUM_SN] = { 52, /* "signingTime" */ 454, /* "simpleSecurityObject" */ 496, /* "singleLevelQuality" */ + 1085, /* "sm-scheme" */ + 1119, /* "sm2encrypt" */ + 1120, /* "sm2encrypt-recommendedParameters" */ + 1121, /* "sm2encrypt-specifiedParameters" */ + 1118, /* "sm2keyagreement" */ + 1116, /* "sm2p256v1" */ + 1117, /* "sm2sign" */ + 1125, /* "sm9encrypt" */ + 1124, /* "sm9keyagreement" */ + 1123, /* "sm9sign" */ 387, /* "snmpv2" */ 660, /* "street" */ 85, /* "subjectAltName" */ @@ -3045,6 +3291,8 @@ static const unsigned int sn_objs[NUM_SN] = { 890, /* "supportedAlgorithms" */ 874, /* "supportedApplicationContext" */ 402, /* "targetInformation" */ + 1143, /* "tate-pairing" */ + 1070, /* "tdes-cbc-in-ecies" */ 864, /* "telephoneNumber" */ 866, /* "teletexTerminalIdentifier" */ 865, /* "telexNumber" */ @@ -3052,9 +3300,14 @@ static const unsigned int sn_objs[NUM_SN] = { 293, /* "textNotice" */ 133, /* "timeStamping" */ 106, /* "title" */ + 1067, /* "tls-kdf" */ 1020, /* "tlsfeature" */ 682, /* "tpBasis" */ 375, /* "trustRoot" */ + 1139, /* "type1curve" */ + 1140, /* "type2curve" */ + 1141, /* "type3curve" */ + 1142, /* "type4curve" */ 436, /* "ucl" */ 102, /* "uid" */ 888, /* "uniqueMember" */ @@ -3077,14 +3330,18 @@ static const unsigned int sn_objs[NUM_SN] = { 740, /* "wap-wsg-idm-ecid-wtls7" */ 741, /* "wap-wsg-idm-ecid-wtls8" */ 742, /* "wap-wsg-idm-ecid-wtls9" */ + 1135, /* "wapip192v1" */ + 1144, /* "weil-pairing" */ 804, /* "whirlpool" */ 868, /* "x121Address" */ 503, /* "x500UniqueIdentifier" */ 158, /* "x509Certificate" */ 160, /* "x509Crl" */ + 1065, /* "x9-63-kdf" */ + 1069, /* "xor-in-ecies" */ }; -#define NUM_LN 1052 +#define NUM_LN 1138 static const unsigned int ln_objs[NUM_LN] = { 363, /* "AD Time Stamping" */ 405, /* "ANSI X9.62" */ @@ -3149,6 +3406,7 @@ static const unsigned int ln_objs[NUM_LN] = { 294, /* "IPSec End System" */ 295, /* "IPSec Tunnel" */ 296, /* "IPSec User" */ + 1083, /* "ISO CN Member Body" */ 182, /* "ISO Member Body" */ 183, /* "ISO US Member Body" */ 667, /* "Independent" */ @@ -3302,9 +3560,16 @@ static const unsigned int ln_objs[NUM_LN] = { 960, /* "aes-256-ocb" */ 428, /* "aes-256-ofb" */ 914, /* "aes-256-xts" */ + 1071, /* "aes128-cbc-in-ecies" */ + 1074, /* "aes128-ctr-in-ecies" */ + 1072, /* "aes192-cbc-in-ecies" */ + 1075, /* "aes192-ctr-in-ecies" */ + 1073, /* "aes256-cbc-in-ecies" */ + 1076, /* "aes256-ctr-in-ecies" */ 376, /* "algorithm" */ 484, /* "associatedDomain" */ 485, /* "associatedName" */ + 1145, /* "ate-pairing" */ 501, /* "audio" */ 1049, /* "auth-dss" */ 1047, /* "auth-ecdsa" */ @@ -3315,10 +3580,12 @@ static const unsigned int ln_objs[NUM_LN] = { 1046, /* "auth-rsa" */ 1052, /* "auth-srp" */ 882, /* "authorityRevocationList" */ + 1138, /* "bb1" */ 91, /* "bf-cbc" */ 93, /* "bf-cfb" */ 92, /* "bf-ecb" */ 94, /* "bf-ofb" */ + 1137, /* "bfibe" */ 1056, /* "blake2b512" */ 1057, /* "blake2s256" */ 921, /* "brainpoolP160r1" */ @@ -3394,6 +3661,7 @@ static const unsigned int ln_objs[NUM_LN] = { 110, /* "cast5-cfb" */ 109, /* "cast5-ecb" */ 111, /* "cast5-ofb" */ + 1082, /* "cbc-mac" */ 152, /* "certBag" */ 677, /* "certicom-arc" */ 517, /* "certificate extensions" */ @@ -3405,6 +3673,9 @@ static const unsigned int ln_objs[NUM_LN] = { 395, /* "clearance" */ 633, /* "cleartext track 2" */ 894, /* "cmac" */ + 1079, /* "cmac-aes128-ecies" */ + 1080, /* "cmac-aes192-ecies" */ + 1081, /* "cmac-aes256-ecies" */ 13, /* "commonName" */ 513, /* "content types" */ 50, /* "contentType" */ @@ -3484,6 +3755,8 @@ static const unsigned int ln_objs[NUM_LN] = { 795, /* "ecdsa-with-SHA384" */ 796, /* "ecdsa-with-SHA512" */ 792, /* "ecdsa-with-Specified" */ + 1063, /* "ecies-recommendedParameters" */ + 1064, /* "ecies-specifiedParameters" */ 48, /* "emailAddress" */ 632, /* "encrypted track 2" */ 885, /* "enhancedSearchGuide" */ @@ -3511,8 +3784,11 @@ static const unsigned int ln_objs[NUM_LN] = { 1014, /* "grasshopper-ofb" */ 1036, /* "hkdf" */ 855, /* "hmac" */ + 1077, /* "hmac-full-ecies" */ + 1078, /* "hmac-half-ecies" */ 780, /* "hmac-md5" */ 781, /* "hmac-sha1" */ + 1127, /* "hmac-sm3" */ 797, /* "hmacWithMD5" */ 163, /* "hmacWithSHA1" */ 798, /* "hmacWithSHA224" */ @@ -3608,6 +3884,7 @@ static const unsigned int ln_objs[NUM_LN] = { 787, /* "id-ct-asciiTextWithCRLF" */ 1060, /* "id-ct-xml" */ 408, /* "id-ecPublicKey" */ + 1061, /* "id-ecSigType" */ 508, /* "id-hex-multipart-message" */ 507, /* "id-hex-partial-message" */ 260, /* "id-it" */ @@ -3671,6 +3948,7 @@ static const unsigned int ln_objs[NUM_LN] = { 322, /* "id-regInfo-certReq" */ 321, /* "id-regInfo-utf8Pairs" */ 973, /* "id-scrypt" */ + 1122, /* "id-sm9PublicKey" */ 191, /* "id-smime-aa" */ 215, /* "id-smime-aa-contentHint" */ 218, /* "id-smime-aa-contentIdentifier" */ @@ -3763,6 +4041,7 @@ static const unsigned int ln_objs[NUM_LN] = { 36, /* "idea-ecb" */ 46, /* "idea-ofb" */ 676, /* "identified-organization" */ + 1068, /* "ikev2-kdf" */ 461, /* "info" */ 101, /* "initials" */ 869, /* "internationaliSDNNumber" */ @@ -3815,11 +4094,13 @@ static const unsigned int ln_objs[NUM_LN] = { 488, /* "mobileTelephoneNumber" */ 481, /* "nSRecord" */ 173, /* "name" */ + 1066, /* "nist-concatenation-kdf" */ 681, /* "onBasis" */ 379, /* "org" */ 17, /* "organizationName" */ 491, /* "organizationalStatus" */ 18, /* "organizationalUnitName" */ + 1084, /* "oscca" */ 475, /* "otherMailbox" */ 876, /* "owner" */ 935, /* "pSpecified" */ @@ -3885,6 +4166,7 @@ static const unsigned int ln_objs[NUM_LN] = { 435, /* "pss" */ 286, /* "qcStatements" */ 457, /* "qualityLabelledData" */ + 1146, /* "r-ate-pairing" */ 450, /* "rFC822localPart" */ 98, /* "rc2-40-cbc" */ 166, /* "rc2-64-cbc" */ @@ -3920,6 +4202,7 @@ static const unsigned int ln_objs[NUM_LN] = { 292, /* "sbgp-routerIdentifier" */ 159, /* "sdsiCertificate" */ 859, /* "searchGuide" */ + 1062, /* "secg-scheme" */ 704, /* "secp112r1" */ 705, /* "secp112r2" */ 706, /* "secp128r1" */ @@ -4093,6 +4376,54 @@ static const unsigned int ln_objs[NUM_LN] = { 52, /* "signingTime" */ 454, /* "simpleSecurityObject" */ 496, /* "singleLevelQuality" */ + 1085, /* "sm-scheme" */ + 1091, /* "sm1-cbc" */ + 1093, /* "sm1-cfb" */ + 1094, /* "sm1-cfb1" */ + 1095, /* "sm1-cfb8" */ + 1090, /* "sm1-ecb" */ + 1092, /* "sm1-ofb" */ + 1119, /* "sm2encrypt" */ + 1120, /* "sm2encrypt-recommendedParameters" */ + 1121, /* "sm2encrypt-specifiedParameters" */ + 1118, /* "sm2keyagreement" */ + 1116, /* "sm2p256v1" */ + 1117, /* "sm2sign" */ + 1134, /* "sm2sign-with-rmd160" */ + 1129, /* "sm2sign-with-sha1" */ + 1132, /* "sm2sign-with-sha224" */ + 1130, /* "sm2sign-with-sha256" */ + 1133, /* "sm2sign-with-sha384" */ + 1131, /* "sm2sign-with-sha512" */ + 1128, /* "sm2sign-with-sm3" */ + 1126, /* "sm3" */ + 1115, /* "sm5" */ + 1087, /* "sm6-cbc" */ + 1089, /* "sm6-cfb" */ + 1086, /* "sm6-ecb" */ + 1088, /* "sm6-ofb" */ + 1125, /* "sm9encrypt" */ + 1124, /* "sm9keyagreement" */ + 1123, /* "sm9sign" */ + 1103, /* "sms4-cbc" */ + 1110, /* "sms4-ccm" */ + 1105, /* "sms4-cfb" */ + 1106, /* "sms4-cfb1" */ + 1107, /* "sms4-cfb8" */ + 1108, /* "sms4-ctr" */ + 1102, /* "sms4-ecb" */ + 1109, /* "sms4-gcm" */ + 1114, /* "sms4-ocb" */ + 1104, /* "sms4-ofb" */ + 1112, /* "sms4-wrap" */ + 1113, /* "sms4-wrap-pad" */ + 1111, /* "sms4-xts" */ + 1097, /* "ssf33-cbc" */ + 1099, /* "ssf33-cfb" */ + 1100, /* "ssf33-cfb1" */ + 1101, /* "ssf33-cfb8" */ + 1096, /* "ssf33-ecb" */ + 1098, /* "ssf33-ofb" */ 16, /* "stateOrProvinceName" */ 660, /* "streetAddress" */ 498, /* "subtreeMaximumQuality" */ @@ -4100,14 +4431,21 @@ static const unsigned int ln_objs[NUM_LN] = { 890, /* "supportedAlgorithms" */ 874, /* "supportedApplicationContext" */ 100, /* "surname" */ + 1143, /* "tate-pairing" */ + 1070, /* "tdes-cbc-in-ecies" */ 864, /* "telephoneNumber" */ 866, /* "teletexTerminalIdentifier" */ 865, /* "telexNumber" */ 459, /* "textEncodedORAddress" */ 293, /* "textNotice" */ 106, /* "title" */ + 1067, /* "tls-kdf" */ 1021, /* "tls1-prf" */ 682, /* "tpBasis" */ + 1139, /* "type1curve" */ + 1140, /* "type2curve" */ + 1141, /* "type3curve" */ + 1142, /* "type4curve" */ 436, /* "ucl" */ 0, /* "undefined" */ 102, /* "uniqueIdentifier" */ @@ -4132,15 +4470,20 @@ static const unsigned int ln_objs[NUM_LN] = { 740, /* "wap-wsg-idm-ecid-wtls7" */ 741, /* "wap-wsg-idm-ecid-wtls8" */ 742, /* "wap-wsg-idm-ecid-wtls9" */ + 1135, /* "wapip192v1" */ + 1144, /* "weil-pairing" */ 804, /* "whirlpool" */ 868, /* "x121Address" */ 503, /* "x500UniqueIdentifier" */ 158, /* "x509Certificate" */ 160, /* "x509Crl" */ + 1065, /* "x9-63-kdf" */ + 1069, /* "xor-in-ecies" */ 125, /* "zlib compression" */ + 1136, /* "zuc" */ }; -#define NUM_OBJ 956 +#define NUM_OBJ 1041 static const unsigned int obj_objs[NUM_OBJ] = { 0, /* OBJ_undef 0 */ 181, /* OBJ_iso 1 */ @@ -4161,6 +4504,7 @@ static const unsigned int obj_objs[NUM_OBJ] = { 512, /* OBJ_id_set 2 23 42 */ 678, /* OBJ_wap 2 23 43 */ 435, /* OBJ_pss 0 9 2342 */ + 1083, /* OBJ_ISO_CN 1 2 156 */ 183, /* OBJ_ISO_US 1 2 840 */ 381, /* OBJ_iana 1 3 6 1 */ 1034, /* OBJ_X25519 1 3 101 110 */ @@ -4261,6 +4605,7 @@ static const unsigned int obj_objs[NUM_OBJ] = { 387, /* OBJ_SNMPv2 1 3 6 1 6 */ 388, /* OBJ_Mail 1 3 6 1 7 */ 376, /* OBJ_algorithm 1 3 14 3 2 */ + 1062, /* OBJ_secg_scheme 1 3 132 1 */ 395, /* OBJ_clearance 2 5 1 5 55 */ 19, /* OBJ_rsa 2 5 8 1 1 */ 96, /* OBJ_mdc2WithRSA 2 5 8 3 100 */ @@ -4378,6 +4723,7 @@ static const unsigned int obj_objs[NUM_OBJ] = { 637, /* OBJ_set_brand_Diners 2 23 42 8 30 */ 638, /* OBJ_set_brand_AmericanExpress 2 23 42 8 34 */ 639, /* OBJ_set_brand_JCB 2 23 42 8 35 */ + 1084, /* OBJ_oscca 1 2 156 10197 */ 805, /* OBJ_cryptopro 1 2 643 2 2 */ 806, /* OBJ_cryptocom 1 2 643 2 9 */ 974, /* OBJ_id_tc26 1 2 643 7 1 */ @@ -4436,6 +4782,12 @@ static const unsigned int obj_objs[NUM_OBJ] = { 732, /* OBJ_sect409r1 1 3 132 0 37 */ 733, /* OBJ_sect571k1 1 3 132 0 38 */ 734, /* OBJ_sect571r1 1 3 132 0 39 */ + 1063, /* OBJ_ecies_recommendedParameters 1 3 132 1 7 */ + 1064, /* OBJ_ecies_specifiedParameters 1 3 132 1 8 */ + 1069, /* OBJ_xor_in_ecies 1 3 132 1 18 */ + 1070, /* OBJ_tdes_cbc_in_ecies 1 3 132 1 19 */ + 1077, /* OBJ_hmac_full_ecies 1 3 132 1 22 */ + 1078, /* OBJ_hmac_half_ecies 1 3 132 1 23 */ 624, /* OBJ_set_rootKeyThumb 2 23 42 3 0 0 */ 625, /* OBJ_set_addPolicy 2 23 42 3 0 1 */ 626, /* OBJ_setAttr_Token_EMV 2 23 42 3 2 1 */ @@ -4456,6 +4808,7 @@ static const unsigned int obj_objs[NUM_OBJ] = { 744, /* OBJ_wap_wsg_idm_ecid_wtls11 2 23 43 1 4 11 */ 745, /* OBJ_wap_wsg_idm_ecid_wtls12 2 23 43 1 4 12 */ 804, /* OBJ_whirlpool 1 0 10118 3 0 55 */ + 1085, /* OBJ_sm_scheme 1 2 156 10197 1 */ 773, /* OBJ_kisa 1 2 410 200004 */ 807, /* OBJ_id_GostR3411_94_with_GostR3410_2001 1 2 643 2 2 3 */ 808, /* OBJ_id_GostR3411_94_with_GostR3410_94 1 2 643 2 2 4 */ @@ -4472,6 +4825,7 @@ static const unsigned int obj_objs[NUM_OBJ] = { 994, /* OBJ_id_tc26_constants 1 2 643 7 1 2 */ 1, /* OBJ_rsadsi 1 2 840 113549 */ 185, /* OBJ_X9cm 1 2 840 10040 4 */ + 1061, /* OBJ_X9_62_id_ecSigType 1 2 840 10045 4 */ 1031, /* OBJ_id_pkinit 1 3 6 1 5 2 3 */ 127, /* OBJ_id_pkix 1 3 6 1 5 5 7 */ 505, /* OBJ_mime_mhs_headings 1 3 6 1 7 1 1 */ @@ -4485,6 +4839,19 @@ static const unsigned int obj_objs[NUM_OBJ] = { 943, /* OBJ_dhSinglePass_cofactorDH_sha256kdf_scheme 1 3 132 1 14 1 */ 944, /* OBJ_dhSinglePass_cofactorDH_sha384kdf_scheme 1 3 132 1 14 2 */ 945, /* OBJ_dhSinglePass_cofactorDH_sha512kdf_scheme 1 3 132 1 14 3 */ + 1065, /* OBJ_x9_63_kdf 1 3 132 1 17 0 */ + 1066, /* OBJ_nist_concatenation_kdf 1 3 132 1 17 1 */ + 1067, /* OBJ_tls_kdf 1 3 132 1 17 2 */ + 1068, /* OBJ_ikev2_kdf 1 3 132 1 17 3 */ + 1071, /* OBJ_aes128_cbc_in_ecies 1 3 132 1 20 0 */ + 1072, /* OBJ_aes192_cbc_in_ecies 1 3 132 1 20 1 */ + 1073, /* OBJ_aes256_cbc_in_ecies 1 3 132 1 20 2 */ + 1074, /* OBJ_aes128_ctr_in_ecies 1 3 132 1 21 0 */ + 1075, /* OBJ_aes192_ctr_in_ecies 1 3 132 1 21 1 */ + 1076, /* OBJ_aes256_ctr_in_ecies 1 3 132 1 21 2 */ + 1079, /* OBJ_cmac_aes128_ecies 1 3 132 1 24 0 */ + 1080, /* OBJ_cmac_aes192_ecies 1 3 132 1 24 1 */ + 1081, /* OBJ_cmac_aes256_ecies 1 3 132 1 24 2 */ 631, /* OBJ_setAttr_GenCryptgrm 2 23 42 3 3 3 1 */ 632, /* OBJ_setAttr_T2Enc 2 23 42 3 3 4 1 */ 633, /* OBJ_setAttr_T2cleartxt 2 23 42 3 3 4 2 */ @@ -4585,6 +4952,47 @@ static const unsigned int obj_objs[NUM_OBJ] = { 971, /* OBJ_camellia_256_ctr 0 3 4401 5 3 1 9 49 */ 972, /* OBJ_camellia_256_cmac 0 3 4401 5 3 1 9 50 */ 437, /* OBJ_pilot 0 9 2342 19200300 100 */ + 1086, /* OBJ_sm6_ecb 1 2 156 10197 1 101 1 */ + 1087, /* OBJ_sm6_cbc 1 2 156 10197 1 101 2 */ + 1088, /* OBJ_sm6_ofb128 1 2 156 10197 1 101 3 */ + 1089, /* OBJ_sm6_cfb128 1 2 156 10197 1 101 4 */ + 1090, /* OBJ_sm1_ecb 1 2 156 10197 1 102 1 */ + 1091, /* OBJ_sm1_cbc 1 2 156 10197 1 102 2 */ + 1092, /* OBJ_sm1_ofb128 1 2 156 10197 1 102 3 */ + 1093, /* OBJ_sm1_cfb128 1 2 156 10197 1 102 4 */ + 1094, /* OBJ_sm1_cfb1 1 2 156 10197 1 102 5 */ + 1095, /* OBJ_sm1_cfb8 1 2 156 10197 1 102 6 */ + 1096, /* OBJ_ssf33_ecb 1 2 156 10197 1 103 1 */ + 1097, /* OBJ_ssf33_cbc 1 2 156 10197 1 103 2 */ + 1098, /* OBJ_ssf33_ofb128 1 2 156 10197 1 103 3 */ + 1099, /* OBJ_ssf33_cfb128 1 2 156 10197 1 103 4 */ + 1100, /* OBJ_ssf33_cfb1 1 2 156 10197 1 103 5 */ + 1101, /* OBJ_ssf33_cfb8 1 2 156 10197 1 103 6 */ + 1102, /* OBJ_sms4_ecb 1 2 156 10197 1 104 1 */ + 1103, /* OBJ_sms4_cbc 1 2 156 10197 1 104 2 */ + 1104, /* OBJ_sms4_ofb128 1 2 156 10197 1 104 3 */ + 1105, /* OBJ_sms4_cfb128 1 2 156 10197 1 104 4 */ + 1106, /* OBJ_sms4_cfb1 1 2 156 10197 1 104 5 */ + 1107, /* OBJ_sms4_cfb8 1 2 156 10197 1 104 6 */ + 1108, /* OBJ_sms4_ctr 1 2 156 10197 1 104 7 */ + 1109, /* OBJ_sms4_gcm 1 2 156 10197 1 104 8 */ + 1110, /* OBJ_sms4_ccm 1 2 156 10197 1 104 9 */ + 1111, /* OBJ_sms4_xts 1 2 156 10197 1 104 10 */ + 1112, /* OBJ_sms4_wrap 1 2 156 10197 1 104 11 */ + 1113, /* OBJ_sms4_wrap_pad 1 2 156 10197 1 104 12 */ + 1114, /* OBJ_sms4_ocb 1 2 156 10197 1 104 100 */ + 1115, /* OBJ_sm5 1 2 156 10197 1 201 */ + 1116, /* OBJ_sm2p256v1 1 2 156 10197 1 301 */ + 1122, /* OBJ_id_sm9PublicKey 1 2 156 10197 1 302 */ + 1126, /* OBJ_sm3 1 2 156 10197 1 401 */ + 1128, /* OBJ_sm2sign_with_sm3 1 2 156 10197 1 501 */ + 1129, /* OBJ_sm2sign_with_sha1 1 2 156 10197 1 502 */ + 1130, /* OBJ_sm2sign_with_sha256 1 2 156 10197 1 503 */ + 1131, /* OBJ_sm2sign_with_sha512 1 2 156 10197 1 504 */ + 1132, /* OBJ_sm2sign_with_sha224 1 2 156 10197 1 505 */ + 1133, /* OBJ_sm2sign_with_sha384 1 2 156 10197 1 506 */ + 1134, /* OBJ_sm2sign_with_rmd160 1 2 156 10197 1 507 */ + 1136, /* OBJ_zuc 1 2 156 10197 1 800 */ 776, /* OBJ_seed_ecb 1 2 410 200004 1 3 */ 777, /* OBJ_seed_cbc 1 2 410 200004 1 4 */ 779, /* OBJ_seed_cfb128 1 2 410 200004 1 5 */ @@ -4785,6 +5193,14 @@ static const unsigned int obj_objs[NUM_OBJ] = { 439, /* OBJ_pilotAttributeSyntax 0 9 2342 19200300 100 3 */ 440, /* OBJ_pilotObjectClass 0 9 2342 19200300 100 4 */ 441, /* OBJ_pilotGroups 0 9 2342 19200300 100 10 */ + 1117, /* OBJ_sm2sign 1 2 156 10197 1 301 1 */ + 1118, /* OBJ_sm2keyagreement 1 2 156 10197 1 301 2 */ + 1119, /* OBJ_sm2encrypt 1 2 156 10197 1 301 3 */ + 1135, /* OBJ_wapip192v1 1 2 156 10197 1 301 101 */ + 1123, /* OBJ_sm9sign 1 2 156 10197 1 302 1 */ + 1124, /* OBJ_sm9keyagreement 1 2 156 10197 1 302 2 */ + 1125, /* OBJ_sm9encrypt 1 2 156 10197 1 302 3 */ + 1127, /* OBJ_hmac_sm3 1 2 156 10197 1 401 2 */ 997, /* OBJ_id_tc26_gost_3410_2012_512_paramSetTest 1 2 643 7 1 2 1 2 0 */ 998, /* OBJ_id_tc26_gost_3410_2012_512_paramSetA 1 2 643 7 1 2 1 2 1 */ 999, /* OBJ_id_tc26_gost_3410_2012_512_paramSetB 1 2 643 7 1 2 1 2 2 */ @@ -4984,6 +5400,18 @@ static const unsigned int obj_objs[NUM_OBJ] = { 455, /* OBJ_pilotOrganization 0 9 2342 19200300 100 4 20 */ 456, /* OBJ_pilotDSA 0 9 2342 19200300 100 4 21 */ 457, /* OBJ_qualityLabelledData 0 9 2342 19200300 100 4 22 */ + 1120, /* OBJ_sm2encrypt_recommendedParameters 1 2 156 10197 1 301 3 1 */ + 1121, /* OBJ_sm2encrypt_specifiedParameters 1 2 156 10197 1 301 3 2 */ + 1139, /* OBJ_type1curve 1 2 840 1 114334 1 1 1 */ + 1140, /* OBJ_type2curve 1 2 840 1 114334 1 1 2 */ + 1141, /* OBJ_type3curve 1 2 840 1 114334 1 1 3 */ + 1142, /* OBJ_type4curve 1 2 840 1 114334 1 1 4 */ + 1137, /* OBJ_bfibe 1 2 840 1 114334 1 2 1 */ + 1138, /* OBJ_bb1 1 2 840 1 114334 1 2 2 */ + 1143, /* OBJ_tate_pairing 1 2 840 1 114334 1 3 1 */ + 1144, /* OBJ_weil_pairing 1 2 840 1 114334 1 3 2 */ + 1145, /* OBJ_ate_pairing 1 2 840 1 114334 1 3 3 */ + 1146, /* OBJ_r_ate_pairing 1 2 840 1 114334 1 3 4 */ 189, /* OBJ_id_smime_mod 1 2 840 113549 1 9 16 0 */ 190, /* OBJ_id_smime_ct 1 2 840 113549 1 9 16 1 */ 191, /* OBJ_id_smime_aa 1 2 840 113549 1 9 16 2 */ diff --git a/crypto/objects/obj_mac.num b/crypto/objects/obj_mac.num index a5995a51..285aa5a0 100644 --- a/crypto/objects/obj_mac.num +++ b/crypto/objects/obj_mac.num @@ -1058,3 +1058,89 @@ blake2s256 1057 id_smime_ct_contentCollection 1058 id_smime_ct_authEnvelopedData 1059 id_ct_xml 1060 +X9_62_id_ecSigType 1061 +secg_scheme 1062 +ecies_recommendedParameters 1063 +ecies_specifiedParameters 1064 +x9_63_kdf 1065 +nist_concatenation_kdf 1066 +tls_kdf 1067 +ikev2_kdf 1068 +xor_in_ecies 1069 +tdes_cbc_in_ecies 1070 +aes128_cbc_in_ecies 1071 +aes192_cbc_in_ecies 1072 +aes256_cbc_in_ecies 1073 +aes128_ctr_in_ecies 1074 +aes192_ctr_in_ecies 1075 +aes256_ctr_in_ecies 1076 +hmac_full_ecies 1077 +hmac_half_ecies 1078 +cmac_aes128_ecies 1079 +cmac_aes192_ecies 1080 +cmac_aes256_ecies 1081 +cbc_mac 1082 +ISO_CN 1083 +oscca 1084 +sm_scheme 1085 +sm6_ecb 1086 +sm6_cbc 1087 +sm6_ofb128 1088 +sm6_cfb128 1089 +sm1_ecb 1090 +sm1_cbc 1091 +sm1_ofb128 1092 +sm1_cfb128 1093 +sm1_cfb1 1094 +sm1_cfb8 1095 +ssf33_ecb 1096 +ssf33_cbc 1097 +ssf33_ofb128 1098 +ssf33_cfb128 1099 +ssf33_cfb1 1100 +ssf33_cfb8 1101 +sms4_ecb 1102 +sms4_cbc 1103 +sms4_ofb128 1104 +sms4_cfb128 1105 +sms4_cfb1 1106 +sms4_cfb8 1107 +sms4_ctr 1108 +sms4_gcm 1109 +sms4_ccm 1110 +sms4_xts 1111 +sms4_wrap 1112 +sms4_wrap_pad 1113 +sms4_ocb 1114 +sm5 1115 +sm2p256v1 1116 +sm2sign 1117 +sm2keyagreement 1118 +sm2encrypt 1119 +sm2encrypt_recommendedParameters 1120 +sm2encrypt_specifiedParameters 1121 +id_sm9PublicKey 1122 +sm9sign 1123 +sm9keyagreement 1124 +sm9encrypt 1125 +sm3 1126 +hmac_sm3 1127 +sm2sign_with_sm3 1128 +sm2sign_with_sha1 1129 +sm2sign_with_sha256 1130 +sm2sign_with_sha512 1131 +sm2sign_with_sha224 1132 +sm2sign_with_sha384 1133 +sm2sign_with_rmd160 1134 +wapip192v1 1135 +zuc 1136 +bfibe 1137 +bb1 1138 +type1curve 1139 +type2curve 1140 +type3curve 1141 +type4curve 1142 +tate_pairing 1143 +weil_pairing 1144 +ate_pairing 1145 +r_ate_pairing 1146 diff --git a/crypto/sm3/asm/sm3-586.pl b/crypto/sm3/asm/sm3-586.pl new file mode 100644 index 00000000..1a049f75 --- /dev/null +++ b/crypto/sm3/asm/sm3-586.pl @@ -0,0 +1 @@ +#! /usr/bin/env perl diff --git a/crypto/sm3/asm/sm3-x86_64.pl b/crypto/sm3/asm/sm3-x86_64.pl new file mode 100755 index 00000000..1a049f75 --- /dev/null +++ b/crypto/sm3/asm/sm3-x86_64.pl @@ -0,0 +1 @@ +#! /usr/bin/env perl diff --git a/crypto/sm3/build.info b/crypto/sm3/build.info new file mode 100644 index 00000000..594338e2 --- /dev/null +++ b/crypto/sm3/build.info @@ -0,0 +1,2 @@ +LIBS=../../libcrypto +SOURCE[../../libcrypto]=sm3.c sm3_hmac.c diff --git a/crypto/sm3/sm3.c b/crypto/sm3/sm3.c new file mode 100644 index 00000000..41ec80e6 --- /dev/null +++ b/crypto/sm3/sm3.c @@ -0,0 +1,214 @@ +/* ==================================================================== + * Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the GmSSL Project. + * (http://gmssl.org/)" + * + * 4. The name "GmSSL Project" must not be used to endorse or promote + * products derived from this software without prior written + * permission. For written permission, please contact + * guanzhi1980@gmail.com. + * + * 5. Products derived from this software may not be called "GmSSL" + * nor may "GmSSL" appear in their names without prior written + * permission of the GmSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the GmSSL Project + * (http://gmssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ + +#include +#include +#include "internal/byteorder.h" + +void sm3_init(sm3_ctx_t *ctx) +{ + ctx->digest[0] = 0x7380166F; + ctx->digest[1] = 0x4914B2B9; + ctx->digest[2] = 0x172442D7; + ctx->digest[3] = 0xDA8A0600; + ctx->digest[4] = 0xA96F30BC; + ctx->digest[5] = 0x163138AA; + ctx->digest[6] = 0xE38DEE4D; + ctx->digest[7] = 0xB0FB0E4E; + + ctx->nblocks = 0; + ctx->num = 0; +} + +void sm3_update(sm3_ctx_t *ctx, const unsigned char* data, size_t data_len) +{ + if (ctx->num) { + unsigned int left = SM3_BLOCK_SIZE - ctx->num; + if (data_len < left) { + memcpy(ctx->block + ctx->num, data, data_len); + ctx->num += data_len; + return; + } else { + memcpy(ctx->block + ctx->num, data, left); + sm3_compress(ctx->digest, ctx->block); + ctx->nblocks++; + data += left; + data_len -= left; + } + } + while (data_len >= SM3_BLOCK_SIZE) { + sm3_compress(ctx->digest, data); + ctx->nblocks++; + data += SM3_BLOCK_SIZE; + data_len -= SM3_BLOCK_SIZE; + } + ctx->num = data_len; + if (data_len) { + memcpy(ctx->block, data, data_len); + } +} + +void sm3_final(sm3_ctx_t *ctx, unsigned char *digest) +{ + int i; + uint32_t *pdigest = (uint32_t *)digest; + uint32_t *count = (uint32_t *)(ctx->block + SM3_BLOCK_SIZE - 8); + + ctx->block[ctx->num] = 0x80; + + if (ctx->num + 9 <= SM3_BLOCK_SIZE) { + memset(ctx->block + ctx->num + 1, 0, SM3_BLOCK_SIZE - ctx->num - 9); + } else { + memset(ctx->block + ctx->num + 1, 0, SM3_BLOCK_SIZE - ctx->num - 1); + sm3_compress(ctx->digest, ctx->block); + memset(ctx->block, 0, SM3_BLOCK_SIZE - 8); + } + + count[0] = cpu_to_be32((ctx->nblocks) >> 23); + count[1] = cpu_to_be32((ctx->nblocks << 9) + (ctx->num << 3)); + + sm3_compress(ctx->digest, ctx->block); + for (i = 0; i < sizeof(ctx->digest)/sizeof(ctx->digest[0]); i++) { + pdigest[i] = cpu_to_be32(ctx->digest[i]); + } +} + +#define ROTATELEFT(X,n) (((X)<<(n)) | ((X)>>(32-(n)))) + +#define P0(x) ((x) ^ ROTATELEFT((x),9) ^ ROTATELEFT((x),17)) +#define P1(x) ((x) ^ ROTATELEFT((x),15) ^ ROTATELEFT((x),23)) + +#define FF0(x,y,z) ( (x) ^ (y) ^ (z)) +#define FF1(x,y,z) (((x) & (y)) | ( (x) & (z)) | ( (y) & (z))) + +#define GG0(x,y,z) ( (x) ^ (y) ^ (z)) +#define GG1(x,y,z) (((x) & (y)) | ( (~(x)) & (z)) ) + + +void sm3_compress(uint32_t digest[8], const unsigned char block[64]) +{ + int j; + uint32_t W[68], W1[64]; + const uint32_t *pblock = (const uint32_t *)block; + + uint32_t A = digest[0]; + uint32_t B = digest[1]; + uint32_t C = digest[2]; + uint32_t D = digest[3]; + uint32_t E = digest[4]; + uint32_t F = digest[5]; + uint32_t G = digest[6]; + uint32_t H = digest[7]; + uint32_t SS1,SS2,TT1,TT2,T[64]; + + for (j = 0; j < 16; j++) { + W[j] = cpu_to_be32(pblock[j]); + } + for (j = 16; j < 68; j++) { + W[j] = P1( W[j-16] ^ W[j-9] ^ ROTATELEFT(W[j-3],15)) ^ ROTATELEFT(W[j - 13],7 ) ^ W[j-6];; + } + for( j = 0; j < 64; j++) { + W1[j] = W[j] ^ W[j+4]; + } + + for(j =0; j < 16; j++) { + + T[j] = 0x79CC4519; + SS1 = ROTATELEFT((ROTATELEFT(A,12) + E + ROTATELEFT(T[j],j)), 7); + SS2 = SS1 ^ ROTATELEFT(A,12); + TT1 = FF0(A,B,C) + D + SS2 + W1[j]; + TT2 = GG0(E,F,G) + H + SS1 + W[j]; + D = C; + C = ROTATELEFT(B,9); + B = A; + A = TT1; + H = G; + G = ROTATELEFT(F,19); + F = E; + E = P0(TT2); + } + + for(j =16; j < 64; j++) { + + T[j] = 0x7A879D8A; + SS1 = ROTATELEFT((ROTATELEFT(A,12) + E + ROTATELEFT(T[j],j)), 7); + SS2 = SS1 ^ ROTATELEFT(A,12); + TT1 = FF1(A,B,C) + D + SS2 + W1[j]; + TT2 = GG1(E,F,G) + H + SS1 + W[j]; + D = C; + C = ROTATELEFT(B,9); + B = A; + A = TT1; + H = G; + G = ROTATELEFT(F,19); + F = E; + E = P0(TT2); + } + + digest[0] ^= A; + digest[1] ^= B; + digest[2] ^= C; + digest[3] ^= D; + digest[4] ^= E; + digest[5] ^= F; + digest[6] ^= G; + digest[7] ^= H; +} + +void sm3(const unsigned char *msg, size_t msglen, + unsigned char dgst[SM3_DIGEST_LENGTH]) +{ + sm3_ctx_t ctx; + + sm3_init(&ctx); + sm3_update(&ctx, msg, msglen); + sm3_final(&ctx, dgst); + + memset(&ctx, 0, sizeof(sm3_ctx_t)); +} diff --git a/crypto/sm3/sm3_hmac.c b/crypto/sm3/sm3_hmac.c new file mode 100644 index 00000000..498e2e2a --- /dev/null +++ b/crypto/sm3/sm3_hmac.c @@ -0,0 +1,125 @@ +/* ==================================================================== + * Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the GmSSL Project. + * (http://gmssl.org/)" + * + * 4. The name "GmSSL Project" must not be used to endorse or promote + * products derived from this software without prior written + * permission. For written permission, please contact + * guanzhi1980@gmail.com. + * + * 5. Products derived from this software may not be called "GmSSL" + * nor may "GmSSL" appear in their names without prior written + * permission of the GmSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the GmSSL Project + * (http://gmssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + */ +#include +#include + +/** + * HMAC_k(m) = H((k ^ opad), H((k ^ ipad), m)) + * pseudo-code: + * function hmac(key, message) + * opad = [0x5c * blocksize] + * ipad = [0x36 * blocksize] + * if (length(key) > blocksize) then + * key = hash(key) + * end if + * for i from 0 to length(key) - 1 step 1 + * ipad[i] = ipad[i] XOR key[i] + * opad[i] = opad[i] XOR key[i] + * end for + * return hash(opad || hash(ipad || message)) + * end function + */ + + +#define IPAD 0x36 +#define OPAD 0x5C + +void sm3_hmac_init(sm3_hmac_ctx_t *ctx, const unsigned char *key, size_t key_len) +{ + int i; + + if (key_len <= SM3_BLOCK_SIZE) { + memcpy(ctx->key, key, key_len); + memset(ctx->key + key_len, 0, SM3_BLOCK_SIZE - key_len); + } else { + sm3_init(&ctx->sm3_ctx); + sm3_update(&ctx->sm3_ctx, key, key_len); + sm3_final(&ctx->sm3_ctx, ctx->key); + memset(ctx->key + SM3_DIGEST_LENGTH, 0, + SM3_BLOCK_SIZE - SM3_DIGEST_LENGTH); + } + for (i = 0; i < SM3_BLOCK_SIZE; i++) { + ctx->key[i] ^= IPAD; + } + + sm3_init(&ctx->sm3_ctx); + sm3_update(&ctx->sm3_ctx, ctx->key, SM3_BLOCK_SIZE); +} + +void sm3_hmac_update(sm3_hmac_ctx_t *ctx, + const unsigned char *data, size_t data_len) +{ + sm3_update(&ctx->sm3_ctx, data, data_len); +} + +void sm3_hmac_final(sm3_hmac_ctx_t *ctx, unsigned char mac[SM3_HMAC_SIZE]) +{ + int i; + for (i = 0; i < SM3_BLOCK_SIZE; i++) { + ctx->key[i] ^= (IPAD ^ OPAD); + } + sm3_final(&ctx->sm3_ctx, mac); + sm3_init(&ctx->sm3_ctx); + sm3_update(&ctx->sm3_ctx, ctx->key, SM3_BLOCK_SIZE); + sm3_update(&ctx->sm3_ctx, mac, SM3_DIGEST_LENGTH); + sm3_final(&ctx->sm3_ctx, mac); +} + +void sm3_hmac(const unsigned char *data, size_t data_len, + const unsigned char *key, size_t key_len, + unsigned char mac[SM3_HMAC_SIZE]) +{ + sm3_hmac_ctx_t ctx; + sm3_hmac_init(&ctx, key, key_len); + sm3_hmac_update(&ctx, data, data_len); + sm3_hmac_final(&ctx, mac); + memset(&ctx, 0, sizeof(ctx)); +} + diff --git a/include/openssl/evp.h b/include/openssl/evp.h index 01f51b7b..6f042433 100644 --- a/include/openssl/evp.h +++ b/include/openssl/evp.h @@ -1,3 +1,51 @@ +/* ==================================================================== + * Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the GmSSL Project. + * (http://gmssl.org/)" + * + * 4. The name "GmSSL Project" must not be used to endorse or promote + * products derived from this software without prior written + * permission. For written permission, please contact + * guanzhi1980@gmail.com. + * + * 5. Products derived from this software may not be called "GmSSL" + * nor may "GmSSL" appear in their names without prior written + * permission of the GmSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the GmSSL Project + * (http://gmssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ /* * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. * @@ -671,6 +719,9 @@ const EVP_MD *EVP_ripemd160(void); # ifndef OPENSSL_NO_WHIRLPOOL const EVP_MD *EVP_whirlpool(void); # endif +# ifndef OPENSSL_NO_SM3 +const EVP_MD *EVP_sm3(void); +# endif const EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */ # ifndef OPENSSL_NO_DES const EVP_CIPHER *EVP_des_ecb(void); diff --git a/include/openssl/obj_mac.h b/include/openssl/obj_mac.h index f97f3eaa..230c5ee9 100644 --- a/include/openssl/obj_mac.h +++ b/include/openssl/obj_mac.h @@ -256,6 +256,8 @@ #define NID_X9_62_prime256v1 415 #define OBJ_X9_62_prime256v1 OBJ_X9_62_primeCurve,7L +#define SN_X9_62_id_ecSigType "id-ecSigType" +#define NID_X9_62_id_ecSigType 1061 #define OBJ_X9_62_id_ecSigType OBJ_ansi_X9_62,4L #define SN_ecdsa_with_SHA1 "ecdsa-with-SHA1" @@ -4391,6 +4393,8 @@ #define OBJ_x9_63_scheme 1L,3L,133L,16L,840L,63L,0L +#define SN_secg_scheme "secg-scheme" +#define NID_secg_scheme 1062 #define OBJ_secg_scheme OBJ_certicom_arc,1L #define SN_dhSinglePass_stdDH_sha1kdf_scheme "dhSinglePass-stdDH-sha1kdf-scheme" @@ -4575,3 +4579,386 @@ #define SN_auth_null "AuthNULL" #define LN_auth_null "auth-null" #define NID_auth_null 1053 + +#define SN_ecies_recommendedParameters "ecies-recommendedParameters" +#define NID_ecies_recommendedParameters 1063 +#define OBJ_ecies_recommendedParameters OBJ_secg_scheme,7L + +#define SN_ecies_specifiedParameters "ecies-specifiedParameters" +#define NID_ecies_specifiedParameters 1064 +#define OBJ_ecies_specifiedParameters OBJ_secg_scheme,8L + +#define SN_x9_63_kdf "x9-63-kdf" +#define NID_x9_63_kdf 1065 +#define OBJ_x9_63_kdf OBJ_secg_scheme,17L,0L + +#define SN_nist_concatenation_kdf "nist-concatenation-kdf" +#define NID_nist_concatenation_kdf 1066 +#define OBJ_nist_concatenation_kdf OBJ_secg_scheme,17L,1L + +#define SN_tls_kdf "tls-kdf" +#define NID_tls_kdf 1067 +#define OBJ_tls_kdf OBJ_secg_scheme,17L,2L + +#define SN_ikev2_kdf "ikev2-kdf" +#define NID_ikev2_kdf 1068 +#define OBJ_ikev2_kdf OBJ_secg_scheme,17L,3L + +#define SN_xor_in_ecies "xor-in-ecies" +#define NID_xor_in_ecies 1069 +#define OBJ_xor_in_ecies OBJ_secg_scheme,18L + +#define SN_tdes_cbc_in_ecies "tdes-cbc-in-ecies" +#define NID_tdes_cbc_in_ecies 1070 +#define OBJ_tdes_cbc_in_ecies OBJ_secg_scheme,19L + +#define SN_aes128_cbc_in_ecies "aes128-cbc-in-ecies" +#define NID_aes128_cbc_in_ecies 1071 +#define OBJ_aes128_cbc_in_ecies OBJ_secg_scheme,20L,0L + +#define SN_aes192_cbc_in_ecies "aes192-cbc-in-ecies" +#define NID_aes192_cbc_in_ecies 1072 +#define OBJ_aes192_cbc_in_ecies OBJ_secg_scheme,20L,1L + +#define SN_aes256_cbc_in_ecies "aes256-cbc-in-ecies" +#define NID_aes256_cbc_in_ecies 1073 +#define OBJ_aes256_cbc_in_ecies OBJ_secg_scheme,20L,2L + +#define SN_aes128_ctr_in_ecies "aes128-ctr-in-ecies" +#define NID_aes128_ctr_in_ecies 1074 +#define OBJ_aes128_ctr_in_ecies OBJ_secg_scheme,21L,0L + +#define SN_aes192_ctr_in_ecies "aes192-ctr-in-ecies" +#define NID_aes192_ctr_in_ecies 1075 +#define OBJ_aes192_ctr_in_ecies OBJ_secg_scheme,21L,1L + +#define SN_aes256_ctr_in_ecies "aes256-ctr-in-ecies" +#define NID_aes256_ctr_in_ecies 1076 +#define OBJ_aes256_ctr_in_ecies OBJ_secg_scheme,21L,2L + +#define SN_hmac_full_ecies "hmac-full-ecies" +#define NID_hmac_full_ecies 1077 +#define OBJ_hmac_full_ecies OBJ_secg_scheme,22L + +#define SN_hmac_half_ecies "hmac-half-ecies" +#define NID_hmac_half_ecies 1078 +#define OBJ_hmac_half_ecies OBJ_secg_scheme,23L + +#define SN_cmac_aes128_ecies "cmac-aes128-ecies" +#define NID_cmac_aes128_ecies 1079 +#define OBJ_cmac_aes128_ecies OBJ_secg_scheme,24L,0L + +#define SN_cmac_aes192_ecies "cmac-aes192-ecies" +#define NID_cmac_aes192_ecies 1080 +#define OBJ_cmac_aes192_ecies OBJ_secg_scheme,24L,1L + +#define SN_cmac_aes256_ecies "cmac-aes256-ecies" +#define NID_cmac_aes256_ecies 1081 +#define OBJ_cmac_aes256_ecies OBJ_secg_scheme,24L,2L + +#define SN_cbc_mac "CBC-MAC" +#define LN_cbc_mac "cbc-mac" +#define NID_cbc_mac 1082 + +#define SN_ISO_CN "ISO-CN" +#define LN_ISO_CN "ISO CN Member Body" +#define NID_ISO_CN 1083 +#define OBJ_ISO_CN OBJ_member_body,156L + +#define SN_oscca "oscca" +#define NID_oscca 1084 +#define OBJ_oscca OBJ_ISO_CN,10197L + +#define SN_sm_scheme "sm-scheme" +#define NID_sm_scheme 1085 +#define OBJ_sm_scheme OBJ_oscca,1L + +#define SN_sm6_ecb "SM6-ECB" +#define LN_sm6_ecb "sm6-ecb" +#define NID_sm6_ecb 1086 +#define OBJ_sm6_ecb OBJ_sm_scheme,101L,1L + +#define SN_sm6_cbc "SM6-CBC" +#define LN_sm6_cbc "sm6-cbc" +#define NID_sm6_cbc 1087 +#define OBJ_sm6_cbc OBJ_sm_scheme,101L,2L + +#define SN_sm6_ofb128 "SM6-OFB" +#define LN_sm6_ofb128 "sm6-ofb" +#define NID_sm6_ofb128 1088 +#define OBJ_sm6_ofb128 OBJ_sm_scheme,101L,3L + +#define SN_sm6_cfb128 "SM6-CFB" +#define LN_sm6_cfb128 "sm6-cfb" +#define NID_sm6_cfb128 1089 +#define OBJ_sm6_cfb128 OBJ_sm_scheme,101L,4L + +#define SN_sm1_ecb "SM1-ECB" +#define LN_sm1_ecb "sm1-ecb" +#define NID_sm1_ecb 1090 +#define OBJ_sm1_ecb OBJ_sm_scheme,102L,1L + +#define SN_sm1_cbc "SM1-CBC" +#define LN_sm1_cbc "sm1-cbc" +#define NID_sm1_cbc 1091 +#define OBJ_sm1_cbc OBJ_sm_scheme,102L,2L + +#define SN_sm1_ofb128 "SM1-OFB" +#define LN_sm1_ofb128 "sm1-ofb" +#define NID_sm1_ofb128 1092 +#define OBJ_sm1_ofb128 OBJ_sm_scheme,102L,3L + +#define SN_sm1_cfb128 "SM1-CFB" +#define LN_sm1_cfb128 "sm1-cfb" +#define NID_sm1_cfb128 1093 +#define OBJ_sm1_cfb128 OBJ_sm_scheme,102L,4L + +#define SN_sm1_cfb1 "SM1-CFB1" +#define LN_sm1_cfb1 "sm1-cfb1" +#define NID_sm1_cfb1 1094 +#define OBJ_sm1_cfb1 OBJ_sm_scheme,102L,5L + +#define SN_sm1_cfb8 "SM1-CFB8" +#define LN_sm1_cfb8 "sm1-cfb8" +#define NID_sm1_cfb8 1095 +#define OBJ_sm1_cfb8 OBJ_sm_scheme,102L,6L + +#define SN_ssf33_ecb "SSF33-ECB" +#define LN_ssf33_ecb "ssf33-ecb" +#define NID_ssf33_ecb 1096 +#define OBJ_ssf33_ecb OBJ_sm_scheme,103L,1L + +#define SN_ssf33_cbc "SSF33-CBC" +#define LN_ssf33_cbc "ssf33-cbc" +#define NID_ssf33_cbc 1097 +#define OBJ_ssf33_cbc OBJ_sm_scheme,103L,2L + +#define SN_ssf33_ofb128 "SSF33-OFB" +#define LN_ssf33_ofb128 "ssf33-ofb" +#define NID_ssf33_ofb128 1098 +#define OBJ_ssf33_ofb128 OBJ_sm_scheme,103L,3L + +#define SN_ssf33_cfb128 "SSF33-CFB" +#define LN_ssf33_cfb128 "ssf33-cfb" +#define NID_ssf33_cfb128 1099 +#define OBJ_ssf33_cfb128 OBJ_sm_scheme,103L,4L + +#define SN_ssf33_cfb1 "SSF33-CFB1" +#define LN_ssf33_cfb1 "ssf33-cfb1" +#define NID_ssf33_cfb1 1100 +#define OBJ_ssf33_cfb1 OBJ_sm_scheme,103L,5L + +#define SN_ssf33_cfb8 "SSF33-CFB8" +#define LN_ssf33_cfb8 "ssf33-cfb8" +#define NID_ssf33_cfb8 1101 +#define OBJ_ssf33_cfb8 OBJ_sm_scheme,103L,6L + +#define SN_sms4_ecb "SMS4-ECB" +#define LN_sms4_ecb "sms4-ecb" +#define NID_sms4_ecb 1102 +#define OBJ_sms4_ecb OBJ_sm_scheme,104L,1L + +#define SN_sms4_cbc "SMS4-CBC" +#define LN_sms4_cbc "sms4-cbc" +#define NID_sms4_cbc 1103 +#define OBJ_sms4_cbc OBJ_sm_scheme,104L,2L + +#define SN_sms4_ofb128 "SMS4-OFB" +#define LN_sms4_ofb128 "sms4-ofb" +#define NID_sms4_ofb128 1104 +#define OBJ_sms4_ofb128 OBJ_sm_scheme,104L,3L + +#define SN_sms4_cfb128 "SMS4-CFB" +#define LN_sms4_cfb128 "sms4-cfb" +#define NID_sms4_cfb128 1105 +#define OBJ_sms4_cfb128 OBJ_sm_scheme,104L,4L + +#define SN_sms4_cfb1 "SMS4-CFB1" +#define LN_sms4_cfb1 "sms4-cfb1" +#define NID_sms4_cfb1 1106 +#define OBJ_sms4_cfb1 OBJ_sm_scheme,104L,5L + +#define SN_sms4_cfb8 "SMS4-CFB8" +#define LN_sms4_cfb8 "sms4-cfb8" +#define NID_sms4_cfb8 1107 +#define OBJ_sms4_cfb8 OBJ_sm_scheme,104L,6L + +#define SN_sms4_ctr "SMS4-CTR" +#define LN_sms4_ctr "sms4-ctr" +#define NID_sms4_ctr 1108 +#define OBJ_sms4_ctr OBJ_sm_scheme,104L,7L + +#define SN_sms4_gcm "SMS4-GCM" +#define LN_sms4_gcm "sms4-gcm" +#define NID_sms4_gcm 1109 +#define OBJ_sms4_gcm OBJ_sm_scheme,104L,8L + +#define SN_sms4_ccm "SMS4-CCM" +#define LN_sms4_ccm "sms4-ccm" +#define NID_sms4_ccm 1110 +#define OBJ_sms4_ccm OBJ_sm_scheme,104L,9L + +#define SN_sms4_xts "SMS4-XTS" +#define LN_sms4_xts "sms4-xts" +#define NID_sms4_xts 1111 +#define OBJ_sms4_xts OBJ_sm_scheme,104L,10L + +#define SN_sms4_wrap "SMS4-WRAP" +#define LN_sms4_wrap "sms4-wrap" +#define NID_sms4_wrap 1112 +#define OBJ_sms4_wrap OBJ_sm_scheme,104L,11L + +#define SN_sms4_wrap_pad "SMS4-WRAP-PAD" +#define LN_sms4_wrap_pad "sms4-wrap-pad" +#define NID_sms4_wrap_pad 1113 +#define OBJ_sms4_wrap_pad OBJ_sm_scheme,104L,12L + +#define SN_sms4_ocb "SMS4-OCB" +#define LN_sms4_ocb "sms4-ocb" +#define NID_sms4_ocb 1114 +#define OBJ_sms4_ocb OBJ_sm_scheme,104L,100L + +#define OBJ_sm7 OBJ_sm_scheme,105L + +#define OBJ_sm8 OBJ_sm_scheme,106L + +#define SN_sm5 "SM5" +#define LN_sm5 "sm5" +#define NID_sm5 1115 +#define OBJ_sm5 OBJ_sm_scheme,201L + +#define SN_sm2p256v1 "sm2p256v1" +#define NID_sm2p256v1 1116 +#define OBJ_sm2p256v1 OBJ_sm_scheme,301L + +#define SN_sm2sign "sm2sign" +#define NID_sm2sign 1117 +#define OBJ_sm2sign OBJ_sm_scheme,301L,1L + +#define SN_sm2keyagreement "sm2keyagreement" +#define NID_sm2keyagreement 1118 +#define OBJ_sm2keyagreement OBJ_sm_scheme,301L,2L + +#define SN_sm2encrypt "sm2encrypt" +#define NID_sm2encrypt 1119 +#define OBJ_sm2encrypt OBJ_sm_scheme,301L,3L + +#define SN_sm2encrypt_recommendedParameters "sm2encrypt-recommendedParameters" +#define NID_sm2encrypt_recommendedParameters 1120 +#define OBJ_sm2encrypt_recommendedParameters OBJ_sm2encrypt,1L + +#define SN_sm2encrypt_specifiedParameters "sm2encrypt-specifiedParameters" +#define NID_sm2encrypt_specifiedParameters 1121 +#define OBJ_sm2encrypt_specifiedParameters OBJ_sm2encrypt,2L + +#define SN_id_sm9PublicKey "id-sm9PublicKey" +#define NID_id_sm9PublicKey 1122 +#define OBJ_id_sm9PublicKey OBJ_sm_scheme,302L + +#define SN_sm9sign "sm9sign" +#define NID_sm9sign 1123 +#define OBJ_sm9sign OBJ_sm_scheme,302L,1L + +#define SN_sm9keyagreement "sm9keyagreement" +#define NID_sm9keyagreement 1124 +#define OBJ_sm9keyagreement OBJ_sm_scheme,302L,2L + +#define SN_sm9encrypt "sm9encrypt" +#define NID_sm9encrypt 1125 +#define OBJ_sm9encrypt OBJ_sm_scheme,302L,3L + +#define SN_sm3 "SM3" +#define LN_sm3 "sm3" +#define NID_sm3 1126 +#define OBJ_sm3 OBJ_sm_scheme,401L + +#define SN_hmac_sm3 "HMAC-SM3" +#define LN_hmac_sm3 "hmac-sm3" +#define NID_hmac_sm3 1127 +#define OBJ_hmac_sm3 OBJ_sm_scheme,401L,2L + +#define SN_sm2sign_with_sm3 "SM2Sign-with-SM3" +#define LN_sm2sign_with_sm3 "sm2sign-with-sm3" +#define NID_sm2sign_with_sm3 1128 +#define OBJ_sm2sign_with_sm3 OBJ_sm_scheme,501L + +#define SN_sm2sign_with_sha1 "SM2Sign-with-SHA1" +#define LN_sm2sign_with_sha1 "sm2sign-with-sha1" +#define NID_sm2sign_with_sha1 1129 +#define OBJ_sm2sign_with_sha1 OBJ_sm_scheme,502L + +#define SN_sm2sign_with_sha256 "SM2Sign-with-SHA256" +#define LN_sm2sign_with_sha256 "sm2sign-with-sha256" +#define NID_sm2sign_with_sha256 1130 +#define OBJ_sm2sign_with_sha256 OBJ_sm_scheme,503L + +#define SN_sm2sign_with_sha512 "SM2Sign-with-SHA511" +#define LN_sm2sign_with_sha512 "sm2sign-with-sha512" +#define NID_sm2sign_with_sha512 1131 +#define OBJ_sm2sign_with_sha512 OBJ_sm_scheme,504L + +#define SN_sm2sign_with_sha224 "SM2Sign-with-SHA224" +#define LN_sm2sign_with_sha224 "sm2sign-with-sha224" +#define NID_sm2sign_with_sha224 1132 +#define OBJ_sm2sign_with_sha224 OBJ_sm_scheme,505L + +#define SN_sm2sign_with_sha384 "SM2Sign-with-SHA384" +#define LN_sm2sign_with_sha384 "sm2sign-with-sha384" +#define NID_sm2sign_with_sha384 1133 +#define OBJ_sm2sign_with_sha384 OBJ_sm_scheme,506L + +#define SN_sm2sign_with_rmd160 "SM2Sign-with-RMD160" +#define LN_sm2sign_with_rmd160 "sm2sign-with-rmd160" +#define NID_sm2sign_with_rmd160 1134 +#define OBJ_sm2sign_with_rmd160 OBJ_sm_scheme,507L + +#define SN_wapip192v1 "wapip192v1" +#define NID_wapip192v1 1135 +#define OBJ_wapip192v1 OBJ_sm_scheme,301L,101L + +#define SN_zuc "ZUC" +#define LN_zuc "zuc" +#define NID_zuc 1136 +#define OBJ_zuc OBJ_sm_scheme,800L + +#define OBJ_ibcs1 OBJ_ISO_US,1L,114334L,1L + +#define SN_bfibe "bfibe" +#define NID_bfibe 1137 +#define OBJ_bfibe OBJ_ibcs1,2L,1L + +#define SN_bb1 "bb1" +#define NID_bb1 1138 +#define OBJ_bb1 OBJ_ibcs1,2L,2L + +#define SN_type1curve "type1curve" +#define NID_type1curve 1139 +#define OBJ_type1curve OBJ_ibcs1,1L,1L + +#define SN_type2curve "type2curve" +#define NID_type2curve 1140 +#define OBJ_type2curve OBJ_ibcs1,1L,2L + +#define SN_type3curve "type3curve" +#define NID_type3curve 1141 +#define OBJ_type3curve OBJ_ibcs1,1L,3L + +#define SN_type4curve "type4curve" +#define NID_type4curve 1142 +#define OBJ_type4curve OBJ_ibcs1,1L,4L + +#define SN_tate_pairing "tate-pairing" +#define NID_tate_pairing 1143 +#define OBJ_tate_pairing OBJ_ibcs1,3L,1L + +#define SN_weil_pairing "weil-pairing" +#define NID_weil_pairing 1144 +#define OBJ_weil_pairing OBJ_ibcs1,3L,2L + +#define SN_ate_pairing "ate-pairing" +#define NID_ate_pairing 1145 +#define OBJ_ate_pairing OBJ_ibcs1,3L,3L + +#define SN_r_ate_pairing "r-ate-pairing" +#define NID_r_ate_pairing 1146 +#define OBJ_r_ate_pairing OBJ_ibcs1,3L,4L diff --git a/include/openssl/sm3.h b/include/openssl/sm3.h new file mode 100644 index 00000000..aff35899 --- /dev/null +++ b/include/openssl/sm3.h @@ -0,0 +1,99 @@ +/* ==================================================================== + * Copyright (c) 2014 - 2016 The GmSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the GmSSL Project. + * (http://gmssl.org/)" + * + * 4. The name "GmSSL Project" must not be used to endorse or promote + * products derived from this software without prior written + * permission. For written permission, please contact + * guanzhi1980@gmail.com. + * + * 5. Products derived from this software may not be called "GmSSL" + * nor may "GmSSL" appear in their names without prior written + * permission of the GmSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the GmSSL Project + * (http://gmssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ + +#ifndef HEADER_SM3_H +#define HEADER_SM3_H +#ifndef NO_GMSSL + +#define SM3_DIGEST_LENGTH 32 +#define SM3_BLOCK_SIZE 64 +#define SM3_CBLOCK (SM3_BLOCK_SIZE) +#define SM3_HMAC_SIZE (SM3_DIGEST_LENGTH) + + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct { + uint32_t digest[8]; + int nblocks; + unsigned char block[64]; + int num; +} sm3_ctx_t; + +void sm3_init(sm3_ctx_t *ctx); +void sm3_update(sm3_ctx_t *ctx, const unsigned char* data, size_t data_len); +void sm3_final(sm3_ctx_t *ctx, unsigned char digest[SM3_DIGEST_LENGTH]); +void sm3_compress(uint32_t digest[8], const unsigned char block[SM3_BLOCK_SIZE]); +void sm3(const unsigned char *data, size_t datalen, + unsigned char digest[SM3_DIGEST_LENGTH]); + + +typedef struct { + sm3_ctx_t sm3_ctx; + unsigned char key[SM3_BLOCK_SIZE]; +} sm3_hmac_ctx_t; + +void sm3_hmac_init(sm3_hmac_ctx_t *ctx, const unsigned char *key, size_t key_len); +void sm3_hmac_update(sm3_hmac_ctx_t *ctx, const unsigned char *data, size_t data_len); +void sm3_hmac_final(sm3_hmac_ctx_t *ctx, unsigned char mac[SM3_HMAC_SIZE]); +void sm3_hmac(const unsigned char *data, size_t data_len, + const unsigned char *key, size_t key_len, unsigned char mac[SM3_HMAC_SIZE]); + +#ifdef __cplusplus +} +#endif +#endif +#endif diff --git a/test/build.info b/test/build.info index 0c2c909b..2ed6dc12 100644 --- a/test/build.info +++ b/test/build.info @@ -16,7 +16,8 @@ IF[{- !$disabled{tests} -}] packettest asynctest secmemtest srptest memleaktest \ dtlsv1listentest ct_test threadstest afalgtest d2i_test \ ssl_test_ctx_test ssl_test x509aux cipherlist_test asynciotest \ - bioprinttest sslapitest dtlstest sslcorrupttest bio_enc_test + bioprinttest sslapitest dtlstest sslcorrupttest bio_enc_test \ + sm3test SOURCE[aborttest]=aborttest.c INCLUDE[aborttest]=../include @@ -283,6 +284,10 @@ IF[{- !$disabled{tests} -}] INCLUDE[bio_enc_test]=../include DEPEND[bio_enc_test]=../libcrypto + SOURCE[sm3test]=sm3test.c + INCLUDE[sm3test]=../include + DEPEND[sm3test]=../libcrypto + IF[{- !$disabled{shared} -}] PROGRAMS_NO_INST=shlibloadtest SOURCE[shlibloadtest]=shlibloadtest.c diff --git a/test/recipes/03-test_ui.t b/test/recipes/03-test_ui.t index b1065d1b..7820616e 100644 --- a/test/recipes/03-test_ui.t +++ b/test/recipes/03-test_ui.t @@ -23,7 +23,7 @@ ensures that one gets tested well enough as well. EOF my $outfile = "rsa_$$.pem"; -ok(run(app(["openssl", "genrsa", "-passout", "pass:password", "-aes128", +ok(run(app(["gmssl", "genrsa", "-passout", "pass:password", "-aes128", "-out", $outfile])), "Checking that genrsa with a password works properly"); diff --git a/test/recipes/05-test_sm3.t b/test/recipes/05-test_sm3.t new file mode 100644 index 00000000..3a11e7cf --- /dev/null +++ b/test/recipes/05-test_sm3.t @@ -0,0 +1,12 @@ +#! /usr/bin/env perl +# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. +# +# Licensed under the OpenSSL license (the "License"). You may not use +# this file except in compliance with the License. You can obtain a copy +# in the file LICENSE in the source distribution or at +# https://www.openssl.org/source/license.html + + +use OpenSSL::Test::Simple; + +simple_test("test_sm3", "sm3test", "sm3"); diff --git a/test/recipes/15-test_rsa.t b/test/recipes/15-test_rsa.t index a57ce63a..7fa53635 100644 --- a/test/recipes/15-test_rsa.t +++ b/test/recipes/15-test_rsa.t @@ -22,7 +22,7 @@ require_ok(srctop_file('test','recipes','tconversion.pl')); ok(run(test(["rsa_test"])), "running rsatest"); -ok(run(app([ 'openssl', 'rsa', '-check', '-in', srctop_file('test', 'testrsa.pem'), '-noout'])), "rsa -check"); +ok(run(app([ 'gmssl', 'rsa', '-check', '-in', srctop_file('test', 'testrsa.pem'), '-noout'])), "rsa -check"); SKIP: { skip "Skipping rsa conversion test", 3 diff --git a/test/recipes/20-test_passwd.t b/test/recipes/20-test_passwd.t index cf9c2cc8..392620ab 100644 --- a/test/recipes/20-test_passwd.t +++ b/test/recipes/20-test_passwd.t @@ -17,17 +17,17 @@ setup("test_passwd"); plan tests => disabled("des") ? 4 : 6; -ok(compare1stline([qw{openssl passwd password}], '^.{13}\R$'), +ok(compare1stline([qw{gmssl passwd password}], '^.{13}\R$'), 'crypt password with random salt') if !disabled("des"); -ok(compare1stline([qw{openssl passwd -1 password}], '^\$1\$.{8}\$.{22}\R$'), +ok(compare1stline([qw{gmssl passwd -1 password}], '^\$1\$.{8}\$.{22}\R$'), 'BSD style MD5 password with random salt'); -ok(compare1stline([qw{openssl passwd -apr1 password}], '^\$apr1\$.{8}\$.{22}\R$'), +ok(compare1stline([qw{gmssl passwd -apr1 password}], '^\$apr1\$.{8}\$.{22}\R$'), 'Apache style MD5 password with random salt'); -ok(compare1stline([qw{openssl passwd -salt xx password}], '^xxj31ZMTZzkVA\R$'), +ok(compare1stline([qw{gmssl passwd -salt xx password}], '^xxj31ZMTZzkVA\R$'), 'crypt password with salt xx') if !disabled("des"); -ok(compare1stline([qw{openssl passwd -salt xxxxxxxx -1 password}], '^\$1\$xxxxxxxx\$UYCIxa628\.9qXjpQCjM4a\.\R$'), +ok(compare1stline([qw{gmssl passwd -salt xxxxxxxx -1 password}], '^\$1\$xxxxxxxx\$UYCIxa628\.9qXjpQCjM4a\.\R$'), 'BSD style MD5 password with salt xxxxxxxx'); -ok(compare1stline([qw{openssl passwd -salt xxxxxxxx -apr1 password}], '^\$apr1\$xxxxxxxx\$dxHfLAsjHkDRmG83UXe8K0\R$'), +ok(compare1stline([qw{gmssl passwd -salt xxxxxxxx -apr1 password}], '^\$apr1\$xxxxxxxx\$dxHfLAsjHkDRmG83UXe8K0\R$'), 'Apache style MD5 password with salt xxxxxxxx'); diff --git a/test/recipes/25-test_req.t b/test/recipes/25-test_req.t index bcc10257..2b772929 100644 --- a/test/recipes/25-test_req.t +++ b/test/recipes/25-test_req.t @@ -34,11 +34,11 @@ subtest "generating certificate requests" => sub { plan tests => 2; - ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"), + ok(run(app(["gmssl", "req", "-config", srctop_file("test", "test.cnf"), @req_new, "-out", "testreq.pem"])), "Generating request"); - ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"), + ok(run(app(["gmssl", "req", "-config", srctop_file("test", "test.cnf"), "-verify", "-in", "testreq.pem", "-noout"])), "Verifying signature on request"); }; @@ -57,7 +57,7 @@ sub run_conversion { my $reqfile = shift; subtest $title => sub { - run(app(["openssl", @openssl_args, + run(app(["gmssl", @openssl_args, "-in", $reqfile, "-inform", "p", "-noout", "-text"], stderr => "req-check.err", stdout => undef)); diff --git a/test/recipes/25-test_verify.t b/test/recipes/25-test_verify.t index 23f8f32d..76c55daf 100644 --- a/test/recipes/25-test_verify.t +++ b/test/recipes/25-test_verify.t @@ -17,7 +17,7 @@ setup("test_verify"); sub verify { my ($cert, $purpose, $trusted, $untrusted, @opts) = @_; - my @args = qw(openssl verify -auth_level 1 -purpose); + my @args = qw(gmssl verify -auth_level 1 -purpose); my @path = qw(test certs); push(@args, "$purpose", @opts); for (@$trusted) { push(@args, "-trusted", srctop_file(@path, "$_.pem")) } diff --git a/test/recipes/tconversion.pl b/test/recipes/tconversion.pl index ee675e93..749fde64 100644 --- a/test/recipes/tconversion.pl +++ b/test/recipes/tconversion.pl @@ -41,7 +41,7 @@ sub tconversion { $totaltests-- if ($testtype eq "p7d"); # no comparison of original test file plan tests => $totaltests; - my @cmd = ("openssl", @openssl_args); + my @cmd = ("gmssl", @openssl_args); my $init; if (scalar @openssl_args > 0 && $openssl_args[0] eq "pkey") { diff --git a/test/sm3test.c b/test/sm3test.c new file mode 100644 index 00000000..81f1ee6d --- /dev/null +++ b/test/sm3test.c @@ -0,0 +1,239 @@ +/* ==================================================================== + * Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the GmSSL Project. + * (http://gmssl.org/)" + * + * 4. The name "GmSSL Project" must not be used to endorse or promote + * products derived from this software without prior written + * permission. For written permission, please contact + * guanzhi1980@gmail.com. + * + * 5. Products derived from this software may not be called "GmSSL" + * nor may "GmSSL" appear in their names without prior written + * permission of the GmSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the GmSSL Project + * (http://gmssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ + +#include +#include +#include + +#include "../e_os.h" + +#ifdef OPENSSL_NO_SM3 +int main(int argc, char **argv) +{ + printf("No SM3 support\n"); + return 0; +} +#else +# include +# include + +static char *testhex[] = { + /* 0 "abc" */ + "616263", + /* 1 "abcd" 16 times */ + "6162636461626364616263646162636461626364616263646162636461626364" + "6162636461626364616263646162636461626364616263646162636461626364", + /* 2 p.57 ZA */ + "0090" + "414C494345313233405941484F4F2E434F4D" + "787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498" + "63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A" + "421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D" + "0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2" + "0AE4C7798AA0F119471BEE11825BE46202BB79E2A5844495E97C04FF4DF2548A" + "7C0240F88F1CD4E16352A73C17B7F16F07353E53A176D684A9FE0C6BB798E857", + /* 3 p.59 ZA */ + "0090" + "414C494345313233405941484F4F2E434F4D" + "000000000000000000000000000000000000000000000000000000000000000000" + "00E78BCD09746C202378A7E72B12BCE00266B9627ECB0B5A25367AD1AD4CC6242B" + "00CDB9CA7F1E6B0441F658343F4B10297C0EF9B6491082400A62E7A7485735FADD" + "013DE74DA65951C4D76DC89220D5F7777A611B1C38BAE260B175951DC8060C2B3E" + "0165961645281A8626607B917F657D7E9382F1EA5CD931F40F6627F357542653B2" + "01686522130D590FB8DE635D8FCA715CC6BF3D05BEF3F75DA5D543454448166612", + /* 4 p.72 ZA */ + "0090" + "414C494345313233405941484F4F2E434F4D" + "787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498" + "63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A" + "421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D" + "0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2" + "3099093BF3C137D8FCBBCDF4A2AE50F3B0F216C3122D79425FE03A45DBFE1655" + "3DF79E8DAC1CF0ECBAA2F2B49D51A4B387F2EFAF482339086A27A8E05BAED98B", + /* 5 p.72 ZB */ + "0088" + "42494C4C343536405941484F4F2E434F4D" + "787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498" + "63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A" + "421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D" + "0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2" + "245493D446C38D8CC0F118374690E7DF633A8A4BFB3329B5ECE604B2B4F37F43" + "53C0869F4B9E17773DE68FEC45E14904E0DEA45BF6CECF9918C85EA047C60A4C", + /* 6 p.75 ZA */ + "0090" + "414C494345313233405941484F4F2E434F4D" + "000000000000000000000000000000000000000000000000000000000000000000" + "00E78BCD09746C202378A7E72B12BCE00266B9627ECB0B5A25367AD1AD4CC6242B" + "00CDB9CA7F1E6B0441F658343F4B10297C0EF9B6491082400A62E7A7485735FADD" + "013DE74DA65951C4D76DC89220D5F7777A611B1C38BAE260B175951DC8060C2B3E" + "008E3BDB2E11F9193388F1F901CCC857BF49CFC065FB38B9069CAAE6D5AFC3592F" + "004555122AAC0075F42E0A8BBD2C0665C789120DF19D77B4E3EE4712F598040415", + /* 7 p.76 ZB */ + "0088" + "42494C4C343536405941484F4F2E434F4D" + "000000000000000000000000000000000000000000000000000000000000000000" + "00E78BCD09746C202378A7E72B12BCE00266B9627ECB0B5A25367AD1AD4CC6242B" + "00CDB9CA7F1E6B0441F658343F4B10297C0EF9B6491082400A62E7A7485735FADD" + "013DE74DA65951C4D76DC89220D5F7777A611B1C38BAE260B175951DC8060C2B3E" + "0034297DD83AB14D5B393B6712F32B2F2E938D4690B095424B89DA880C52D4A7D9" + "0199BBF11AC95A0EA34BBD00CA50B93EC24ACB68335D20BA5DCFE3B33BDBD2B62D", + /* 8 TopsecCA cert ZA */ + "0080" + "31323334353637383132333435363738" + "FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC" + "28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93" + "32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7" + "BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0" + "D69C2F1EEC3BFB6B95B30C28085C77B125D77A9C39525D8190768F37D6B205B5" + "89DCD316BBE7D89A9DC21917F17799E698531F5E6E3E10BD31370B259C3F81C3", + /* 9 */ + "4D38D2958CA7FD2CFAE3AF04486959CF92C8EF48E8B83A05C112E739D5F181D0" + "3082020CA003020102020900" + "AF28725D98D33143300C06082A811CCF" + "550183750500307D310B300906035504" + "060C02636E310B300906035504080C02" + "626A310B300906035504070C02626A31" + "0F300D060355040A0C06746F70736563" + "310F300D060355040B0C06746F707365" + "633111300F06035504030C08546F7073" + "65634341311F301D06092A864886F70D" + "0109010C10626A40746F707365632E63" + "6F6D2E636E301E170D31323036323430" + "37353433395A170D3332303632303037" + "353433395A307D310B30090603550406" + "0C02636E310B300906035504080C0262" + "6A310B300906035504070C02626A310F" + "300D060355040A0C06746F7073656331" + "0F300D060355040B0C06746F70736563" + "3111300F06035504030C08546F707365" + "634341311F301D06092A864886F70D01" + "09010C10626A40746F707365632E636F" + "6D2E636E3059301306072A8648CE3D02" + "0106082A811CCF5501822D03420004D6" + "9C2F1EEC3BFB6B95B30C28085C77B125" + "D77A9C39525D8190768F37D6B205B589" + "DCD316BBE7D89A9DC21917F17799E698" + "531F5E6E3E10BD31370B259C3F81C3A3" + "733071300F0603551D130101FF040530" + "030101FF301D0603551D0E041604148E" + "5D90347858BAAAD870D8BDFBA6A85E7B" + "563B64301F0603551D23041830168014" + "8E5D90347858BAAAD870D8BDFBA6A85E" + "7B563B64300B0603551D0F0404030201" + "06301106096086480186F84201010404" + "03020057", +}; + +static char *dgsthex[] = { + "66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0", + "debe9ff92275b8a138604889c18e5a4d6fdb70e5387e5765293dcba39c0c5732", + "F4A38489E32B45B6F876E3AC2168CA392362DC8F23459C1D1146FC3DBFB7BC9A", + "26352AF82EC19F207BBC6F9474E11E90CE0F7DDACE03B27F801817E897A81FD5", + "E4D1D0C3CA4C7F11BC8FF8CB3F4C02A78F108FA098E51A668487240F75E20F31", + "6B4B6D0E276691BD4A11BF72F4FB501AE309FDACB72FA6CC336E6656119ABD67", + "ECF0080215977B2E5D6D61B98A99442F03E8803DC39E349F8DCA5621A9ACDF2B", + "557BAD30E183559AEEC3B2256E1C7C11F870D22B165D015ACF9465B09B87B527", + "4D38D2958CA7FD2CFAE3AF04486959CF92C8EF48E8B83A05C112E739D5F181D0", + "C3B02E500A8B60B77DEDCF6F4C11BEF8D56E5CDE708C72065654FD7B2167915A", +}; + +static char *pt(unsigned char *md) +{ + int i; + static char buf[80]; + + for (i = 0; i < SM3_DIGEST_LENGTH; i++) { + sprintf(&(buf[i * 2]), "%02x", md[i]); + } + return (buf); +} + +int main(int argc, char **argv) +{ + int err = 0; + char *p; + unsigned char *testbuf = NULL; + unsigned char *dgstbuf = NULL; + long testbuflen, dgstbuflen; + unsigned char dgst[EVP_MAX_MD_SIZE]; + unsigned int dgstlen; + int i; + + for (i = 0; i < OSSL_NELEM(testhex); i++) { + if (!(testbuf = OPENSSL_hexstr2buf(testhex[i], &testbuflen))) { + EXIT(1); + } + if (!(dgstbuf = OPENSSL_hexstr2buf(dgsthex[i], &dgstbuflen))) { + EXIT(1); + } + + dgstlen = sizeof(dgst); + if (!EVP_Digest(testbuf, testbuflen, dgst, &dgstlen, EVP_sm3(), NULL)) { + EXIT(1); + } + + p = pt(dgst); + if (memcmp(dgstbuf, dgst, dgstlen) != 0) { + printf("error calculating SM3 on %s\n", testhex[i]); + printf("got %s instead of %s\n", p, testhex[i]); + } else { + printf("test %d ok\n", i+1); + } + + OPENSSL_free(testbuf); + OPENSSL_free(dgstbuf); + testbuf = NULL; + dgstbuf = NULL; + } + + OPENSSL_free(testbuf); + OPENSSL_free(dgstbuf); + EXIT(err); +} +#endif diff --git a/util/libcrypto.num b/util/libcrypto.num index c1a09455..409f6305 100644 --- a/util/libcrypto.num +++ b/util/libcrypto.num @@ -4214,3 +4214,4 @@ X509_VERIFY_PARAM_set_inh_flags 4174 1_1_0d EXIST::FUNCTION: X509_VERIFY_PARAM_get_inh_flags 4175 1_1_0d EXIST::FUNCTION: X509_VERIFY_PARAM_get_time 4181 1_1_0d EXIST::FUNCTION: DH_check_params 4183 1_1_0d EXIST::FUNCTION:DH +EVP_sm3 4184 1_1_0d EXIST::FUNCTION: