xref: /rk3399_ARM-atf/include/drivers/auth/crypto_mod.h (revision 05799ae0c80ca4592ff2eba1e61027f8661529eb)
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 __CRYPTO_MOD_H__
32*05799ae0SJuan Castillo #define __CRYPTO_MOD_H__
33*05799ae0SJuan Castillo 
34*05799ae0SJuan Castillo /* Return values */
35*05799ae0SJuan Castillo enum crypto_ret_value {
36*05799ae0SJuan Castillo 	CRYPTO_SUCCESS = 0,
37*05799ae0SJuan Castillo 	CRYPTO_ERR_INIT,
38*05799ae0SJuan Castillo 	CRYPTO_ERR_HASH,
39*05799ae0SJuan Castillo 	CRYPTO_ERR_SIGNATURE,
40*05799ae0SJuan Castillo 	CRYPTO_ERR_UNKNOWN
41*05799ae0SJuan Castillo };
42*05799ae0SJuan Castillo 
43*05799ae0SJuan Castillo /*
44*05799ae0SJuan Castillo  * Cryptographic library descriptor
45*05799ae0SJuan Castillo  */
46*05799ae0SJuan Castillo typedef struct crypto_lib_desc_s {
47*05799ae0SJuan Castillo 	const char *name;
48*05799ae0SJuan Castillo 
49*05799ae0SJuan Castillo 	/* Initialize library. This function is not expected to fail. All errors
50*05799ae0SJuan Castillo 	 * must be handled inside the function, asserting or panicing in case of
51*05799ae0SJuan Castillo 	 * a non-recoverable error */
52*05799ae0SJuan Castillo 	void (*init)(void);
53*05799ae0SJuan Castillo 
54*05799ae0SJuan Castillo 	/* Verify a digital signature. Return one of the
55*05799ae0SJuan Castillo 	 * 'enum crypto_ret_value' options */
56*05799ae0SJuan Castillo 	int (*verify_signature)(void *data_ptr, unsigned int data_len,
57*05799ae0SJuan Castillo 				void *sig_ptr, unsigned int sig_len,
58*05799ae0SJuan Castillo 				void *sig_alg, unsigned int sig_alg_len,
59*05799ae0SJuan Castillo 				void *pk_ptr, unsigned int pk_len);
60*05799ae0SJuan Castillo 
61*05799ae0SJuan Castillo 	/* Verify a hash. Return one of the 'enum crypto_ret_value' options */
62*05799ae0SJuan Castillo 	int (*verify_hash)(void *data_ptr, unsigned int data_len,
63*05799ae0SJuan Castillo 			   void *digest_info_ptr, unsigned int digest_info_len);
64*05799ae0SJuan Castillo } crypto_lib_desc_t;
65*05799ae0SJuan Castillo 
66*05799ae0SJuan Castillo /* Public functions */
67*05799ae0SJuan Castillo void crypto_mod_init(void);
68*05799ae0SJuan Castillo int crypto_mod_verify_signature(void *data_ptr, unsigned int data_len,
69*05799ae0SJuan Castillo 				void *sig_ptr, unsigned int sig_len,
70*05799ae0SJuan Castillo 				void *sig_alg, unsigned int sig_alg_len,
71*05799ae0SJuan Castillo 				void *pk_ptr, unsigned int pk_len);
72*05799ae0SJuan Castillo int crypto_mod_verify_hash(void *data_ptr, unsigned int data_len,
73*05799ae0SJuan Castillo 			   void *digest_info_ptr, unsigned int digest_info_len);
74*05799ae0SJuan Castillo 
75*05799ae0SJuan Castillo /* Macro to register a cryptographic library */
76*05799ae0SJuan Castillo #define REGISTER_CRYPTO_LIB(_name, _init, _verify_signature, _verify_hash) \
77*05799ae0SJuan Castillo 	const crypto_lib_desc_t crypto_lib_desc = { \
78*05799ae0SJuan Castillo 		.name = _name, \
79*05799ae0SJuan Castillo 		.init = _init, \
80*05799ae0SJuan Castillo 		.verify_signature = _verify_signature, \
81*05799ae0SJuan Castillo 		.verify_hash = _verify_hash \
82*05799ae0SJuan Castillo 	}
83*05799ae0SJuan Castillo 
84*05799ae0SJuan Castillo #endif /* __CRYPTO_MOD_H__ */
85