1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
/*
* Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef PROTOBUF_CRYPTO_CLIENT_H
#define PROTOBUF_CRYPTO_CLIENT_H
#include <service/crypto/client/cpp/crypto_client.h>
#include <service/crypto/protobuf/key_attributes.pb.h>
/*
* A concrete crypto_client that uses the protobuf based crypto access protocol
*/
class protobuf_crypto_client : public crypto_client
{
public:
protobuf_crypto_client();
protobuf_crypto_client(struct rpc_caller *caller);
virtual ~protobuf_crypto_client();
/* Key lifecycle methods */
psa_status_t generate_key(
const psa_key_attributes_t *attributes,
psa_key_id_t *id);
psa_status_t destroy_key(
psa_key_id_t id);
psa_status_t import_key(
const psa_key_attributes_t *attributes,
const uint8_t *data, size_t data_length, psa_key_id_t *id);
psa_status_t copy_key(
psa_key_id_t source_key,
const psa_key_attributes_t *attributes,
psa_key_id_t *target_key);
psa_status_t purge_key(
psa_key_id_t id);
psa_status_t get_key_attributes(
psa_key_id_t id,
psa_key_attributes_t *attributes);
/* Key export methods */
psa_status_t export_key(
psa_key_id_t id,
uint8_t *data, size_t data_size,
size_t *data_length);
psa_status_t export_public_key(
psa_key_id_t id,
uint8_t *data, size_t data_size, size_t *data_length);
/* Sign/verify methods */
psa_status_t sign_hash(
psa_key_id_t id,
psa_algorithm_t alg,
const uint8_t *hash, size_t hash_length,
uint8_t *signature, size_t signature_size, size_t *signature_length);
psa_status_t verify_hash(
psa_key_id_t id,
psa_algorithm_t alg,
const uint8_t *hash, size_t hash_length,
const uint8_t *signature, size_t signature_length);
/* Asymmetric encrypt/decrypt */
psa_status_t asymmetric_encrypt(
psa_key_id_t id,
psa_algorithm_t alg,
const uint8_t *input, size_t input_length,
const uint8_t *salt, size_t salt_length,
uint8_t *output, size_t output_size, size_t *output_length);
psa_status_t asymmetric_decrypt(
psa_key_id_t id,
psa_algorithm_t alg,
const uint8_t *input, size_t input_length,
const uint8_t *salt, size_t salt_length,
uint8_t *output, size_t output_size, size_t *output_length);
/* Random number generation */
psa_status_t generate_random(
uint8_t *output, size_t output_size);
/* Hash methods */
size_t hash_max_update_size() const;
psa_status_t hash_setup(
uint32_t *op_handle,
psa_algorithm_t alg);
psa_status_t hash_update(
uint32_t op_handle,
const uint8_t *input, size_t input_length);
psa_status_t hash_finish(
uint32_t op_handle,
uint8_t *hash, size_t hash_size, size_t *hash_length);
psa_status_t hash_abort(
uint32_t op_handle);
psa_status_t hash_verify(
uint32_t op_handle,
const uint8_t *hash, size_t hash_length);
psa_status_t hash_clone(
uint32_t source_op_handle,
uint32_t *target_op_handle);
private:
void translate_key_attributes(
ts_crypto_KeyAttributes &proto_attributes,
const psa_key_attributes_t &psa_attributes);
};
#endif /* PROTOBUF_CRYPTO_CLIENT_H */
|