CryptoAuthLib v3.9.0
Microchip CryptoAuthentication Library
 
Loading...
Searching...
No Matches
Basic Crypto API methods (atcab_)

These methods provide the most convenient, simple API to CryptoAuth chips. More...

Macros

#define atcab_get_addr(...)   calib_get_addr(__VA_ARGS__)
 
#define atca_execute_command(...)   calib_execute_command(__VA_ARGS__)
 

Functions

ATCA_STATUS atcab_version (char *ver_str)
 basic API methods are all prefixed with atcab_ (CryptoAuthLib Basic) the fundamental premise of the basic API is it is based on a single interface instance and that instance is global, so all basic API commands assume that one global device is the one to operate on.
 
ATCA_STATUS atcab_init_ext (ATCADevice *device, ATCAIfaceCfg *cfg)
 Creates and initializes a ATCADevice context.
 
ATCA_STATUS atcab_init (ATCAIfaceCfg *cfg)
 Creates a global ATCADevice object used by Basic API.
 
ATCA_STATUS atcab_init_device (ATCADevice ca_device)
 Initialize the global ATCADevice object to point to one of your choosing for use with all the atcab_ basic API.
 
ATCA_STATUS atcab_release_ext (ATCADevice *device)
 release (free) the an ATCADevice instance.
 
ATCA_STATUS atcab_release (void)
 release (free) the global ATCADevice instance. This must be called in order to release or free up the interface.
 
ATCADevice atcab_get_device (void)
 Get the global device object.
 
ATCADeviceType atcab_get_device_type_ext (ATCADevice device)
 Get the selected device type of rthe device context.
 
ATCADeviceType atcab_get_device_type (void)
 Get the current device type configured for the global ATCADevice.
 
uint8_t atcab_get_device_address (ATCADevice device)
 Get the current device address based on the configured device and interface.
 
bool atcab_is_ca_device (ATCADeviceType dev_type)
 Check whether the device is cryptoauth device.
 
bool atcab_is_ca2_device (ATCADeviceType dev_type)
 Check whether the device is cryptoauth device.
 
bool atcab_is_ta_device (ATCADeviceType dev_type)
 Check whether the device is Trust Anchor device.
 

Variables

ATCADevice g_atcab_device_ptr
 
ATCA_STATUS atcab_bin2hex (const uint8_t *bin, size_t bin_size, char *hex, size_t *hex_size)
 Convert a binary buffer to a hex string for easy reading.
 
ATCA_STATUS atcab_bin2hex_ (const uint8_t *bin, size_t bin_size, char *hex, size_t *hex_size, bool is_pretty, bool is_space, bool is_upper)
 Function that converts a binary buffer to a hex string suitable for easy reading.
 
ATCA_STATUS atcab_hex2bin (const char *ascii_hex, size_t ascii_hex_len, uint8_t *binary, size_t *bin_len)
 Function that converts a hex string to binary buffer.
 
ATCA_STATUS atcab_hex2bin_ (const char *hex, size_t hex_size, uint8_t *bin, size_t *bin_size, bool is_space)
 
ATCA_STATUS packHex (const char *ascii_hex, size_t ascii_hex_len, char *packed_hex, size_t *packed_len)
 Remove spaces from a ASCII hex string.
 
bool isDigit (char c)
 Checks to see if a character is an ASCII representation of a digit ((c ge '0') and (c le '9'))
 
bool isBlankSpace (char c)
 Checks to see if a character is blank space.
 
bool isAlpha (char c)
 Checks to see if a character is an ASCII representation of hex ((c >= 'A') and (c <= 'F')) || ((c >= 'a') and (c <= 'f'))
 
bool isHexAlpha (char c)
 Checks to see if a character is an ASCII representation of hex ((c >= 'A') and (c <= 'F')) || ((c >= 'a') and (c <= 'f'))
 
bool isHex (char c)
 Returns true if this character is a valid hex character or if this is blankspace (The character can be included in a valid hexstring).
 
bool isHexDigit (char c)
 Returns true if this character is a valid hex character.
 
bool isBase64 (char c, const uint8_t *rules)
 Returns true if this character is a valid base 64 character or if this is space (A character can be included in a valid base 64 string).
 
bool isBase64Digit (char c, const uint8_t *rules)
 Returns true if this character is a valid base 64 character.
 
const uint8_t * atcab_b64rules_default (void)
 
const uint8_t * atcab_b64rules_mime (void)
 
const uint8_t * atcab_b64rules_urlsafe (void)
 
ATCA_STATUS atcab_base64decode_ (const char *encoded, size_t encoded_size, uint8_t *data, size_t *data_size, const uint8_t *rules)
 Decode base64 string to data with ruleset option.
 
ATCA_STATUS atcab_base64encode (const uint8_t *byte_array, size_t array_len, char *encoded, size_t *encoded_len)
 Encode data as base64 string.
 
ATCA_STATUS atcab_base64encode_ (const uint8_t *data, size_t data_size, char *encoded, size_t *encoded_size, const uint8_t *rules)
 Encode data as base64 string with ruleset option.
 
ATCA_STATUS atcab_base64decode (const char *encoded, size_t encoded_len, uint8_t *byte_array, size_t *array_len)
 Decode base64 string to data.
 
ATCA_STATUS atcab_reversal (const uint8_t *bin, size_t bin_size, uint8_t *dest, size_t *dest_size)
 To reverse the input data.
 
int atcab_memset_s (void *dest, size_t destsz, int ch, size_t count)
 Guaranteed to perform memory writes regardless of optimization level. Matches memset_s signature.
 
size_t atcab_pointer_delta (const void *start, const void *end)
 Helper function to calculate the number of bytes between two pointers.
 
char lib_toupper (char c)
 Converts a character to uppercase.
 
char lib_tolower (char c)
 Converts a character to lowercase.
 
#define IS_ADD_SAFE_UINT16_T(a, b)   (((UINT16_MAX - (a)) >= (b)) ? true : false)
 
#define IS_ADD_SAFE_UINT32_T(a, b)   (((UINT32_MAX - (a)) >= (b)) ? true : false)
 
#define IS_ADD_SAFE_UINT64_T(a, b)   (((UINT64_MAX - (a)) >= (b)) ? true : false)
 
#define IS_ADD_SAFE_SIZE_T(a, b)   (((SIZE_MAX - (a)) >= (b)) ? true : false)
 
#define IS_MUL_SAFE_UINT16_T(a, b)   ((((a) <= UINT16_MAX / (b))) ? true : false)
 
#define IS_MUL_SAFE_UINT32_T(a, b)   ((((a) <= UINT32_MAX / (b))) ? true : false)
 
#define IS_MUL_SAFE_UINT64_T(a, b)   ((((a) <= UINT64_MAX / (b))) ? true : false)
 
#define IS_MUL_SAFE_SIZE_T(a, b)   ((((a) <= SIZE_MAX / (b))) ? true : false)
 
#define ABS_VAL(x)   (((x) < 0) ? -(x) : (x))
 

Detailed Description

These methods provide the most convenient, simple API to CryptoAuth chips.

Function Documentation

◆ atcab_base64decode()

ATCA_STATUS atcab_base64decode ( const char *  encoded,
size_t  encoded_len,
uint8_t *  byte_array,
size_t *  array_len 
)

Decode base64 string to data.

Parameters
[in]encodedBase64 string to be decoded.
[in]encoded_lenSize of the base64 string in bytes.
[out]byte_arrayDecoded data will be returned here.
[in,out]array_lenAs input, the size of the byte_array buffer. As output, the length of the decoded data.
Returns
ATCA_SUCCESS on success, otherwise an error code.

◆ atcab_base64decode_()

ATCA_STATUS atcab_base64decode_ ( const char *  encoded,
size_t  encoded_size,
uint8_t *  data,
size_t *  data_size,
const uint8_t *  rules 
)

Decode base64 string to data with ruleset option.

Parameters
[in]encodedBase64 string to be decoded.
[in]encoded_sizeSize of the base64 string in bytes.
[out]dataDecoded data will be returned here.
[in,out]data_sizeAs input, the size of the byte_array buffer. As output, the length of the decoded data.
[in]rulesbase64 ruleset to use

◆ atcab_base64encode()

ATCA_STATUS atcab_base64encode ( const uint8_t *  byte_array,
size_t  array_len,
char *  encoded,
size_t *  encoded_len 
)

Encode data as base64 string.

Parameters
[in]byte_arrayData to be encode in base64.
[in]array_lenSize of byte_array in bytes.
[in]encodedBase64 output is returned here.
[in,out]encoded_lenAs input, the size of the encoded buffer. As output, the length of the encoded base64 character string.
Returns
ATCA_SUCCESS on success, otherwise an error code.

◆ atcab_base64encode_()

ATCA_STATUS atcab_base64encode_ ( const uint8_t *  data,
size_t  data_size,
char *  encoded,
size_t *  encoded_size,
const uint8_t *  rules 
)

Encode data as base64 string with ruleset option.

Parameters
[in]dataThe input byte array that will be converted to base 64 encoded characters
[in]data_sizeThe length of the byte array
[in]encodedThe output converted to base 64 encoded characters.
[in,out]encoded_sizeInput: The size of the encoded buffer, Output: The length of the encoded base 64 character string
[in]rulesruleset to use during encoding

◆ atcab_bin2hex()

ATCA_STATUS atcab_bin2hex ( const uint8_t *  bin,
size_t  bin_size,
char *  hex,
size_t *  hex_size 
)

Convert a binary buffer to a hex string for easy reading.

Parameters
[in]binInput data to convert.
[in]bin_sizeSize of data to convert.
[out]hexBuffer that receives hex string.
[in,out]hex_sizeAs input, the size of the hex buffer. As output, the size of the output hex.
Returns
ATCA_SUCCESS on success, otherwise an error code.

◆ atcab_bin2hex_()

ATCA_STATUS atcab_bin2hex_ ( const uint8_t *  bin,
size_t  bin_size,
char *  hex,
size_t *  hex_size,
bool  is_pretty,
bool  is_space,
bool  is_upper 
)

Function that converts a binary buffer to a hex string suitable for easy reading.

Parameters
[in]binInput data to convert.
[in]bin_sizeSize of data to convert.
[out]hexBuffer that receives hex string.
[in,out]hex_sizeAs input, the size of the hex buffer. As output, the size of the output hex.
[in]is_prettyIndicates whether new lines should be added for pretty printing.
[in]is_spaceConvert the output hex with space between it.
[in]is_upperConvert the output hex to upper case.
Returns
ATCA_SUCCESS on success, otherwise an error code.

◆ atcab_get_device()

ATCADevice atcab_get_device ( void  )

Get the global device object.

Returns
instance of global ATCADevice

◆ atcab_get_device_address()

uint8_t atcab_get_device_address ( ATCADevice  device)

Get the current device address based on the configured device and interface.

Returns
the device address if applicable else 0xFF

◆ atcab_get_device_type()

ATCADeviceType atcab_get_device_type ( void  )

Get the current device type configured for the global ATCADevice.

Returns
Device type if basic api is initialized or ATCA_DEV_UNKNOWN.

◆ atcab_get_device_type_ext()

ATCADeviceType atcab_get_device_type_ext ( ATCADevice  device)

Get the selected device type of rthe device context.

Parameters
[in]deviceDevice context pointer
Returns
Device type if basic api is initialized or ATCA_DEV_UNKNOWN.

◆ atcab_hex2bin()

ATCA_STATUS atcab_hex2bin ( const char *  ascii_hex,
size_t  ascii_hex_len,
uint8_t *  binary,
size_t *  bin_len 
)

Function that converts a hex string to binary buffer.

Returns
ATCA_SUCCESS on success, otherwise an error code.
Parameters
[in]ascii_hexInput buffer to convert
[in]ascii_hex_lenLength of buffer to convert
[out]binaryBuffer that receives binary
[in,out]bin_lenAs input, the size of the bin buffer. As output, the size of the bin data.

◆ atcab_init()

ATCA_STATUS atcab_init ( ATCAIfaceCfg *  cfg)

Creates a global ATCADevice object used by Basic API.

Parameters
[in]cfgLogical interface configuration. Some predefined configurations can be found in atca_cfgs.h
Returns
ATCA_SUCCESS on success, otherwise an error code.

◆ atcab_init_device()

ATCA_STATUS atcab_init_device ( ATCADevice  ca_device)

Initialize the global ATCADevice object to point to one of your choosing for use with all the atcab_ basic API.

Deprecated:
This function is not recommended for use generally. Use of _ext is recommended instead. You can use atcab_init_ext to obtain an initialized instance and associated it with the global structure - but this shouldn't be a required process except in extremely unusual circumstances.
Parameters
[in]ca_deviceATCADevice instance to use as the global Basic API crypto device instance
Returns
ATCA_SUCCESS on success, otherwise an error code.

◆ atcab_init_ext()

ATCA_STATUS atcab_init_ext ( ATCADevice *  device,
ATCAIfaceCfg *  cfg 
)

Creates and initializes a ATCADevice context.

Parameters
[out]devicePointer to the device context pointer
[in]cfgLogical interface configuration. Some predefined configurations can be found in atca_cfgs.h
Returns
ATCA_SUCCESS on success, otherwise an error code.

◆ atcab_is_ca2_device()

bool atcab_is_ca2_device ( ATCADeviceType  dev_type)

Check whether the device is cryptoauth device.

Returns
True if device is cryptoauth device or False.

◆ atcab_is_ca_device()

bool atcab_is_ca_device ( ATCADeviceType  dev_type)

Check whether the device is cryptoauth device.

Returns
True if device is cryptoauth device or False.

◆ atcab_is_ta_device()

bool atcab_is_ta_device ( ATCADeviceType  dev_type)

Check whether the device is Trust Anchor device.

Returns
True if device is Trust Anchor device or False.

◆ atcab_release()

ATCA_STATUS atcab_release ( void  )

release (free) the global ATCADevice instance. This must be called in order to release or free up the interface.

Returns
Returns ATCA_SUCCESS .

◆ atcab_release_ext()

ATCA_STATUS atcab_release_ext ( ATCADevice *  device)

release (free) the an ATCADevice instance.

Parameters
[in]devicePointer to the device context pointer
Returns
Returns ATCA_SUCCESS .

◆ atcab_reversal()

ATCA_STATUS atcab_reversal ( const uint8_t *  bin,
size_t  bin_size,
uint8_t *  dest,
size_t *  dest_size 
)

To reverse the input data.

Parameters
[in]binInput data to reverse.
[in]bin_sizeSize of data to reverse.
[out]destBuffer to store reversed binary data.
[in]dest_sizeThe size of the dest buffer.
Returns
ATCA_SUCCESS on success, otherwise an error code.

◆ atcab_version()

ATCA_STATUS atcab_version ( char *  ver_str)

basic API methods are all prefixed with atcab_ (CryptoAuthLib Basic) the fundamental premise of the basic API is it is based on a single interface instance and that instance is global, so all basic API commands assume that one global device is the one to operate on.

returns a version string for the CryptoAuthLib release. The format of the version string returned is "yyyymmdd"

Parameters
[out]ver_strptr to space to receive version string
Returns
ATCA_SUCCESS on success, otherwise an error code.

◆ isAlpha()

bool isAlpha ( char  c)

Checks to see if a character is an ASCII representation of hex ((c >= 'A') and (c <= 'F')) || ((c >= 'a') and (c <= 'f'))

Parameters
[in]ccharacter to check
Returns
True if the character is a hex

◆ isBase64()

bool isBase64 ( char  c,
const uint8_t *  rules 
)

Returns true if this character is a valid base 64 character or if this is space (A character can be included in a valid base 64 string).

Parameters
[in]ccharacter to check
[in]rulesbase64 ruleset to use
Returns
True if the character can be included in a valid base 64 string

◆ isBase64Digit()

bool isBase64Digit ( char  c,
const uint8_t *  rules 
)

Returns true if this character is a valid base 64 character.

Parameters
[in]ccharacter to check
[in]rulesbase64 ruleset to use
Returns
True if the character can be included in a valid base 64 string

◆ isBlankSpace()

bool isBlankSpace ( char  c)

Checks to see if a character is blank space.

Parameters
[in]ccharacter to check
Returns
True if the character is blankspace

◆ isDigit()

bool isDigit ( char  c)

Checks to see if a character is an ASCII representation of a digit ((c ge '0') and (c le '9'))

Parameters
[in]ccharacter to check
Returns
True if the character is a digit

◆ isHex()

bool isHex ( char  c)

Returns true if this character is a valid hex character or if this is blankspace (The character can be included in a valid hexstring).

Parameters
[in]ccharacter to check
Returns
True if the character can be included in a valid hexstring

◆ isHexAlpha()

bool isHexAlpha ( char  c)

Checks to see if a character is an ASCII representation of hex ((c >= 'A') and (c <= 'F')) || ((c >= 'a') and (c <= 'f'))

Parameters
[in]ccharacter to check
Returns
True if the character is a hex

◆ isHexDigit()

bool isHexDigit ( char  c)

Returns true if this character is a valid hex character.

Parameters
[in]ccharacter to check
Returns
True if the character can be included in a valid hexstring

◆ packHex()

ATCA_STATUS packHex ( const char *  ascii_hex,
size_t  ascii_hex_len,
char *  packed_hex,
size_t *  packed_len 
)

Remove spaces from a ASCII hex string.

Parameters
[in]ascii_hexInitial hex string to remove blankspace from
[in]ascii_hex_lenLength of the initial hex string
[in]packed_hexResulting hex string without blankspace
[in,out]packed_lenIn: Size to packed_hex buffer Out: Number of bytes in the packed hex string
Returns
ATCA_SUCCESS on success, otherwise an error code.