1 |
adx |
30 |
/* |
2 |
michael |
2916 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
7006 |
* Copyright (c) 2000-2016 ircd-hybrid development team |
5 |
adx |
30 |
* |
6 |
|
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
michael |
4565 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
adx |
30 |
* USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
michael |
2916 |
/*! \file rsa.c |
23 |
|
|
* \brief Functions for use with RSA public key cryptography. |
24 |
|
|
* \version $Id$ |
25 |
|
|
*/ |
26 |
|
|
|
27 |
adx |
30 |
#include "stdinc.h" |
28 |
michael |
1307 |
#ifdef HAVE_LIBCRYPTO |
29 |
adx |
30 |
#include <openssl/pem.h> |
30 |
|
|
#include <openssl/rand.h> |
31 |
|
|
#include <openssl/rsa.h> |
32 |
|
|
#include <openssl/bn.h> |
33 |
|
|
#include <openssl/evp.h> |
34 |
|
|
#include <openssl/err.h> |
35 |
michael |
1013 |
#include <openssl/opensslv.h> |
36 |
adx |
30 |
|
37 |
|
|
#include "memory.h" |
38 |
michael |
1309 |
#include "conf.h" |
39 |
|
|
#include "log.h" |
40 |
michael |
7105 |
#endif |
41 |
adx |
30 |
|
42 |
michael |
7105 |
#include "rsa.h" |
43 |
adx |
30 |
|
44 |
michael |
7105 |
#ifdef HAVE_LIBCRYPTO |
45 |
adx |
30 |
/* |
46 |
|
|
* report_crypto_errors - Dump crypto error list to log |
47 |
|
|
*/ |
48 |
|
|
void |
49 |
|
|
report_crypto_errors(void) |
50 |
|
|
{ |
51 |
michael |
1752 |
unsigned long e = 0; |
52 |
adx |
30 |
|
53 |
michael |
1752 |
while ((e = ERR_get_error())) |
54 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "SSL error: %s", ERR_error_string(e, 0)); |
55 |
adx |
30 |
} |
56 |
michael |
7105 |
#endif |
57 |
adx |
30 |
|
58 |
michael |
4113 |
void |
59 |
michael |
4110 |
binary_to_hex(const unsigned char *bin, char *hex, unsigned int length) |
60 |
adx |
30 |
{ |
61 |
|
|
static const char trans[] = "0123456789ABCDEF"; |
62 |
|
|
|
63 |
michael |
4948 |
for (const unsigned char *const end = bin + length; bin < end; ++bin) |
64 |
adx |
30 |
{ |
65 |
michael |
4110 |
*hex++ = trans[*bin >> 4]; |
66 |
|
|
*hex++ = trans[*bin & 0xf]; |
67 |
adx |
30 |
} |
68 |
|
|
|
69 |
michael |
4110 |
*hex = '\0'; |
70 |
adx |
30 |
} |