ctaocrypt equivalent of RSA C++ constructor

Yusuf X
  • Yusuf X

    Yusuf X - 2009-04-02

    In the TaoCrypt FAQ (http://www.yassl.com/taocrypt.html), it says

        A public key can also be constructed from a private key: RSA_PublicKey rsaPub(rsaPriv);

    How can this be done with the ctaocrypt API? I didn't find an equivalent in rsa.h or asn.h.

    • Todd Ouska

      Todd Ouska - 2009-04-02

      That's the beauty of inheritance and constructor overloading.  C doesn't provide the same features easily.  You'll need to use the individual functions:




      see example usage in ctaocrypt/test/test.c

    • Yusuf X

      Yusuf X - 2009-04-04

      That's what I thought, but when I modify rsa_test() in test.c to do a public key encryption, I get a seg fault.

      Specifically, rsa_test() originally has this, where encrypt and decrypt are done with the same private key:

          InitRsaKey(&key, 0); 
          RsaPrivateKeyDecode(tmp, &idx, &key, (word32)bytes);
          RsaPublicEncrypt(in, inLen, out, sizeof(out), &key, &rng); 
          RsaPrivateDecrypt(out, 64, plain, sizeof(plain), &key);

      When I change it to this, where there is a public key and a private key:

          InitRsaKey(&public_key, 0); 
          InitRsaKey(&private_key, 0); 
          RsaPublicKeyDecode(tmp, &idx, &public_key, (word32)bytes);
          RsaPrivateKeyDecode(tmp, &idx, &private_key, (word32)bytes);
          RsaPublicEncrypt(in, inLen, out, sizeof(out), &public_key, &rng);   // segmentation fault
          RsaPrivateDecrypt(out, 64, plain, sizeof(plain), &private_key);

      It crashes trying to encrypt. If I substitute in private_key on that line, the test passes.

      Is that not the right way to to keypair encryption?

      Thanks for answering my questions, btw.

      • Todd Ouska

        Todd Ouska - 2009-04-06

        Are you using fast-math, that is, did you --enable-fastmath when configuring?  If so, and the key is bigger than 2048 bits, you'll need to set to static memory size higher.  The fast-math portion doesn't use dynamic memory.  You'll need to change FP_MAX_SIZE in tfm.h.

        If not, are you checking the return codes from the Key Decodes?  If so and they're fine can you send me .der file containing the keys so I can see the problem.  I can't duplicate it myself.  Please send to todd@yassl.com .



Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks