-
Notifications
You must be signed in to change notification settings - Fork 0
/
sm3.h
119 lines (101 loc) · 2.92 KB
/
sm3.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*************************************************************************
> File Name: sm3.h
> Author:NEWPLAN
> E-mail:[email protected]
> Created Time: Thu Apr 13 23:55:50 2017
************************************************************************/
#ifndef XYSSL_SM3_H
#define XYSSL_SM3_H
/**
* \brief SM3 context structure
*/
typedef struct
{
unsigned int total[2]; /*!< number of bytes processed */
unsigned int state[8]; /*!< intermediate digest state */
unsigned char buffer[64]; /*!< data block being processed */
unsigned char ipad[64]; /*!< HMAC: inner padding */
unsigned char opad[64]; /*!< HMAC: outer padding */
}
sm3_context;
#ifdef __cplusplus
extern "C" {
#endif
/**
* \brief SM3 context setup
*
* \param ctx context to be initialized
*/
void sm3_starts( sm3_context *ctx );
/**
* \brief SM3 process buffer
*
* \param ctx SM3 context
* \param input buffer holding the data
* \param ilen length of the input data
*/
void sm3_update( sm3_context *ctx, unsigned char *input, int ilen );
/**
* \brief SM3 final digest
*
* \param ctx SM3 context
*/
void sm3_finish( sm3_context *ctx, unsigned char output[32] );
/**
* \brief Output = SM3( input buffer )
*
* \param input buffer holding the data
* \param ilen length of the input data
* \param output SM3 checksum result
*/
void sm3( unsigned char *input, int ilen,
unsigned char output[32]);
/**
* \brief Output = SM3( file contents )
*
* \param path input file name
* \param output SM3 checksum result
*
* \return 0 if successful, 1 if fopen failed,
* or 2 if fread failed
*/
int sm3_file( char *path, unsigned char output[32] );
/**
* \brief SM3 HMAC context setup
*
* \param ctx HMAC context to be initialized
* \param key HMAC secret key
* \param keylen length of the HMAC key
*/
void sm3_hmac_starts( sm3_context *ctx, unsigned char *key, int keylen);
/**
* \brief SM3 HMAC process buffer
*
* \param ctx HMAC context
* \param input buffer holding the data
* \param ilen length of the input data
*/
void sm3_hmac_update( sm3_context *ctx, unsigned char *input, int ilen );
/**
* \brief SM3 HMAC final digest
*
* \param ctx HMAC context
* \param output SM3 HMAC checksum result
*/
void sm3_hmac_finish( sm3_context *ctx, unsigned char output[32] );
/**
* \brief Output = HMAC-SM3( hmac key, input buffer )
*
* \param key HMAC secret key
* \param keylen length of the HMAC key
* \param input buffer holding the data
* \param ilen length of the input data
* \param output HMAC-SM3 result
*/
void sm3_hmac( unsigned char *key, int keylen,
unsigned char *input, int ilen,
unsigned char output[32] );
#ifdef __cplusplus
}
#endif
#endif /* sm3.h */