Home | History | Annotate | Download | only in auth
      1 /*
      2  * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
      3  *
      4  * SPDX-License-Identifier: BSD-3-Clause
      5  */
      6 
      7 #ifndef __IMG_PARSER_MOD_H__
      8 #define __IMG_PARSER_MOD_H__
      9 
     10 #include <auth_common.h>
     11 
     12 /*
     13  * Return values
     14  */
     15 enum img_parser_ret_value {
     16 	IMG_PARSER_OK,
     17 	IMG_PARSER_ERR,			/* Parser internal error */
     18 	IMG_PARSER_ERR_FORMAT,		/* Malformed image */
     19 	IMG_PARSER_ERR_NOT_FOUND	/* Authentication data not found */
     20 };
     21 
     22 /*
     23  * Image types. A parser should be instantiated and registered for each type
     24  */
     25 typedef enum img_type_enum {
     26 	IMG_RAW,			/* Binary image */
     27 	IMG_PLAT,			/* Platform specific format */
     28 	IMG_CERT,			/* X509v3 certificate */
     29 	IMG_MAX_TYPES,
     30 } img_type_t;
     31 
     32 /* Image parser library structure */
     33 typedef struct img_parser_lib_desc_s {
     34 	img_type_t img_type;
     35 	const char *name;
     36 
     37 	void (*init)(void);
     38 	int (*check_integrity)(void *img, unsigned int img_len);
     39 	int (*get_auth_param)(const auth_param_type_desc_t *type_desc,
     40 			void *img, unsigned int img_len,
     41 			void **param, unsigned int *param_len);
     42 } img_parser_lib_desc_t;
     43 
     44 /* Exported functions */
     45 void img_parser_init(void);
     46 int img_parser_check_integrity(img_type_t img_type,
     47 		void *img, unsigned int img_len);
     48 int img_parser_get_auth_param(img_type_t img_type,
     49 		const auth_param_type_desc_t *type_desc,
     50 		void *img, unsigned int img_len,
     51 		void **param_ptr, unsigned int *param_len);
     52 
     53 /* Macro to register an image parser library */
     54 #define REGISTER_IMG_PARSER_LIB(_type, _name, _init, _check_int, _get_param) \
     55 	static const img_parser_lib_desc_t __img_parser_lib_desc_##_type \
     56 	__section(".img_parser_lib_descs") __used = { \
     57 		.img_type = _type, \
     58 		.name = _name, \
     59 		.init = _init, \
     60 		.check_integrity = _check_int, \
     61 		.get_auth_param = _get_param \
     62 	}
     63 
     64 #endif /* __IMG_PARSER_MOD_H__ */
     65