OPTIGA Trust M  1.1.0
C++ library for Optiga Trust M Chip Security Controller
pal_crypt_mbedtls.c File Reference

This file implements the platform abstraction layer APIs for cryptographic functions using mbedTLS SW Crypto. More...

Include dependency graph for pal_crypt_mbedtls.c:

Macros

#define PAL_CRYPT_DIGEST_MAX_SIZE   (32U)
 
#define AES128_KEY_BITS_SIZE   (16U)
 
#define MAC_TAG_BUFFER_SIZE   (16U)
 
#define AES128_KEY_BITS_SIZE   (16U)
 
#define PAL_CRYPT_MAX_LABEL_SEED_LENGTH   (96U)
 
pal_status_t pal_crypt_tls_prf_sha256 (pal_crypt_t *p_pal_crypt, const uint8_t *p_secret, uint16_t secret_length, const uint8_t *p_label, uint16_t label_length, const uint8_t *p_seed, uint16_t seed_length, uint8_t *p_derived_key, uint16_t derived_key_length)
 Derives the key using the TLS PRF SHA256 for a given secret. More...
 
pal_status_t pal_crypt_encrypt_aes128_ccm (pal_crypt_t *p_pal_crypt, const uint8_t *p_plain_text, uint16_t plain_text_length, const uint8_t *p_encrypt_key, const uint8_t *p_nonce, uint16_t nonce_length, const uint8_t *p_associated_data, uint16_t associated_data_length, uint8_t mac_size, uint8_t *p_cipher_text)
 Encrypts the input plain text using AES CCM algorithm and provides the cipher text as well as MAC into output buffer. More...
 
pal_status_t pal_crypt_decrypt_aes128_ccm (pal_crypt_t *p_pal_crypt, const uint8_t *p_cipher_text, uint16_t cipher_text_length, const uint8_t *p_decrypt_key, const uint8_t *p_nonce, uint16_t nonce_length, const uint8_t *p_associated_data, uint16_t associated_data_length, uint8_t mac_size, uint8_t *p_plain_text)
 Decrypts the cipher text using AES CCM algorithm and provides the plain text. More...
 
pal_status_t pal_crypt_version (uint8_t *p_crypt_lib_version_info, uint16_t *length)
 Gets the external crypto library version number. More...
 

Detailed Description

This file implements the platform abstraction layer APIs for cryptographic functions using mbedTLS SW Crypto.

Copyright (c) 2019 Infineon Technologies AG

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE

\endcopyright

Author
Infineon Technologies AG

Macro Definition Documentation

◆ AES128_KEY_BITS_SIZE [1/2]

#define AES128_KEY_BITS_SIZE   (16U)

◆ AES128_KEY_BITS_SIZE [2/2]

#define AES128_KEY_BITS_SIZE   (16U)

◆ MAC_TAG_BUFFER_SIZE

#define MAC_TAG_BUFFER_SIZE   (16U)

◆ PAL_CRYPT_DIGEST_MAX_SIZE

#define PAL_CRYPT_DIGEST_MAX_SIZE   (32U)

◆ PAL_CRYPT_MAX_LABEL_SEED_LENGTH

#define PAL_CRYPT_MAX_LABEL_SEED_LENGTH   (96U)

Function Documentation

◆ pal_crypt_decrypt_aes128_ccm()

pal_status_t pal_crypt_decrypt_aes128_ccm ( pal_crypt_t p_pal_crypt,
const uint8_t *  p_cipher_text,
uint16_t  cipher_text_length,
const uint8_t *  p_decrypt_key,
const uint8_t *  p_nonce,
uint16_t  nonce_length,
const uint8_t *  p_associated_data,
uint16_t  associated_data_length,
uint8_t  mac_size,
uint8_t *  p_plain_text 
)

Decrypts the cipher text using AES CCM algorithm and provides the plain text.

Decrypts the cipher text using AES CCM algorithm and provides the plain text.

  • Decrypts the cipher text using the provided decryption key, nonce and associated data
  • This operation validates the MAC internally and provided the plain text if the MAC is successfully validated.
Precondition
  • None
Note
  • If mac_size is set to 8 AES128_CCM_8 algorithm will be used for decryption.
  • If mac_size is set to 16 AES128_CCM algorithm will be used for decryption.
Parameters
[in]p_pal_cryptCrypt context
[in]p_cipher_textValid pointer to the Cipher text + MAC data.
[in]cipher_text_lengthCipher text data size.
[in]p_decrypt_keyValid pointer to decrypt key.
[in]p_nonceValid pointer to Nonce data.
[in]nonce_lengthNonce size.
[in]p_associated_dataValid pointer to Associated data.
[in]associated_data_lengthAssociated data size.
[in]mac_sizeLength of MAC data.
[in,out]p_plain_textValid pointer to store plain text. Buffer length must be at-least Cipher_text_length - mac_size.
Return values
PAL_STATUS_SUCCESSIn case of success
PAL_STATUS_FAILUREIn case of failure
Here is the call graph for this function:

◆ pal_crypt_encrypt_aes128_ccm()

pal_status_t pal_crypt_encrypt_aes128_ccm ( pal_crypt_t p_pal_crypt,
const uint8_t *  p_plain_text,
uint16_t  plain_text_length,
const uint8_t *  p_encrypt_key,
const uint8_t *  p_nonce,
uint16_t  nonce_length,
const uint8_t *  p_associated_data,
uint16_t  associated_data_length,
uint8_t  mac_size,
uint8_t *  p_cipher_text 
)

Encrypts the input plain text using AES CCM algorithm and provides the cipher text as well as MAC into output buffer.

Encrypts the input plain text using AES CCM algorithm and provides the cipher text as well as MAC into output buffer.

  • Encrypts the given plain text using the provided encryption key, nonce and associated data.
Precondition
  • None
Note
  • If mac_size is set to 8 AES128_CCM_8 algorithm will be used for encryption.
  • If mac_size is set to 16 AES128_CCM algorithm will be used for encryption.
Parameters
[in]p_pal_cryptCrypt context
[in]p_plain_textValid pointer to plain text data.
[in]plain_text_lengthPlain text data size.
[in]p_encrypt_keyValid pointer to Encrypt key .
[in]p_nonceValid pointer to Nonce data.
[in]nonce_lengthNonce data size.
[in]p_associated_dataValid pointer to Associated data.
[in]associated_data_lengthAssociated data size.
[in]mac_sizeLength of expected MAC data.
[in,out]p_cipher_textValid pointer to store cipher text and MAC output. Buffer length must be at-least plain_text_length + MAC mac_size.
Return values
PAL_STATUS_SUCCESSIn case of success
PAL_STATUS_FAILUREIn case of failure
Here is the call graph for this function:

◆ pal_crypt_tls_prf_sha256()

pal_status_t pal_crypt_tls_prf_sha256 ( pal_crypt_t p_pal_crypt,
const uint8_t *  p_secret,
uint16_t  secret_length,
const uint8_t *  p_label,
uint16_t  label_length,
const uint8_t *  p_seed,
uint16_t  seed_length,
uint8_t *  p_derived_key,
uint16_t  derived_key_length 
)

Derives the key using the TLS PRF SHA256 for a given secret.

Derives the key using the TLS PRF SHA256 for a given secret.

  • Derives a key using the user provided secret.
Precondition
  • None
Note
  • None
Parameters
[in]p_pal_cryptCrypt context
[in]p_secretValid pointer to input shared secret.
[in]secret_lengthLength of the shared secret.
[in]p_labelValid pointer to Label for PRF calculation.
[in]label_lengthLabel length.
[in]p_seedValid pointer to the buffer which contains seed.
[in]seed_lengthseed length.
[in,out]p_derived_keyValid pointer to the buffer where PRF output to be saved.
[in]derived_key_lengthLength of the key to be derived from secret.
Return values
PAL_STATUS_SUCCESSIn case of success
PAL_STATUS_FAILUREIn case of failure
Here is the call graph for this function:

◆ pal_crypt_version()

pal_status_t pal_crypt_version ( uint8_t *  p_crypt_lib_version_info,
uint16_t *  length 
)

Gets the external crypto library version number.

Gets the external crypto library version number.

Precondition
  • None
Note
  • Format of version information : vX.Y.Z
  • mbedTLS Version: vX.Y.Z
Parameters
[in,out]p_crypt_lib_version_infoValid pointer to store the version number.
[in,out]lengthversion number size.
Return values
PAL_STATUS_SUCCESSIn case of success
PAL_STATUS_FAILUREIn case of failure