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