xref: /netbsd-src/external/ibm-public/postfix/dist/src/tls/tls_rsa.c (revision 413d532bcc3f62d122e56d92e13ac64825a40baf)
1 /*	$NetBSD: tls_rsa.c,v 1.1.1.1 2009/06/23 10:08:57 tron Exp $	*/
2 
3 /*++
4 /* NAME
5 /*	tls_rsa
6 /* SUMMARY
7 /*	RSA support
8 /* SYNOPSIS
9 /*	#define TLS_INTERNAL
10 /*	#include <tls.h>
11 /*
12 /*	RSA	*tls_tmp_rsa_cb(ssl, export, keylength)
13 /*	SSL	*ssl; /* unused */
14 /*	int	export;
15 /*	int	keylength;
16 /* DESCRIPTION
17 /*	This module maintains parameters for Diffie-Hellman key generation.
18 /*
19 /*	tls_tmp_rsa_cb() is a call-back routine for the
20 /*	SSL_CTX_set_tmp_rsa_callback() function.
21 /* LICENSE
22 /* .ad
23 /* .fi
24 /*	This software is free. You can do with it whatever you want.
25 /*	The original author kindly requests that you acknowledge
26 /*	the use of his software.
27 /* AUTHOR(S)
28 /*	Originally written by:
29 /*	Lutz Jaenicke
30 /*	BTU Cottbus
31 /*	Allgemeine Elektrotechnik
32 /*	Universitaetsplatz 3-4
33 /*	D-03044 Cottbus, Germany
34 /*
35 /*	Updated by:
36 /*	Wietse Venema
37 /*	IBM T.J. Watson Research
38 /*	P.O. Box 704
39 /*	Yorktown Heights, NY 10598, USA
40 /*--*/
41 
42 /* System library. */
43 
44 #include <sys_defs.h>
45 
46 #ifdef USE_TLS
47 
48 /* TLS library. */
49 
50 #define TLS_INTERNAL
51 #include <tls.h>
52 
53 /* tls_tmp_rsa_cb - call-back to generate ephemeral RSA key */
54 
55 RSA *tls_tmp_rsa_cb(SSL *unused_ssl, int unused_export, int keylength)
56 {
57     static RSA *rsa_tmp;
58 
59     /* Code adapted from OpenSSL apps/s_cb.c */
60 
61     if (rsa_tmp == 0)
62 	rsa_tmp = RSA_generate_key(keylength, RSA_F4, NULL, NULL);
63     return (rsa_tmp);
64 }
65 
66 #ifdef TEST
67 
68 int main(int unused_argc, char **unused_argv)
69 {
70     tls_tmp_rsa_cb(0, 1, 512);
71     tls_tmp_rsa_cb(0, 1, 1024);
72     tls_tmp_rsa_cb(0, 1, 2048);
73     tls_tmp_rsa_cb(0, 0, 512);
74 }
75 
76 #endif
77 
78 #endif
79