blob: 5a55624949deaa3955ad62f4664f02f63ba77597 [file] [log] [blame]
Juan Castillo8e55d932015-04-02 09:48:16 +01001/*
2 * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef __CRYPTO_MOD_H__
32#define __CRYPTO_MOD_H__
33
34/* Return values */
35enum crypto_ret_value {
36 CRYPTO_SUCCESS = 0,
37 CRYPTO_ERR_INIT,
38 CRYPTO_ERR_HASH,
39 CRYPTO_ERR_SIGNATURE,
40 CRYPTO_ERR_UNKNOWN
41};
42
43/*
44 * Cryptographic library descriptor
45 */
46typedef struct crypto_lib_desc_s {
47 const char *name;
48
49 /* Initialize library. This function is not expected to fail. All errors
50 * must be handled inside the function, asserting or panicing in case of
51 * a non-recoverable error */
52 void (*init)(void);
53
54 /* Verify a digital signature. Return one of the
55 * 'enum crypto_ret_value' options */
56 int (*verify_signature)(void *data_ptr, unsigned int data_len,
57 void *sig_ptr, unsigned int sig_len,
58 void *sig_alg, unsigned int sig_alg_len,
59 void *pk_ptr, unsigned int pk_len);
60
61 /* Verify a hash. Return one of the 'enum crypto_ret_value' options */
62 int (*verify_hash)(void *data_ptr, unsigned int data_len,
63 void *digest_info_ptr, unsigned int digest_info_len);
64} crypto_lib_desc_t;
65
66/* Public functions */
67void crypto_mod_init(void);
68int crypto_mod_verify_signature(void *data_ptr, unsigned int data_len,
69 void *sig_ptr, unsigned int sig_len,
70 void *sig_alg, unsigned int sig_alg_len,
71 void *pk_ptr, unsigned int pk_len);
72int crypto_mod_verify_hash(void *data_ptr, unsigned int data_len,
73 void *digest_info_ptr, unsigned int digest_info_len);
74
75/* Macro to register a cryptographic library */
76#define REGISTER_CRYPTO_LIB(_name, _init, _verify_signature, _verify_hash) \
77 const crypto_lib_desc_t crypto_lib_desc = { \
78 .name = _name, \
79 .init = _init, \
80 .verify_signature = _verify_signature, \
81 .verify_hash = _verify_hash \
82 }
83
84#endif /* __CRYPTO_MOD_H__ */