xref: /rk3399_ARM-atf/include/drivers/auth/crypto_mod.h (revision c3cf06f1a3a9b9ee8ac7a0ae505f95c45f7dca84)
105799ae0SJuan Castillo /*
2735181b6SRoberto Vargas  * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
305799ae0SJuan Castillo  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
505799ae0SJuan Castillo  */
605799ae0SJuan Castillo 
7*c3cf06f1SAntonio Nino Diaz #ifndef CRYPTO_MOD_H
8*c3cf06f1SAntonio Nino Diaz #define CRYPTO_MOD_H
905799ae0SJuan Castillo 
1005799ae0SJuan Castillo /* Return values */
1105799ae0SJuan Castillo enum crypto_ret_value {
1205799ae0SJuan Castillo 	CRYPTO_SUCCESS = 0,
1305799ae0SJuan Castillo 	CRYPTO_ERR_INIT,
1405799ae0SJuan Castillo 	CRYPTO_ERR_HASH,
1505799ae0SJuan Castillo 	CRYPTO_ERR_SIGNATURE,
1605799ae0SJuan Castillo 	CRYPTO_ERR_UNKNOWN
1705799ae0SJuan Castillo };
1805799ae0SJuan Castillo 
1905799ae0SJuan Castillo /*
2005799ae0SJuan Castillo  * Cryptographic library descriptor
2105799ae0SJuan Castillo  */
2205799ae0SJuan Castillo typedef struct crypto_lib_desc_s {
2305799ae0SJuan Castillo 	const char *name;
2405799ae0SJuan Castillo 
2505799ae0SJuan Castillo 	/* Initialize library. This function is not expected to fail. All errors
2605799ae0SJuan Castillo 	 * must be handled inside the function, asserting or panicing in case of
2705799ae0SJuan Castillo 	 * a non-recoverable error */
2805799ae0SJuan Castillo 	void (*init)(void);
2905799ae0SJuan Castillo 
3005799ae0SJuan Castillo 	/* Verify a digital signature. Return one of the
3105799ae0SJuan Castillo 	 * 'enum crypto_ret_value' options */
3205799ae0SJuan Castillo 	int (*verify_signature)(void *data_ptr, unsigned int data_len,
3305799ae0SJuan Castillo 				void *sig_ptr, unsigned int sig_len,
3405799ae0SJuan Castillo 				void *sig_alg, unsigned int sig_alg_len,
3505799ae0SJuan Castillo 				void *pk_ptr, unsigned int pk_len);
3605799ae0SJuan Castillo 
3705799ae0SJuan Castillo 	/* Verify a hash. Return one of the 'enum crypto_ret_value' options */
3805799ae0SJuan Castillo 	int (*verify_hash)(void *data_ptr, unsigned int data_len,
3905799ae0SJuan Castillo 			   void *digest_info_ptr, unsigned int digest_info_len);
4005799ae0SJuan Castillo } crypto_lib_desc_t;
4105799ae0SJuan Castillo 
4205799ae0SJuan Castillo /* Public functions */
4305799ae0SJuan Castillo void crypto_mod_init(void);
4405799ae0SJuan Castillo int crypto_mod_verify_signature(void *data_ptr, unsigned int data_len,
4505799ae0SJuan Castillo 				void *sig_ptr, unsigned int sig_len,
46735181b6SRoberto Vargas 				void *sig_alg_ptr, unsigned int sig_alg_len,
4705799ae0SJuan Castillo 				void *pk_ptr, unsigned int pk_len);
4805799ae0SJuan Castillo int crypto_mod_verify_hash(void *data_ptr, unsigned int data_len,
4905799ae0SJuan Castillo 			   void *digest_info_ptr, unsigned int digest_info_len);
5005799ae0SJuan Castillo 
5105799ae0SJuan Castillo /* Macro to register a cryptographic library */
5205799ae0SJuan Castillo #define REGISTER_CRYPTO_LIB(_name, _init, _verify_signature, _verify_hash) \
5305799ae0SJuan Castillo 	const crypto_lib_desc_t crypto_lib_desc = { \
5405799ae0SJuan Castillo 		.name = _name, \
5505799ae0SJuan Castillo 		.init = _init, \
5605799ae0SJuan Castillo 		.verify_signature = _verify_signature, \
5705799ae0SJuan Castillo 		.verify_hash = _verify_hash \
5805799ae0SJuan Castillo 	}
5905799ae0SJuan Castillo 
603b94189aSRoberto Vargas extern const crypto_lib_desc_t crypto_lib_desc;
613b94189aSRoberto Vargas 
62*c3cf06f1SAntonio Nino Diaz #endif /* CRYPTO_MOD_H */
63