diff options
author | Jack Lloyd <jack.lloyd@ribose.com> | 2017-10-25 13:19:02 -0400 |
---|---|---|
committer | Ronald Tse <ronald.tse@ribose.com> | 2017-11-06 07:21:11 +0800 |
commit | a0c3e4fa9089f571ff4b406cb914d0a504847b10 (patch) | |
tree | 46bc0fccfcc317d2572145d3a13acf029523973d /include | |
parent | cf72c7579201086cee303eadcb60bd28eff78dd9 (diff) |
SM3: Add SM3 hash function
SM3 is a secure hash function which is part of the Chinese
"Commercial Cryptography" suite of algorithms which use is
required for certain commercial applications in China.
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4616)
Diffstat (limited to 'include')
-rw-r--r-- | include/openssl/evp.h | 3 | ||||
-rw-r--r-- | include/openssl/obj_mac.h | 10 | ||||
-rw-r--r-- | include/openssl/sm3.h | 47 |
3 files changed, 60 insertions, 0 deletions
diff --git a/include/openssl/evp.h b/include/openssl/evp.h index 3a98e1da9e..e002d63d24 100644 --- a/include/openssl/evp.h +++ b/include/openssl/evp.h @@ -717,6 +717,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 02447dcd50..8a9e25284c 100644 --- a/include/openssl/obj_mac.h +++ b/include/openssl/obj_mac.h @@ -1132,6 +1132,16 @@ #define NID_hmacWithSHA1 163 #define OBJ_hmacWithSHA1 OBJ_rsadsi,2L,7L +#define SN_sm3 "SM3" +#define LN_sm3 "sm3" +#define NID_sm3 1143 +#define OBJ_sm3 OBJ_member_body,156L,10197L,1L,401L + +#define SN_sm3WithRSAEncryption "RSA-SM3" +#define LN_sm3WithRSAEncryption "sm3WithRSAEncryption" +#define NID_sm3WithRSAEncryption 1144 +#define OBJ_sm3WithRSAEncryption OBJ_member_body,156L,10197L,1L,504L + #define LN_hmacWithSHA224 "hmacWithSHA224" #define NID_hmacWithSHA224 798 #define OBJ_hmacWithSHA224 OBJ_rsadsi,2L,8L diff --git a/include/openssl/sm3.h b/include/openssl/sm3.h new file mode 100644 index 0000000000..84f8570235 --- /dev/null +++ b/include/openssl/sm3.h @@ -0,0 +1,47 @@ +/* + * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2017 [Ribose Inc.](https://www.ribose.com). 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 + */ + +#ifndef HEADER_SM3_H +# define HEADER_SM3_H + +# include <openssl/opensslconf.h> + +# ifdef OPENSSL_NO_SM3 +# error SM3 is disabled. +# endif + +# ifdef __cplusplus +extern "C" { +# endif + +#define SM3_DIGEST_LENGTH 32 +#define SM3_WORD unsigned int + +# define SM3_CBLOCK 64 +# define SM3_LBLOCK (SM3_CBLOCK/4) + +typedef struct SM3state_st { + SM3_WORD A, B, C, D, E, F, G, H; + SM3_WORD Nl, Nh; + SM3_WORD data[SM3_LBLOCK]; + unsigned int num; +} SM3_CTX; + +int SM3_Init(SM3_CTX *c); +int SM3_Update(SM3_CTX *c, const void *data, size_t len); +int SM3_Final(unsigned char *md, SM3_CTX *c); +void SM3_Transform(SM3_CTX *c, const unsigned char *data); +unsigned char *SM3(const unsigned char *d, size_t n, unsigned char *md); + +# ifdef __cplusplus +} +# endif + +#endif |