b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | #ifndef WAPICRYPTO_H
|
| 2 | #define WAPICRYPTO_H 1
|
| 3 |
|
| 4 | #define ENCRYPT 0
|
| 5 | #define DECRYPT 1
|
| 6 |
|
| 7 | struct tx_insn;
|
| 8 |
|
| 9 | /**
|
| 10 | * \brief SHA-256 context structure
|
| 11 | */
|
| 12 | typedef 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 | }
|
| 22 | sha2_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 | */
|
| 30 | void 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 | */
|
| 39 | void 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 | */
|
| 47 | void 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 | */
|
| 57 | void 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 | */
|
| 71 | int 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 | */
|
| 81 | void 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 | */
|
| 91 | void 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 | */
|
| 99 | void 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 | */
|
| 111 | void 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 | */
|
| 120 | int sha2_self_test( int verbose );
|
| 121 |
|
| 122 | typedef 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 | */
|
| 133 | void sha256_hmac( unsigned char *key, int keylen,
|
| 134 | unsigned char *input, int ilen,
|
| 135 | unsigned char *output, int hlen);
|
| 136 |
|
| 137 | void KD_hmac_sha256( unsigned char *key, int keylen,
|
| 138 | unsigned char *input, int ilen,
|
| 139 | unsigned char *output, int hlen);
|
| 140 |
|
| 141 | void WapiSMS4ForMNKEncrypt(uint8 *key, uint8*IV, uint8*input, uint32 inputLength, uint8 *output, uint8 *outputLength, uint32 CryptFlag);
|
| 142 | void GenerateRandomData(unsigned char * data, unsigned int len);
|
| 143 | int32 init_SMS4_CK_Sbox(void);
|
| 144 |
|
| 145 | void SecSWSMS4Encryption(struct rtl8192cd_priv *priv, struct tx_insn* txcfg);
|
| 146 | int32 SecSWSMS4Decryption(struct rtl8192cd_priv *priv, struct stat_info *pstat, struct rx_frinfo* pfrinfo);
|
| 147 | #endif /* WAPICRYPTO_H */
|