Loading...
Searching...
No Matches

FIDO2 CTAP flash memory helper. More...

Detailed Description

FIDO2 CTAP flash memory helper.

Files

file  ctap_mem.h
 Definitions for CTAP flash memory helper functions.
 

Macros

#define CONFIG_FIDO2_CTAP_NUM_FLASHPAGES   4
 Default amount of flashpages to use.
 
#define CTAP_FLASH_ALIGN_PAD(x)
 Calculate padding needed to align struct size for saving to flash.
 
#define CTAP_FLASH_RK_SZ
 Resident key size with alignment padding.
 
#define CTAP_FLASH_STATE_SZ
 State struct size with alignment padding.
 
#define CTAP_FLASH_MAX_NUM_RKS
 Max amount of resident keys that can be stored on device.
 
#define CTAP_FLASH_MIN_SECTOR_SZ   _MAX(CTAP_FLASH_STATE_SZ, CTAP_FLASH_RK_SZ)
 Minimum flash sector size needed to hold CTAP related data.
 
#define CTAP_FLASH_PAGES_PER_SECTOR   ((CTAP_FLASH_MIN_SECTOR_SZ / FLASHPAGE_SIZE) + 1)
 Pages per sector needed.
 
#define CTAP_FLASH_RK_OFF   0x1
 Offset of flashpage for storing resident keys.
 

Functions

ctap_status_code_t fido2_ctap_mem_init (void)
 Initialize memory helper.
 
ctap_status_code_t fido2_ctap_mem_read (void *buf, uint32_t page, uint32_t offset, uint32_t len)
 Read from flash memory.
 
ctap_status_code_t fido2_ctap_mem_erase_flash (void)
 Erase all flashpages containing CTAP data.
 
ctap_status_code_t fido2_ctap_mem_read_state_from_flash (ctap_state_t *state)
 Read authenticator state from flash.
 
ctap_status_code_t fido2_ctap_mem_write_state_to_flash (ctap_state_t *state)
 Write authenticator state to flash.
 
ctap_status_code_t fido2_ctap_mem_read_rk_from_flash (ctap_resident_key_t *key, uint8_t *rp_id_hash, uint32_t *addr)
 Find resident credential for rp_id_hash in flash.
 
ctap_status_code_t fido2_ctap_mem_write_rk_to_flash (ctap_resident_key_t *rk)
 Write resident credential to flash.
 
#define _MAX(a, b)   ((a) > (b) ? (a) : (b))
 MAX function for internal use.
 

Macro Definition Documentation

◆ _MAX

#define _MAX (   a,
 
)    ((a) > (b) ? (a) : (b))

MAX function for internal use.

Definition at line 39 of file ctap_mem.h.

◆ CONFIG_FIDO2_CTAP_NUM_FLASHPAGES

#define CONFIG_FIDO2_CTAP_NUM_FLASHPAGES   4

Default amount of flashpages to use.

Definition at line 47 of file ctap_mem.h.

◆ CTAP_FLASH_ALIGN_PAD

#define CTAP_FLASH_ALIGN_PAD (   x)
Value:
(sizeof(x) % FLASHPAGE_WRITE_BLOCK_SIZE == \
0 ? \
0 : FLASHPAGE_WRITE_BLOCK_SIZE - \
sizeof(x) % FLASHPAGE_WRITE_BLOCK_SIZE)

Calculate padding needed to align struct size for saving to flash.

Definition at line 57 of file ctap_mem.h.

◆ CTAP_FLASH_MAX_NUM_RKS

#define CTAP_FLASH_MAX_NUM_RKS
Value:
#define FLASHPAGE_SIZE
Flash page configuration.
Definition cpu_conf.h:50
#define CONFIG_FIDO2_CTAP_NUM_FLASHPAGES
Default amount of flashpages to use.
Definition ctap_mem.h:47
#define CTAP_FLASH_RK_SZ
Resident key size with alignment padding.
Definition ctap_mem.h:65

Max amount of resident keys that can be stored on device.

Definition at line 77 of file ctap_mem.h.

◆ CTAP_FLASH_MIN_SECTOR_SZ

#define CTAP_FLASH_MIN_SECTOR_SZ   _MAX(CTAP_FLASH_STATE_SZ, CTAP_FLASH_RK_SZ)

Minimum flash sector size needed to hold CTAP related data.

This is needed to ensure that the MTD work_area buffer is big enough

Definition at line 85 of file ctap_mem.h.

◆ CTAP_FLASH_PAGES_PER_SECTOR

#define CTAP_FLASH_PAGES_PER_SECTOR   ((CTAP_FLASH_MIN_SECTOR_SZ / FLASHPAGE_SIZE) + 1)

Pages per sector needed.

Definition at line 90 of file ctap_mem.h.

◆ CTAP_FLASH_RK_OFF

#define CTAP_FLASH_RK_OFF   0x1

Offset of flashpage for storing resident keys.

The offset is in units of flashpages from the beginning of the flash memory area dedicated for storing CTAP data.

Definition at line 98 of file ctap_mem.h.

◆ CTAP_FLASH_RK_SZ

#define CTAP_FLASH_RK_SZ
Value:
(sizeof(ctap_resident_key_t) + \
struct ctap_resident_key ctap_resident_key_t
CTAP resident key credential forward declaration.
Definition ctap.h:387
#define CTAP_FLASH_ALIGN_PAD(x)
Calculate padding needed to align struct size for saving to flash.
Definition ctap_mem.h:57
CTAP resident key struct.
Definition ctap.h:486

Resident key size with alignment padding.

Definition at line 65 of file ctap_mem.h.

◆ CTAP_FLASH_STATE_SZ

#define CTAP_FLASH_STATE_SZ
Value:
(sizeof(ctap_state_t) + \
CTAP state struct.
Definition ctap.h:402

State struct size with alignment padding.

Definition at line 71 of file ctap_mem.h.

Function Documentation

◆ fido2_ctap_mem_erase_flash()

ctap_status_code_t fido2_ctap_mem_erase_flash ( void  )

Erase all flashpages containing CTAP data.

Returns
ctap_status_code_t

◆ fido2_ctap_mem_init()

ctap_status_code_t fido2_ctap_mem_init ( void  )

Initialize memory helper.

Returns
ctap_status_code_t

◆ fido2_ctap_mem_read()

ctap_status_code_t fido2_ctap_mem_read ( void *  buf,
uint32_t  page,
uint32_t  offset,
uint32_t  len 
)

Read from flash memory.

Parameters
[out]bufbuffer to fil in
[in]pagepage to read from
[in]offsetoffset from the start of the page (in bytes)
[in]lennumber of bytes to write
Returns
ctap_status_code_t

◆ fido2_ctap_mem_read_rk_from_flash()

ctap_status_code_t fido2_ctap_mem_read_rk_from_flash ( ctap_resident_key_t key,
uint8_t *  rp_id_hash,
uint32_t *  addr 
)

Find resident credential for rp_id_hash in flash.

The function stores the flash address of the next credential in addr. This allows for consecutive calls of the function in order to find all stored credentials stored for the relying party identified by rp_id_hash.

Parameters
[in]keypointer to authenticator state
[in]rp_id_hashpointer to hash of rp domain string
[in]addrpointer to address where to read from
Returns
ctap_status_code_t

◆ fido2_ctap_mem_read_state_from_flash()

ctap_status_code_t fido2_ctap_mem_read_state_from_flash ( ctap_state_t state)

Read authenticator state from flash.

Parameters
[in]statepointer to authenticator state
Returns
ctap_status_code_t

◆ fido2_ctap_mem_write_rk_to_flash()

ctap_status_code_t fido2_ctap_mem_write_rk_to_flash ( ctap_resident_key_t rk)

Write resident credential to flash.

Parameters
[in]rkpointer to resident credential
Returns
ctap_status_code_t

◆ fido2_ctap_mem_write_state_to_flash()

ctap_status_code_t fido2_ctap_mem_write_state_to_flash ( ctap_state_t state)

Write authenticator state to flash.

Parameters
[in]statepointer to authenticator state
Returns
ctap_status_code_t