WS63 SDK 文档 7021f4f@fbb_ws63
ws63 和 ws63e 解决方案的 SDK 文档
载入中...
搜索中...
未找到
nv_key.h
浏览该文件的文档.
1/*
2 * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2019-2022. All rights reserved.
3 * Description: KV Storage Library key access interface
4 */
5
6#ifndef NV_KEY_H
7#define NV_KEY_H
8
9#include "stdbool.h"
10#include "errcode.h"
11
12#ifdef __cplusplus
13#if __cplusplus
14extern "C" {
15#endif /* __cplusplus */
16#endif /* __cplusplus */
17
18#define KV_KEY_MAGIC 0xA9
19#define KV_KEY_VALID 0xFF
20#define KV_KEY_INVALID 0
21#define KV_KEY_NO_MAGIC 0xFF
22
23#define KV_KEY_TYPE_NORMAL 0xFF
24#define KV_KEY_TYPE_PERMANENT 0
25
26#define KV_KEY_FORCE_UPDATE 0xf0
27
28#define KV_CRYPTO_HASH_SIZE 32
29#define KV_CRYPTO_CRC_SIZE 4
30#define KV_CRYPTO_CRC32_SIZE 32
31#define AES_BLOCK_SIZE 16
32#define NV_AES_GCM_TAG_LENGTH 16
33#define MIN_AES_DECRYPT_LEN (2 * AES_BLOCK_SIZE)
34#define AES_KDFKEY_SDRK_TYPE 0x52
35#define CRC_SWAP_SIZE8 8
36#define CRC_SWAP_SIZE24 24
37#define INVAILD_CRYPTO_HANDLE 0xFFFFFFFF
38
44
50
54typedef enum {
55 KV_ATTRIBUTE_PERMANENT = 0x1, /* Key is permanent and can't be deleted or modified */
56 KV_ATTRIBUTE_ENCRYPTED = 0x2, /* Key is encrypted in flash */
57 KV_ATTRIBUTE_NON_UPGRADE = 0x4 /* key cannot be modified during the upgrade. */
59
65
66typedef uint16_t kv_key_id;
67
70typedef const void *kv_key_location;
71
73typedef struct {
74 kv_key_location location; /* (retained) location is out of context here */
75 kv_key_id pattern; /* Pattern of bits matched against a key_id, after mask has been applied */
76 kv_key_id mask; /* Mask is applied to a key id before matching pattern */
77 kv_key_filter_state_t state; /* Include only keys of the specified state in search results */
78 kv_key_filter_type_t type; /* Include only keys of the specified type in search results */
80
82typedef struct {
83 uint8_t magic; /* Magic number to indicate the start of the item */
84 uint8_t valid; /* flag to indicate whether the value is valid. */
85 uint16_t length; /* Length of the key_data field in bytes */
86 uint8_t type; /* Normal (0xFF) or permanent (0x00) */
87 uint8_t upgrade; /* Indicating whether upgradeable(not.0x00) */
88 uint16_t key_id; /* The Key ID */
89 uint16_t enc_key; /* Allows some customisation of the data AES key used, */
90 /* 0x0 - key_data is plaintext, Others - key_data is encrypted */
91 uint16_t version; /* Version of the key */
92 uint32_t rnd; /* align the header to be 16bytes, random number */
94
96typedef struct {
98 kv_key_location key_location; /* Location in flash of the KV key */
100
113
114extern uint8_t g_nv_header_magic;
115
116errcode_t kv_key_helper_copy_flash(uint32_t dest_location, uint32_t src_location, uint16_t length);
117errcode_t kv_key_direct_write_flash(uint32_t dest, uint32_t length, const uint8_t *src);
118errcode_t kv_key_direct_erase_flash(uint32_t dest, const uint32_t size);
119errcode_t kv_key_write_flash(uint32_t dest, uint32_t length, const uint8_t *src);
120errcode_t kv_key_erase_flash(uint32_t dest, const uint32_t size);
121bool kv_key_is_erased(const kv_key_handle_t *key);
122errcode_t kv_key_validate_integrity(kv_key_handle_t *key, bool ignor_invalid);
123errcode_t kv_key_validation(kv_key_handle_t *key, bool ignor_invalid);
127errcode_t kv_key_locations_in_same_page(kv_key_location first_key_location, kv_key_location second_key_location);
130uint16_t kv_key_padded_data_length(kv_attributes_t attributes, uint16_t unpadded_length);
132errcode_t kv_key_read_data(kv_key_handle_t *key, uint8_t *dest_location);
133errcode_t kv_helper_compare_key_data(kv_key_handle_t *key, const uint8_t *compare_data, uint16_t compare_length);
134void kv_key_build_from_new(kv_key_handle_t *key, const kv_key_details_t *new_key, kv_key_location key_location);
136
137uint32_t kv_crc32_swap(uint32_t crc);
138
139#ifdef __cplusplus
140#if __cplusplus
141}
142#endif /* __cplusplus */
143#endif /* __cplusplus */
144
145#endif /* NV_KEY_H */
uint32_t errcode_t
Definition of error code.
Definition errcode.h:30
errcode_t kv_key_get_next_handle(kv_key_handle_t *key, kv_key_validate_status_t key_status)
Definition nv_key.c:552
uint8_t g_nv_header_magic
Definition nv_key.c:20
errcode_t kv_helper_compare_key_data(kv_key_handle_t *key, const uint8_t *compare_data, uint16_t compare_length)
Definition nv_key.c:240
errcode_t kv_key_get_handle_from_location(kv_key_location key_location, kv_key_handle_t *key)
Definition nv_key.c:376
uint16_t kv_key_flash_size(kv_key_handle_t *key)
Definition nv_key.c:850
errcode_t kv_key_read_data(kv_key_handle_t *key, uint8_t *dest_location)
Definition nv_key.c:162
errcode_t kv_key_locations_in_same_page(kv_key_location first_key_location, kv_key_location second_key_location)
Definition nv_key.c:399
uint16_t kv_key_id
Definition nv_key.h:66
kv_key_filter_type_t
Definition nv_key.h:45
@ KV_KEY_FILTER_TYPE_NORMAL
Definition nv_key.h:46
@ KV_KEY_FILTER_TYPE_ANY
Definition nv_key.h:48
@ KV_KEY_FILTER_TYPE_PERMANENT
Definition nv_key.h:47
errcode_t kv_key_direct_erase_flash(uint32_t dest, const uint32_t size)
Definition nv_key.c:71
errcode_t kv_key_validate_integrity(kv_key_handle_t *key, bool ignor_invalid)
Definition nv_key.c:734
errcode_t kv_key_does_filter_match(kv_key_handle_t *key, kv_key_filter_t *search_filter)
Definition nv_key.c:330
errcode_t kv_key_get_next_magic_position(kv_key_location key_location, kv_key_handle_t *key)
Definition nv_key.c:411
kv_attributes_t
Definition nv_key.h:54
@ KV_ATTRIBUTE_PERMANENT
Definition nv_key.h:55
@ KV_ATTRIBUTE_NON_UPGRADE
Definition nv_key.h:57
@ KV_ATTRIBUTE_ENCRYPTED
Definition nv_key.h:56
errcode_t kv_key_helper_copy_flash(uint32_t dest_location, uint32_t src_location, uint16_t length)
Definition nv_key.c:25
kv_key_validate_status_t
Definition nv_key.h:60
@ KV_KEY_VALIDATE_WRONG
Definition nv_key.h:63
@ KV_KEY_VALIDATE_CORRECT
Definition nv_key.h:62
@ KV_KEY_NOT_VALIDATE
Definition nv_key.h:61
kv_attributes_t kv_key_attributes(const kv_key_handle_t *key)
Definition nv_key.c:821
errcode_t kv_key_validation(kv_key_handle_t *key, bool ignor_invalid)
Definition nv_key.c:772
uint32_t kv_crc32_swap(uint32_t crc)
Definition nv_key.c:894
errcode_t kv_key_write_flash(uint32_t dest, uint32_t length, const uint8_t *src)
Definition nv_key.c:89
bool kv_key_is_valid(kv_key_handle_t *key)
Definition nv_key.c:304
uint16_t kv_key_padded_data_length(kv_attributes_t attributes, uint16_t unpadded_length)
Definition nv_key.c:839
errcode_t kv_key_erase_flash(uint32_t dest, const uint32_t size)
Definition nv_key.c:98
errcode_t kv_key_direct_write_flash(uint32_t dest, uint32_t length, const uint8_t *src)
Definition nv_key.c:54
void kv_key_build_from_new(kv_key_handle_t *key, const kv_key_details_t *new_key, kv_key_location key_location)
Definition nv_key.c:868
kv_key_filter_state_t
Definition nv_key.h:39
@ KV_KEY_FILTER_STATE_INVALID
Definition nv_key.h:41
@ KV_KEY_FILTER_STATE_ANY
Definition nv_key.h:42
@ KV_KEY_FILTER_STATE_VALID
Definition nv_key.h:40
bool kv_key_is_erased(const kv_key_handle_t *key)
Definition nv_key.c:292
const void * kv_key_location
Definition nv_key.h:70
Definition nv_key.h:108
uint8_t * key_data_chunk
Definition nv_key.h:110
uint32_t crypto_handle
Definition nv_key.h:109
uint8_t * compare_data_chunk
Definition nv_key.h:111
Definition nv_key.h:101
kv_key_id key_id
Definition nv_key.h:102
uint32_t kvalue_length
Definition nv_key.h:105
bool focre_write
Definition nv_key.h:103
kv_attributes_t attributes
Definition nv_key.h:106
const uint8_t * kvalue
Definition nv_key.h:104
Definition nv_key.h:73
kv_key_id mask
Definition nv_key.h:76
kv_key_location location
Definition nv_key.h:74
kv_key_filter_type_t type
Definition nv_key.h:78
kv_key_id pattern
Definition nv_key.h:75
kv_key_filter_state_t state
Definition nv_key.h:77
Definition nv_key.h:96
kv_key_header_t header
Definition nv_key.h:97
kv_key_location key_location
Definition nv_key.h:98
Definition nv_key.h:82
uint16_t key_id
Definition nv_key.h:88
uint16_t version
Definition nv_key.h:91
uint8_t valid
Definition nv_key.h:84
uint8_t magic
Definition nv_key.h:83
uint16_t length
Definition nv_key.h:85
uint8_t upgrade
Definition nv_key.h:87
uint16_t enc_key
Definition nv_key.h:89
uint8_t type
Definition nv_key.h:86
uint32_t rnd
Definition nv_key.h:92