Add i2d_RSAPrivateKey.

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@19703 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2007-01-04 20:23:24 +00:00
parent 3abdc16e2a
commit 7c04a560eb
2 changed files with 47 additions and 0 deletions

View File

@@ -379,6 +379,50 @@ d2i_RSAPrivateKey(RSA *rsa, const unsigned char **pp, size_t len)
return k;
}
int
i2d_RSAPrivateKey(RSA *rsa, unsigned char **pp)
{
RSAPrivateKey data;
size_t size;
int ret;
memset(&data, 0, sizeof(data));
ret = bn2heim_int(rsa->n, &data.modulus)
ret |= bn2heim_int(rsa->e, &data.publicExponent);
ret |= bn2heim_int(rsa->d, &data.privateExponent);
ret |= bn2heim_int(rsa->p, &data.prime1);
ret |= bn2heim_int(rsa->q, &data.prime2);
ret |= bn2heim_int(rsa->dmp1, &data.exponent1);
ret |= bn2heim_int(rsa->dmq1, &data.exponent2);
if (ret) {
free_RSAPrivateKey(&data);
return -1;
}
if (pp == NULL) {
size = length_RSAPrivateKey(&data);
free_RSAPrivateKey(&data);
} else {
void *p;
size_t len;
ASN1_MALLOC_ENCODE(RSAPrivateKey, p, len, &data, &size, ret);
free_RSAPrivateKey(&data);
if (ret)
return -1;
if (len != size)
abort();
memcpy(*pp, p, size);
free(p);
*pp += size;
}
return size;
}
int
i2d_RSAPublicKey(RSA *rsa, unsigned char **pp)
{

View File

@@ -61,6 +61,7 @@
#define RSA_verify hc_RSA_verify
#define RSA_generate_key_ex hc_RSA_generate_key_ex
#define d2i_RSAPrivateKey hc_d2i_RSAPrivateKey
#define i2d_RSAPrivateKey hc_i2d_RSAPrivateKey
#define i2d_RSAPublicKey hc_i2d_RSAPublicKey
/*
@@ -167,6 +168,8 @@ int RSA_verify(int, const unsigned char *, unsigned int,
int RSA_generate_key_ex(RSA *, int, BIGNUM *, BN_GENCB *);
RSA * d2i_RSAPrivateKey(RSA *, const unsigned char **, size_t);
int i2d_RSAPrivateKey(RSA *, unsigned char **);
int i2d_RSAPublicKey(RSA *, unsigned char **);
#endif /* _HEIM_RSA_H */