Microchip® Advanced Software Framework

lorawan/sal/inc/sal.h File Reference

Macros

#define SAL_EUI_LEN   8
 
#define SAL_ITEMS_NUM   SAL_MAX_ITEMS
 
#define SAL_KEY_LEN   16
 

Typedefs

typedef enum _salItems salItems_t
 
typedef enum _SalStatus SalStatus_t
 

Enumerations

enum  _salItems {
  SAL_APP_KEY = 0x00,
  SAL_APPS_KEY = 0x01,
  SAL_NWKS_KEY = 0x02,
  SAL_MCAST_APPS_KEY = 0x03,
  SAL_MCAST_NWKS_KEY = 0x04,
  SAL_KEY_ENC_KEY = 0x05,
  SAL_JOIN_EUI = 0x06,
  SAL_DEV_EUI = 0x07,
  SAL_MAX_ITEMS
}
 
enum  _SalStatus {
  SAL_SUCCESS = 0x00,
  SAL_FAILURE = 0x01,
  SAL_INVALID_KEY_TYPE = 0x02
}
 

Functions

SalStatus_t SAL_AESCmac (uint8_t *key, salItems_t key_type, uint8_t *output, uint8_t *input, uint16_t size)
 This function calculates the CMAC value using the key specified. More...
 
SalStatus_t SAL_AESEncode (unsigned char *buffer, salItems_t key_type, unsigned char *key)
 This function encrypts the given block of data with the key specified/the key stored in ECC608A. More...
 
SalStatus_t SAL_DeriveSessionKey (unsigned char *block, salItems_t src_key, unsigned char *key, salItems_t target_key)
 This function derives the session key using the Block of data given as input. More...
 
SalStatus_t SAL_Init (void)
 This function initializes the security modules like AES, ECC608 (If used) More...
 
SalStatus_t SAL_Read (salItems_t key_type, uint8_t *key)
 This function reads back the keys from ECC608 device using Encrypted Read. More...
 

#define SAL_EUI_LEN   8

Referenced by SAL_Read().

#define SAL_ITEMS_NUM   SAL_MAX_ITEMS
#define SAL_KEY_LEN   16

typedef enum _salItems salItems_t
typedef enum _SalStatus SalStatus_t

enum _salItems
Enumerator
SAL_APP_KEY 
SAL_APPS_KEY 
SAL_NWKS_KEY 
SAL_MCAST_APPS_KEY 
SAL_MCAST_NWKS_KEY 
SAL_KEY_ENC_KEY 
SAL_JOIN_EUI 
SAL_DEV_EUI 
SAL_MAX_ITEMS 
enum _SalStatus
Enumerator
SAL_SUCCESS 
SAL_FAILURE 
SAL_INVALID_KEY_TYPE 

SalStatus_t SAL_AESCmac ( uint8_t *  key,
salItems_t  key_type,
uint8_t *  output,
uint8_t *  input,
uint16_t  size 
)

This function calculates the CMAC value using the key specified.

Parameters
[in]*key- Pointer to the key which is used for calculating CMAC value for the given buffer (AppKey/NwkSKey/AppSKey)
[in]key_type- value of type salItems_t - Name of the key which is used to calculate the CMAC (Note: This parameter is used when key is stored in ECC608)
[out]*output- Pointer to the 16bytes CMAC value
[in]*input- Pointer to the data for which CMAC value is being calculated
[in]size- Length of the data for which CMAC value is being calculated
Returns
value of type SalStatus_t SAL_SUCCESS – when CMAC calculation is successful SAL_FAILURE – when CMAC calculation is failed SAL_INVALID_KEY_TYPE – when invalid key_type is given as input parameter

References flag, i, j, NULL, ptr, SAL_AESEncode(), sal_GenerateSubkey(), and SAL_SUCCESS.

SalStatus_t SAL_AESEncode ( unsigned char *  buffer,
salItems_t  key_type,
unsigned char *  key 
)

This function encrypts the given block of data with the key specified/the key stored in ECC608A.

Parameters
[in]*buffer- pointer to block of data to be encrypted
[in]key_type- Name of the key which is used to encrypt the data (Note: This parameter is used when Key is stored in ECC608)
[in]*key- Pointer to the key used for Encryption (Note: This parameter is used when Key is provided by the upper layer)
Returns
value of type SalStatus_t SAL_SUCCESS – when encryption is successful SAL_FAILURE – when encryption is failed SAL_INVALID_KEY_TYPE – when invalid key_type is given as input parameter

References AESEncode(), SAL_APP_KEY, SAL_APPS_KEY, SAL_FAILURE, SAL_INVALID_KEY_TYPE, SAL_MCAST_APPS_KEY, SAL_MCAST_NWKS_KEY, SAL_NWKS_KEY, and SAL_SUCCESS.

Referenced by SAL_AESCmac(), SAL_DeriveSessionKey(), and sal_GenerateSubkey().

SalStatus_t SAL_DeriveSessionKey ( unsigned char *  block,
salItems_t  src_key,
unsigned char *  key,
salItems_t  target_key 
)

This function derives the session key using the Block of data given as input.

Parameters
[in]*block- pointer to block of data (16 Bytes) used for deriving the session key
[in]src_key- value of type salItems_t - Name of the key which is used to derive the session key (Note: This parameter is used when src_key is stored in ECC608)
[in]target_key- value of type salItems_t - Name of the Derived Session Key (NwkSKey/AppSKey)
[out]*key- Pointer to the derived key (NwkSKey/AppSKey) (Note: Incase ECC608 is used as Keystorage device, Session keys will be directly stored in the memory slots and this pointer will be invalid in that case)
Returns
value of type SalStatus_t SAL_SUCCESS – when Session key derivation is successful SAL_FAILURE – when Session key derivation is failed SAL_INVALID_KEY_TYPE – when invalid key_type is given as input parameter

References NULL, SAL_AESEncode(), SAL_APP_KEY, SAL_FAILURE, and SAL_SUCCESS.

SalStatus_t SAL_Init ( void  )

This function initializes the security modules like AES, ECC608 (If used)

Returns
value of type SalStatus_t SAL_SUCCESS – when initialization is successful SAL_FAILURE – when initialization of AES/ECC608 is failed

References AESInit(), and SAL_SUCCESS.

SalStatus_t SAL_Read ( salItems_t  key_type,
uint8_t *  key 
)

This function reads back the keys from ECC608 device using Encrypted Read.

Parameters
[in]key_type- value of type salItems_t - Name of the key which is being read back from ECC608
[in]*key- Pointer to the key which is read back from ECC608
Returns
value of type SalStatus_t SAL_SUCCESS – when the key is successfully read back from ECC608 device SAL_FAILURE – when the read function got failed SAL_INVALID_KEY_TYPE – when invalid key_type is given as input parameter

This function reads back the keys from ECC608 device using Encrypted Read.

Parameters
[in]key_type- value of type salItems_t - Name of the key which is being read back from ECC608
[in]*key- Pointer to the key which is read back from ECC608
Returns
value of type SalStatus_t SAL_SUCCESS – when the key is successfully read back from ECC608 device SAL_FAILURE – when the read function got failed SAL_INVALID_KEY_TYPE – when invalid key_type is given as input parameter

References SAL_APPS_KEY, SAL_DEV_EUI, SAL_EUI_LEN, SAL_FAILURE, SAL_INVALID_KEY_TYPE, SAL_JOIN_EUI, SAL_MCAST_APPS_KEY, SAL_MCAST_NWKS_KEY, SAL_NWKS_KEY, and SAL_SUCCESS.