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
9#pragma once
10
23
24#include <stdint.h>
25
26#include "fido2/ctap/ctap.h"
27#include "periph/flashpage.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
37#ifndef _MAX
38#define _MAX(a, b) ((a) > (b) ? (a) : (b))
39#endif
41
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
105
116ctap_status_code_t fido2_ctap_mem_read(void *buf, uint32_t page, uint32_t offset, uint32_t len);
117
124
133
142
158 uint32_t *addr);
159
168
169#ifdef __cplusplus
170}
171#endif
Internal FIDO2 CTAP defines, structures and function declarations.
Low-level flash page peripheral driver interface.
struct ctap_resident_key ctap_resident_key_t
CTAP resident key credential forward declaration.
Definition ctap.h:386
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:46
CTAP state struct.
Definition ctap.h:401