Microchip® Advanced Software Framework

crypto.h File Reference

APIs and data types for cryptographic algorithms.

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

Data Structures

struct  tstrDHPublicKey
 Diffie-Hellman Public Key Definition. More...
 
struct  tstrECPublicKey
 
struct  tstrHash512Context
 
struct  tstrHashContext
 
struct  tstrHashInfo
 
struct  tstrPublicKey
 Generic Public Key Structure. More...
 
struct  tstrRSAPublicKey
 RSA Public Key Definition. More...
 
struct  tstrShaHashContext
 

Macros

#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 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 SHA224_DIGEST_SIZE   (28)
 
#define SHA256_DIGEST_SIZE   (32)
 
#define SHA256_FINISH(ctxt, digest)   SHA256_Hash((ctxt), SHA_FLAGS_FINISH, NULL, 0, digest)
 
#define SHA256_INIT(ctxt)   SHA256_Hash((ctxt), SHA_FLAGS_INIT, NULL, 0, NULL)
 
#define SHA256_UPDATE(ctxt, data, dataLen)   SHA256_Hash((ctxt), SHA_FLAGS_UPDATE, (data), (dataLen), NULL)
 
#define SHA384_DIGEST_SIZE   (48)
 
#define SHA512_BLOCK_SIZE   (128)
 
#define SHA512_DIGEST_SIZE   (64)
 
#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   SHA512_DIGEST_SIZE
 
#define SHA_ROTL(x, n)   (SHA_SHL(x,n) | SHA_SHR(x , (32 - n)))
 
#define SHA_ROTL_64(high, low, n, high_o, low_o)
 
#define SHA_ROTR(x, n)   (SHA_SHR(x,n) | SHA_SHL(x , (32 - n)))
 
#define SHA_ROTR_64(high, low, n, high_o, low_o)
 
#define SHA_SHL(x, n)   ((x & 0xFFFFFFFF) << n)
 
#define SHA_SHL_64(high, low, n, high_o, low_o)
 
#define SHA_SHR(x, n)   ((x & 0xFFFFFFFF) >> n)
 
#define SHA_SHR_64(high, low, n, high_o, low_o)
 

Typedefs

typedef void(* tpfHash )(tstrShaHashContext *pstrHashContext, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest)
 
typedef void(* tpfHashProcessBlock )(uint32 *pu32HashState, const uint8 *pu8MessageBlock)
 
typedef tstrShaHashContext tstrMd5Context
 
typedef tstrRSAPublicKey tstrRSAPrivateKey
 
typedef tstrShaHashContext tstrSha1Context
 
typedef tstrShaHashContext tstrSha256Context
 

Enumerations

enum  tenuHashAlg {
  HASH_ALG_NONE,
  HASH_ALG_MD5,
  HASH_ALG_SHA1,
  HASH_ALG_SHA224,
  HASH_ALG_SHA256,
  HASH_ALG_SHA384,
  HASH_ALG_SHA512,
  HASH_ALG_MAX
}
 TLS Defined Hash Algorithms. More...
 
enum  tenuPubKeyAlg {
  PUBKEY_ALG_NONE,
  PUBKEY_ALG_RSA,
  PUBKEY_ALG_DH,
  PUBKEY_ALG_ECC
}
 
enum  tenuTlsSignAlg {
  TLS_SIG_ANON,
  TLS_SIG_ALG_RSA,
  TLS_SIG_ALG_DSA,
  TLS_SIG_ALG_ECDSA
}
 TLS Defined Signature Algorithms. More...
 

Functions

void hmac_md5 (uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Key, uint32 u32KeyLength, uint8 *pu8Digest)
 
void hmac_sha1 (uint8 *pu8Key, uint32 u32KeyLength, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest)
 
void HMAC_SHA256 (uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Key, uint32 u32KeyLength, uint8 *pu8Digest)
 
void HMAC_Vector (tenuHashAlg enuHashAlg, uint8 *pu8Key, uint32 u32KeyLength, tstrBuffer *pstrInData, uint8 u8NumInputs, uint8 *pu8Out)
 
void MD4_Hash (uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest)
 
void MD5_Hash (tstrShaHashContext *pstrSha1Context, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest)
 
void MD5_HashSW (tstrHash512Context *pstrMD5Cxt, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest)
 
void SHA1_Hash (tstrShaHashContext *pstrSha1Context, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest)
 
void SHA1_HashSW (tstrHash512Context *pstrSha1Cxt, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest)
 
void SHA224_Hash (tstrShaHashContext *pstrSha1Context, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest)
 
void SHA224_HashSW (tstrHash512Context *pstrSha224Cxt, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest)
 
void SHA256_Hash (tstrShaHashContext *pstrSha1Context, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest)
 
void SHA256_HashSW (tstrHash512Context *pstrSha256Cxt, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest)
 
void SHA384_Hash (tstrShaHashContext *pstrSha1Context, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest)
 
void SHA512_Hash (tstrShaHashContext *pstrSha1Context, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest)
 
void SHA512_HashSW (tstrHash512Context *pstrSha512Cxt, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest, uint8 u8IsSHA384)
 

Variables

tstrHashInfo eastrTlsHashes [HASH_ALG_MAX]
 

#define MD4_DIGEST_SIZE   (16)

Referenced by MD4_Hash().

#define MD5_DIGEST_SIZE   (16)

Referenced by MD5_HashSW().

#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 SHA1_DIGEST_SIZE   (20)

Referenced by SHA1_HashSW().

#define SHA1_FINISH (   ctxt,
  digest 
)    SHA1_Hash((ctxt), SHA_FLAGS_FINISH, NULL, 0, digest)

Referenced by Cert_DecodeX520Name().

#define SHA1_INIT (   ctxt)    SHA1_Hash((ctxt), SHA_FLAGS_INIT, NULL, 0, NULL)

Referenced by Cert_DecodeX520Name().

#define SHA1_UPDATE (   ctxt,
  data,
  dataLen 
)    SHA1_Hash((ctxt), SHA_FLAGS_UPDATE, (data), (dataLen), NULL)

Referenced by Cert_DecodeX520Name().

#define SHA224_DIGEST_SIZE   (28)

Referenced by SHA224_HashSW().

#define SHA256_DIGEST_SIZE   (32)
#define SHA256_FINISH (   ctxt,
  digest 
)    SHA256_Hash((ctxt), SHA_FLAGS_FINISH, NULL, 0, digest)
#define SHA256_INIT (   ctxt)    SHA256_Hash((ctxt), SHA_FLAGS_INIT, NULL, 0, NULL)
#define SHA256_UPDATE (   ctxt,
  data,
  dataLen 
)    SHA256_Hash((ctxt), SHA_FLAGS_UPDATE, (data), (dataLen), NULL)
#define SHA384_DIGEST_SIZE   (48)

Referenced by SHA512_HashSW().

#define SHA512_BLOCK_SIZE   (128)

Referenced by HMAC_Vector(), and SHA512_HashSW().

#define SHA512_DIGEST_SIZE   (64)

Referenced by SHA512_HashSW().

#define SHA_BLOCK_SIZE   (64)
#define SHA_FLAGS_FINISH   0x04

Finalize the hashing and calculate the final result.

Referenced by Cert_ComputeTBSCertHash(), HMAC_Vector(), MD5_HashSW(), SHA1_HashSW(), SHA224_HashSW(), SHA256_HashSW(), and SHA512_HashSW().

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

#define SHA_FLAGS_INIT   0x01

A flag to tell the hash function to start hash from the initial state.

Referenced by Cert_ComputeTBSCertHash(), HMAC_Vector(), MD5_HashSW(), SHA1_HashSW(), SHA224_HashSW(), SHA256_HashSW(), and SHA512_HashSW().

#define SHA_FLAGS_UPDATE   0x02

Update the current hash with the given data.

Referenced by Cert_ComputeTBSCertHash(), HMAC_Vector(), MD5_HashSW(), SHA1_HashSW(), SHA224_HashSW(), SHA256_HashSW(), and SHA512_HashSW().

#define SHA_MAX_DIGEST_SIZE   SHA512_DIGEST_SIZE

Referenced by HMAC_Vector().

#define SHA_ROTL (   x,
 
)    (SHA_SHL(x,n) | SHA_SHR(x , (32 - n)))

Referenced by SHA1ProcessBlock().

#define SHA_ROTL_64 (   high,
  low,
  n,
  high_o,
  low_o 
)
Value:
(high_o = SHA_SHL(high,n) | SHA_SHR(low , (32 - n)));\
(low_o = SHA_SHL(low,n) | SHA_SHR(high , (32 - n)))
#define SHA_SHL(x, n)
Definition: crypto.h:105
#define SHA_SHR(x, n)
Definition: crypto.h:104
#define SHA_ROTR (   x,
 
)    (SHA_SHR(x,n) | SHA_SHL(x , (32 - n)))
#define SHA_ROTR_64 (   high,
  low,
  n,
  high_o,
  low_o 
)
Value:
(high_o = SHA_SHR(high,n) | SHA_SHL(low , (32 - n)));\
(low_o = SHA_SHR(low,n) | SHA_SHL(high , (32 - n)))
#define SHA_SHL(x, n)
Definition: crypto.h:105
#define SHA_SHR(x, n)
Definition: crypto.h:104

Referenced by SHA512ProcessBlock().

#define SHA_SHL (   x,
 
)    ((x & 0xFFFFFFFF) << n)
#define SHA_SHL_64 (   high,
  low,
  n,
  high_o,
  low_o 
)
Value:
(high_o = SHA_SHL(high,n) | SHA_SHR(low , (32 - n)));\
(low_o = SHA_SHL(low,n))
#define SHA_SHL(x, n)
Definition: crypto.h:105
#define SHA_SHR(x, n)
Definition: crypto.h:104
#define SHA_SHR (   x,
 
)    ((x & 0xFFFFFFFF) >> n)
#define SHA_SHR_64 (   high,
  low,
  n,
  high_o,
  low_o 
)
Value:
(high_o = SHA_SHR(high,n));\
(low_o = SHA_SHR(low,n) | SHA_SHL(high , (32 - n)))
#define SHA_SHL(x, n)
Definition: crypto.h:105
#define SHA_SHR(x, n)
Definition: crypto.h:104

Referenced by SHA512ProcessBlock().

tpfHash
tpfHashProcessBlock

TLS Defined Hash Algorithms.

Hash algorithms mapped to the IDs defined by the TLS protocol specifications. It is used in the signature_algorithms Hello Extension that must be included in the TLS.Handshake.ClientHello message starting from TLS 1.2.

Enumerator
HASH_ALG_NONE 
HASH_ALG_MD5 
HASH_ALG_SHA1 
HASH_ALG_SHA224 
HASH_ALG_SHA256 
HASH_ALG_SHA384 
HASH_ALG_SHA512 
HASH_ALG_MAX 
Enumerator
PUBKEY_ALG_NONE 
PUBKEY_ALG_RSA 
PUBKEY_ALG_DH 
PUBKEY_ALG_ECC 

TLS Defined Signature Algorithms.

Public Key Signature algorithms mapped to the IDs defined by the TLS protocol specifications. It is used in the signature_algorithms Hello Extension that must be included in the TLS.Handshake.ClientHello message starting from TLS 1.2.

Enumerator
TLS_SIG_ANON 
TLS_SIG_ALG_RSA 
TLS_SIG_ALG_DSA 
TLS_SIG_ALG_ECDSA 

void hmac_md5 ( uint8 pu8Data,
uint32  u32DataLength,
uint8 pu8Key,
uint32  u32KeyLength,
uint8 pu8Digest 
)
void hmac_sha1 ( uint8 pu8Key,
uint32  u32KeyLength,
uint8 pu8Data,
uint32  u32DataLength,
uint8 pu8Digest 
)
void HMAC_SHA256 ( uint8 pu8Data,
uint32  u32DataLength,
uint8 pu8Key,
uint32  u32KeyLength,
uint8 pu8Digest 
)
void MD5_Hash ( tstrShaHashContext pstrSha1Context,
uint8  u8Flags,
uint8 pu8Data,
uint32  u32DataLength,
uint8 pu8Digest 
)

References MD5_HASH_SW.

void SHA1_Hash ( tstrShaHashContext pstrSha1Context,
uint8  u8Flags,
uint8 pu8Data,
uint32  u32DataLength,
uint8 pu8Digest 
)

References SHA1_HASH_SW.

void SHA224_Hash ( tstrShaHashContext pstrSha1Context,
uint8  u8Flags,
uint8 pu8Data,
uint32  u32DataLength,
uint8 pu8Digest 
)

References SHA224_HASH_SW.

void SHA256_Hash ( tstrShaHashContext pstrSha1Context,
uint8  u8Flags,
uint8 pu8Data,
uint32  u32DataLength,
uint8 pu8Digest 
)

References SHA256_HASH_SW.

void SHA384_Hash ( tstrShaHashContext pstrSha1Context,
uint8  u8Flags,
uint8 pu8Data,
uint32  u32DataLength,
uint8 pu8Digest 
)

References SHA384_HASH_SW.

void SHA512_Hash ( tstrShaHashContext pstrSha1Context,
uint8  u8Flags,
uint8 pu8Data,
uint32  u32DataLength,
uint8 pu8Digest 
)

References SHA512_HASH_SW.

tstrHashInfo eastrTlsHashes[HASH_ALG_MAX]

Referenced by Cert_ComputeTBSCertHash().