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 <types_ext.h> 31 32 enum shdr_img_type { 33 SHDR_TA = 0, 34 }; 35 36 #define SHDR_MAGIC 0x4f545348 37 38 /** 39 * struct shdr - signed header 40 * @magic: magic number must match SHDR_MAGIC 41 * @img_type: image type, values defined by enum shdr_img_type 42 * @img_size: image size in bytes 43 * @algo: algorithm, defined by public key algorithms TEE_ALG_* 44 * from TEE Internal API specification 45 * @hash_size: size of the signed hash 46 * @sig_size: size of the signature 47 * @hash: hash of an image 48 * @sig: signature of @hash 49 */ 50 struct shdr { 51 uint32_t magic; 52 uint32_t img_type; 53 uint32_t img_size; 54 uint32_t algo; 55 uint16_t hash_size; 56 uint16_t sig_size; 57 /* 58 * Commented out element used to visualize the layout dynamic part 59 * of the struct. 60 * 61 * hash is accessed through the macro SHDR_GET_HASH and 62 * signature is accessed through the macro SHDR_GET_SIG 63 * 64 * uint8_t hash[hash_size]; 65 * uint8_t sig[sig_size]; 66 */ 67 }; 68 69 #define SHDR_GET_SIZE(x) (sizeof(struct shdr) + (x)->hash_size + \ 70 (x)->sig_size) 71 #define SHDR_GET_HASH(x) (uint8_t *)(((struct shdr *)(x)) + 1) 72 #define SHDR_GET_SIG(x) (SHDR_GET_HASH(x) + (x)->hash_size) 73 74 #endif /*SIGNED_HDR_H*/ 75 76