1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright 2018-2020 NXP
4  *
5  * Brief   Cryptographic library using the HW crypto driver.
6  *         Mathematical operation using HW if available.
7  */
8 #ifndef __DRVCRYPT_MATH_H__
9 #define __DRVCRYPT_MATH_H__
10 
11 #include <drvcrypt.h>
12 
13 /*
14  * Binary Modular operation data
15  */
16 struct drvcrypt_mod_op {
17 	struct drvcrypt_buf n;	    /* Modulus N */
18 	struct drvcrypt_buf a;	    /* Operand A */
19 	struct drvcrypt_buf b;	    /* Operand B */
20 	struct drvcrypt_buf result; /* Result of operation */
21 };
22 
23 /*
24  * Operation (A xor B) mod N
25  *
26  * @data   [in/out] Data operation
27  */
28 TEE_Result drvcrypt_xor_mod_n(struct drvcrypt_mod_op *data);
29 
30 /*
31  * Crypto Library Binaries Modular driver operations
32  */
33 struct drvcrypt_math {
34 	/* (A xor B) mod N */
35 	TEE_Result (*xor_mod_n)(struct drvcrypt_mod_op *op_data);
36 };
37 
38 /*
39  * Register a mathematical processing driver in the crypto API
40  *
41  * @ops - Driver operations in the HW layer
42  */
drvcrypt_register_math(const struct drvcrypt_math * ops)43 static inline TEE_Result drvcrypt_register_math(const struct drvcrypt_math *ops)
44 {
45 	return drvcrypt_register(CRYPTO_MATH, (void *)ops);
46 }
47 #endif /* __DRVCRYPT_MATH_H__ */
48