crypto: rsa - Store rest of the private key components
When parsing a private key, store all non-optional fields. These are required for enabling CRT mode for decrypt and verify Signed-off-by: Salvatore Benedetto <salvatore.benedetto@intel.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
e24860f2a6
commit
8be0b84e58
3 changed files with 100 additions and 5 deletions
|
@ -78,6 +78,81 @@ int rsa_get_d(void *context, size_t hdrlen, unsigned char tag,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int rsa_get_p(void *context, size_t hdrlen, unsigned char tag,
|
||||
const void *value, size_t vlen)
|
||||
{
|
||||
struct rsa_key *key = context;
|
||||
|
||||
/* invalid key provided */
|
||||
if (!value || !vlen || vlen > key->n_sz)
|
||||
return -EINVAL;
|
||||
|
||||
key->p = value;
|
||||
key->p_sz = vlen;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rsa_get_q(void *context, size_t hdrlen, unsigned char tag,
|
||||
const void *value, size_t vlen)
|
||||
{
|
||||
struct rsa_key *key = context;
|
||||
|
||||
/* invalid key provided */
|
||||
if (!value || !vlen || vlen > key->n_sz)
|
||||
return -EINVAL;
|
||||
|
||||
key->q = value;
|
||||
key->q_sz = vlen;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rsa_get_dp(void *context, size_t hdrlen, unsigned char tag,
|
||||
const void *value, size_t vlen)
|
||||
{
|
||||
struct rsa_key *key = context;
|
||||
|
||||
/* invalid key provided */
|
||||
if (!value || !vlen || vlen > key->n_sz)
|
||||
return -EINVAL;
|
||||
|
||||
key->dp = value;
|
||||
key->dp_sz = vlen;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rsa_get_dq(void *context, size_t hdrlen, unsigned char tag,
|
||||
const void *value, size_t vlen)
|
||||
{
|
||||
struct rsa_key *key = context;
|
||||
|
||||
/* invalid key provided */
|
||||
if (!value || !vlen || vlen > key->n_sz)
|
||||
return -EINVAL;
|
||||
|
||||
key->dq = value;
|
||||
key->dq_sz = vlen;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rsa_get_qinv(void *context, size_t hdrlen, unsigned char tag,
|
||||
const void *value, size_t vlen)
|
||||
{
|
||||
struct rsa_key *key = context;
|
||||
|
||||
/* invalid key provided */
|
||||
if (!value || !vlen || vlen > key->n_sz)
|
||||
return -EINVAL;
|
||||
|
||||
key->qinv = value;
|
||||
key->qinv_sz = vlen;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* rsa_parse_pub_key() - decodes the BER encoded buffer and stores in the
|
||||
* provided struct rsa_key, pointers to the raw key as is,
|
||||
|
|
|
@ -3,9 +3,9 @@ RsaPrivKey ::= SEQUENCE {
|
|||
n INTEGER ({ rsa_get_n }),
|
||||
e INTEGER ({ rsa_get_e }),
|
||||
d INTEGER ({ rsa_get_d }),
|
||||
prime1 INTEGER,
|
||||
prime2 INTEGER,
|
||||
exponent1 INTEGER,
|
||||
exponent2 INTEGER,
|
||||
coefficient INTEGER
|
||||
prime1 INTEGER ({ rsa_get_p }),
|
||||
prime2 INTEGER ({ rsa_get_q }),
|
||||
exponent1 INTEGER ({ rsa_get_dp }),
|
||||
exponent2 INTEGER ({ rsa_get_dq }),
|
||||
coefficient INTEGER ({ rsa_get_qinv })
|
||||
}
|
||||
|
|
|
@ -19,17 +19,37 @@
|
|||
* @n : RSA modulus raw byte stream
|
||||
* @e : RSA public exponent raw byte stream
|
||||
* @d : RSA private exponent raw byte stream
|
||||
* @p : RSA prime factor p of n raw byte stream
|
||||
* @q : RSA prime factor q of n raw byte stream
|
||||
* @dp : RSA exponent d mod (p - 1) raw byte stream
|
||||
* @dq : RSA exponent d mod (q - 1) raw byte stream
|
||||
* @qinv : RSA CRT coefficient q^(-1) mod p raw byte stream
|
||||
* @n_sz : length in bytes of RSA modulus n
|
||||
* @e_sz : length in bytes of RSA public exponent
|
||||
* @d_sz : length in bytes of RSA private exponent
|
||||
* @p_sz : length in bytes of p field
|
||||
* @q_sz : length in bytes of q field
|
||||
* @dp_sz : length in bytes of dp field
|
||||
* @dq_sz : length in bytes of dq field
|
||||
* @qinv_sz : length in bytes of qinv field
|
||||
*/
|
||||
struct rsa_key {
|
||||
const u8 *n;
|
||||
const u8 *e;
|
||||
const u8 *d;
|
||||
const u8 *p;
|
||||
const u8 *q;
|
||||
const u8 *dp;
|
||||
const u8 *dq;
|
||||
const u8 *qinv;
|
||||
size_t n_sz;
|
||||
size_t e_sz;
|
||||
size_t d_sz;
|
||||
size_t p_sz;
|
||||
size_t q_sz;
|
||||
size_t dp_sz;
|
||||
size_t dq_sz;
|
||||
size_t qinv_sz;
|
||||
};
|
||||
|
||||
int rsa_parse_pub_key(struct rsa_key *rsa_key, const void *key,
|
||||
|
|
Loading…
Reference in a new issue