1 /* -*- c-basic-offset: 8 -*-
2    rdesktop: A Remote Desktop Protocol client.
3    Secure sockets abstraction layer
4    Copyright (C) Matthew Chapman 1999-2008
5    Copyright (C) Jay Sorg 2006-2008
6    Copyright 2017 Henrik Andersson <hean01@cendio.se> for Cendio AB
7    Copyright 2017 Alexander Zakharov <uglym8@gmail.com>
8 
9    This program is free software: you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation, either version 3 of the License, or
12    (at your option) any later version.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #ifndef _RDSSL_H
24 #define _RDSSL_H
25 
26 #include <nettle/md5.h>
27 #include <nettle/sha1.h>
28 #include <nettle/arcfour.h>
29 #include <nettle/hmac.h>
30 #include <nettle/rsa.h>
31 
32 #include <gnutls/x509.h>
33 
34 #define RDSSL_RC4 struct arcfour_ctx
35 #define RDSSL_SHA1 struct sha1_ctx
36 #define RDSSL_MD5 struct md5_ctx
37 #define RDSSL_CERT gnutls_x509_crt_t
38 #define RDSSL_RKEY struct rsa_public_key
39 
40 void rdssl_sha1_init(RDSSL_SHA1 * sha1);
41 void rdssl_sha1_update(RDSSL_SHA1 * sha1, uint8 * data, uint32 len);
42 void rdssl_sha1_final(RDSSL_SHA1 * sha1, uint8 * out_data);
43 void rdssl_md5_init(RDSSL_MD5 * md5);
44 void rdssl_md5_update(RDSSL_MD5 * md5, uint8 * data, uint32 len);
45 void rdssl_md5_final(RDSSL_MD5 * md5, uint8 * out_data);
46 void rdssl_rc4_set_key(RDSSL_RC4 * rc4, uint8 * key, uint32 len);
47 void rdssl_rc4_crypt(RDSSL_RC4 * rc4, uint8 * in_data, uint8 * out_data, uint32 len);
48 void rdssl_rsa_encrypt(uint8 * out, uint8 * in, int len, uint32 modulus_size, uint8 * modulus,
49 		       uint8 * exponent);
50 RDSSL_CERT *rdssl_cert_read(uint8 * data, uint32 len);
51 void rdssl_cert_free(RDSSL_CERT * cert);
52 RDSSL_RKEY *rdssl_cert_to_rkey(RDSSL_CERT * cert, uint32 * key_len);
53 RD_BOOL rdssl_certs_ok(RDSSL_CERT * server_cert, RDSSL_CERT * cacert);
54 int rdssl_cert_print_fp(FILE * fp, RDSSL_CERT * cert);
55 void rdssl_rkey_free(RDSSL_RKEY * rkey);
56 int rdssl_rkey_get_exp_mod(RDSSL_RKEY * rkey, uint8 * exponent, uint32 max_exp_len, uint8 * modulus,
57 			   uint32 max_mod_len);
58 RD_BOOL rdssl_sig_ok(uint8 * exponent, uint32 exp_len, uint8 * modulus, uint32 mod_len,
59 		     uint8 * signature, uint32 sig_len);
60 
61 void rdssl_hmac_md5(const void *key, int key_len,
62 		    const unsigned char *msg, int msg_len, unsigned char *md);
63 #endif
64