105799ae0SJuan Castillo /* 205799ae0SJuan Castillo * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved. 305799ae0SJuan Castillo * 405799ae0SJuan Castillo * Redistribution and use in source and binary forms, with or without 505799ae0SJuan Castillo * modification, are permitted provided that the following conditions are met: 605799ae0SJuan Castillo * 705799ae0SJuan Castillo * Redistributions of source code must retain the above copyright notice, this 805799ae0SJuan Castillo * list of conditions and the following disclaimer. 905799ae0SJuan Castillo * 1005799ae0SJuan Castillo * Redistributions in binary form must reproduce the above copyright notice, 1105799ae0SJuan Castillo * this list of conditions and the following disclaimer in the documentation 1205799ae0SJuan Castillo * and/or other materials provided with the distribution. 1305799ae0SJuan Castillo * 1405799ae0SJuan Castillo * Neither the name of ARM nor the names of its contributors may be used 1505799ae0SJuan Castillo * to endorse or promote products derived from this software without specific 1605799ae0SJuan Castillo * prior written permission. 1705799ae0SJuan Castillo * 1805799ae0SJuan Castillo * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 1905799ae0SJuan Castillo * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2005799ae0SJuan Castillo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2105799ae0SJuan Castillo * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 2205799ae0SJuan Castillo * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2305799ae0SJuan Castillo * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2405799ae0SJuan Castillo * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2505799ae0SJuan Castillo * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2605799ae0SJuan Castillo * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2705799ae0SJuan Castillo * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2805799ae0SJuan Castillo * POSSIBILITY OF SUCH DAMAGE. 2905799ae0SJuan Castillo */ 3005799ae0SJuan Castillo 3105799ae0SJuan Castillo #ifndef __IMG_PARSER_MOD_H__ 3205799ae0SJuan Castillo #define __IMG_PARSER_MOD_H__ 3305799ae0SJuan Castillo 3405799ae0SJuan Castillo #include <auth_common.h> 3505799ae0SJuan Castillo 3605799ae0SJuan Castillo /* 3705799ae0SJuan Castillo * Return values 3805799ae0SJuan Castillo */ 3905799ae0SJuan Castillo enum img_parser_ret_value { 4005799ae0SJuan Castillo IMG_PARSER_OK, 4105799ae0SJuan Castillo IMG_PARSER_ERR, /* Parser internal error */ 4205799ae0SJuan Castillo IMG_PARSER_ERR_FORMAT, /* Malformed image */ 4305799ae0SJuan Castillo IMG_PARSER_ERR_NOT_FOUND /* Authentication data not found */ 4405799ae0SJuan Castillo }; 4505799ae0SJuan Castillo 4605799ae0SJuan Castillo /* 4705799ae0SJuan Castillo * Image types. A parser should be instantiated and registered for each type 4805799ae0SJuan Castillo */ 4905799ae0SJuan Castillo typedef enum img_type_enum { 5005799ae0SJuan Castillo IMG_RAW, /* Binary image */ 5105799ae0SJuan Castillo IMG_PLAT, /* Platform specific format */ 5205799ae0SJuan Castillo IMG_CERT, /* X509v3 certificate */ 5305799ae0SJuan Castillo IMG_MAX_TYPES, 5405799ae0SJuan Castillo } img_type_t; 5505799ae0SJuan Castillo 5605799ae0SJuan Castillo /* Image parser library structure */ 5705799ae0SJuan Castillo typedef struct img_parser_lib_desc_s { 5805799ae0SJuan Castillo img_type_t img_type; 5905799ae0SJuan Castillo const char *name; 6005799ae0SJuan Castillo 6105799ae0SJuan Castillo void (*init)(void); 6205799ae0SJuan Castillo int (*check_integrity)(void *img, unsigned int img_len); 6305799ae0SJuan Castillo int (*get_auth_param)(const auth_param_type_desc_t *type_desc, 6405799ae0SJuan Castillo void *img, unsigned int img_len, 6505799ae0SJuan Castillo void **param, unsigned int *param_len); 6605799ae0SJuan Castillo } img_parser_lib_desc_t; 6705799ae0SJuan Castillo 6805799ae0SJuan Castillo /* Exported functions */ 6905799ae0SJuan Castillo void img_parser_init(void); 7005799ae0SJuan Castillo int img_parser_check_integrity(img_type_t img_type, 7105799ae0SJuan Castillo void *img, unsigned int img_len); 7205799ae0SJuan Castillo int img_parser_get_auth_param(img_type_t img_type, 7305799ae0SJuan Castillo const auth_param_type_desc_t *type_desc, 7405799ae0SJuan Castillo void *img, unsigned int img_len, 7505799ae0SJuan Castillo void **param_ptr, unsigned int *param_len); 7605799ae0SJuan Castillo 7705799ae0SJuan Castillo /* Macro to register an image parser library */ 7805799ae0SJuan Castillo #define REGISTER_IMG_PARSER_LIB(_type, _name, _init, _check_int, _get_param) \ 7905799ae0SJuan Castillo static const img_parser_lib_desc_t __img_parser_lib_desc_##_type \ 80*65cd299fSSoren Brinkmann __section(".img_parser_lib_descs") __used = { \ 8105799ae0SJuan Castillo .img_type = _type, \ 8205799ae0SJuan Castillo .name = _name, \ 8305799ae0SJuan Castillo .init = _init, \ 8405799ae0SJuan Castillo .check_integrity = _check_int, \ 8505799ae0SJuan Castillo .get_auth_param = _get_param \ 8605799ae0SJuan Castillo } 8705799ae0SJuan Castillo 8805799ae0SJuan Castillo #endif /* __IMG_PARSER_MOD_H__ */ 89