PEM encoder supports encoding from RSA components directly, allowing gcrypt plugin to encode in PEM

This commit is contained in:
Martin Willi
2010-04-29 09:36:45 +02:00
parent dd8cb2b089
commit dd04a68f22
3 changed files with 42 additions and 37 deletions
@@ -406,13 +406,7 @@ static bool get_encoding(private_gmp_rsa_private_key_t *this,
key_encoding_type_t type, chunk_t *encoding)
{
chunk_t n, e, d, p, q, exp1, exp2, coeff;
bool success, pem = FALSE;
if (type == KEY_PRIV_PEM)
{
pem = TRUE;
type = KEY_PRIV_ASN1_DER;
}
bool success;
n = gmp_mpz_to_chunk(this->n);
e = gmp_mpz_to_chunk(this->e);
@@ -438,15 +432,6 @@ static bool get_encoding(private_gmp_rsa_private_key_t *this,
chunk_clear(&exp2);
chunk_clear(&coeff);
if (pem && success)
{
chunk_t asn1_encoding = *encoding;
success = lib->encoding->encode(lib->encoding, KEY_PRIV_PEM, NULL,
encoding, KEY_PART_RSA_PRIV_ASN1_DER,
asn1_encoding, KEY_PART_END);
chunk_clear(&asn1_encoding);
}
return success;
}
@@ -399,13 +399,7 @@ static bool get_encoding(private_gmp_rsa_public_key_t *this,
key_encoding_type_t type, chunk_t *encoding)
{
chunk_t n, e;
bool success, pem = FALSE;
if (type == KEY_PUB_PEM)
{
pem = TRUE;
type = KEY_PUB_SPKI_ASN1_DER;
}
bool success;
n = gmp_mpz_to_chunk(this->n);
e = gmp_mpz_to_chunk(this->e);
@@ -415,15 +409,6 @@ static bool get_encoding(private_gmp_rsa_public_key_t *this,
chunk_free(&n);
chunk_free(&e);
if (pem && success)
{
chunk_t asn1_encoding = *encoding;
success = lib->encoding->encode(lib->encoding, KEY_PUB_PEM, NULL,
encoding, KEY_PART_RSA_PUB_ASN1_DER,
asn1_encoding, KEY_PART_END);
chunk_clear(&asn1_encoding);
}
return success;
}