1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright 2014 Freescale Semiconductor, Inc.
13 * struct key_prop - holder for a public key properties
15 * The struct has pointers to modulus (Typically called N),
16 * The inverse, R^2, exponent. These can be typecasted and
17 * used as byte arrays or converted to the required format
18 * as per requirement of RSA implementation.
21 const void *rr; /* R^2 can be treated as byte array */
22 const void *modulus; /* modulus as byte array */
23 const void *public_exponent; /* public exponent as byte array */
24 uint32_t n0inv; /* -1 / modulus[0] mod 2^32 */
25 int num_bits; /* Key length in bits */
26 uint32_t exp_len; /* Exponent length in number of uint8_t */
30 * rsa_mod_exp_sw() - Perform RSA Modular Exponentiation in sw
32 * Operation: out[] = sig ^ exponent % modulus
34 * @sig: RSA PKCS1.5 signature
35 * @sig_len: Length of signature in number of bytes
36 * @node: Node with RSA key elements like modulus, exponent, R^2, n0inv
37 * @out: Result in form of byte array of len equal to sig_len
39 int rsa_mod_exp_sw(const uint8_t *sig, uint32_t sig_len,
40 struct key_prop *node, uint8_t *out);
42 int rsa_mod_exp(struct udevice *dev, const uint8_t *sig, uint32_t sig_len,
43 struct key_prop *node, uint8_t *out);
45 #if defined(CONFIG_CMD_ZYNQ_RSA)
46 int zynq_pow_mod(u32 *keyptr, u32 *inout);
50 * struct struct mod_exp_ops - Driver model for RSA Modular Exponentiation
53 * The uclass interface is implemented by all crypto devices which use
58 * Perform Modular Exponentiation
60 * Operation: out[] = sig ^ exponent % modulus
63 * @sig: RSA PKCS1.5 signature
64 * @sig_len: Length of signature in number of bytes
65 * @node: Node with RSA key elements like modulus, exponent,
67 * @out: Result in form of byte array of len equal to sig_len
69 * This function computes exponentiation over the signature.
70 * Returns: 0 if exponentiation is successful, or a negative value
73 int (*mod_exp)(struct udevice *dev, const uint8_t *sig,
74 uint32_t sig_len, struct key_prop *node,