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