Toggle navigation
Documentation
The friendly Operating System for the Internet of Things
ctap_mem.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2021 Freie Universität Berlin
3
*
4
* This file is subject to the terms and conditions of the GNU Lesser
5
* General Public License v2.1. See the file LICENSE in the top level
6
* directory for more details.
7
*/
8
9
#pragma once
10
24
#include <stdint.h>
25
26
#include "
fido2/ctap/ctap.h
"
27
#include "
periph/flashpage.h
"
28
29
#ifdef __cplusplus
30
extern
"C"
{
31
#endif
32
37
#ifndef _MAX
38
#define _MAX(a, b) ((a) > (b) ? (a) : (b))
39
#endif
45
#ifndef CONFIG_FIDO2_CTAP_NUM_FLASHPAGES
46
#define CONFIG_FIDO2_CTAP_NUM_FLASHPAGES 4
47
#endif
48
49
#if CONFIG_FIDO2_CTAP_NUM_FLASHPAGES < 2
50
#error "ctap_mem.h: Configured number of flashpages is invalid"
51
#endif
52
56
#define CTAP_FLASH_ALIGN_PAD(x) (sizeof(x) % FLASHPAGE_WRITE_BLOCK_SIZE == \
57
0 ? \
58
0 : FLASHPAGE_WRITE_BLOCK_SIZE - \
59
sizeof(x) % FLASHPAGE_WRITE_BLOCK_SIZE)
60
64
#define CTAP_FLASH_RK_SZ (sizeof(ctap_resident_key_t) + \
65
CTAP_FLASH_ALIGN_PAD(ctap_resident_key_t))
66
70
#define CTAP_FLASH_STATE_SZ (sizeof(ctap_state_t) + \
71
CTAP_FLASH_ALIGN_PAD(ctap_state_t))
72
76
#define CTAP_FLASH_MAX_NUM_RKS ((CONFIG_FIDO2_CTAP_NUM_FLASHPAGES - 1) * \
77
FLASHPAGE_SIZE / CTAP_FLASH_RK_SZ)
78
84
#define CTAP_FLASH_MIN_SECTOR_SZ _MAX(CTAP_FLASH_STATE_SZ, CTAP_FLASH_RK_SZ)
85
89
#define CTAP_FLASH_PAGES_PER_SECTOR ((CTAP_FLASH_MIN_SECTOR_SZ / FLASHPAGE_SIZE) + 1)
90
97
#define CTAP_FLASH_RK_OFF 0x1
98
104
ctap_status_code_t
fido2_ctap_mem_init
(
void
);
105
116
ctap_status_code_t
fido2_ctap_mem_read
(
void
*buf, uint32_t page, uint32_t offset, uint32_t len);
117
123
ctap_status_code_t
fido2_ctap_mem_erase_flash
(
void
);
124
132
ctap_status_code_t
fido2_ctap_mem_read_state_from_flash
(
ctap_state_t
*state);
133
141
ctap_status_code_t
fido2_ctap_mem_write_state_to_flash
(
ctap_state_t
*state);
142
157
ctap_status_code_t
fido2_ctap_mem_read_rk_from_flash
(
ctap_resident_key_t
*key, uint8_t *rp_id_hash,
158
uint32_t *addr);
159
167
ctap_status_code_t
fido2_ctap_mem_write_rk_to_flash
(
ctap_resident_key_t
*rk);
168
169
#ifdef __cplusplus
170
}
171
#endif
ctap.h
Internal FIDO2 CTAP defines, structures and function declarations.
flashpage.h
Low-level flash page peripheral driver interface.
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.
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.
fido2_ctap_mem_erase_flash
ctap_status_code_t fido2_ctap_mem_erase_flash(void)
Erase all flashpages containing CTAP data.
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.
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.
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.
fido2_ctap_mem_init
ctap_status_code_t fido2_ctap_mem_init(void)
Initialize memory helper.
ctap_status_code_t
ctap_status_code_t
CTAP status codes.
Definition:
ctap.h:46
ctap_resident_key
CTAP resident key struct.
Definition:
ctap.h:485
ctap_state_t
CTAP state struct.
Definition:
ctap.h:401
Generated on Mon Jun 30 2025 18:46:46 by
1.9.1