1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (C) Foundries Ltd. 2021 - All Rights Reserved
4  * Author: Jorge Ramirez <jorge@foundries.io>
5  */
6  /*
7   * This is the Cryptographic Secure Element API, part of the Cryptographic
8   * Provider API.
9   *
10   * These requests shall be handled in the secure element normally placed on
11   * a serial communication bus (SPI, I2C).
12   */
13 #ifndef __CRYPTO_SE_H
14 #define __CRYPTO_SE_H
15 
16 #include <tee_api_types.h>
17 
18 /*
19  * Type identifier for the APDU message as described by Smart Card Standard
20  * ISO7816-4 about ADPU message bodies decoding convention:
21  *
22  * https://cardwerk.com/smart-card-standard-iso7816-4-section-5-basic-organizations/#chap5_3_2
23  */
24 enum crypto_apdu_type {
25 	CRYPTO_APDU_CASE_NO_HINT,
26 	CRYPTO_APDU_CASE_1,
27 	CRYPTO_APDU_CASE_2,
28 	CRYPTO_APDU_CASE_2E,
29 	CRYPTO_APDU_CASE_3,
30 	CRYPTO_APDU_CASE_3E,
31 	CRYPTO_APDU_CASE_4,
32 	CRYPTO_APDU_CASE_4E,
33 };
34 
35 TEE_Result crypto_se_do_apdu(enum crypto_apdu_type type,
36 			     uint8_t *header, size_t hdr_len,
37 			     uint8_t *src_data, size_t src_len,
38 			     uint8_t *dst_data, size_t *dst_len);
39 
40 /*
41  * Enable Secure Channel Protocol 03 to communicate with the Secure Element.
42  *
43  * Since SCP03 uses symmetric encryption, this interface also allows the user to
44  * attempt the rotation the keys stored in the Secure Element.
45  *
46  * https://globalplatform.org/wp-content/uploads/2014/07/GPC_2.3_D_SCP03_v1.1.2_PublicRelease.pdf
47  */
48 TEE_Result crypto_se_enable_scp03(bool rotate_keys);
49 #endif
50