1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (C) Foundries Ltd. 2020 - All Rights Reserved
4  * Author: Jorge Ramirez <jorge@foundries.io>
5  */
6 
7 #ifndef SE050_APDU_APIS_H_
8 #define SE050_APDU_APIS_H_
9 
10 #include <se050.h>
11 
12 struct s050_scp_rotate_cmd;
13 
14 sss_status_t se050_factory_reset(pSe05xSession_t ctx);
15 
16 bool se050_key_exists(uint32_t k_id, pSe05xSession_t ctx);
17 
18 struct se050_rsa_keypair {
19 	uint8_t *e;
20 	size_t e_len;
21 	uint8_t *d;
22 	size_t d_len;
23 	uint8_t *n;
24 	size_t n_len;
25 
26 	uint8_t *p;
27 	size_t p_len;
28 	uint8_t *q;
29 	size_t q_len;
30 	uint8_t *qp;
31 	size_t qp_len;
32 	uint8_t *dp;
33 	size_t dp_len;
34 	uint8_t *dq;
35 	size_t dq_len;
36 };
37 
38 struct se050_rsa_keypub {
39 	uint8_t *e;
40 	size_t e_len;
41 	uint8_t *n;
42 	size_t n_len;
43 };
44 
45 sss_status_t se050_key_store_set_rsa_key_bin(sss_se05x_key_store_t *k_store,
46 					     sss_se05x_object_t *k_object,
47 					     struct se050_rsa_keypair *k_pair,
48 					     struct se050_rsa_keypub *k_pub,
49 					     size_t k_bit_len);
50 
51 sss_status_t se050_get_free_memory(pSe05xSession_t ctx, uint16_t *t,
52 				   SE05x_MemoryType_t type);
53 
54 sss_status_t se050_scp03_send_rotate_cmd(pSe05xSession_t ctx,
55 					 struct s050_scp_rotate_cmd *cmd);
56 
57 struct se050_ecc_keypub {
58 	uint8_t *x;
59 	size_t x_len;
60 	uint8_t *y;
61 	size_t y_len;
62 	uint32_t curve;
63 };
64 
65 struct se050_ecc_keypair {
66 	struct se050_ecc_keypub pub;
67 	uint8_t *d;
68 	size_t d_len;
69 };
70 
71 sss_status_t se050_key_store_set_ecc_key_bin(sss_se05x_key_store_t *store,
72 					     sss_se05x_object_t *object,
73 					     struct se050_ecc_keypair *pair,
74 					     struct se050_ecc_keypub *pub);
75 
76 sss_status_t se050_key_store_get_ecc_key_bin(sss_se05x_key_store_t *store,
77 					     sss_se05x_object_t *object,
78 					     uint8_t *key, size_t *len);
79 
80 sss_status_t se050_ecc_gen_shared_secret(pSe05xSession_t ctx, uint32_t id,
81 					 struct se050_ecc_keypub *pub,
82 					 uint8_t *secret, size_t *len);
83 
84 #endif /* SE050_APDU_APIS_H_ */
85