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