ctap_mem.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2021 Freie Universität Berlin
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
21 #include <stdint.h>
22 
23 #include "fido2/ctap/ctap.h"
24 #include "periph/flashpage.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
34 #ifndef _MAX
35 #define _MAX(a, b) ((a) > (b) ? (a) : (b))
36 #endif
42 #ifndef CONFIG_FIDO2_CTAP_NUM_FLASHPAGES
43 #define CONFIG_FIDO2_CTAP_NUM_FLASHPAGES 4
44 #endif
45 
46 #if CONFIG_FIDO2_CTAP_NUM_FLASHPAGES < 2
47 #error "ctap_mem.h: Configured number of flashpages is invalid"
48 #endif
49 
53 #define CTAP_FLASH_ALIGN_PAD(x) (sizeof(x) % FLASHPAGE_WRITE_BLOCK_SIZE == \
54  0 ? \
55  0 : FLASHPAGE_WRITE_BLOCK_SIZE - \
56  sizeof(x) % FLASHPAGE_WRITE_BLOCK_SIZE)
57 
61 #define CTAP_FLASH_RK_SZ (sizeof(ctap_resident_key_t) + \
62  CTAP_FLASH_ALIGN_PAD(ctap_resident_key_t))
63 
67 #define CTAP_FLASH_STATE_SZ (sizeof(ctap_state_t) + \
68  CTAP_FLASH_ALIGN_PAD(ctap_state_t))
69 
73 #define CTAP_FLASH_MAX_NUM_RKS ((CONFIG_FIDO2_CTAP_NUM_FLASHPAGES - 1) * \
74  FLASHPAGE_SIZE / CTAP_FLASH_RK_SZ)
75 
81 #define CTAP_FLASH_MIN_SECTOR_SZ _MAX(CTAP_FLASH_STATE_SZ, CTAP_FLASH_RK_SZ)
82 
86 #define CTAP_FLASH_PAGES_PER_SECTOR ((CTAP_FLASH_MIN_SECTOR_SZ / FLASHPAGE_SIZE) + 1)
87 
94 #define CTAP_FLASH_RK_OFF 0x1
95 
102 
113 ctap_status_code_t fido2_ctap_mem_read(void *buf, uint32_t page, uint32_t offset, uint32_t len);
114 
121 
130 
139 
155  uint32_t *addr);
156 
165 
166 #ifdef __cplusplus
167 }
168 #endif
Internal FIDO2 CTAP defines, structures and function declarations.
Low-level flash page peripheral driver interface.
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_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_erase_flash(void)
Erase all flashpages containing CTAP data.
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_write_rk_to_flash(ctap_resident_key_t *rk)
Write resident credential to flash.
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_init(void)
Initialize memory helper.
ctap_status_code_t
CTAP status codes.
Definition: ctap.h:43
CTAP resident key struct.
Definition: ctap.h:482
CTAP state struct.
Definition: ctap.h:398