1 /*
2  * Copyright (C) 2020 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/hwwsk/hwwsk.h>
20 
21 #include <err.h>
22 #include <stdint.h>
23 #include <sys/types.h>
24 #include <sys/uio.h>
25 #include <trusty_ipc.h>
26 
27 /*
28  * Client for Hardware wrapped storage key (HWWSK) service
29  */
30 
31 __BEGIN_CDECLS
32 
33 /**
34  * hwwsk_generate_key() - creates new persistent key
35  * @chan: IPC channel to HWWSK service
36  * @buf: pointer to the buffers to store resulting key blob
37  * @buf_sz: size of the @buf buffer
38  * @key_size: key size in bits
39  * @key_flag: a combination of &enum hwwsk_key_flags to specify an additional
40  *            properties of generated key.
41  * @raw_key: pointer to the buffer containing raw key data for import operation
42  * @raw_key_len: size of key specified by @raw_key parameter
43  *
44  * This routine creates new hardware wrapped storage key by either generating
45  * a new random key or importing raw key material if specified by caller.
46  * The resulting key must be persistent.
47  *
48  * Return: number of bytes placed into @buf buffer on success,
49  *         negative error code otherwise
50  *
51  */
52 int hwwsk_generate_key(handle_t chan,
53                        void* buf,
54                        size_t buf_sz,
55                        uint32_t key_size,
56                        uint32_t key_flags,
57                        const void* raw_key,
58                        size_t raw_key_len);
59 
60 /**
61  * hwwsk_export_key() - rewrap specified SK key with ESK
62  * @chan: IPC channel to HWWSK service
63  * @buf: pointer to the buffers to store resulting key blob
64  * @buf_sz: size of the @buf buffer
65  * @key_blob: pointer to key blob to rewrap
66  * @key_blob_len: size of key blob specified by @key_blob
67  *
68  * This routine rewraps specified persistent SK key with ephemeral storage
69  * key (ESK). The resulting key is only good for current session.
70  *
71  * Return: number of bytes placed into @buf buffer on success,
72  *         negative  error code otherwise
73  */
74 int hwwsk_export_key(handle_t chan,
75                      void* buf,
76                      size_t buf_sz,
77                      const void* key_blob,
78                      size_t key_blob_len);
79 
80 __END_CDECLS
81