blob: 170a90e9af53bb5a42a623aa3dce33c8a8ea854b [file] [log] [blame]
Bo Lv72d0e902023-01-02 14:27:34 +00001/* SPDX-License-Identifier: (GPL-2.0+ OR MIT) */
2/*
3 * Copyright (c) 2019 Amlogic, Inc. All rights reserved.
4 */
5
6#ifndef __AMLKEY_IF_H__
7#define __AMLKEY_IF_H__
8
9#define AMLKEY_NAME_LEN_MAX (80)
10
11struct amlkey_if {
12 int32_t (*init)(uint8_t *seed, uint32_t len, int encrypt_type);
13 int32_t (*exsit)(const uint8_t *name);
14 ssize_t (*size)(const uint8_t *name);
15 uint32_t (*get_attr)(const uint8_t *name);
16 ssize_t (*read)(const uint8_t *name, uint8_t *buffer, uint32_t len);
17 ssize_t (*write)(const uint8_t *name, uint8_t *buffer, uint32_t len, uint32_t attr);
18 int32_t (*hash)(const uint8_t *name, uint8_t *hash);
19};
20
21extern struct amlkey_if *amlkey_if;
22
23static inline uint32_t amlkey_get_attr(const uint8_t *name)
24{
25 return amlkey_if->get_attr(name);
26}
27
28int amlkey_if_init(const void* dt_addr);
29
30//1.init
31static inline int32_t amlkey_init(uint8_t *seed, uint32_t len, int encrypt_type)
32{
33 return amlkey_if->init(seed, len, encrypt_type);
34}
35
36//2. query if the key already programmed, exsit 1, non 0
37static inline int32_t amlkey_isexsit(const uint8_t * name)
38{
39 return amlkey_if->exsit(name);
40}
41
42//3. query attr, key must exsit before those functions were called.
43 //3.1 whether the programmed key is secure, secure 1, non 0
44int32_t amlkey_issecure(const uint8_t * name);
45
46 //3.2 whether the programmed key is encrypt, encrypt 1, non 0
47int32_t amlkey_isencrypt(const uint8_t * name);
48
49//4. actual bytes of key value
50static inline ssize_t amlkey_size(const uint8_t *name)
51{
52 return amlkey_if->size(name);
53}
54
55//5. read non-secure key in bytes, return byets readback actually.
56static inline ssize_t amlkey_read(const uint8_t *name, uint8_t *buffer, uint32_t len)
57{
58 return amlkey_if->read(name, buffer, len);
59}
60
61//6.write key with attribute in bytes , return byets readback actually
62 //attr: bit0: secure/non-secure;
63 // bit8: encrypt/non-encrypt
64#define UNIFYKEY_ATTR_SECURE_MASK (1<<0)
65#define UNIFYKEY_ATTR_ENCRYPT_MASK (1<<8)
66static inline ssize_t amlkey_write(const uint8_t *name, uint8_t *buffer, uint32_t len,
67 uint32_t attr)
68{
69 return amlkey_if->write(name, buffer, len, attr);
70}
71
72//7. get the hash value of programmed secure key | 32bytes length, sha256
73static inline int32_t amlkey_hash_4_secure(const uint8_t *name, uint8_t *hash)
74{
75 return amlkey_if->hash(name, hash);
76}
77
78#endif// #ifndef __AMLKEY_IF_H__
79