xref: /optee_os/core/include/signed_hdr.h (revision 82b5346da53bcae5aae8696a0098bb0d1d92f858)
1 /*
2  * Copyright (c) 2015, Linaro Limited
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 #ifndef SIGNED_HDR_H
28 #define SIGNED_HDR_H
29 
30 #include <inttypes.h>
31 #include <tee_api_types.h>
32 
33 enum shdr_img_type {
34 	SHDR_TA = 0,
35 	SHDR_BOOTSTRAP_TA = 1,
36 };
37 
38 #define SHDR_MAGIC	0x4f545348
39 
40 /**
41  * struct shdr - signed header
42  * @magic:	magic number must match SHDR_MAGIC
43  * @img_type:	image type, values defined by enum shdr_img_type
44  * @img_size:	image size in bytes
45  * @algo:	algorithm, defined by public key algorithms TEE_ALG_*
46  *		from TEE Internal API specification
47  * @hash_size:	size of the signed hash
48  * @sig_size:	size of the signature
49  * @hash:	hash of an image
50  * @sig:	signature of @hash
51  */
52 struct shdr {
53 	uint32_t magic;
54 	uint32_t img_type;
55 	uint32_t img_size;
56 	uint32_t algo;
57 	uint16_t hash_size;
58 	uint16_t sig_size;
59 	/*
60 	 * Commented out element used to visualize the layout dynamic part
61 	 * of the struct.
62 	 *
63 	 * hash is accessed through the macro SHDR_GET_HASH and
64 	 * signature is accessed through the macro SHDR_GET_SIG
65 	 *
66 	 * uint8_t hash[hash_size];
67 	 * uint8_t sig[sig_size];
68 	 */
69 };
70 
71 #define SHDR_GET_SIZE(x)	(sizeof(struct shdr) + (x)->hash_size + \
72 				 (x)->sig_size)
73 #define SHDR_GET_HASH(x)	(uint8_t *)(((struct shdr *)(x)) + 1)
74 #define SHDR_GET_SIG(x)		(SHDR_GET_HASH(x) + (x)->hash_size)
75 
76 struct shdr_bootstrap_ta {
77 	uint8_t uuid[sizeof(TEE_UUID)];
78 	uint32_t version;
79 };
80 
81 #endif /*SIGNED_HDR_H*/
82 
83