blob: 3a4210569c0b8748cff42a3933bb6f93cd130b1c [file] [log] [blame]
Juan Castillo8e55d932015-04-02 09:48:16 +01001/*
Roberto Vargasbe126ed2018-02-12 12:36:17 +00002 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
Juan Castillo8e55d932015-04-02 09:48:16 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Juan Castillo8e55d932015-04-02 09:48:16 +01005 */
6
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00007#ifndef CRYPTO_MOD_H
8#define CRYPTO_MOD_H
Juan Castillo8e55d932015-04-02 09:48:16 +01009
10/* Return values */
11enum 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 */
22typedef 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 */
43void crypto_mod_init(void);
44int crypto_mod_verify_signature(void *data_ptr, unsigned int data_len,
45 void *sig_ptr, unsigned int sig_len,
Roberto Vargasbe126ed2018-02-12 12:36:17 +000046 void *sig_alg_ptr, unsigned int sig_alg_len,
Juan Castillo8e55d932015-04-02 09:48:16 +010047 void *pk_ptr, unsigned int pk_len);
48int 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 Vargas52f707f2018-02-12 12:36:17 +000060extern const crypto_lib_desc_t crypto_lib_desc;
61
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +000062#endif /* CRYPTO_MOD_H */