diff --git a/src/modules/_Crypto/rsa.c b/src/modules/_Crypto/rsa.c index 189b7f641684fce2ee83b9181dbac4f602d9b074..b0b37065ed46bf9aa46a6acf3f86f0bc762337d8 100644 --- a/src/modules/_Crypto/rsa.c +++ b/src/modules/_Crypto/rsa.c @@ -1,5 +1,5 @@ /* - * $Id: rsa.c,v 1.17 2000/05/04 16:02:27 grubba Exp $ + * $Id: rsa.c,v 1.18 2000/06/13 19:22:31 grubba Exp $ * * Glue to RSA BSAFE's RSA implementation. * @@ -31,7 +31,7 @@ #include <bsafe.h> -RCSID("$Id: rsa.c,v 1.17 2000/05/04 16:02:27 grubba Exp $"); +RCSID("$Id: rsa.c,v 1.18 2000/06/13 19:22:31 grubba Exp $"); struct pike_rsa_data { @@ -324,6 +324,72 @@ static void f_cooked_get_e(INT32 args) rsa_public_key->exponent.len)); } +/* string cooked_get_d() */ +static void f_cooked_get_d(INT32 args) +{ + A_PKCS_RSA_PRIVATE_KEY *rsa_private_key = NULL; + int code; + + if (!THIS->n) { + error("Public key has not been set.\n"); + } + + if ((code = B_GetKeyInfo((POINTER *)&rsa_private_key, THIS->private_key, + KI_PKCS_RSAPrivate))) { + error("Crypto rsa.cooked_get_d(): " + "Failed to get private key: %04x\n", code); + } + + pop_n_elems(args); + + push_string(make_shared_binary_string(rsa_private_key->privateExponent.data, + rsa_private_key->privateExponent.len)); +} + +/* string cooked_get_p() */ +static void f_cooked_get_p(INT32 args) +{ + A_PKCS_RSA_PRIVATE_KEY *rsa_private_key = NULL; + int code; + + if (!THIS->n) { + error("Public key has not been set.\n"); + } + + if ((code = B_GetKeyInfo((POINTER *)&rsa_private_key, THIS->private_key, + KI_PKCS_RSAPrivate))) { + error("Crypto rsa.cooked_get_p(): " + "Failed to get private key: %04x\n", code); + } + + pop_n_elems(args); + + push_string(make_shared_binary_string(rsa_private_key->prime[0].data, + rsa_private_key->prime[0].len)); +} + +/* string cooked_get_q() */ +static void f_cooked_get_q(INT32 args) +{ + A_PKCS_RSA_PRIVATE_KEY *rsa_private_key = NULL; + int code; + + if (!THIS->n) { + error("Public key has not been set.\n"); + } + + if ((code = B_GetKeyInfo((POINTER *)&rsa_private_key, THIS->private_key, + KI_PKCS_RSAPrivate))) { + error("Crypto rsa.cooked_get_q(): " + "Failed to get private key: %04x\n", code); + } + + pop_n_elems(args); + + push_string(make_shared_binary_string(rsa_private_key->prime[1].data, + rsa_private_key->prime[1].len)); +} + /* int query_blocksize() */ static void f_query_blocksize(INT32 args) { @@ -861,6 +927,15 @@ void pike_rsa_init(void) ADD_FUNCTION("cooked_get_e", f_cooked_get_e, tFunc(tNone, tString), 0); + ADD_FUNCTION("cooked_get_d", f_cooked_get_d, + tFunc(tNone, tString), 0); + + ADD_FUNCTION("cooked_get_p", f_cooked_get_p, + tFunc(tNone, tString), 0); + + ADD_FUNCTION("cooked_get_q", f_cooked_get_q, + tFunc(tNone, tString), 0); + ADD_FUNCTION("query_blocksize", f_query_blocksize, tFunc(tNone, tInt), 0);