Codebase list openssl / 67e247f
SM3: restructure to EVP internal and update doc to right location Reviewed-by: Paul Dale <paul.dale@oracle.com> Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/4616) Ronald Tse 6 years ago
14 changed file(s) with 187 addition(s) and 240 deletion(s). Raw diff Collapse all Expand all
511511 Build without support for the specified algorithm, where
512512 <alg> is one of: bf, blake2, camellia, cast, chacha, cmac,
513513 des, dh, dsa, ecdh, ecdsa, idea, md4, mdc2, ocb, poly1305,
514 rc2, rc4, rmd160, scrypt, seed, siphash, sm3, sm4 or
515 whirlpool. The "ripemd" algorithm is deprecated and if used
516 is synonymous with rmd160.
514 rc2, rc4, rmd160, scrypt, seed, siphash, sm3, sm4 or
515 whirlpool. The "ripemd" algorithm is deprecated and if used
516 is synonymous with rmd160.
517517
518518 -Dxxx, lxxx, -Lxxx, -Wl, -rpath, -R, -framework, -static
519519 These system specific options will be recognised and
44 e_rc4.c e_aes.c names.c e_seed.c e_aria.c e_sm4.c \
55 e_xcbc_d.c e_rc2.c e_cast.c e_rc5.c \
66 m_null.c m_md2.c m_md4.c m_md5.c m_sha1.c m_wp.c \
7 m_md5_sha1.c m_mdc2.c m_ripemd.c m_sha3.c m_sm3.c \
7 m_md5_sha1.c m_mdc2.c m_ripemd.c m_sha3.c \
88 p_open.c p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c p_dec.c \
99 bio_md.c bio_b64.c bio_enc.c evp_err.c e_null.c \
1010 c_allc.c c_alld.c evp_lib.c bio_ok.c \
+0
-55
crypto/evp/m_sm3.c less more
0 /*
1 * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
2 * Copyright 2017 Ribose Inc. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10 #include <stdio.h>
11 #include "internal/cryptlib.h"
12
13 #ifndef OPENSSL_NO_SM3
14
15 # include <openssl/evp.h>
16 # include <openssl/objects.h>
17 # include <openssl/sm3.h>
18 # include "internal/evp_int.h"
19
20 static int init(EVP_MD_CTX *ctx)
21 {
22 return SM3_Init(EVP_MD_CTX_md_data(ctx));
23 }
24
25 static int update(EVP_MD_CTX *ctx, const void *data, size_t count)
26 {
27 return SM3_Update(EVP_MD_CTX_md_data(ctx), data, count);
28 }
29
30 static int final(EVP_MD_CTX *ctx, unsigned char *md)
31 {
32 return SM3_Final(md, EVP_MD_CTX_md_data(ctx));
33 }
34
35 static const EVP_MD sm3_md = {
36 NID_sm3,
37 NID_sm3WithRSAEncryption,
38 SM3_DIGEST_LENGTH,
39 0,
40 init,
41 update,
42 final,
43 NULL,
44 NULL,
45 SM3_CBLOCK,
46 sizeof(EVP_MD *) + sizeof(SM3_CTX),
47 };
48
49 const EVP_MD *EVP_sm3(void)
50 {
51 return &sm3_md;
52 }
53 #endif
54
0 /*
1 * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
2 * Copyright 2017 Ribose Inc. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10 #ifndef HEADER_SM3_H
11 # define HEADER_SM3_H
12
13 # include <openssl/opensslconf.h>
14
15 # ifdef OPENSSL_NO_SM3
16 # error SM3 is disabled.
17 # endif
18
19 # define SM3_DIGEST_LENGTH 32
20 # define SM3_WORD unsigned int
21
22 # define SM3_CBLOCK 64
23 # define SM3_LBLOCK (SM3_CBLOCK/4)
24
25 typedef struct SM3state_st {
26 SM3_WORD A, B, C, D, E, F, G, H;
27 SM3_WORD Nl, Nh;
28 SM3_WORD data[SM3_LBLOCK];
29 unsigned int num;
30 } SM3_CTX;
31
32 int sm3_init(SM3_CTX *c);
33 int sm3_update(SM3_CTX *c, const void *data, size_t len);
34 int sm3_final(unsigned char *md, SM3_CTX *c);
35
36 void sm3_block_data_order(SM3_CTX *c, const void *p, size_t num);
37
38 #endif
00 LIBS=../../libcrypto
1 SOURCE[../../libcrypto]=sm3.c
1 SOURCE[../../libcrypto]=sm3.c m_sm3.c
0 /*
1 * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
2 * Copyright 2017 Ribose Inc. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10 #include "internal/cryptlib.h"
11
12 #ifndef OPENSSL_NO_SM3
13 # include <openssl/evp.h>
14 # include "internal/evp_int.h"
15 # include "internal/sm3.h"
16
17 static int init(EVP_MD_CTX *ctx)
18 {
19 return sm3_init(EVP_MD_CTX_md_data(ctx));
20 }
21
22 static int update(EVP_MD_CTX *ctx, const void *data, size_t count)
23 {
24 return sm3_update(EVP_MD_CTX_md_data(ctx), data, count);
25 }
26
27 static int final(EVP_MD_CTX *ctx, unsigned char *md)
28 {
29 return sm3_final(md, EVP_MD_CTX_md_data(ctx));
30 }
31
32 static const EVP_MD sm3_md = {
33 NID_sm3,
34 NID_sm3WithRSAEncryption,
35 SM3_DIGEST_LENGTH,
36 0,
37 init,
38 update,
39 final,
40 NULL,
41 NULL,
42 SM3_CBLOCK,
43 sizeof(EVP_MD *) + sizeof(SM3_CTX),
44 };
45
46 const EVP_MD *EVP_sm3(void)
47 {
48 return &sm3_md;
49 }
50
51 #endif
88 * https://www.openssl.org/source/license.html
99 */
1010
11 #include <stdio.h>
11 #include <openssl/e_os2.h>
12 #include "sm3_locl.h"
1213
13 #ifndef OPENSSL_NO_SM3
14
15 #include "sm3_locl.h"
16 #include <openssl/opensslv.h>
17
18 int SM3_Init(SM3_CTX *c)
14 int sm3_init(SM3_CTX *c)
1915 {
2016 memset(c, 0, sizeof(*c));
2117 c->A = SM3_A;
2723 c->G = SM3_G;
2824 c->H = SM3_H;
2925 return 1;
30 }
31
32 unsigned char *SM3(const unsigned char *d, size_t n, unsigned char *md)
33 {
34 SM3_CTX c;
35 static unsigned char m[SM3_DIGEST_LENGTH];
36
37 if (md == NULL)
38 md = m;
39 if (!SM3_Init(&c))
40 return NULL;
41 SM3_Update(&c, d, n);
42 SM3_Final(md, &c);
43 OPENSSL_cleanse(&c, sizeof(c)); /* security consideration */
44 return md;
4526 }
4627
4728 void sm3_block_data_order(SM3_CTX *ctx, const void *p, size_t num)
211192 ctx->H ^= H;
212193 }
213194 }
214 #endif
195
88 * https://www.openssl.org/source/license.html
99 */
1010
11 #include <stdlib.h>
1211 #include <string.h>
13 #include <openssl/e_os2.h>
14 #include <openssl/sm3.h>
15
16 void sm3_block_data_order(SM3_CTX *c, const void *p, size_t num);
12 #include "internal/sm3.h"
1713
1814 #define DATA_ORDER_IS_BIG_ENDIAN
1915
2016 #define HASH_LONG SM3_WORD
2117 #define HASH_CTX SM3_CTX
2218 #define HASH_CBLOCK SM3_CBLOCK
23 #define HASH_UPDATE SM3_Update
24 #define HASH_TRANSFORM SM3_Transform
25 #define HASH_FINAL SM3_Final
26 #define HASH_MAKE_STRING(c,s) do { \
27 unsigned long ll; \
28 ll=(c)->A; (void)HOST_l2c(ll,(s)); \
29 ll=(c)->B; (void)HOST_l2c(ll,(s)); \
30 ll=(c)->C; (void)HOST_l2c(ll,(s)); \
31 ll=(c)->D; (void)HOST_l2c(ll,(s)); \
32 ll=(c)->E; (void)HOST_l2c(ll,(s)); \
33 ll=(c)->F; (void)HOST_l2c(ll,(s)); \
34 ll=(c)->G; (void)HOST_l2c(ll,(s)); \
35 ll=(c)->H; (void)HOST_l2c(ll,(s)); \
36 } while (0)
19 #define HASH_UPDATE sm3_update
20 #define HASH_TRANSFORM sm3_transform
21 #define HASH_FINAL sm3_final
22 #define HASH_MAKE_STRING(c, s) \
23 do { \
24 unsigned long ll; \
25 ll=(c)->A; (void)HOST_l2c(ll, (s)); \
26 ll=(c)->B; (void)HOST_l2c(ll, (s)); \
27 ll=(c)->C; (void)HOST_l2c(ll, (s)); \
28 ll=(c)->D; (void)HOST_l2c(ll, (s)); \
29 ll=(c)->E; (void)HOST_l2c(ll, (s)); \
30 ll=(c)->F; (void)HOST_l2c(ll, (s)); \
31 ll=(c)->G; (void)HOST_l2c(ll, (s)); \
32 ll=(c)->H; (void)HOST_l2c(ll, (s)); \
33 } while (0)
3734 #define HASH_BLOCK_DATA_ORDER sm3_block_data_order
35
36 void sm3_transform(SM3_CTX *c, const unsigned char *data);
3837
3938 #include "internal/md32_common.h"
4039
5049 #define EXPAND(W0,W7,W13,W3,W10) \
5150 (P1(W0 ^ W7 ^ ROTATE(W13, 15)) ^ ROTATE(W3, 7) ^ W10)
5251
53 #define RND(A,B,C,D,E,F,G,H,TJ,Wi,Wj,FF,GG) do { \
54 const SM3_WORD A12 = ROTATE(A, 12); \
55 const SM3_WORD A12_SM = A12 + E + TJ; \
56 const SM3_WORD SS1 = ROTATE(A12_SM, 7); \
57 const SM3_WORD TT1 = FF(A,B,C) + D + (SS1 ^ A12) + (Wj); \
58 const SM3_WORD TT2 = GG(E,F,G) + H + SS1 + Wi; \
59 B = ROTATE(B, 9); \
60 D = TT1; \
61 F = ROTATE(F, 19); \
62 H = P0(TT2); \
63 } while(0);
52 #define RND(A, B, C, D, E, F, G, H, TJ, Wi, Wj, FF, GG) \
53 do { \
54 const SM3_WORD A12 = ROTATE(A, 12); \
55 const SM3_WORD A12_SM = A12 + E + TJ; \
56 const SM3_WORD SS1 = ROTATE(A12_SM, 7); \
57 const SM3_WORD TT1 = FF(A, B, C) + D + (SS1 ^ A12) + (Wj); \
58 const SM3_WORD TT2 = GG(E, F, G) + H + SS1 + Wi; \
59 B = ROTATE(B, 9); \
60 D = TT1; \
61 F = ROTATE(F, 19); \
62 H = P0(TT2); \
63 } while(0)
6464
6565 #define R1(A,B,C,D,E,F,G,H,TJ,Wi,Wj) \
6666 RND(A,B,C,D,E,F,G,H,TJ,Wi,Wj,FF0,GG0)
300300 L<EVP_sha1(3)>,
301301 L<EVP_sha224(3)>,
302302 L<EVP_sha3_224(3)>,
303 L<EVP_sm3(3)>,
303304 L<EVP_whirlpool(3)>
304305
305306 =head1 HISTORY
0 =pod
1
2 =head1 NAME
3
4 EVP_sm3
5 - SM3 for EVP
6
7 =head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 const EVP_MD *EVP_sm3(void)
12
13 =head1 DESCRIPTION
14
15 SM3 is a cryptographic hash function with a 256-bit output, defined in GB/T
16 32905-2016.
17
18 =over 4
19
20 =item EVP_sm3()
21
22 The SM3 hash function.
23
24 =back
25
26
27 =head1 RETURN VALUES
28
29 These functions return a B<EVP_MD> structure that contains the
30 implementation of the symmetric cipher. See L<EVP_MD_meth_new(3)> for
31 details of the B<EVP_MD> structure.
32
33 =head1 CONFORMING TO
34
35 GB/T 32905-2016 and GM/T 0004-2012.
36
37 =head1 SEE ALSO
38
39 L<evp(7)>,
40 L<EVP_DigestInit(3)>
41
42 =head1 COPYRIGHT
43
44 Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
45 Copyright 2017 Ribose Inc. All Rights Reserved.
46
47 Licensed under the OpenSSL license (the "License"). You may not use
48 this file except in compliance with the License. You can obtain a copy
49 in the file LICENSE in the source distribution or at
50 L<https://www.openssl.org/source/license.html>.
51
52 =cut
53
+0
-76
doc/man3/SM3.pod less more
0 =pod
1
2 =head1 NAME
3
4 SM3_Init,
5 SM3_Update,
6 SM3_Final
7
8 =head1 SYNOPSIS
9
10 #include <openssl/sm3.h>
11
12 unsigned char *SM3(const unsigned char *d, size_t n, unsigned char *md);
13
14 int SM3_Init(SM3_CTX *c);
15 int SM3_Update(SM3_CTX *c, const void *data, size_t len);
16 int SM3_Final(unsigned char *md, SM3_CTX *c);
17
18 =head1 DESCRIPTION
19
20 SM3 is a cryptographic hash function with a 256-bit output, defined in GB/T
21 32905-2016.
22
23 SM3() computes the SM3 message digest of the B<n> bytes at B<d> and places it
24 in B<md> (which must have space for SM3_DIGEST_LENGTH == 32 bytes of output).
25 If B<md> is NULL, the digest is placed in a static array.
26
27 The following functions may be used if the message is not completely stored in
28 memory:
29
30 SM3_Init() initializes a B<SM3_CTX> structure.
31
32 SM3_Update() can be called repeatedly with chunks of the message to be hashed
33 (B<len> bytes at B<data>).
34
35 SM3_Final() places the message digest in B<md>, which must have space for
36 B<SM3_DIGEST_LENGTH> == 32 bytes of output, and erases the B<SM3_CTX>.
37
38 =head1 RETURN VALUES
39
40 =over 4
41
42 =item SM3()
43
44 Returns pointers to the hash value.
45
46 =item SM3_Init(), SM3_Update(), SM3_Final()
47
48 Returns 1 for success, 0 otherwise.
49
50 =back
51
52 =head1 NOTE
53
54 Applications should use the higher level functions such as L<EVP_DigestInit(3)>
55 instead of calling these functions directly.
56
57 =head1 CONFORMING TO
58
59 GB/T 32905-2016 and GM/T 0004-2012.
60
61 =head1 SEE ALSO
62
63 L<EVP_DigestInit(3)>
64
65 =head1 COPYRIGHT
66
67 Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
68 Copyright 2017 Ribose Inc. All Rights Reserved.
69
70 Licensed under the OpenSSL license (the "License"). You may not use
71 this file except in compliance with the License. You can obtain a copy
72 in the file LICENSE in the source distribution or at
73 L<https://www.openssl.org/source/license.html>.
74
75 =cut
10141014 OBJ_ISO_CN="\x2A\x81\x1C"
10151015 OBJ_oscca="\x2A\x81\x1C\xCF\x55"
10161016 OBJ_sm_scheme="\x2A\x81\x1C\xCF\x55\x01"
1017 OBJ_sm3="\x2A\x81\x1C\xCF\x55\x01\x83\x11"
1018 OBJ_sm3WithRSAEncryption="\x2A\x81\x1C\xCF\x55\x01\x83\x78"
+0
-47
include/openssl/sm3.h less more
0 /*
1 * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
2 * Copyright 2017 [Ribose Inc.](https://www.ribose.com). All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10 #ifndef HEADER_SM3_H
11 # define HEADER_SM3_H
12
13 # include <openssl/opensslconf.h>
14
15 # ifdef OPENSSL_NO_SM3
16 # error SM3 is disabled.
17 # endif
18
19 # ifdef __cplusplus
20 extern "C" {
21 # endif
22
23 #define SM3_DIGEST_LENGTH 32
24 #define SM3_WORD unsigned int
25
26 # define SM3_CBLOCK 64
27 # define SM3_LBLOCK (SM3_CBLOCK/4)
28
29 typedef struct SM3state_st {
30 SM3_WORD A, B, C, D, E, F, G, H;
31 SM3_WORD Nl, Nh;
32 SM3_WORD data[SM3_LBLOCK];
33 unsigned int num;
34 } SM3_CTX;
35
36 int SM3_Init(SM3_CTX *c);
37 int SM3_Update(SM3_CTX *c, const void *data, size_t len);
38 int SM3_Final(unsigned char *md, SM3_CTX *c);
39 void SM3_Transform(SM3_CTX *c, const unsigned char *data);
40 unsigned char *SM3(const unsigned char *d, size_t n, unsigned char *md);
41
42 # ifdef __cplusplus
43 }
44 # endif
45
46 #endif
44254425 EVP_sm4_ecb 4371 1_1_1 EXIST::FUNCTION:SM4
44264426 EVP_sm4_cfb128 4372 1_1_1 EXIST::FUNCTION:SM4
44274427 EVP_sm3 4373 1_1_1 EXIST::FUNCTION:SM3
4428 SM3_Update 4374 1_1_1 EXIST::FUNCTION:SM3
4429 SM3 4375 1_1_1 EXIST::FUNCTION:SM3
4430 SM3_Init 4376 1_1_1 EXIST::FUNCTION:SM3
4431 SM3_Final 4377 1_1_1 EXIST::FUNCTION:SM3