m2mb API docs  25.30.003
m2mb API sets documentation
m2mb_crypto.h File Reference

Crypto APIs implementation. More...

Go to the source code of this file.

Data Structures

struct  M2MB_CRYPTO_ECC_AFFINE_POINT_T
 Structure representing the X,Y coordinates of a point. The point is zero, or "at infinity", if infinity == 1. Otherwise, X and Y are its standard (affine) coordinates. key_size respresents the x or y coordinates content length (for 160 bit key, size should be 20). More...
 

Macros

#define TZ_LOGGING
 
#define m2mb_crypto_md_free   m2mb_crypto_md_deinit
 
#define m2mb_crypto_hmac_free   m2mb_crypto_hmac_deinit
 
#define m2mb_crypto_cmac_free   m2mb_crypto_cmac_deinit
 
#define m2mb_crypto_aes_free   m2mb_crypto_aes_deinit
 
#define m2mb_crypto_des_free   m2mb_crypto_des_deinit
 
#define m2mb_crypto_rsa_free   m2mb_crypto_rsa_deinit
 
#define m2mb_crypto_ecc_free   m2mb_crypto_ecc_deinit
 
#define M2MB_CRYPTO_AES_ECB_BLOCK_SIZE   16
 
#define M2MB_CRYPTO_AES_IV_SIZE   16
 
#define M2MB_CRYPTO_DES_KEY_SIZE   8
 
#define M2MB_CRYPTO_3DES_KEY2_SIZE   16
 
#define M2MB_CRYPTO_3DES_KEY3_SIZE   24
 
#define M2MB_CRYPTO_DES_BLOCK_BYTE_LEN   8
 
#define M2MB_CRYPTO_DES_IV_BYTE_LEN   8
 
#define M2MB_CRYPTO_ECC_BIGLEN   18
 Number of 32-bytes required for a big number.
 
#define M2MB_MAX_ECC_KEY_SIZE   32
 Maximum size for key size (x or y coordinates in binary format, private key).
 
#define M2MB_CRYPTO_PRNG_MAX_BYTES   512
 

Typedefs

typedef struct M2MB_CRYPTO_GEN_CONTEXT_TAG * M2MB_CRYPTO_GEN_CONTEXT
 Opaque structure for context.
 
typedef struct M2MB_CRYPTO_MD_CONTEXT_TAG * M2MB_CRYPTO_MD_CONTEXT
 Opaque structure for context.
 
typedef struct M2MB_CRYPTO_HMAC_CONTEXT_TAG * M2MB_CRYPTO_HMAC_CONTEXT
 Opaque structure for context.
 
typedef struct M2MB_CRYPTO_CMAC_CONTEXT_TAG * M2MB_CRYPTO_CMAC_CONTEXT
 Opaque structure for context.
 
typedef struct M2MB_CRYPTO_AES_CONTEXT_TAG * M2MB_CRYPTO_AES_CONTEXT
 Opaque structure for context.
 
typedef struct M2MB_CRYPTO_DES_CONTEXT_TAG * M2MB_CRYPTO_DES_CONTEXT
 Opaque structure for context.
 
typedef struct M2MB_CRYPTO_RSA_CONTEXT_TAG * M2MB_CRYPTO_RSA_CONTEXT
 Opaque structure for context.
 
typedef struct M2MB_CRYPTO_ECC_CONTEXT_TAG * M2MB_CRYPTO_ECC_CONTEXT
 Opaque structure for context.
 

Enumerations

enum  M2MB_CRYPTO_CTX_ALG_E {
  M2MB_CRYPTO_CTX_ALG_NONE =0, M2MB_CRYPTO_CTX_ALG_MD2, M2MB_CRYPTO_CTX_ALG_MD4, M2MB_CRYPTO_CTX_ALG_MD5,
  M2MB_CRYPTO_CTX_ALG_SHA1, M2MB_CRYPTO_CTX_ALG_SHA224, M2MB_CRYPTO_CTX_ALG_SHA256, M2MB_CRYPTO_CTX_ALG_SHA384,
  M2MB_CRYPTO_CTX_ALG_SHA512, M2MB_CRYPTO_CTX_ALG_HMAC, M2MB_CRYPTO_CTX_ALG_CMAC, M2MB_CRYPTO_CTX_ALG_RSA,
  M2MB_CRYPTO_CTX_ALG_ECC, M2MB_CRYPTO_CTX_ALG_AES, M2MB_CRYPTO_CTX_ALG_DES
}
 Enumeration representing all supported Crypto algorithms.
 
enum  M2MB_CRYPTO_MD_ALG_E {
  M2MB_CRYPTO_MD_ALG_NONE =0, M2MB_CRYPTO_MD_ALG_MD2, M2MB_CRYPTO_MD_ALG_MD4, M2MB_CRYPTO_MD_ALG_MD5,
  M2MB_CRYPTO_MD_ALG_SHA1, M2MB_CRYPTO_MD_ALG_SHA224, M2MB_CRYPTO_MD_ALG_SHA256, M2MB_CRYPTO_MD_ALG_SHA384,
  M2MB_CRYPTO_MD_ALG_SHA512
}
 Enumeration respresenting all supported HASH algorithms.
 
enum  M2MB_CRYPTO_CMAC_ALG_E { M2MB_CRYPTO_CMAC_ALG_AES_128 = 1, M2MB_CRYPTO_CMAC_ALG_AES_192 = 2, M2MB_CRYPTO_CMAC_ALG_AES_256 = 3 }
 
enum  M2MB_CRYPTO_AES_MODE_E { M2MB_CRYPTO_AES_MODE_ENCRYPT, M2MB_CRYPTO_AES_MODE_DECRYPT }
 AES operation mode (encrypt decrypt)
 
enum  M2MB_CRYPTO_DES_ALG_TYPE_E { M2MB_CRYPTO_ALG_DES, M2MB_CRYPTO_ALG_3DES }
 
enum  M2MB_CRYPTO_DES_MODE_E { M2MB_CRYPTO_DES_MODE_ENCRYPT, M2MB_CRYPTO_DES_MODE_DECRYPT }
 
enum  M2MB_CRYPTO_RSA_PADDING_TYPE_E {
  M2MB_CRYPTO_RSA_PADDING_PKCS1_V15, M2MB_CRYPTO_RSA_PADDING_PKCS1_OAEP, M2MB_CRYPTO_RSA_PADDING_PKCS1_PSS, M2MB_CRYPTO_RSA_PADDING_PKCS1_PSS_AUTORECOVER_SALTLEN,
  M2MB_CRYPTO_RSA_PADDING_NONE
}
 Padding types for RSA encryption. More...
 
enum  M2MB_CRYPTO_RSA_MODE_E { M2MB_CRYPTO_RSA_PUBLIC, M2MB_CRYPTO_RSA_PRIVATE }
 The operation mode (encrypt/decrypt).
 
enum  M2MB_CRYPTO_ECC_DOMAIN_GROUP_ID_E { M2MB_CRYPTO_ECC_DP_BP256R1, M2MB_CRYPTO_ECC_DP_SECP256R1, M2MB_CRYPTO_ECC_DP_CUSTOM }
 
enum  M2MB_CRYPTO_ECC_DP_E {
  M2MB_CRYPTO_ECC_DP_P, M2MB_CRYPTO_ECC_DP_A, M2MB_CRYPTO_ECC_DP_B, M2MB_CRYPTO_ECC_DP_G_X,
  M2MB_CRYPTO_ECC_DP_G_Y, M2MB_CRYPTO_ECC_DP_N, M2MB_CRYPTO_ECC_DP_H
}
 Enumeration representing all the ECC Domain Parameters.
 

Functions

M2MB_CRYPTO_CTX_ALG_E m2mb_crypto_get_algo (M2MB_CRYPTO_GEN_CONTEXT ctx)
 Returns the Crypto algorithm. More...
 
UINT32 m2mb_crypto_ctx_info_for_tee (M2MB_CRYPTO_GEN_CONTEXT ctx, UINT8 *info)
 Returns the context ID for the given context structure. More...
 
M2MB_RESULT_E m2mb_crypto_md_init (M2MB_CRYPTO_MD_CONTEXT *ctx)
 Allocates an M2MB_CRYPTO_MD_CONTEXT structure. More...
 
M2MB_RESULT_E m2mb_crypto_md_setup (M2MB_CRYPTO_MD_CONTEXT ctx, const M2MB_CRYPTO_MD_ALG_E md_info)
 Sets up a M2MB_CRYPTO_MD_CONTEXT structure. More...
 
M2MB_RESULT_E m2mb_crypto_md_update (M2MB_CRYPTO_MD_CONTEXT ctx, const UINT8 *data, SIZE_T len)
 Continuously hashing of data. This function should be called repeatedly with chunks of the message to be hashed (len bytes from data). More...
 
M2MB_RESULT_E m2mb_crypto_md_final (M2MB_CRYPTO_MD_CONTEXT ctx, UINT8 *md)
 This function computes the final digest for the hash process. More...
 
M2MB_RESULT_E m2mb_crypto_md_deinit (M2MB_CRYPTO_MD_CONTEXT ctx)
 This function frees an MD context. More...
 
UINT8 * m2mb_crypto_md (const M2MB_CRYPTO_MD_ALG_E md_info, const UINT8 *data, SIZE_T len, UINT8 *md)
 This function will compute the message digest in one shot, in case of limited and available size of data. More...
 
M2MB_RESULT_E m2mb_crypto_hmac_init (M2MB_CRYPTO_HMAC_CONTEXT *ctx)
 Opaque structure for context. More...
 
M2MB_RESULT_E m2mb_crypto_hmac_setup (M2MB_CRYPTO_HMAC_CONTEXT ctx, M2MB_CRYPTO_MD_ALG_E md_info, const UINT8 *key, SIZE_T keylen)
 Sets up an M2MB_CRYPTO_HMAC_CONTEXT structure. More...
 
M2MB_RESULT_E m2mb_crypto_hmac_update (M2MB_CRYPTO_HMAC_CONTEXT ctx, const UINT8 *data, SIZE_T len)
 Continuously HMAC of data. This function can be called repeatedly similar to streaming. More...
 
M2MB_RESULT_E m2mb_crypto_hmac_final (M2MB_CRYPTO_HMAC_CONTEXT ctx, UINT8 *hmac)
 This function computes the final HMAC for all previously provided messages for the given context. More...
 
M2MB_RESULT_E m2mb_crypto_hmac_reset (M2MB_CRYPTO_HMAC_CONTEXT ctx)
 Prepare to run HMAC for a new message reusing the context. More...
 
M2MB_RESULT_E m2mb_crypto_hmac_deinit (M2MB_CRYPTO_HMAC_CONTEXT ctx)
 This function free an HMAC context releasing the associated resources. More...
 
UINT8 * m2mb_crypto_hmac (M2MB_CRYPTO_MD_ALG_E md_info, const UINT8 *key, const SIZE_T keylen, const UINT8 *input, const SIZE_T inlen, UINT8 *hmac)
 This function will compute the HMAC in one shot without needing any context. More...
 
M2MB_RESULT_E m2mb_crypto_cmac_init (M2MB_CRYPTO_CMAC_CONTEXT *ctx)
 Allocates a M2MB_CRYPTO_CMAC_CONTEXT structure. More...
 
M2MB_RESULT_E m2mb_crypto_cmac_setup (M2MB_CRYPTO_CMAC_CONTEXT ctx, const UINT8 *key, SIZE_T keylen)
 Sets up an M2MB_CRYPTO_CMAC_CONTEXT structure. More...
 
M2MB_RESULT_E m2mb_crypto_cmac_update (M2MB_CRYPTO_CMAC_CONTEXT ctx, const UINT8 *data, SIZE_T len)
 continuously CMAC of data. This function can be called repeatedly similar to streaming More...
 
M2MB_RESULT_E m2mb_crypto_cmac_final (M2MB_CRYPTO_CMAC_CONTEXT ctx, UINT8 *cmac)
 This function computes the final CMAC for all previously provided messages for the given context. More...
 
M2MB_RESULT_E m2mb_crypto_cmac_reset (M2MB_CRYPTO_CMAC_CONTEXT ctx)
 Prepare to run CMAC for a new message. More...
 
M2MB_RESULT_E m2mb_crypto_cmac_deinit (M2MB_CRYPTO_CMAC_CONTEXT ctx)
 This function free an CMAC context. More...
 
UINT8 * m2mb_crypto_cmac (M2MB_CRYPTO_CMAC_ALG_E cmac_alg, const UINT8 *key, const SIZE_T keylen, const UINT8 *input, const SIZE_T inlen, UINT8 *cmac)
 This function will compute the CMAC in one shot without needing any context. More...
 
M2MB_RESULT_E m2mb_crypto_aes_init (M2MB_CRYPTO_AES_CONTEXT *ctx)
 Allocates an M2MB_CRYPTO_AES_CONTEXT structure. More...
 
M2MB_RESULT_E m2mb_crypto_aes_deinit (M2MB_CRYPTO_AES_CONTEXT ctx)
 Free an M2MB_CRYPTO_AES_CONTEXT structure. More...
 
M2MB_RESULT_E m2mb_crypto_aes_generate_key (M2MB_CRYPTO_AES_CONTEXT ctx, UINT32 keybits)
 Generates an AES encryption key for a given context. More...
 
M2MB_RESULT_E m2mb_crypto_aes_keyblob_export (M2MB_CRYPTO_AES_CONTEXT ctx, UINT8 *keyblob, UINT32 *keyblob_length)
 Exports the AES symmetric key from the given context. More...
 
M2MB_RESULT_E m2mb_crypto_aes_keyblob_import (M2MB_CRYPTO_AES_CONTEXT ctx, const UINT8 *keyblob, UINT32 keyblob_length)
 Import a symmetric key, previously generated on the same device, into a given context. More...
 
M2MB_RESULT_E m2mb_crypto_aes_externalkey_import (M2MB_CRYPTO_AES_CONTEXT ctx, const UINT8 *key, UINT32 keylength)
 Imports a symmetric key into the given context. This is a plaintext key that may have been generated externally. More...
 
M2MB_RESULT_E m2mb_crypto_aes_ecb_encdec (M2MB_CRYPTO_AES_CONTEXT ctx, M2MB_CRYPTO_AES_MODE_E mode, const UINT8 in[M2MB_CRYPTO_AES_ECB_BLOCK_SIZE], UINT8 out[M2MB_CRYPTO_AES_ECB_BLOCK_SIZE])
 Encrypts/decrypts a single 16 bytes block onto the output buffer using the AES ECB algorithm. More...
 
M2MB_RESULT_E m2mb_crypto_aes_cbc_encdec (M2MB_CRYPTO_AES_CONTEXT ctx, M2MB_CRYPTO_AES_MODE_E mode, const UINT8 *in, UINT8 *out, SIZE_T inlen, UINT8 ivec[M2MB_CRYPTO_AES_IV_SIZE])
 Encrypts/decrypts a given buffer with a given length using the AES CBC. The length must be a multiple of the block size (16 bytes). More...
 
M2MB_RESULT_E m2mb_crypto_des_init (M2MB_CRYPTO_DES_CONTEXT *ctx, M2MB_CRYPTO_DES_ALG_TYPE_E des_alg)
 Allocates an M2MB_CRYPTO_DES_CONTEXT structure. More...
 
M2MB_RESULT_E m2mb_crypto_des_deinit (M2MB_CRYPTO_DES_CONTEXT ctx)
 Free an M2MB_CRYPTO_DES_CONTEXT structure. More...
 
M2MB_RESULT_E m2mb_crypto_des_generate_key (M2MB_CRYPTO_DES_CONTEXT ctx, UINT32 keybits)
 Generates a DES encryption key for a given context. More...
 
M2MB_RESULT_E m2mb_crypto_des_externalkey_import (M2MB_CRYPTO_DES_CONTEXT ctx, const UINT8 key[M2MB_CRYPTO_DES_KEY_SIZE])
 Sets up a DES encryption key (64 bits = 56 effective bits key + parity) for a given context. More...
 
M2MB_RESULT_E m2mb_crypto_3des_2externalkey_import (M2MB_CRYPTO_DES_CONTEXT ctx, const UINT8 key[M2MB_CRYPTO_3DES_KEY2_SIZE])
 Sets up a 3DES encryption key (128 bits = 112 effective bits key + parity) for a given context. More...
 
M2MB_RESULT_E m2mb_crypto_3des_3externalkey_import (M2MB_CRYPTO_DES_CONTEXT ctx, const UINT8 key[M2MB_CRYPTO_3DES_KEY3_SIZE])
 Sets up a 3DES encryption key (192 bits = 168 effective bits key + parity) for a given context. More...
 
M2MB_RESULT_E m2mb_crypto_des_keyblob_import (M2MB_CRYPTO_DES_CONTEXT ctx, const UINT8 *keyblob, UINT32 keyblob_length)
 Imports a DES/3DES symmetric key into the context. More...
 
M2MB_RESULT_E m2mb_crypto_des_keyblob_export (M2MB_CRYPTO_DES_CONTEXT ctx, UINT8 *keyblob, UINT32 *keyblob_length)
 Exports a DES key blob from the given context. The blob is encrypted with a device specific key and can only be used on the same HW originating it. More...
 
M2MB_RESULT_E m2mb_crypto_des_ecb_encdec (M2MB_CRYPTO_DES_CONTEXT ctx, M2MB_CRYPTO_DES_MODE_E mode, const UINT8 in[M2MB_CRYPTO_DES_BLOCK_BYTE_LEN], UINT8 out[M2MB_CRYPTO_DES_BLOCK_BYTE_LEN])
 Encrypts/decrypts a single 8 bytes block onto the output buffer using the DES ECB algorithm. More...
 
M2MB_RESULT_E m2mb_crypto_des_cbc_encdec (M2MB_CRYPTO_DES_CONTEXT ctx, M2MB_CRYPTO_DES_MODE_E mode, const UINT8 *in, UINT8 *out, SIZE_T inlen, UINT8 ivec[M2MB_CRYPTO_DES_IV_BYTE_LEN])
 Encrypts/decrypts a given buffer with a given length using the DES CBC. The length must be a multiple of the block size (8 bytes). More...
 
M2MB_RESULT_E m2mb_crypto_rsa_init (M2MB_CRYPTO_RSA_CONTEXT *ctx, M2MB_CRYPTO_RSA_PADDING_TYPE_E padding_type, M2MB_CRYPTO_MD_ALG_E hash_id)
 Allocates an M2MB_CRYPTO_RSA_CONTEXT structure. More...
 
M2MB_RESULT_E m2mb_crypto_rsa_deinit (M2MB_CRYPTO_RSA_CONTEXT ctx)
 Free an M2MB_CRYPTO_RSA_CONTEXT structure. More...
 
M2MB_RESULT_E m2mb_crypto_rsa_public (M2MB_CRYPTO_RSA_CONTEXT ctx, const UINT8 *in, UINT8 *out)
 RSA public key operation. More...
 
M2MB_RESULT_E m2mb_crypto_rsa_private (M2MB_CRYPTO_RSA_CONTEXT ctx, const UINT8 *in, UINT8 *out)
 RSA private key operation. More...
 
M2MB_RESULT_E m2mb_crypto_rsa_generate_key (M2MB_CRYPTO_RSA_CONTEXT ctx, UINT32 key_size, UINT32 public_exponent)
 Generates an RSA key pair. More...
 
M2MB_RESULT_E m2mb_crypto_rsa_keyblob_export (M2MB_CRYPTO_RSA_CONTEXT ctx, UINT8 *keyblob, UINT32 *keyblob_length)
 Exports an RSA key pair blob from the given context. The blob is encrypted with a device specific key and can only be used on the same HW originating it. More...
 
M2MB_RESULT_E m2mb_crypto_rsa_keyblob_import (M2MB_CRYPTO_RSA_CONTEXT ctx, const UINT8 *keyblob, UINT32 keyblob_length)
 Imports an RSA key pair into the context. More...
 
M2MB_RESULT_E m2mb_crypto_rsa_public_key_export (M2MB_CRYPTO_RSA_CONTEXT ctx, UINT8 *modulus, UINT32 *modulus_size, UINT8 *public_exponent, UINT32 *public_exponent_size)
 Exports an RSA public key from the given context. More...
 
M2MB_RESULT_E m2mb_crypto_rsa_public_key_import (M2MB_CRYPTO_RSA_CONTEXT ctx, const UINT8 *modulus, UINT32 modulus_size, const UINT8 *public_exponent, UINT32 public_exponent_size)
 Imports an RSA public key to the given context. More...
 
M2MB_RESULT_E m2mb_crypto_rsa_externalkey_import (M2MB_CRYPTO_RSA_CONTEXT ctx, const UINT8 *modulus, UINT32 modulus_size, const UINT8 *p_factor, UINT32 p_factor_size, const UINT8 *q_factor, UINT32 q_factor_size, const UINT8 *public_exponent, UINT32 public_exponent_size, const UINT8 *private_exponent, UINT32 private_exponent_size, M2MB_CRYPTO_RSA_PADDING_TYPE_E padding_type)
 Imports an externally generated RSA key pair into the context. More...
 
M2MB_RESULT_E m2mb_crypto_rsa_encrypt (M2MB_CRYPTO_RSA_CONTEXT ctx, M2MB_CRYPTO_RSA_MODE_E mode, SIZE_T inlen, const UINT8 *in, UINT8 *out)
 Generic RSA PKCS#1 encryption method. This function adds the message padding, then performs an RSA operation (encryption). More...
 
M2MB_RESULT_E m2mb_crypto_rsa_decrypt (M2MB_CRYPTO_RSA_CONTEXT ctx, M2MB_CRYPTO_RSA_MODE_E mode, SIZE_T *outlen, UINT8 *out, SIZE_T out_max_len, const UINT8 *in)
 Generic RSA PKCS#1 decryption method. This function performs an RSA operation (decryption), then removes the message padding. More...
 
M2MB_RESULT_E m2mb_crypto_rsa_sign (M2MB_CRYPTO_RSA_CONTEXT ctx, M2MB_CRYPTO_RSA_MODE_E mode, M2MB_CRYPTO_MD_ALG_E md_alg, UINT32 hashlen, const UINT8 *hash, UINT8 *sig)
 Generic RSA PKCS#1 signature creation method. The signature is created using the context key (created via the m2mb_crypto_rsa_generate_key()). More...
 
M2MB_RESULT_E m2mb_crypto_rsa_verify (M2MB_CRYPTO_RSA_CONTEXT ctx, UINT8 *pubkey, UINT32 pubkey_length, M2MB_CRYPTO_MD_ALG_E md_alg, UINT32 hashlen, const UINT8 *hash, const UINT8 *sig)
 Generic RSA PKCS#1 signature verification method. More...
 
M2MB_RESULT_E m2mb_crypto_ecc_init (M2MB_CRYPTO_ECC_CONTEXT *ctx, M2MB_CRYPTO_ECC_DOMAIN_GROUP_ID_E curve_domain_params)
 Allocates an M2MB_CRYPTO_ECC_CONTEXT structure. More...
 
M2MB_RESULT_E m2mb_crypto_ecc_dp_init (M2MB_CRYPTO_ECC_CONTEXT ctx, UINT8 *p, UINT8 *a, UINT8 *b, UINT8 *g_x, UINT8 *g_y, UINT8 *n, UINT32 *h)
 Allocates an M2MB_CRYPTO_ECC_CONTEXT structure. More...
 
M2MB_RESULT_E m2mb_crypto_ecc_dp_import (M2MB_CRYPTO_ECC_CONTEXT ctx, M2MB_CRYPTO_ECC_DP_E domain, UINT32 len, const UINT8 *param)
 Imports an ECC Domain Parameter to the given context. More...
 
M2MB_RESULT_E m2mb_crypto_ecdsa_sign (M2MB_CRYPTO_ECC_CONTEXT ctx, UINT8 *msg, UINT32 msg_len, UINT8 *sig, SIZE_T sig_len)
 ECDSA signature function. More...
 
M2MB_RESULT_E m2mb_crypto_ecdsa_verify (M2MB_CRYPTO_ECC_CONTEXT ctx, UINT8 *msg, UINT32 msg_len, M2MB_CRYPTO_ECC_AFFINE_POINT_T *pubkey, UINT8 *sig, SIZE_T sig_len)
 ECDSA signature verification function. More...
 
M2MB_RESULT_E m2mb_crypto_ecdh_shared_key_derive (M2MB_CRYPTO_ECC_CONTEXT ctx, UINT8 *shared_keyblob, UINT16 *shared_keyblob_len, const M2MB_CRYPTO_ECC_AFFINE_POINT_T *pubkey)
 Function to derive the shared key for the DH algorithm. More...
 
M2MB_RESULT_E m2mb_crypto_ecc_keypair_generate (M2MB_CRYPTO_ECC_CONTEXT ctx)
 Function to generate an ECC keypair. More...
 
M2MB_RESULT_E m2mb_crypto_ecc_keyblob_export (M2MB_CRYPTO_ECC_CONTEXT ctx, UINT8 *keyblob, UINT16 *keyblob_length)
 Exports an ECC key pair blob from the given context. The blob is encrypted with a device specific key and can only be used on the same HW originating it. More...
 
M2MB_RESULT_E m2mb_crypto_ecc_keyblob_import (M2MB_CRYPTO_ECC_CONTEXT ctx, const UINT8 *keyblob, UINT32 keyblob_length)
 Imports an ECC key pair keyblob into the context. More...
 
M2MB_RESULT_E m2mb_crypto_ecc_public_key_export (M2MB_CRYPTO_ECC_CONTEXT ctx, M2MB_CRYPTO_ECC_AFFINE_POINT_T *pubkey)
 Exports an ECC public key from the given context. More...
 
M2MB_RESULT_E m2mb_crypto_ecc_public_key_import (M2MB_CRYPTO_ECC_CONTEXT ctx, const M2MB_CRYPTO_ECC_AFFINE_POINT_T *pubkey)
 Imports an ECC public key to the given context. More...
 
M2MB_RESULT_E m2mb_crypto_ecc_private_key_import (M2MB_CRYPTO_ECC_CONTEXT ctx, const UINT8 *privkey, UINT16 privkey_len)
 Imports an ECC private key to the given context. More...
 
M2MB_RESULT_E m2mb_crypto_ecc_deinit (M2MB_CRYPTO_ECC_CONTEXT ctx)
 Free an M2MB_CRYPTO_ECC_CONTEXT structure. More...
 
UINT32 m2mb_crypto_prng_get_data (UINT8 *prng_data, UINT32 prng_data_len)
 Generates prng data. More...
 

Detailed Description

Crypto APIs implementation.

m2m/m2m_generic/common/m2mb_inc/m2mb_crypto.h

Crypto apis including hash, hmac, asymmetric & symmetric key operations

@notes Dependencies: m2mb_types.h

Author
Tiran Kaskas, Alessandro Papagno
Date
10/09/2017

Function Documentation

◆ m2mb_crypto_ctx_info_for_tee()

UINT32 m2mb_crypto_ctx_info_for_tee ( M2MB_CRYPTO_GEN_CONTEXT  ctx,
UINT8 *  info 
)

Returns the context ID for the given context structure.

This function returns the context ID for the given context structure, as the structure is opaque.

Parameters
[in]ctxPointer to a context structure.
[out]infoPointer to return the context id. Must be allocated by caller. If set to NULL, the function will return the size required for the info.
Returns
The required size of the info buffer.

◆ m2mb_crypto_get_algo()

M2MB_CRYPTO_CTX_ALG_E m2mb_crypto_get_algo ( M2MB_CRYPTO_GEN_CONTEXT  ctx)

Returns the Crypto algorithm.

This function returns an enum that indicates what algorithm was used to initialize it.

Parameters
[in]ctxPointer to a context structure.
Returns
M2MB_CRYPTO_CTX_ALG_E

◆ m2mb_crypto_hmac()

UINT8* m2mb_crypto_hmac ( M2MB_CRYPTO_MD_ALG_E  md_info,
const UINT8 *  key,
const SIZE_T  keylen,
const UINT8 *  input,
const SIZE_T  inlen,
UINT8 *  hmac 
)

This function will compute the HMAC in one shot without needing any context.

This function is used to calculate an HMAC for a given data, key & hash algorithm. If hmac is NULL, the HMAC is placed in a static array. This function is similar to running the following function flow: m2mb_crypto_hmac_init(); m2mb_crypto_hmac_setup(); m2mb_crypto_hmac_update(); m2mb_crypto_hmac_final(); m2mb_crypto_hmac_deinit();

Parameters
[in]md_infoThe hash algorithm to use for the HMAC
[in]keyThe symmetric key to use for the HMAC
[in]keylenThe length of the provided key in bytes
[in]inputBuffer holding the data to compute HMAC for
[in]inlenlength of the provided data
[out]hmacThe calculated HMAC
Returns
if hmac is provided returned value equal to hmac in case of success
If hmac is NULL, returns a pointer to a static array containing the HMAC in case of success
NULL in case of fail
Note
Setting hmac to NULL is not thread safe.

◆ m2mb_crypto_hmac_deinit()

M2MB_RESULT_E m2mb_crypto_hmac_deinit ( M2MB_CRYPTO_HMAC_CONTEXT  ctx)

This function free an HMAC context releasing the associated resources.

This function release the provided context memory.

Parameters
[in]ctxPointer to a previously initialized context structure to free
Returns
M2MB_RESULT_SUCCESS on success
see M2MB_RESULT_E for different values in case of fail
Note

◆ m2mb_crypto_hmac_final()

M2MB_RESULT_E m2mb_crypto_hmac_final ( M2MB_CRYPTO_HMAC_CONTEXT  ctx,
UINT8 *  hmac 
)

This function computes the final HMAC for all previously provided messages for the given context.

This function is the final step for HMAC calculation. It returns the calculated HMAC based on all the previous messages (sent via m2mb_crypto_hmac_update)

Parameters
[in]ctxA previously allocated hmac context. The context setup must be also done before using this function (using m2mb_crypto_hmac_setup)
[out]hmacThe calculated hmac. Must be large enough to hold the HMAC for the selected message digest algorithm used during setup.
Returns
M2MB_RESULT_SUCCESS on success
see M2MB_RESULT_E for different values in case of fail
Note

◆ m2mb_crypto_hmac_init()

M2MB_RESULT_E m2mb_crypto_hmac_init ( M2MB_CRYPTO_HMAC_CONTEXT ctx)

Opaque structure for context.

Allocates a M2MB_CRYPTO_HMAC_CONTEXT structure

This function allocates an HMAC context to be later used by any HMAC function.

Parameters
[in]ctxPointer to a context structure to be allocated by this function. Any consecutive call to HMAC function must use the context.
Returns
M2MB_RESULT_SUCCESS on success
see M2MB_RESULT_E for different values in case of fail
Note

◆ m2mb_crypto_hmac_reset()

M2MB_RESULT_E m2mb_crypto_hmac_reset ( M2MB_CRYPTO_HMAC_CONTEXT  ctx)

Prepare to run HMAC for a new message reusing the context.

Resets all previously provided messages. The same key & hash algorithm provided to m2mb_crypto_hmac_setup() remains and will be used for new HMAC. Usually used after m2mb_crypto_hmac_final() and before m2mb_crypto_hmac_update()

Parameters
[in]ctxPointer to a previously allocated context structure to reset
Returns
M2MB_RESULT_SUCCESS on success
see M2MB_RESULT_E for different values in case of fail
Note

◆ m2mb_crypto_hmac_setup()

M2MB_RESULT_E m2mb_crypto_hmac_setup ( M2MB_CRYPTO_HMAC_CONTEXT  ctx,
M2MB_CRYPTO_MD_ALG_E  md_info,
const UINT8 *  key,
SIZE_T  keylen 
)

Sets up an M2MB_CRYPTO_HMAC_CONTEXT structure.

This function performs setup of a HMAC context providing the hash algorithm to use and the symmetric key. Usually comes after m2mb_crypto_hmac_init() or m2mb_crypto_hmac_final(). Might also be called after m2mb_crypto_hmac_update() in order to restart the digest process.

Parameters
[in]ctxPointer to a previously allocated context structure
[in]md_infoThe hash algorithm to use for the HMAC
[in]keyThe symmetric key to use for the hmac
[in]keylenThe length of the provided key in bytes
Returns
M2MB_RESULT_SUCCESS on success
see M2MB_RESULT_E for different values in case of fail
Note
It is under user responsibility the correct use of keylen, conformed with M2MB_CRYPTO_MD_ALG_E, for key pointer

◆ m2mb_crypto_hmac_update()

M2MB_RESULT_E m2mb_crypto_hmac_update ( M2MB_CRYPTO_HMAC_CONTEXT  ctx,
const UINT8 *  data,
SIZE_T  len 
)

Continuously HMAC of data. This function can be called repeatedly similar to streaming.

This function is used to continuosly hash data (streaming data when not all buffer to be hashed is available in one shot). This function can be called repeatedly.

Parameters
[in]ctxA previously allocated hmac context. The context setup must be also done before using this function (using m2mb_crypto_hmac_setup)
[in]dataBuffer pointer holding the data as start of hmacking
[in]lenlength of the provided data
Returns
M2MB_RESULT_SUCCESS on success
see M2MB_RESULT_E for different values in case of fail
Note

◆ m2mb_crypto_md()

UINT8* m2mb_crypto_md ( const M2MB_CRYPTO_MD_ALG_E  md_info,
const UINT8 *  data,
SIZE_T  len,
UINT8 *  md 
)

This function will compute the message digest in one shot, in case of limited and available size of data.

This function is used to create a message digest for a given data. It will compute the required message digest of <len> bytes from <data> and places it in md. If md is NULL, the digest is placed in a static array which address is provided on return. This function is similar of running the following function flow in one shot: m2mb_crypto_md_init(); m2mb_crypto_md_setup(); m2mb_crypto_md_update(); m2mb_crypto_md_final(); m2mb_crypto_md_deinit();

Parameters
[in]md_infoThe message digest method to use.
[in]dataPointer to the data to hash
[in]lenlength of the data to hash
[out]mdMessage digest array to be returned from the hash function. Must be large enough to hold the result message digest based on the hash algorithm used.
Returns
if md is provided returned value equal to md in case of success
If md is NULL, returns a pointer to a static array containing the message digest in case of success
NULL in case of fail
Note
Setting md to NULL is not thread safe.

◆ m2mb_crypto_md_deinit()

M2MB_RESULT_E m2mb_crypto_md_deinit ( M2MB_CRYPTO_MD_CONTEXT  ctx)

This function frees an MD context.

This function free the provided context. No further use of the context shall be made.

Parameters
[in]ctxPointer to a previously allocated context structure to be free.
Returns
M2MB_RESULT_SUCCESS on success
see M2MB_RESULT_E for different values in case of fail
Note

◆ m2mb_crypto_md_final()

M2MB_RESULT_E m2mb_crypto_md_final ( M2MB_CRYPTO_MD_CONTEXT  ctx,
UINT8 *  md 
)

This function computes the final digest for the hash process.

This function is the final step for digest calculation in a streaming mode. It will return the calculated digest based on all the previous messages (sent via m2mb_crypto_md_update)

Parameters
[in]ctxPointer to a previously initialized context structure
[in]mdMessage digest array to be returned from the hash function. Must be large enough to hold the result message digest based on the hash algorithm used.
Returns
M2MB_RESULT_SUCCESS on success
see M2MB_RESULT_E for different values in case of fail
Note

◆ m2mb_crypto_md_init()

M2MB_RESULT_E m2mb_crypto_md_init ( M2MB_CRYPTO_MD_CONTEXT ctx)

Allocates an M2MB_CRYPTO_MD_CONTEXT structure.

This function allocates an MD context to be later used by any MD function.

Parameters
[in]ctxPointer to a context structure to be allocated by this function. Any consecutive call to MD function must use the context.
Returns
M2MB_RESULT_SUCCESS on success
see M2MB_RESULT_E for different values in case of fail
Note
Context must be free via a call to m2mb_crypto_md_deinit().

◆ m2mb_crypto_md_setup()

M2MB_RESULT_E m2mb_crypto_md_setup ( M2MB_CRYPTO_MD_CONTEXT  ctx,
const M2MB_CRYPTO_MD_ALG_E  md_info 
)

Sets up a M2MB_CRYPTO_MD_CONTEXT structure.

This function performs setup of a MD context to be later used by any MD function.

Parameters
[in]ctxPointer to a previously allocated context structure
[in]md_infoThe message digest method to use.
Returns
M2MB_RESULT_SUCCESS on success
see M2MB_RESULT_E for different values in case of fail
Note
Has typicalli to be used after m2mb_crypto_md_init call, to set up the handler

◆ m2mb_crypto_md_update()

M2MB_RESULT_E m2mb_crypto_md_update ( M2MB_CRYPTO_MD_CONTEXT  ctx,
const UINT8 *  data,
SIZE_T  len 
)

Continuously hashing of data. This function should be called repeatedly with chunks of the message to be hashed (len bytes from data).

This function is used to continuosly hash data (streaming data when not all buffer to be hashed is available in one shot). This function should be called repeatedly with chunks of the message to be hashed (len bytes from data).

Parameters
[in]ctxPointer to a previously allocated context structure
[in]dataPointer of the starting data to hash
[in]lenlength of the data to hash
Returns
M2MB_RESULT_SUCCESS on success
see M2MB_RESULT_E for different values in case of fail
Note