1 /* 2 * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * 7 * Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 9 * 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * Neither the name of ARM nor the names of its contributors may be used 15 * to endorse or promote products derived from this software without specific 16 * prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef __IMG_PARSER_MOD_H__ 32 #define __IMG_PARSER_MOD_H__ 33 34 #include <auth_common.h> 35 36 /* 37 * Return values 38 */ 39 enum img_parser_ret_value { 40 IMG_PARSER_OK, 41 IMG_PARSER_ERR, /* Parser internal error */ 42 IMG_PARSER_ERR_FORMAT, /* Malformed image */ 43 IMG_PARSER_ERR_NOT_FOUND /* Authentication data not found */ 44 }; 45 46 /* 47 * Image types. A parser should be instantiated and registered for each type 48 */ 49 typedef enum img_type_enum { 50 IMG_RAW, /* Binary image */ 51 IMG_PLAT, /* Platform specific format */ 52 IMG_CERT, /* X509v3 certificate */ 53 IMG_MAX_TYPES, 54 } img_type_t; 55 56 /* Image parser library structure */ 57 typedef struct img_parser_lib_desc_s { 58 img_type_t img_type; 59 const char *name; 60 61 void (*init)(void); 62 int (*check_integrity)(void *img, unsigned int img_len); 63 int (*get_auth_param)(const auth_param_type_desc_t *type_desc, 64 void *img, unsigned int img_len, 65 void **param, unsigned int *param_len); 66 } img_parser_lib_desc_t; 67 68 /* Exported functions */ 69 void img_parser_init(void); 70 int img_parser_check_integrity(img_type_t img_type, 71 void *img, unsigned int img_len); 72 int img_parser_get_auth_param(img_type_t img_type, 73 const auth_param_type_desc_t *type_desc, 74 void *img, unsigned int img_len, 75 void **param_ptr, unsigned int *param_len); 76 77 /* Macro to register an image parser library */ 78 #define REGISTER_IMG_PARSER_LIB(_type, _name, _init, _check_int, _get_param) \ 79 static const img_parser_lib_desc_t __img_parser_lib_desc_##_type \ 80 __section(".img_parser_lib_descs") __used = { \ 81 .img_type = _type, \ 82 .name = _name, \ 83 .init = _init, \ 84 .check_integrity = _check_int, \ 85 .get_auth_param = _get_param \ 86 } 87 88 #endif /* __IMG_PARSER_MOD_H__ */ 89