Microchip® Advanced Software Framework

PMK.c File Reference

Implementation of HASH algorithms.

Copyright (c) 2016-2018 Microchip Technology Inc. and its subsidiaries.

#include "driver/include/m2m_types.h"
#include "drv_hash/crypto.h"

Macros

#define A_SHA_DIGEST_LEN   20
 
#define F1(x, y, z)   (((x) & (y)) | (~(x) & (z)))
 
#define F2(x, y, z)   (((x) & (z)) | ((y) & ~(z)))
 
#define F3(x, y, z)   ((x) ^ (y) ^ (z))
 
#define F4(x, y, z)   (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
 
#define F5(x, y, z)   ((y) ^ ((x) | ~(z)))
 
#define SHA1_CH(x, y, z)   F1(x,y,z)
 SHA1 specific defines. More...
 
#define SHA1_INERMEDIATE(A, B, C, D, E, W, K)
 
#define SHA1_MAJ(x, y, z)   F4(x,y,z)
 
#define SHA256_CAP_SIGMA0(x)   (SHA_ROTR(x, 2) ^ SHA_ROTR(x,13) ^ SHA_ROTR(x,22))
 
#define SHA256_CAP_SIGMA1(x)   (SHA_ROTR(x, 6) ^ SHA_ROTR(x,11) ^ SHA_ROTR(x,25))
 
#define SHA256_CH(x, y, z)   (z ^ (x & (y ^ z)))
 
#define SHA256_MAJ(x, y, z)   ((x & y) | (z & (x | y)))
 
#define SHA256_SMALL_SIGMA0(x)   (SHA_ROTR(x, 7) ^ SHA_ROTR(x,18) ^ SHA_SHR(x, 3))
 SHA256 specific defines. More...
 
#define SHA256_SMALL_SIGMA1(x)   (SHA_ROTR(x,17) ^ SHA_ROTR(x,19) ^ SHA_SHR(x,10))
 
#define SHA_PAD_BYTE   0x80
 
#define SHA_PARITY(x, y, z)   F3(x,y,z)
 

Functions

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)
 
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...
 
uint8 pbkdf2_sha1_f (uint8 *key, uint8 key_length, uint8 *data, uint32 data_len, uint32 iterations, uint32 count, uint8 *digest)
 This function iterates the hashing of digest as per the key. More...
 
void SHA1ProcessBlock (uint32 *pu32Sha1State, const uint8 *pu8MessageBlock)
 
void Sha_HashFinish (tstrHashContext *pstrHashCxt, uint8 *pu8LengthPadding)
 
void Sha_HashUpdate (tstrHashContext *pstrHashCxt, uint8 *pu8Data, uint32 u32DataLength)
 

#define A_SHA_DIGEST_LEN   20

Referenced by pbkdf2_sha1(), and pbkdf2_sha1_f().

#define F1 (   x,
  y,
 
)    (((x) & (y)) | (~(x) & (z)))
#define F2 (   x,
  y,
 
)    (((x) & (z)) | ((y) & ~(z)))
#define F3 (   x,
  y,
 
)    ((x) ^ (y) ^ (z))
#define F4 (   x,
  y,
 
)    (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
#define F5 (   x,
  y,
 
)    ((y) ^ ((x) | ~(z)))
#define SHA1_CH (   x,
  y,
 
)    F1(x,y,z)

SHA1 specific defines.

Referenced by SHA1ProcessBlock().

#define SHA1_INERMEDIATE (   A,
  B,
  C,
  D,
  E,
  W,
 
)
Value:
{ \
W += SHA_ROTL(A,5) + E + K; \
E = D; \
D = C; \
C = SHA_ROTL(B,30); \
B = A; \
A = W; \
}
#define SHA_ROTL(x, n)
Definition: wilc/drv_hash/crypto.h:161

Referenced by SHA1ProcessBlock().

#define SHA1_MAJ (   x,
  y,
 
)    F4(x,y,z)

Referenced by SHA1ProcessBlock().

#define SHA256_CAP_SIGMA0 (   x)    (SHA_ROTR(x, 2) ^ SHA_ROTR(x,13) ^ SHA_ROTR(x,22))
#define SHA256_CAP_SIGMA1 (   x)    (SHA_ROTR(x, 6) ^ SHA_ROTR(x,11) ^ SHA_ROTR(x,25))
#define SHA256_CH (   x,
  y,
 
)    (z ^ (x & (y ^ z)))
#define SHA256_MAJ (   x,
  y,
 
)    ((x & y) | (z & (x | y)))
#define SHA256_SMALL_SIGMA0 (   x)    (SHA_ROTR(x, 7) ^ SHA_ROTR(x,18) ^ SHA_SHR(x, 3))

SHA256 specific defines.

#define SHA256_SMALL_SIGMA1 (   x)    (SHA_ROTR(x,17) ^ SHA_ROTR(x,19) ^ SHA_SHR(x,10))
#define SHA_PAD_BYTE   0x80

Referenced by Sha_HashFinish().

#define SHA_PARITY (   x,
  y,
 
)    F3(x,y,z)

Referenced by SHA1ProcessBlock().

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.

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().

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.

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().

uint8 pbkdf2_sha1_f ( uint8 key,
uint8  key_length,
uint8 data,
uint32  data_len,
uint32  iterations,
uint32  count,
uint8 digest 
)

This function iterates the hashing of digest as per the key.

Returns
1 on success, 0 on failure.

References A_SHA_DIGEST_LEN, DRV_hmac_sha1(), and m2m_memcpy().

Referenced by pbkdf2_sha1().

void SHA1ProcessBlock ( uint32 pu32Sha1State,
const uint8 pu8MessageBlock 
)