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 AUTH_H_
32 #define AUTH_H_
33 
34 #include <stddef.h>
35 #include <stdint.h>
36 
37 /*
38  * Authentication infrastructure for Trusted Boot
39  *
40  * This infrastructure provides an API to access the authentication module. This
41  * module will implement the required operations for Trusted Boot by creating an
42  * instance of the structure 'auth_mod_t'. This instance must be called
43  * 'auth_mod' and must provide the functions to initialize the module and
44  * verify the authenticity of the images.
45  */
46 
47 /* Objects (images and certificates) involved in the TBB process */
48 enum {
49 	AUTH_BL2_IMG_CERT,
50 	AUTH_BL2_IMG,
51 	AUTH_TRUSTED_KEY_CERT,
52 	AUTH_BL30_KEY_CERT,
53 	AUTH_BL30_IMG_CERT,
54 	AUTH_BL30_IMG,
55 	AUTH_BL31_KEY_CERT,
56 	AUTH_BL31_IMG_CERT,
57 	AUTH_BL31_IMG,
58 	AUTH_BL32_KEY_CERT,
59 	AUTH_BL32_IMG_CERT,
60 	AUTH_BL32_IMG,
61 	AUTH_BL33_KEY_CERT,
62 	AUTH_BL33_IMG_CERT,
63 	AUTH_BL33_IMG,
64 	AUTH_NUM_OBJ
65 };
66 
67 /* Authentication module structure */
68 typedef struct auth_mod_s {
69 	/* [mandatory] Module name. Printed to the log during initialization */
70 	const char *name;
71 
72 	/* [mandatory] Initialize the authentication module */
73 	int (*init)(void);
74 
75 	/* [mandatory] This function will be called to authenticate a new
76 	 * object loaded into memory. The obj_id corresponds to one of the
77 	 * values in the enumeration above */
78 	int (*verify)(unsigned int obj_id, uintptr_t obj_buf, size_t len);
79 } auth_mod_t;
80 
81 /* This variable must be instantiated by the authentication module */
82 extern const auth_mod_t auth_mod;
83 
84 /* Public functions */
85 void auth_init(void);
86 int auth_verify_obj(unsigned int obj_id, uintptr_t obj_buf, size_t len);
87 
88 #endif /* AUTH_H_ */
89