1
/* -*- c-basic-offset: 8 -*-
2
FreeRDP: A Remote Desktop Protocol client.
3
PolarSSL Cryptographic Abstraction Layer
5
Copyright (C) Mads Kiilerich <mads@kiilerich.com> 2010
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28
#include <polarssl/sha1.h>
29
#include <polarssl/md5.h>
30
#include <polarssl/arc4.h>
31
#include <polarssl/x509.h>
32
#include <polarssl/rsa.h>
35
crypto_global_init(void)
41
crypto_global_finish(void)
46
struct crypto_sha1_struct
52
crypto_sha1_init(void)
54
CryptoSha1 sha1 = xmalloc(sizeof(*sha1));
55
sha1_starts(&sha1->ctx);
60
crypto_sha1_update(CryptoSha1 sha1, uint8 * data, uint32 len)
62
sha1_update(&sha1->ctx, data, len);
66
crypto_sha1_final(CryptoSha1 sha1, uint8 * out_data)
68
sha1_finish(&sha1->ctx, out_data);
73
struct crypto_md5_struct
81
CryptoMd5 md5 = xmalloc(sizeof(*md5));
82
md5_starts(&md5->ctx);
87
crypto_md5_update(CryptoMd5 md5, uint8 * data, uint32 len)
89
md5_update(&md5->ctx, data, len);
93
crypto_md5_final(CryptoMd5 md5, uint8 * out_data)
95
md5_finish(&md5->ctx, out_data);
100
struct crypto_rc4_struct
106
crypto_rc4_init(uint8 * key, uint32 len)
108
CryptoRc4 rc4 = xmalloc(sizeof(*rc4));
109
arc4_setup(&rc4->ctx, key, len);
114
crypto_rc4(CryptoRc4 rc4, uint32 len, uint8 * in_data, uint8 * out_data)
116
arc4_crypt(&rc4->ctx, len, in_data, out_data);
120
crypto_rc4_free(CryptoRc4 rc4)
125
struct crypto_cert_struct
131
crypto_cert_read(uint8 * data, uint32 len)
137
crypto_cert_free(CryptoCert cert)
143
crypto_cert_verify(CryptoCert server_cert, CryptoCert cacert)
149
crypto_cert_print_fp(FILE * fp, CryptoCert cert)
155
crypto_cert_get_pub_exp_mod(CryptoCert cert, uint32 * key_len,
156
uint8 * exponent, uint32 max_exp_len, uint8 * modulus, uint32 max_mod_len)
162
crypto_rsa_encrypt(int len, uint8 * in, uint8 * out, uint32 modulus_size, uint8 * modulus, uint8 * exponent)
165
rsa_init(&ctx, 0, 0);
166
ctx.len = modulus_size;
167
mpi_init(&ctx.N, &ctx.E, NULL);
168
mpi_read_binary(&ctx.N, modulus, modulus_size);
169
mpi_read_binary(&ctx.E, exponent, SEC_EXPONENT_SIZE);
170
assert(!rsa_check_pubkey( &ctx ));
172
assert(modulus_size <= SEC_MAX_MODULUS_SIZE);
173
uint8 in2[SEC_MAX_MODULUS_SIZE];
174
memset(in2, 0, modulus_size - len);
175
memcpy(in2 + modulus_size - len, in, len);
176
int err = rsa_public(&ctx, in2, out);
178
mpi_free(&ctx.N, &ctx.E, NULL);