Ruchika Gupta | fc2f424 | 2015-01-23 16:01:50 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014, Ruchika Gupta. |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #ifndef _RSA_MOD_EXP_H |
| 8 | #define _RSA_MOD_EXP_H |
| 9 | |
| 10 | #include <errno.h> |
| 11 | #include <image.h> |
| 12 | |
| 13 | /** |
| 14 | * struct key_prop - holder for a public key properties |
| 15 | * |
| 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. |
| 20 | */ |
| 21 | struct key_prop { |
| 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 */ |
| 28 | }; |
| 29 | |
| 30 | /** |
| 31 | * rsa_mod_exp_sw() - Perform RSA Modular Exponentiation in sw |
| 32 | * |
| 33 | * Operation: out[] = sig ^ exponent % modulus |
| 34 | * |
| 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 |
| 39 | */ |
| 40 | int rsa_mod_exp_sw(const uint8_t *sig, uint32_t sig_len, |
| 41 | struct key_prop *node, uint8_t *out); |
| 42 | |
| 43 | #endif |