2 * Copyright (c) 2014, Ruchika Gupta.
4 * SPDX-License-Identifier: GPL-2.0+
14 * struct key_prop - holder for a public key properties
16 * The struct has pointers to modulus (Typically called N),
17 * The inverse, R^2, exponent. These can be typecasted and
18 * used as byte arrays or converted to the required format
19 * as per requirement of RSA implementation.
22 const void *rr; /* R^2 can be treated as byte array */
23 const void *modulus; /* modulus as byte array */
24 const void *public_exponent; /* public exponent as byte array */
25 uint32_t n0inv; /* -1 / modulus[0] mod 2^32 */
26 int num_bits; /* Key length in bits */
27 uint32_t exp_len; /* Exponent length in number of uint8_t */
31 * rsa_mod_exp_sw() - Perform RSA Modular Exponentiation in sw
33 * Operation: out[] = sig ^ exponent % modulus
35 * @sig: RSA PKCS1.5 signature
36 * @sig_len: Length of signature in number of bytes
37 * @node: Node with RSA key elements like modulus, exponent, R^2, n0inv
38 * @out: Result in form of byte array of len equal to sig_len
40 int rsa_mod_exp_sw(const uint8_t *sig, uint32_t sig_len,
41 struct key_prop *node, uint8_t *out);
43 int rsa_mod_exp(struct udevice *dev, const uint8_t *sig, uint32_t sig_len,
44 struct key_prop *node, uint8_t *out);
47 * struct struct mod_exp_ops - Driver model for RSA Modular Exponentiation
50 * The uclass interface is implemented by all crypto devices which use
55 * Perform Modular Exponentiation
57 * Operation: out[] = sig ^ exponent % modulus
60 * @sig: RSA PKCS1.5 signature
61 * @sig_len: Length of signature in number of bytes
62 * @node: Node with RSA key elements like modulus, exponent,
64 * @out: Result in form of byte array of len equal to sig_len
66 * This function computes exponentiation over the signature.
67 * Returns: 0 if exponentiation is successful, or a negative value
70 int (*mod_exp)(struct udevice *dev, const uint8_t *sig,
71 uint32_t sig_len, struct key_prop *node,