TrustCore SDK NanoCert API reference  version 7.0
crypto.h File Reference

Header file for the NanoCrypto general crypto APIs. More...

Go to the source code of this file.

Data Structures

struct  BulkEncryptionAlgo
 Structure to hold function pointers to symmetric key cipher methods. More...
 
struct  BulkHashAlgo
 Structure to hold function pointers to hashing or extenable output methods. More...
 

Macros

#define CERT_MAXDIGESTSIZE   (64) /*(SHA512_RESULT_SIZE)*/
 
#define MAX_ENC_KEY_LENGTH   (32) /* AES-256 */
 
#define MAX_IV_LENGTH   (16) /* AES */
 

Typedefs

typedef MSTATUS(* AeadCipherFunc) (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte *nonce, ubyte4 nlen, ubyte *adata, ubyte4 alen, ubyte *data, ubyte4 dataLength, ubyte4 verifyLen, sbyte4 encrypt)
 
typedef MSTATUS(* AeadCloneFunc) (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, BulkCtx *ppNewCtx)
 
typedef MSTATUS(* BulkCtxAllocFunc) (MOC_HASH(hwAccelDescr hwAccelCtx) BulkCtx *pCtx)
 
typedef MSTATUS(* BulkCtxDigestFunc) (MOC_HASH(hwAccelDescr hwAccelCtx) ubyte *pData, ubyte4 dataLen, ubyte *pResult)
 
typedef MSTATUS(* BulkCtxDigestXOFFunc) (MOC_HASH(hwAccelDescr hwAccelCtx) ubyte *pData, ubyte4 dataLen, ubyte *pResult, ubyte4 resultLen)
 
typedef MSTATUS(* BulkCtxFinalFunc) (MOC_HASH(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte *pResult)
 
typedef MSTATUS(* BulkCtxFinalXOFFunc) (MOC_HASH(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte *pResult, ubyte4 resultLen)
 
typedef MSTATUS(* BulkCtxFreeFunc) (MOC_HASH(hwAccelDescr hwAccelCtx) BulkCtx *pCtx)
 
typedef MSTATUS(* BulkCtxInitFunc) (MOC_HASH(hwAccelDescr hwAccelCtx) BulkCtx ctx)
 
typedef MSTATUS(* BulkCtxUpdateFunc) (MOC_HASH(hwAccelDescr hwAccelCtx) BulkCtx ctx, const ubyte *pData, ubyte4 datalength)
 
typedef MSTATUS(* CipherFunc) (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte *data, sbyte4 dataLength, sbyte4 encrypt, ubyte *iv)
 
typedef MSTATUS(* CloneFunc) (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, BulkCtx *ppNewCtx)
 
typedef BulkCtx(* CreateAeadCtxFunc) (MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *keyMaterial, sbyte4 keyLength, sbyte4 encrypt)
 
typedef BulkCtx(* CreateBulkCtxFunc) (MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *keyMaterial, sbyte4 keyLength, sbyte4 encrypt)
 
typedef MSTATUS(* DeleteAeadCtxFunc) (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *ctx)
 
typedef MSTATUS(* DeleteBulkCtxFunc) (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *ctx)
 

Enumerations

enum  {
  rsaEncryption = 1, pkcs1Mgf = 8, rsaSsaPss = 10, md2withRSAEncryption = 2,
  md4withRSAEncryption = 3, md5withRSAEncryption = 4, sha1withRSAEncryption = 5, sha256withRSAEncryption = 11,
  sha384withRSAEncryption = 12, sha512withRSAEncryption = 13, sha224withRSAEncryption = 14, ht_none = 0,
  ht_md2 = 2, ht_md4 = 3, ht_md5 = 4, ht_sha1 = 5,
  ht_sha3_224 = 7, ht_sha3_256 = 8, ht_sha3_384 = 9, ht_sha3_512 = 10,
  ht_shake128 = 111, ht_shake256 = 112, ht_sha256 = 11, ht_sha384 = 12,
  ht_sha512 = 13, ht_sha224 = 14, ht_blake2b = 15, ht_blake2s = 16,
  sha1_with_no_sig = 31
}
 Enum of identifiers for the available hashing methods. More...
 

Functions

MOC_EXTERN MSTATUS CRYPTO_computeBufferHash (MOC_HASH(hwAccelDescr hwAccelCtx) const ubyte *buffer, ubyte4 bytesToHash, ubyte hash[], sbyte4 *hashSize, ubyte4 rsaAlgoId)
 Computes a hash of a buffer of data given a hash identifier. More...
 
MOC_EXTERN MSTATUS CRYPTO_getECCHashAlgo (ubyte eccAlgoId, BulkHashAlgo **ppBulkHashAlgo)
 Gets a hash suite of function pointers, appropriate for ECC, given a hash identifier. More...
 
MOC_EXTERN MSTATUS CRYPTO_getRSAHashAlgo (ubyte rsaAlgoId, const BulkHashAlgo **ppBulkHashAlgo)
 Gets a hash suite of function pointers, appropriate for RSA, given a hash identifier. More...
 
MOC_EXTERN MSTATUS CRYPTO_Process (MOC_SYM(hwAccelDescr hwAccelCtx) const BulkEncryptionAlgo *pAlgo, ubyte *keyMaterial, sbyte4 keyLength, ubyte *iv, ubyte *data, sbyte4 dataLength, sbyte4 encrypt)
 Performs a symmetric key cipher algorithm on a buffer of data. More...
 

Variables

MOC_EXTERN const BulkEncryptionAlgo CRYPTO_AESCtrSuite
 
MOC_EXTERN const BulkEncryptionAlgo CRYPTO_AESSuite
 
MOC_EXTERN const BulkEncryptionAlgo CRYPTO_RC4Suite
 
MOC_EXTERN const BulkEncryptionAlgo CRYPTO_TripleDESSuite
 
MOC_EXTERN const BulkEncryptionAlgo CRYPTO_TwoKeyTripleDESSuite
 

Detailed Description

Header file for the NanoCrypto general crypto APIs.

crypto.h

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Enum of identifiers for the available hashing methods. When possible this is the suffix of the pkcs1_OID.

Function Documentation

◆ CRYPTO_computeBufferHash()

MOC_EXTERN MSTATUS CRYPTO_computeBufferHash ( MOC_HASH(hwAccelDescr hwAccelCtx) const ubyte *  buffer,
ubyte4  bytesToHash,
ubyte  hash[],
sbyte4 *  hashSize,
ubyte4  rsaAlgoId 
)

Computes a hash of a buffer of data given a hash identifier.

Parameters
bufferThe buffer of data to be hashed.
bytesToHashThe length of the data to hash in bytes.
hashBuffer to hold the resulting output data.
hashSizeContents will be set to the length of the output data in bytes.
rsaAlgoIdThe identifier for the hash algorithm to be used.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h.

crypto.h

◆ CRYPTO_getECCHashAlgo()

MOC_EXTERN MSTATUS CRYPTO_getECCHashAlgo ( ubyte  eccAlgoId,
BulkHashAlgo **  ppBulkHashAlgo 
)

Gets a hash suite of function pointers, appropriate for ECC, given a hash identifier.

Parameters
eccAlgoIdThe identifier for the hash algorithm.
ppBulkHashAlgoPointer whose contents will be set to the location of the hash suite for the algorithm requested.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h.

crypto.h

◆ CRYPTO_getRSAHashAlgo()

MOC_EXTERN MSTATUS CRYPTO_getRSAHashAlgo ( ubyte  rsaAlgoId,
const BulkHashAlgo **  ppBulkHashAlgo 
)

Gets a hash suite of function pointers, appropriate for RSA, given a hash identifier.

Parameters
rsaAlgoIdThe identifier for the hash algorithm.
ppBulkHashAlgoPointer whose contents will be set to the location of the hash suite for the algorithm requested.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h.

crypto.h

◆ CRYPTO_Process()

MOC_EXTERN MSTATUS CRYPTO_Process ( MOC_SYM(hwAccelDescr hwAccelCtx) const BulkEncryptionAlgo pAlgo,
ubyte *  keyMaterial,
sbyte4  keyLength,
ubyte *  iv,
ubyte *  data,
sbyte4  dataLength,
sbyte4  encrypt 
)

Performs a symmetric key cipher algorithm on a buffer of data.

Parameters
pAlgoPointer to a suite holding the function pointer cipher methods to be used.
keyMaterialBuffer holding the key material as a byte array.
keyLengthThe length of the key in bytes. This may vary depending on the cipher chosen.
ivInitialization vector (if required by the cipher chosen)
dataBuffer holding the input data to be processed by the cipher chosen. This will be processed in place.
dataLengthThe length of the data in bytes. Whether this needs to be a multiple of the cipher blocklength depends on the cipher chosen.
encryptEnter TRUE (1) for encryption and FALSE (0) for decryption. For stream ciphers or ciphers where the encryption operation is the same as the decryption operation, this parameter will be ignored.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h.

crypto.h