APIs and data types for cryptographic algorithms.
Copyright (c) 2016-2018 Microchip Technology Inc. and its subsidiaries.
#include "driver/include/m2m_types.h"
Data Structures | |
struct | tstrBuffer |
struct | tstrHashContext |
struct | tstrRSAPublicKey |
Macros | |
#define | AES_BLOCK_SIZE (16) |
#define | BI_FAIL (-1) |
#define | BI_SUCCESS (0) |
#define | BITS_PER_DIGIT ((uint32)32) |
#define | GETU16(BUF, OFFSET) ((((uint16)((BUF)[OFFSET]) << 8)) |(((uint16)(BUF)[OFFSET + 1]))) |
#define | GETU32(BUF, OFFSET) |
#define | M2M_MEMCPY m2m_memcpy |
#define | M2M_MEMSET m2m_memset |
#define | MD4_DIGEST_SIZE (16) |
#define | MD5_DIGEST_SIZE (16) |
#define | MD5_FINISH(ctxt, digest) MD5_Hash((ctxt), SHA_FLAGS_FINISH, NULL, 0, digest) |
#define | MD5_INIT(ctxt) MD5_Hash((ctxt), SHA_FLAGS_INIT, NULL, 0, NULL) |
#define | MD5_UPDATE(ctxt, data, dataLen) MD5_Hash((ctxt), SHA_FLAGS_UPDATE, (data), (dataLen), NULL) |
#define | PUTU16(VAL16, BUF, OFFSET) |
#define | PUTU32(VAL32, BUF, OFFSET) |
#define | SHA1_DIGEST_SIZE (20) |
#define | SHA1_FINISH(ctxt, digest) SHA1_Hash((ctxt), SHA_FLAGS_FINISH, NULL, 0, digest) |
#define | SHA1_INIT(ctxt) SHA1_Hash((ctxt), SHA_FLAGS_INIT, NULL, 0, NULL) |
#define | SHA1_UPDATE(ctxt, data, dataLen) SHA1_Hash((ctxt), SHA_FLAGS_UPDATE, (data), (dataLen), NULL) |
#define | SHA256_DIGEST_SIZE (32) |
#define | SHA_BLOCK_SIZE (64) |
#define | SHA_FLAGS_FINISH 0x04 |
#define | SHA_FLAGS_FULL_HASH (SHA_FLAGS_INIT | SHA_FLAGS_UPDATE | SHA_FLAGS_FINISH) |
#define | SHA_FLAGS_INIT 0x01 |
#define | SHA_FLAGS_UPDATE 0x02 |
#define | SHA_MAX_DIGEST_SIZE SHA256_DIGEST_SIZE |
#define | SHA_ROTL(x, n) (SHA_SHL(x,n) | SHA_SHR(x , (32 - n))) |
#define | SHA_ROTR(x, n) (SHA_SHR(x,n) | SHA_SHL(x , (32 - n))) |
#define | SHA_SHL(x, n) ((x & 0xFFFFFFFF) << n) |
#define | SHA_SHR(x, n) ((x & 0xFFFFFFFF) >> n) |
Typedefs | |
typedef void(* | tpfHash )(tstrHashContext *pstrHashContext, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest) |
typedef void(* | tpfHashProcessBlock )(uint32 *pu32HashState, const uint8 *pu8MessageBlock) |
typedef tstrHashContext | tstrMd5Context |
typedef tstrHashContext | tstrSha1Context |
typedef tstrHashContext | tstrSha256Context |
Functions | |
void | AES_CbcDec (uint8 *pu8IV, uint8 *pu8Data, uint16 u16DataSize, uint8 *pu8Key, uint8 u8KeySize) |
Decrypts a stream of data (in place) using AES algorithm in the Cipher Block Chain (CBC) mode. More... | |
void | AES_CbcEnc (uint8 *pu8IV, uint8 *pu8Data, uint16 u16DataSize, uint8 *pu8Key, uint8 u8KeySize) |
Encrypts a stream of data (in place) using AES algorithm in the Cipher Block Chain (CBC) mode. More... | |
sint32 | BI_ModExp (uint8 *pu8X, uint32 u32XSize, uint8 *pu8E, uint32 u32ESize, uint8 *pu8N, uint32 u32NSize, uint8 *pu8Y, uint32 u32YSize) |
Computes the modular exponentiation of big integers for the expression: Result = (Base ^ Power) % Mod. More... | |
void | DES_EncryptBlock (uint8 *pu8PlainTxt, uint8 *pu8CipherKey, uint8 *pu8CipherTxt) |
void | DRV_hmac_sha1 (uint8 *pu8Key, uint32 u32KeyLength, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest) |
void | DRV_HMAC_Vector (tpfHash fpHash, uint8 *pu8Key, uint32 u32KeyLength, tstrBuffer *pstrInData, uint8 u8NumInputs, uint8 *pu8Out) |
Perform the HMAC operation on a given vector of data streams using the hash function passed to the DRV_HMAC_Vector. More... | |
void | DRV_SHA1_Hash (tstrHashContext *pstrSha1Context, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest) |
void | hmac_md5 (uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Key, uint32 u32KeyLength, uint8 *pu8Digest) |
void | HMAC_SHA256 (uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Key, uint32 u32KeyLength, uint8 *pu8Out) |
void | MD4_Hash (uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest) |
void | MD5_Hash (tstrHashContext *pstrMD5Context, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest) |
uint8 | pbkdf2_sha1 (uint8 *key, uint8 key_len, uint8 *data, uint8 data_len, uint8 *digest) |
This function runs the PBKDF2 on the data with a given key. More... | |
uint16 | RSA_Encrypt (tstrRSAPublicKey *pstrKey, uint8 *pu8Plain, uint16 u16PlainSize, uint8 *pu8Cipher) |
sint8 | RSA_SignVerify (tstrRSAPublicKey *pstrKey, uint8 *pu8Signature, uint16 u16SignLen, uint8 *pu8Hash, uint16 u16HashLength) |
void | SHA256_Hash (tstrHashContext *pstrSha256Context, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest) |
#define AES_BLOCK_SIZE (16) |
#define BI_FAIL (-1) |
#define BI_SUCCESS (0) |
#define BITS_PER_DIGIT ((uint32)32) |
Retrieve 2 bytes from the given buffer at the given offset as 16-bit unsigned integer in the Network byte order.
#define GETU32 | ( | BUF, | |
OFFSET | |||
) |
Retrieve 4 bytes from the given buffer at the given offset as 32-bit unsigned integer in the Network byte order.
Referenced by SHA1ProcessBlock().
#define M2M_MEMCPY m2m_memcpy |
Referenced by Sha_HashFinish(), and Sha_HashUpdate().
#define M2M_MEMSET m2m_memset |
Referenced by DRV_HMAC_Vector(), DRV_SHA1_Hash(), and Sha_HashFinish().
#define MD4_DIGEST_SIZE (16) |
#define MD5_DIGEST_SIZE (16) |
#define MD5_FINISH | ( | ctxt, | |
digest | |||
) | MD5_Hash((ctxt), SHA_FLAGS_FINISH, NULL, 0, digest) |
#define MD5_INIT | ( | ctxt | ) | MD5_Hash((ctxt), SHA_FLAGS_INIT, NULL, 0, NULL) |
#define MD5_UPDATE | ( | ctxt, | |
data, | |||
dataLen | |||
) | MD5_Hash((ctxt), SHA_FLAGS_UPDATE, (data), (dataLen), NULL) |
#define PUTU16 | ( | VAL16, | |
BUF, | |||
OFFSET | |||
) |
#define PUTU32 | ( | VAL32, | |
BUF, | |||
OFFSET | |||
) |
Referenced by DRV_SHA1_Hash().
#define SHA1_DIGEST_SIZE (20) |
Referenced by DRV_SHA1_Hash().
#define SHA1_FINISH | ( | ctxt, | |
digest | |||
) | SHA1_Hash((ctxt), SHA_FLAGS_FINISH, NULL, 0, digest) |
#define SHA1_INIT | ( | ctxt | ) | SHA1_Hash((ctxt), SHA_FLAGS_INIT, NULL, 0, NULL) |
#define SHA1_UPDATE | ( | ctxt, | |
data, | |||
dataLen | |||
) | SHA1_Hash((ctxt), SHA_FLAGS_UPDATE, (data), (dataLen), NULL) |
#define SHA256_DIGEST_SIZE (32) |
#define SHA_BLOCK_SIZE (64) |
Referenced by DRV_HMAC_Vector(), and DRV_SHA1_Hash().
#define SHA_FLAGS_FINISH 0x04 |
Finalize the hashing and calculate the final result.
Referenced by DRV_HMAC_Vector(), and DRV_SHA1_Hash().
#define SHA_FLAGS_FULL_HASH (SHA_FLAGS_INIT | SHA_FLAGS_UPDATE | SHA_FLAGS_FINISH) |
Perform Full hash operation with the DIGEST returned to the caller.
Referenced by DRV_HMAC_Vector().
#define SHA_FLAGS_INIT 0x01 |
A flag to tell the hash function to start hash from the initial state.
Referenced by DRV_HMAC_Vector(), and DRV_SHA1_Hash().
#define SHA_FLAGS_UPDATE 0x02 |
Update the current hash with the given data.
Referenced by DRV_HMAC_Vector(), and DRV_SHA1_Hash().
#define SHA_MAX_DIGEST_SIZE SHA256_DIGEST_SIZE |
Referenced by DRV_HMAC_Vector().
Referenced by SHA1ProcessBlock().
#define SHA_SHL | ( | x, | |
n | |||
) | ((x & 0xFFFFFFFF) << n) |
#define SHA_SHR | ( | x, | |
n | |||
) | ((x & 0xFFFFFFFF) >> n) |
typedef void(* tpfHash)(tstrHashContext *pstrHashContext, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest) |
typedef tstrHashContext tstrMd5Context |
typedef tstrHashContext tstrSha1Context |
typedef tstrHashContext tstrSha256Context |
void AES_CbcDec | ( | uint8 * | pu8IV, |
uint8 * | pu8Data, | ||
uint16 | u16DataSize, | ||
uint8 * | pu8Key, | ||
uint8 | u8KeySize | ||
) |
Decrypts a stream of data (in place) using AES algorithm in the Cipher Block Chain (CBC) mode.
[in] | pu8IV | Initialization vector. |
[in/out] | pu8Data Data to be decrypted. | |
[in] | u16DataSize | Size of data in bytes. |
[in] | pu8Key | Decryption Key. |
[in] | u8KeySize | Size of the input key in bytes. |
void AES_CbcEnc | ( | uint8 * | pu8IV, |
uint8 * | pu8Data, | ||
uint16 | u16DataSize, | ||
uint8 * | pu8Key, | ||
uint8 | u8KeySize | ||
) |
Encrypts a stream of data (in place) using AES algorithm in the Cipher Block Chain (CBC) mode.
[in] | pu8IV | Initialization vector. |
[in/out] | pu8Data Data to be encrypted. | |
[in] | u16DataSize | Size of data in bytes. |
[in] | pu8Key | Encryption Key. |
[in] | u8KeySize | Size of the input key in bytes. |
sint32 BI_ModExp | ( | uint8 * | pu8X, |
uint32 | u32XSize, | ||
uint8 * | pu8E, | ||
uint32 | u32ESize, | ||
uint8 * | pu8N, | ||
uint32 | u32NSize, | ||
uint8 * | pu8Y, | ||
uint32 | u32YSize | ||
) |
Computes the modular exponentiation of big integers for the expression: Result = (Base ^ Power) % Mod.
[in] | pu32Base | A big integer representing the base digit.. |
[in] | u32BaseSize | Size of the base digit in 32-bit words. |
[in] | pu32Power | A big integer representing the exponent digit.. |
[in] | u32PowerSize | Size of the exponent digit in 32-bit words. |
[in] | pu32Mod | A big integer representing the modulo digit.. |
[in] | u32ModSize | Size of the modulo digit in 32-bit words. |
[out] | pu32Result | The resultant big integer. |
[in] | u32ResultSize | Size of the result digit in 32-bit words. |
void DRV_hmac_sha1 | ( | uint8 * | pu8Key, |
uint32 | u32KeyLength, | ||
uint8 * | pu8Data, | ||
uint32 | u32DataLength, | ||
uint8 * | pu8Digest | ||
) |
References DRV_HMAC_Vector(), DRV_SHA1_Hash(), tstrBuffer::pu8Data, and tstrBuffer::u16BufferSize.
Referenced by pbkdf2_sha1_f().
void DRV_HMAC_Vector | ( | tpfHash | fpHash, |
uint8 * | pu8Key, | ||
uint32 | u32KeyLength, | ||
tstrBuffer * | pstrInData, | ||
uint8 | u8NumInputs, | ||
uint8 * | pu8Out | ||
) |
Perform the HMAC operation on a given vector of data streams using the hash function passed to the DRV_HMAC_Vector.
References M2M_MEMSET, NULL, SHA_BLOCK_SIZE, SHA_FLAGS_FINISH, SHA_FLAGS_FULL_HASH, SHA_FLAGS_INIT, SHA_FLAGS_UPDATE, SHA_MAX_DIGEST_SIZE, and tstrHashContext::u8DigestSize.
Referenced by DRV_hmac_sha1().
void DRV_SHA1_Hash | ( | tstrHashContext * | pstrSha1Context, |
uint8 | u8Flags, | ||
uint8 * | pu8Data, | ||
uint32 | u32DataLength, | ||
uint8 * | pu8Digest | ||
) |
References tstrHashContext::au32HashState, tstrHashContext::fpHash, M2M_MEMSET, NULL, PUTU32, SHA1_DIGEST_SIZE, SHA1ProcessBlock(), SHA_BLOCK_SIZE, SHA_FLAGS_FINISH, SHA_FLAGS_INIT, SHA_FLAGS_UPDATE, Sha_HashFinish(), Sha_HashUpdate(), tstrHashContext::u32TotalLength, tstrHashContext::u8BlockSize, and tstrHashContext::u8DigestSize.
Referenced by DRV_hmac_sha1().
void hmac_md5 | ( | uint8 * | pu8Data, |
uint32 | u32DataLength, | ||
uint8 * | pu8Key, | ||
uint32 | u32KeyLength, | ||
uint8 * | pu8Digest | ||
) |
void HMAC_SHA256 | ( | uint8 * | pu8Data, |
uint32 | u32DataLength, | ||
uint8 * | pu8Key, | ||
uint32 | u32KeyLength, | ||
uint8 * | pu8Out | ||
) |
void MD5_Hash | ( | tstrHashContext * | pstrMD5Context, |
uint8 | u8Flags, | ||
uint8 * | pu8Data, | ||
uint32 | u32DataLength, | ||
uint8 * | pu8Digest | ||
) |
This function runs the PBKDF2 on the data with a given key.
To obtain the PSK from the password, PBKDF2 is run on SSID (data) with password (key).
References A_SHA_DIGEST_LEN, and pbkdf2_sha1_f().
Referenced by m2m_wifi_connect(), and m2m_wifi_enable_ap().
uint16 RSA_Encrypt | ( | tstrRSAPublicKey * | pstrKey, |
uint8 * | pu8Plain, | ||
uint16 | u16PlainSize, | ||
uint8 * | pu8Cipher | ||
) |
sint8 RSA_SignVerify | ( | tstrRSAPublicKey * | pstrKey, |
uint8 * | pu8Signature, | ||
uint16 | u16SignLen, | ||
uint8 * | pu8Hash, | ||
uint16 | u16HashLength | ||
) |
void SHA256_Hash | ( | tstrHashContext * | pstrSha256Context, |
uint8 | u8Flags, | ||
uint8 * | pu8Data, | ||
uint32 | u32DataLength, | ||
uint8 * | pu8Digest | ||
) |