Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 1 | /* |
Roberto Vargas | be126ed | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 2 | * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __CRYPTO_MOD_H__ |
| 8 | #define __CRYPTO_MOD_H__ |
| 9 | |
| 10 | /* Return values */ |
| 11 | enum crypto_ret_value { |
| 12 | CRYPTO_SUCCESS = 0, |
| 13 | CRYPTO_ERR_INIT, |
| 14 | CRYPTO_ERR_HASH, |
| 15 | CRYPTO_ERR_SIGNATURE, |
| 16 | CRYPTO_ERR_UNKNOWN |
| 17 | }; |
| 18 | |
| 19 | /* |
| 20 | * Cryptographic library descriptor |
| 21 | */ |
| 22 | typedef struct crypto_lib_desc_s { |
| 23 | const char *name; |
| 24 | |
| 25 | /* Initialize library. This function is not expected to fail. All errors |
| 26 | * must be handled inside the function, asserting or panicing in case of |
| 27 | * a non-recoverable error */ |
| 28 | void (*init)(void); |
| 29 | |
| 30 | /* Verify a digital signature. Return one of the |
| 31 | * 'enum crypto_ret_value' options */ |
| 32 | int (*verify_signature)(void *data_ptr, unsigned int data_len, |
| 33 | void *sig_ptr, unsigned int sig_len, |
| 34 | void *sig_alg, unsigned int sig_alg_len, |
| 35 | void *pk_ptr, unsigned int pk_len); |
| 36 | |
| 37 | /* Verify a hash. Return one of the 'enum crypto_ret_value' options */ |
| 38 | int (*verify_hash)(void *data_ptr, unsigned int data_len, |
| 39 | void *digest_info_ptr, unsigned int digest_info_len); |
| 40 | } crypto_lib_desc_t; |
| 41 | |
| 42 | /* Public functions */ |
| 43 | void crypto_mod_init(void); |
| 44 | int crypto_mod_verify_signature(void *data_ptr, unsigned int data_len, |
| 45 | void *sig_ptr, unsigned int sig_len, |
Roberto Vargas | be126ed | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 46 | void *sig_alg_ptr, unsigned int sig_alg_len, |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 47 | void *pk_ptr, unsigned int pk_len); |
| 48 | int crypto_mod_verify_hash(void *data_ptr, unsigned int data_len, |
| 49 | void *digest_info_ptr, unsigned int digest_info_len); |
| 50 | |
| 51 | /* Macro to register a cryptographic library */ |
| 52 | #define REGISTER_CRYPTO_LIB(_name, _init, _verify_signature, _verify_hash) \ |
| 53 | const crypto_lib_desc_t crypto_lib_desc = { \ |
| 54 | .name = _name, \ |
| 55 | .init = _init, \ |
| 56 | .verify_signature = _verify_signature, \ |
| 57 | .verify_hash = _verify_hash \ |
| 58 | } |
| 59 | |
Roberto Vargas | 52f707f | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 60 | extern const crypto_lib_desc_t crypto_lib_desc; |
| 61 | |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 62 | #endif /* __CRYPTO_MOD_H__ */ |