- memset(buf2, 0, sizeof buf2);
- memset(buf3, 0, sizeof buf2);
- if(!rsa_public_encrypt(rsa_pub, buf1, sizeof buf1, buf2)) {
+ memset(buf2, 0, len);
+ memset(buf3, 0, len);
+ bool result = false;
+
+ if(rsa_public_encrypt(rsa_pub, buf1, len, buf2)) {
+ if(rsa_private_decrypt(rsa_priv, buf2, len, buf3)) {
+ if(memcmp(buf1, buf3, len)) {
+ result = true;
+ } else {
+ fprintf(stderr, "ERROR: public and private RSA keys do not match.\n");
+ }
+ } else {
+ fprintf(stderr, "ERROR: private RSA key does not work.\n");
+ }
+ } else {