0

I am a newbie in cryptography. Need little help to start off.

I have Modulus field & Private Exponent field given by the server and i need to compose the private key from it using Tomcrypt library.

I am not able to figure out which Api from tomcrypt would do this for me. If anybody can let me know the api or the steps to do it , it would be divine.

Thanks

CodeTry
  • 312
  • 1
  • 19

1 Answers1

0

I am not sure if the tomcrypt has the support to generate private key from the given private exponent and modulus field. However, tomcrypt provides rsa_make_key functions to generate keys. The public/private keys can then be exported from these keys using rsa_export function.

/** 
   Create an RSA key
   @param prng     An active PRNG state
   @param wprng    The index of the PRNG desired
   @param size     The size of the modulus (key size) desired (octets)
   @param e        The "e" value (public key).  e==65537 is a good choice
   @param key      [out] Destination of a newly created private key pair
   @return CRYPT_OK if successful, upon error all allocated ram is freed
*/
int rsa_make_key(prng_state *prng, int wprng, int size, long e, rsa_key *key)

/**
    This will export either an RSAPublicKey or RSAPrivateKey [defined in LTC_PKCS #1 v2.1] 
    @param out       [out] Destination of the packet
    @param outlen    [in/out] The max size and resulting size of the packet
    @param type      The type of exported key (PK_PRIVATE or PK_PUBLIC)
    @param key       The RSA key to export
    @return CRYPT_OK if successful
*/
int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key)
Ashok Vairavan
  • 1,862
  • 1
  • 15
  • 21