blob: 45abebd51604ce9929214a06743760e33b0137d6 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#ifndef WAPICRYPTO_H
2#define WAPICRYPTO_H 1
3
4#define ENCRYPT 0
5#define DECRYPT 1
6
7struct tx_insn;
8
9/**
10 * \brief SHA-256 context structure
11 */
12typedef struct
13{
14 unsigned long total[2]; /*!< number of bytes processed */
15 unsigned long state[8]; /*!< intermediate digest state */
16 unsigned char buffer[64]; /*!< data block being processed */
17
18 unsigned char ipad[64]; /*!< HMAC: inner padding */
19 unsigned char opad[64]; /*!< HMAC: outer padding */
20 int is224; /*!< 0 => SHA-256, else SHA-224 */
21}
22sha2_context;
23
24/**
25 * \brief SHA-256 context setup
26 *
27 * \param ctx context to be initialized
28 * \param is224 0 = use SHA256, 1 = use SHA224
29 */
30void sha2_starts( sha2_context *ctx, int is224 );
31
32/**
33 * \brief SHA-256 process buffer
34 *
35 * \param ctx SHA-256 context
36 * \param input buffer holding the data
37 * \param ilen length of the input data
38 */
39void sha2_update( sha2_context *ctx, unsigned char *input, int ilen );
40
41/**
42 * \brief SHA-256 final digest
43 *
44 * \param ctx SHA-256 context
45 * \param output SHA-224/256 checksum result
46 */
47void sha2_finish( sha2_context *ctx, unsigned char output[32] );
48
49/**
50 * \brief Output = SHA-256( input buffer )
51 *
52 * \param input buffer holding the data
53 * \param ilen length of the input data
54 * \param output SHA-224/256 checksum result
55 * \param is224 0 = use SHA256, 1 = use SHA224
56 */
57void sha2( unsigned char *input, int ilen,
58 unsigned char output[32], int is224 );
59
60#if 0
61/**
62 * \brief Output = SHA-256( file contents )
63 *
64 * \param path input file name
65 * \param output SHA-224/256 checksum result
66 * \param is224 0 = use SHA256, 1 = use SHA224
67 *
68 * \return 0 if successful, 1 if fopen failed,
69 * or 2 if fread failed
70 */
71int sha2_file( char *path, unsigned char output[32], int is224 );
72#endif
73/**
74 * \brief SHA-256 HMAC context setup
75 *
76 * \param ctx HMAC context to be initialized
77 * \param key HMAC secret key
78 * \param keylen length of the HMAC key
79 * \param is224 0 = use SHA256, 1 = use SHA224
80 */
81void sha2_hmac_starts( sha2_context *ctx, unsigned char *key, int keylen,
82 int is224 );
83
84/**
85 * \brief SHA-256 HMAC process buffer
86 *
87 * \param ctx HMAC context
88 * \param input buffer holding the data
89 * \param ilen length of the input data
90 */
91void sha2_hmac_update( sha2_context *ctx, unsigned char *input, int ilen );
92
93/**
94 * \brief SHA-256 HMAC final digest
95 *
96 * \param ctx HMAC context
97 * \param output SHA-224/256 HMAC checksum result
98 */
99void sha2_hmac_finish( sha2_context *ctx, unsigned char output[32] );
100
101/**
102 * \brief Output = HMAC-SHA-256( hmac key, input buffer )
103 *
104 * \param key HMAC secret key
105 * \param keylen length of the HMAC key
106 * \param input buffer holding the data
107 * \param ilen length of the input data
108 * \param output HMAC-SHA-224/256 result
109 * \param is224 0 = use SHA256, 1 = use SHA224
110 */
111void sha2_hmac( unsigned char *key, int keylen,
112 unsigned char *input, int ilen,
113 unsigned char output[32], int is224 );
114
115/**
116 * \brief Checkup routine
117 *
118 * \return 0 if successful, or 1 if the test failed
119 */
120int sha2_self_test( int verbose );
121
122typedef struct _WPISMS4HEADER {
123 uint8 keyIdx;
124 uint8 reserved;
125 uint8 pn[WAPI_PN_LEN];
126 uint8 data[0];
127} __WLAN_ATTRIB_PACK__ wpiSMS4Hdr;
128
129//extern unsigned short rtl_SMS4_rxSeq[RX_QUEUE_NUM];
130/*
131* output = HMAC-SHA-256 ( hmac key, input buffer )
132*/
133void sha256_hmac( unsigned char *key, int keylen,
134 unsigned char *input, int ilen,
135 unsigned char *output, int hlen);
136
137void KD_hmac_sha256( unsigned char *key, int keylen,
138 unsigned char *input, int ilen,
139 unsigned char *output, int hlen);
140
141void WapiSMS4ForMNKEncrypt(uint8 *key, uint8*IV, uint8*input, uint32 inputLength, uint8 *output, uint8 *outputLength, uint32 CryptFlag);
142void GenerateRandomData(unsigned char * data, unsigned int len);
143int32 init_SMS4_CK_Sbox(void);
144
145void SecSWSMS4Encryption(struct rtl8192cd_priv *priv, struct tx_insn* txcfg);
146int32 SecSWSMS4Decryption(struct rtl8192cd_priv *priv, struct stat_info *pstat, struct rx_frinfo* pfrinfo);
147#endif /* WAPICRYPTO_H */