Tadeusz Struk | cfc2bb3 | 2015-06-16 10:31:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * RSA internal helpers |
| 3 | * |
| 4 | * Copyright (c) 2015, Intel Corporation |
| 5 | * Authors: Tadeusz Struk <tadeusz.struk@intel.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the Free |
| 9 | * Software Foundation; either version 2 of the License, or (at your option) |
| 10 | * any later version. |
| 11 | * |
| 12 | */ |
| 13 | #ifndef _RSA_HELPER_ |
| 14 | #define _RSA_HELPER_ |
Tudor Ambarus | 5a7de97 | 2016-06-14 16:14:58 +0300 | [diff] [blame] | 15 | #include <linux/types.h> |
Tadeusz Struk | cfc2bb3 | 2015-06-16 10:31:01 -0700 | [diff] [blame] | 16 | |
Tudor Ambarus | 5a7de97 | 2016-06-14 16:14:58 +0300 | [diff] [blame] | 17 | /** |
| 18 | * rsa_key - RSA key structure |
| 19 | * @n : RSA modulus raw byte stream |
| 20 | * @e : RSA public exponent raw byte stream |
| 21 | * @d : RSA private exponent raw byte stream |
Salvatore Benedetto | 8be0b84 | 2016-07-04 17:21:38 +0100 | [diff] [blame] | 22 | * @p : RSA prime factor p of n raw byte stream |
| 23 | * @q : RSA prime factor q of n raw byte stream |
| 24 | * @dp : RSA exponent d mod (p - 1) raw byte stream |
| 25 | * @dq : RSA exponent d mod (q - 1) raw byte stream |
| 26 | * @qinv : RSA CRT coefficient q^(-1) mod p raw byte stream |
Tudor Ambarus | 5a7de97 | 2016-06-14 16:14:58 +0300 | [diff] [blame] | 27 | * @n_sz : length in bytes of RSA modulus n |
| 28 | * @e_sz : length in bytes of RSA public exponent |
| 29 | * @d_sz : length in bytes of RSA private exponent |
Salvatore Benedetto | 8be0b84 | 2016-07-04 17:21:38 +0100 | [diff] [blame] | 30 | * @p_sz : length in bytes of p field |
| 31 | * @q_sz : length in bytes of q field |
| 32 | * @dp_sz : length in bytes of dp field |
| 33 | * @dq_sz : length in bytes of dq field |
| 34 | * @qinv_sz : length in bytes of qinv field |
Tudor Ambarus | 5a7de97 | 2016-06-14 16:14:58 +0300 | [diff] [blame] | 35 | */ |
Tadeusz Struk | cfc2bb3 | 2015-06-16 10:31:01 -0700 | [diff] [blame] | 36 | struct rsa_key { |
Tudor Ambarus | 5a7de97 | 2016-06-14 16:14:58 +0300 | [diff] [blame] | 37 | const u8 *n; |
| 38 | const u8 *e; |
| 39 | const u8 *d; |
Salvatore Benedetto | 8be0b84 | 2016-07-04 17:21:38 +0100 | [diff] [blame] | 40 | const u8 *p; |
| 41 | const u8 *q; |
| 42 | const u8 *dp; |
| 43 | const u8 *dq; |
| 44 | const u8 *qinv; |
Tudor Ambarus | 5a7de97 | 2016-06-14 16:14:58 +0300 | [diff] [blame] | 45 | size_t n_sz; |
| 46 | size_t e_sz; |
| 47 | size_t d_sz; |
Salvatore Benedetto | 8be0b84 | 2016-07-04 17:21:38 +0100 | [diff] [blame] | 48 | size_t p_sz; |
| 49 | size_t q_sz; |
| 50 | size_t dp_sz; |
| 51 | size_t dq_sz; |
| 52 | size_t qinv_sz; |
Tadeusz Struk | cfc2bb3 | 2015-06-16 10:31:01 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
Tadeusz Struk | 22287b0 | 2015-10-08 09:26:55 -0700 | [diff] [blame] | 55 | int rsa_parse_pub_key(struct rsa_key *rsa_key, const void *key, |
| 56 | unsigned int key_len); |
| 57 | |
| 58 | int rsa_parse_priv_key(struct rsa_key *rsa_key, const void *key, |
| 59 | unsigned int key_len); |
Tadeusz Struk | cfc2bb3 | 2015-06-16 10:31:01 -0700 | [diff] [blame] | 60 | |
Andrzej Zaborowski | 3d5b1ec | 2015-12-05 17:09:34 +0100 | [diff] [blame] | 61 | extern struct crypto_template rsa_pkcs1pad_tmpl; |
Tadeusz Struk | cfc2bb3 | 2015-06-16 10:31:01 -0700 | [diff] [blame] | 62 | #endif |