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.
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
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:
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:
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.
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 email@example.com .
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.