blob: 08884ab2218a55ba80ad79e170c6e1689f7dad9f [file] [log] [blame]
Juan Castillo8e55d932015-04-02 09:48:16 +01001/*
2 * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Juan Castillo8e55d932015-04-02 09:48:16 +01005 */
6
7#ifndef __CRYPTO_MOD_H__
8#define __CRYPTO_MOD_H__
9
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,
46 void *sig_alg, unsigned int sig_alg_len,
47 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
60#endif /* __CRYPTO_MOD_H__ */