^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * RSA internal helpers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2015, Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Authors: Tadeusz Struk <tadeusz.struk@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #ifndef _RSA_HELPER_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define _RSA_HELPER_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * rsa_key - RSA key structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * @n : RSA modulus raw byte stream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * @e : RSA public exponent raw byte stream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * @d : RSA private exponent raw byte stream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * @p : RSA prime factor p of n raw byte stream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * @q : RSA prime factor q of n raw byte stream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * @dp : RSA exponent d mod (p - 1) raw byte stream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * @dq : RSA exponent d mod (q - 1) raw byte stream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * @qinv : RSA CRT coefficient q^(-1) mod p raw byte stream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * @n_sz : length in bytes of RSA modulus n
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * @e_sz : length in bytes of RSA public exponent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * @d_sz : length in bytes of RSA private exponent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * @p_sz : length in bytes of p field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * @q_sz : length in bytes of q field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * @dp_sz : length in bytes of dp field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * @dq_sz : length in bytes of dq field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * @qinv_sz : length in bytes of qinv field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct rsa_key {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) const u8 *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) const u8 *e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) const u8 *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) const u8 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) const u8 *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) const u8 *dp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) const u8 *dq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) const u8 *qinv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) size_t n_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) size_t e_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) size_t d_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) size_t p_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) size_t q_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) size_t dp_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) size_t dq_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) size_t qinv_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) int rsa_parse_pub_key(struct rsa_key *rsa_key, const void *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) unsigned int key_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) int rsa_parse_priv_key(struct rsa_key *rsa_key, const void *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) unsigned int key_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) extern struct crypto_template rsa_pkcs1pad_tmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #endif