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