1 /*
2  * Copyright (c) 2022-2023, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #include <delegated_attestation.h>
9 #include <psa/client.h>
10 #include <psa_manifest/sid.h>
11 
12 psa_status_t
rss_delegated_attest_get_delegated_key(uint8_t ecc_curve,uint32_t key_bits,uint8_t * key_buf,size_t key_buf_size,size_t * key_size,uint32_t hash_algo)13 rss_delegated_attest_get_delegated_key(uint8_t   ecc_curve,
14 				       uint32_t  key_bits,
15 				       uint8_t  *key_buf,
16 				       size_t    key_buf_size,
17 				       size_t   *key_size,
18 				       uint32_t  hash_algo)
19 {
20 	psa_status_t status;
21 	psa_invec in_vec[] = {
22 		{&ecc_curve, sizeof(ecc_curve)},
23 		{&key_bits,  sizeof(key_bits)},
24 		{&hash_algo, sizeof(hash_algo)}
25 	};
26 	psa_outvec out_vec[] = {
27 		{key_buf, key_buf_size}
28 	};
29 
30 	if (key_size == NULL) {
31 		return PSA_ERROR_INVALID_ARGUMENT;
32 	}
33 
34 	status = psa_call(RSS_DELEGATED_SERVICE_HANDLE,
35 			  RSS_DELEGATED_ATTEST_GET_DELEGATED_KEY,
36 			  in_vec,  IOVEC_LEN(in_vec),
37 			  out_vec, IOVEC_LEN(out_vec));
38 	if (status == PSA_SUCCESS) {
39 		*key_size = out_vec[0].len;
40 	}
41 
42 	return status;
43 }
44 
45 psa_status_t
rss_delegated_attest_get_token(const uint8_t * dak_pub_hash,size_t dak_pub_hash_size,uint8_t * token_buf,size_t token_buf_size,size_t * token_size)46 rss_delegated_attest_get_token(const uint8_t *dak_pub_hash,
47 			       size_t         dak_pub_hash_size,
48 			       uint8_t       *token_buf,
49 			       size_t         token_buf_size,
50 			       size_t        *token_size)
51 {
52 	psa_status_t status;
53 	psa_invec in_vec[] = {
54 		{dak_pub_hash, dak_pub_hash_size}
55 	};
56 	psa_outvec out_vec[] = {
57 		{token_buf, token_buf_size}
58 	};
59 
60 	if (token_size == NULL) {
61 		return PSA_ERROR_INVALID_ARGUMENT;
62 	}
63 
64 	status = psa_call(RSS_DELEGATED_SERVICE_HANDLE,
65 			  RSS_DELEGATED_ATTEST_GET_PLATFORM_TOKEN,
66 			  in_vec, IOVEC_LEN(in_vec),
67 			  out_vec, IOVEC_LEN(out_vec));
68 	if (status == PSA_SUCCESS) {
69 		*token_size = out_vec[0].len;
70 	}
71 
72 	return status;
73 }
74