CryptoAuthLib v3.7.6
Microchip CryptoAuthentication Library
 
Loading...
Searching...
No Matches
atca_helpers.c File Reference

Helpers to support the CryptoAuthLib Basic API methods. More...

#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "cryptoauthlib.h"
#include "atca_helpers.h"

Macros

#define B64_IS_EQUAL   (64u)
 
#define B64_IS_INVALID   (-1)
 

Functions

const uint8_t * atcab_b64rules_default (void)
 
const uint8_t * atcab_b64rules_mime (void)
 
const uint8_t * atcab_b64rules_urlsafe (void)
 
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_reversal (const uint8_t *bin, size_t bin_size, uint8_t *dest, size_t *dest_size)
 To reverse the input data.
 
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 *hex, size_t hex_size, uint8_t *bin, size_t *bin_size, bool is_space)
 
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.
 
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.
 
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 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.
 
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 *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_base64encode (const uint8_t *byte_array, size_t array_len, char *encoded, size_t *encoded_len)
 Encode data as base64 string.
 
ATCA_STATUS atcab_base64decode (const char *encoded, size_t encoded_len, uint8_t *byte_array, size_t *array_len)
 Decode base64 string to data.
 
size_t atcab_pointer_delta (const void *start, const void *end)
 Helper function to calculate the number of bytes between two pointers.
 
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.
 
char lib_toupper (char c)
 Converts a character to uppercase.
 
char lib_tolower (char c)
 Converts a character to lowercase.
 
const char * lib_strcasestr (const char *haystack, const char *needle)
 Search for a substring in a case insenstive format.
 

Detailed Description

Helpers to support the CryptoAuthLib Basic API methods.

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_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_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.

◆ 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.