Loading...
Searching...
No Matches
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
22#ifndef FIDO2_CTAP_CTAP_MEM_H
23#define FIDO2_CTAP_CTAP_MEM_H
24
25#include <stdint.h>
26
27#include "fido2/ctap/ctap.h"
28#include "periph/flashpage.h"
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
38#ifndef _MAX
39#define _MAX(a, b) ((a) > (b) ? (a) : (b))
40#endif
46#ifndef CONFIG_FIDO2_CTAP_NUM_FLASHPAGES
47#define CONFIG_FIDO2_CTAP_NUM_FLASHPAGES 4
48#endif
49
50#if CONFIG_FIDO2_CTAP_NUM_FLASHPAGES < 2
51#error "ctap_mem.h: Configured number of flashpages is invalid"
52#endif
53
57#define CTAP_FLASH_ALIGN_PAD(x) (sizeof(x) % FLASHPAGE_WRITE_BLOCK_SIZE == \
58 0 ? \
59 0 : FLASHPAGE_WRITE_BLOCK_SIZE - \
60 sizeof(x) % FLASHPAGE_WRITE_BLOCK_SIZE)
61
65#define CTAP_FLASH_RK_SZ (sizeof(ctap_resident_key_t) + \
66 CTAP_FLASH_ALIGN_PAD(ctap_resident_key_t))
67
71#define CTAP_FLASH_STATE_SZ (sizeof(ctap_state_t) + \
72 CTAP_FLASH_ALIGN_PAD(ctap_state_t))
73
77#define CTAP_FLASH_MAX_NUM_RKS ((CONFIG_FIDO2_CTAP_NUM_FLASHPAGES - 1) * \
78 FLASHPAGE_SIZE / CTAP_FLASH_RK_SZ)
79
85#define CTAP_FLASH_MIN_SECTOR_SZ _MAX(CTAP_FLASH_STATE_SZ, CTAP_FLASH_RK_SZ)
86
90#define CTAP_FLASH_PAGES_PER_SECTOR ((CTAP_FLASH_MIN_SECTOR_SZ / FLASHPAGE_SIZE) + 1)
91
98#define CTAP_FLASH_RK_OFF 0x1
99
106
117int fido2_ctap_mem_read(void *buf, uint32_t page, uint32_t offset, uint32_t len);
118
125
134
143
159 uint32_t *addr);
160
169
170#ifdef __cplusplus
171}
172#endif
173#endif /* FIDO2_CTAP_CTAP_MEM_H */
Internal FIDO2 CTAP defines, structures and function declarations.
Low-level flash page peripheral driver interface.
int fido2_ctap_mem_write_rk_to_flash(ctap_resident_key_t *rk)
Write resident credential to flash.
int fido2_ctap_mem_read_state_from_flash(ctap_state_t *state)
Read authenticator state from flash.
int fido2_ctap_mem_init(void)
Initialize memory helper.
int fido2_ctap_mem_erase_flash(void)
Erase all flashpages containing CTAP data.
int fido2_ctap_mem_write_state_to_flash(ctap_state_t *state)
Write authenticator state to flash.
int fido2_ctap_mem_read(void *buf, uint32_t page, uint32_t offset, uint32_t len)
Read from flash memory.
int 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 resident key struct.
Definition ctap.h:497
CTAP state struct.
Definition ctap.h:413