Detached encrypt/decrypt example, fix decrypt sample.
[openssl.git] / demos / tunala / cb.c
index cd32f74c70a2c723af58faf69ee0f34e7e75fdb6..f6e452ae93579767944e8aba728c1a0efe0c4362 100644 (file)
@@ -129,5 +129,34 @@ void cb_ssl_verify_set_level(unsigned int level)
                cb_ssl_verify_level = level;
 }
 
+RSA *cb_generate_tmp_rsa(SSL *s, int is_export, int keylength)
+{
+       /* TODO: Perhaps make it so our global key can be generated on-the-fly
+        * after certain intervals? */
+       static RSA *rsa_tmp = NULL;
+       BIGNUM *bn = NULL;
+       int ok = 1;
+       if(!rsa_tmp) {
+               ok = 0;
+               if(!(bn = BN_new()))
+                       goto end;
+               if(!BN_set_word(bn, RSA_F4))
+                       goto end;
+               if(!(rsa_tmp = RSA_new()))
+                       goto end;
+               if(!RSA_generate_key_ex(rsa_tmp, keylength, bn, NULL))
+                       goto end;
+               ok = 1;
+       }
+end:
+       if(bn)
+               BN_free(bn);
+       if(!ok) {
+               RSA_free(rsa_tmp);
+               rsa_tmp = NULL;
+       }
+       return rsa_tmp;
+}
+
 #endif /* !defined(NO_OPENSSL) */