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 __AUTH_COMMON_H__ 32*05799ae0SJuan Castillo #define __AUTH_COMMON_H__ 33*05799ae0SJuan Castillo 34*05799ae0SJuan Castillo /* 35*05799ae0SJuan Castillo * Authentication framework common types 36*05799ae0SJuan Castillo */ 37*05799ae0SJuan Castillo 38*05799ae0SJuan Castillo /* 39*05799ae0SJuan Castillo * Type of parameters that can be extracted from an image and 40*05799ae0SJuan Castillo * used for authentication 41*05799ae0SJuan Castillo */ 42*05799ae0SJuan Castillo typedef enum auth_param_type_enum { 43*05799ae0SJuan Castillo AUTH_PARAM_NONE, 44*05799ae0SJuan Castillo AUTH_PARAM_RAW_DATA, /* Raw image data */ 45*05799ae0SJuan Castillo AUTH_PARAM_SIG, /* The image signature */ 46*05799ae0SJuan Castillo AUTH_PARAM_SIG_ALG, /* The image signature algorithm */ 47*05799ae0SJuan Castillo AUTH_PARAM_HASH, /* A hash (including the algorithm) */ 48*05799ae0SJuan Castillo AUTH_PARAM_PUB_KEY, /* A public key */ 49*05799ae0SJuan Castillo } auth_param_type_t; 50*05799ae0SJuan Castillo 51*05799ae0SJuan Castillo /* 52*05799ae0SJuan Castillo * Defines an authentication parameter. The cookie will be interpreted by the 53*05799ae0SJuan Castillo * image parser module. 54*05799ae0SJuan Castillo */ 55*05799ae0SJuan Castillo typedef struct auth_param_type_desc_s { 56*05799ae0SJuan Castillo auth_param_type_t type; 57*05799ae0SJuan Castillo void *cookie; 58*05799ae0SJuan Castillo } auth_param_type_desc_t; 59*05799ae0SJuan Castillo 60*05799ae0SJuan Castillo /* 61*05799ae0SJuan Castillo * Store a pointer to the authentication parameter and its length 62*05799ae0SJuan Castillo */ 63*05799ae0SJuan Castillo typedef struct auth_param_data_desc_s { 64*05799ae0SJuan Castillo void *ptr; 65*05799ae0SJuan Castillo unsigned int len; 66*05799ae0SJuan Castillo } auth_param_data_desc_t; 67*05799ae0SJuan Castillo 68*05799ae0SJuan Castillo /* 69*05799ae0SJuan Castillo * Authentication parameter descriptor, including type and value 70*05799ae0SJuan Castillo */ 71*05799ae0SJuan Castillo typedef struct auth_param_desc_s { 72*05799ae0SJuan Castillo auth_param_type_desc_t *type_desc; 73*05799ae0SJuan Castillo auth_param_data_desc_t data; 74*05799ae0SJuan Castillo } auth_param_desc_t; 75*05799ae0SJuan Castillo 76*05799ae0SJuan Castillo /* 77*05799ae0SJuan Castillo * The method type defines how an image is authenticated 78*05799ae0SJuan Castillo */ 79*05799ae0SJuan Castillo typedef enum auth_method_type_enum { 80*05799ae0SJuan Castillo AUTH_METHOD_NONE = 0, 81*05799ae0SJuan Castillo AUTH_METHOD_HASH, /* Authenticate by hash matching */ 82*05799ae0SJuan Castillo AUTH_METHOD_SIG, /* Authenticate by PK operation */ 83*05799ae0SJuan Castillo AUTH_METHOD_NUM /* Number of methods */ 84*05799ae0SJuan Castillo } auth_method_type_t; 85*05799ae0SJuan Castillo 86*05799ae0SJuan Castillo /* 87*05799ae0SJuan Castillo * Parameters for authentication by hash matching 88*05799ae0SJuan Castillo */ 89*05799ae0SJuan Castillo typedef struct auth_method_param_hash_s { 90*05799ae0SJuan Castillo auth_param_type_desc_t *data; /* Data to hash */ 91*05799ae0SJuan Castillo auth_param_type_desc_t *hash; /* Hash to match with */ 92*05799ae0SJuan Castillo } auth_method_param_hash_t; 93*05799ae0SJuan Castillo 94*05799ae0SJuan Castillo /* 95*05799ae0SJuan Castillo * Parameters for authentication by signature 96*05799ae0SJuan Castillo */ 97*05799ae0SJuan Castillo typedef struct auth_method_param_sig_s { 98*05799ae0SJuan Castillo auth_param_type_desc_t *pk; /* Public key */ 99*05799ae0SJuan Castillo auth_param_type_desc_t *sig; /* Signature to check */ 100*05799ae0SJuan Castillo auth_param_type_desc_t *alg; /* Signature algorithm */ 101*05799ae0SJuan Castillo auth_param_type_desc_t *data; /* Data signed */ 102*05799ae0SJuan Castillo } auth_method_param_sig_t; 103*05799ae0SJuan Castillo 104*05799ae0SJuan Castillo /* 105*05799ae0SJuan Castillo * Parameters for authentication by NV counter 106*05799ae0SJuan Castillo */ 107*05799ae0SJuan Castillo typedef struct auth_method_param_nv_ctr_s { 108*05799ae0SJuan Castillo auth_param_type_desc_t *nv_ctr; /* NV counter value */ 109*05799ae0SJuan Castillo } auth_method_param_nv_ctr_t; 110*05799ae0SJuan Castillo 111*05799ae0SJuan Castillo /* 112*05799ae0SJuan Castillo * Authentication method descriptor 113*05799ae0SJuan Castillo */ 114*05799ae0SJuan Castillo typedef struct auth_method_desc_s { 115*05799ae0SJuan Castillo auth_method_type_t type; 116*05799ae0SJuan Castillo union { 117*05799ae0SJuan Castillo auth_method_param_hash_t hash; 118*05799ae0SJuan Castillo auth_method_param_sig_t sig; 119*05799ae0SJuan Castillo auth_method_param_nv_ctr_t nv_ctr; 120*05799ae0SJuan Castillo } param; 121*05799ae0SJuan Castillo } auth_method_desc_t; 122*05799ae0SJuan Castillo 123*05799ae0SJuan Castillo /* 124*05799ae0SJuan Castillo * Helper macro to define an authentication parameter type descriptor 125*05799ae0SJuan Castillo */ 126*05799ae0SJuan Castillo #define AUTH_PARAM_TYPE_DESC(_type, _cookie) \ 127*05799ae0SJuan Castillo { \ 128*05799ae0SJuan Castillo .type = _type, \ 129*05799ae0SJuan Castillo .cookie = (void *)_cookie \ 130*05799ae0SJuan Castillo } 131*05799ae0SJuan Castillo 132*05799ae0SJuan Castillo /* 133*05799ae0SJuan Castillo * Helper macro to define an authentication parameter data descriptor 134*05799ae0SJuan Castillo */ 135*05799ae0SJuan Castillo #define AUTH_PARAM_DATA_DESC(_ptr, _len) \ 136*05799ae0SJuan Castillo { \ 137*05799ae0SJuan Castillo .ptr = (void *)_ptr, \ 138*05799ae0SJuan Castillo .len = (unsigned int)_len \ 139*05799ae0SJuan Castillo } 140*05799ae0SJuan Castillo 141*05799ae0SJuan Castillo #endif /* __AUTH_COMMON_H__ */ 142