1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <interface/hwaes/hwaes.h>
20 #include <lk/compiler.h>
21 #include <stdbool.h>
22 #include <sys/types.h>
23 #include <trusty_ipc.h>
24 
25 __BEGIN_CDECLS
26 
27 struct tipc_hset;
28 
29 /**
30  * struct hwaes_arg_in - Input argument struct for hwaes_aes_op
31  * @data_ptr: Pointer to the argument data.
32  * @len:      Length of the argument data.
33  */
34 struct hwaes_arg_in {
35     const uint8_t* data_ptr;
36     size_t len;
37 };
38 
39 /**
40  * struct hwaes_arg_out - Output argument struct for hwaes_aes_op
41  * @data_ptr: Pointer to the argument data.
42  * @len:      Length of the argument data.
43  */
44 struct hwaes_arg_out {
45     uint8_t* data_ptr;
46     size_t len;
47 };
48 
49 /**
50  * struct hwaes_aes_op_args - Arguments struct for hwaes_aes_op
51  * @key:           The AES key.
52  * @iv:            The initialization vector.
53  * @aad:           The additional authenticated data (AAD).
54  * @text_in:       The input text data.
55  * @tag_in:        The input tag.
56  * @text_out:      The output text data.
57  * @tag_out:       The output tag.
58  * @key_type:      The key_type, one of instances at enum hwaes_key_type.
59  * @padding:       The padding type, one of instances at enum hwaes_padding.
60  * @mode:          The AES mode, one of instances at enum hwaes_mode.
61  * @encrypt:       Flag for encryption (true) or decryption (false).
62  */
63 struct hwaes_aes_op_args {
64     struct hwaes_arg_in key;
65     struct hwaes_arg_in iv;
66     struct hwaes_arg_in aad;
67     struct hwaes_arg_in text_in;
68     struct hwaes_arg_in tag_in;
69     struct hwaes_arg_out text_out;
70     struct hwaes_arg_out tag_out;
71     uint32_t key_type;
72     uint32_t padding;
73     uint32_t mode;
74     bool encrypt;
75 };
76 
77 /**
78  * hwaes_aes_op() - Perform AES operation
79  * @args: Arguments for the AES operation
80  *
81  * Must be implemented by client of lib_hwaes_server.
82  *
83  * Return: 0 on success, or an error code (enum hwaes_err type) on failure.
84  */
85 uint32_t hwaes_aes_op(const struct hwaes_aes_op_args* args);
86 
87 /**
88  * add_hwaes_service() - Add hwaes service
89  * @hset: Handle set created by tipc_hset_create()
90  * @allowed_clients: Array of pointers to allowed client UUIDs
91  * @allowed_clients_len: Length of @allowed_clients
92  *
93  * Client should call tipc_run_event_loop at some point after this call returns.
94  *
95  * This function does not take ownership of @allowed_clients. The array must
96  * live at least as long as the service.
97  *
98  * Return: 0 on success, or an error code < 0 on failure.
99  */
100 int add_hwaes_service(struct tipc_hset* hset,
101                       const uuid_t** allowed_clients,
102                       size_t allowed_clients_len);
103 
104 __END_CDECLS
105