Selaa lähdekoodia

[crypto] Remove unused files

tags/v0.9.7
Michael Brown 15 vuotta sitten
vanhempi
commit
5a99c586cf

+ 0
- 120
src/crypto/cryptoLayer.h Näytä tiedosto

@@ -1,120 +0,0 @@
1
-#ifndef _MATRIXSSL_CRYPTOLAYER_H
2
-#define _MATRIXSSL_CRYPTOLAYER_H
3
-
4
-/** @file
5
- *
6
- * Compatibility layer for MatrixSSL
7
- *
8
- */
9
-
10
-#include <stdint.h>
11
-#include <stddef.h>
12
-#include <stdlib.h>
13
-#include <string.h>
14
-#include <ctype.h>
15
-#include <assert.h>
16
-#include <byteswap.h>
17
-#include <gpxe/rotate.h>
18
-#include <gpxe/crypto.h>
19
-
20
-/* Drag in pscrypto.h */
21
-typedef uint64_t ulong64;
22
-typedef void psPool_t;
23
-#define SMALL_CODE
24
-#define USE_INT64
25
-#define USE_RSA
26
-#define USE_RSA_PUBLIC_ENCRYPT
27
-#define CRYPT
28
-#include "matrixssl/pscrypto.h"
29
-#define SMALL_CODE
30
-#undef CLEAN_STACK
31
-
32
-#define sslAssert( ... ) assert ( __VA_ARGS__ )
33
-
34
-static inline __attribute__ (( always_inline )) void * __malloc
35
-psMalloc ( psPool_t *pool __unused, size_t len ) {
36
-	return malloc ( len );
37
-}
38
-
39
-static inline __attribute__ (( always_inline )) void *
40
-psRealloc ( void *ptr, size_t len ) {
41
-	return realloc ( ptr, len );
42
-}
43
-
44
-static inline __attribute__ (( always_inline )) void psFree ( void *ptr ) {
45
-	free ( ptr );
46
-}
47
-
48
-#define matrixStrDebugMsg( ... ) DBG ( __VA_ARGS__ )
49
-#define matrixIntDebugMsg( ... ) DBG ( __VA_ARGS__ )
50
-
51
-/* Use our standard cpu_to_leXX etc. macros */
52
-
53
-#undef LOAD32L
54
-#define LOAD32L( cpu32, ptr ) do {				\
55
-		uint32_t *le32 = ( ( uint32_t * ) ptr );	\
56
-		cpu32 = le32_to_cpu ( *le32 );			\
57
-	} while ( 0 )
58
-
59
-#undef LOAD32H
60
-#define LOAD32H( cpu32, ptr ) do {				\
61
-		uint32_t *be32 = ( ( uint32_t * ) ptr );	\
62
-		cpu32 = be32_to_cpu ( *be32 );			\
63
-	} while ( 0 )
64
-
65
-#undef LOAD64L
66
-#define LOAD64L( cpu64, ptr ) do {				\
67
-		uint64_t *le64 = ( ( uint64_t * ) ptr );	\
68
-		cpu64 = le64_to_cpu ( *le64 );			\
69
-	} while ( 0 )
70
-
71
-#undef LOAD64H
72
-#define LOAD64H( cpu64, ptr ) do {				\
73
-		uint64_t *be64 = ( ( uint64_t * ) ptr );	\
74
-		cpu64 = be64_to_cpu ( *be64 );			\
75
-	} while ( 0 )
76
-
77
-#undef STORE32L
78
-#define STORE32L( cpu32, ptr ) do {				\
79
-		uint32_t *le32 = ( ( uint32_t * ) ptr );	\
80
-		*le32 = cpu_to_le32 ( cpu32 );			\
81
-	} while ( 0 )
82
-
83
-#undef STORE32H
84
-#define STORE32H( cpu32, ptr ) do {				\
85
-		uint32_t *be32 = ( ( uint32_t * ) ptr );	\
86
-		*be32 = cpu_to_be32 ( cpu32 );			\
87
-	} while ( 0 )
88
-
89
-#undef STORE64L
90
-#define STORE64L( cpu64, ptr ) do {				\
91
-		uint64_t *le64 = ( ( uint64_t * ) ptr );	\
92
-		*le64 = cpu_to_le64 ( cpu64 );			\
93
-	} while ( 0 )
94
-
95
-#undef STORE64H
96
-#define STORE64H( cpu64, ptr ) do {				\
97
-		uint64_t *be64 = ( ( uint64_t * ) ptr );	\
98
-		*be64 = cpu_to_be64 ( cpu64 );			\
99
-	} while ( 0 )
100
-
101
-/* Use rolXX etc. from bitops.h */
102
-
103
-#undef ROL
104
-#define ROL( data, rotation )	 rol32 ( (data), (rotation) )
105
-#undef ROLc
106
-#define ROLc( data, rotation )	 rol32 ( (data), (rotation) )
107
-#undef ROR
108
-#define ROR( data, rotation )	 ror32 ( (data), (rotation) )
109
-#undef RORc
110
-#define RORc( data, rotation )	 ror32 ( (data), (rotation) )
111
-#undef ROL64
112
-#define ROL64( data, rotation )	 rol64 ( (data), (rotation) )
113
-#undef ROL64c
114
-#define ROL64c( data, rotation ) rol64 ( (data), (rotation) )
115
-#undef ROR64
116
-#define ROR64( data, rotation )	 ror64 ( (data), (rotation) )
117
-#undef ROR64c
118
-#define ROR64c( data, rotation ) ror64 ( (data), (rotation) )
119
-
120
-#endif /* _MATRIXSSL_CRYPTOLAYER_H */

+ 0
- 86
src/crypto/framework.c Näytä tiedosto

@@ -1,86 +0,0 @@
1
-/* mcb - this file breaks the build process; temporarily deactivating */
2
-#if 0
3
-
4
-#include <stdlib.h>
5
-#include <sys/types.h>
6
-#include <sys/socket.h>
7
-#include <netinet/in.h>
8
-#include <netdb.h>
9
-#include "ssl.h"
10
-
11
-int main(int argc, char *argv[])
12
-{
13
-  SSL_t ssl;
14
-  int sockfd, portno, rc;
15
-  struct sockaddr_in serv_addr;
16
-  struct hostent *server;
17
-
18
-  portno = 443;
19
-  sockfd = socket(AF_INET,SOCK_STREAM,0);
20
-  if(sockfd<0){
21
-    fprintf(stderr,"Error creating socket\n");
22
-    exit(sockfd);
23
-  }
24
-
25
-  server = gethostbyname(argv[1]);
26
-  if(server==NULL){
27
-    fprintf(stderr,"Error looking up host %s\n",argv[1]);
28
-    exit(1);
29
-  }
30
-
31
-  /**
32
-   *matrixSslOpen()
33
-   *matrixSslReadKeys()
34
-   **/
35
-  printf("Calling CreateSSLHello()\n");
36
-  rc = CreateSSLHello(&ssl);
37
-  printf("Finished calling CreateSSLHello()\n");
38
-
39
-  bzero((char *) &serv_addr, sizeof(serv_addr));
40
-  serv_addr.sin_family = AF_INET;
41
-  bcopy((char *)server->h_addr,(char *)&serv_addr.sin_addr.s_addr,server->h_length);
42
-  serv_addr.sin_port = htons(portno);
43
-  if(connect(sockfd,(struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0){
44
-    fprintf(stderr,"ERROR connecting to server\n");
45
-    exit(1);
46
-  }
47
-
48
-  PrintSSLPacket(&ssl);
49
-
50
-  printf("Write ssl.buffer\n");
51
-  write(sockfd,ssl.buffer,ssl.length);
52
-  printf("Finished writing\n");
53
-  ssl.length = read(sockfd,ssl.buffer,ssl.max_size);
54
-  ReadSSLHello(&ssl);
55
-
56
-  /**
57
-   *matrixSslNewSession()
58
-   *matrixSslSetCetValidator()
59
-   *encodeSslHandshake()
60
-
61
-   *write handshake buffer
62
-
63
-   *readSslResponse() <-+
64
-                        |
65
-   *read return code    |-- similar/same function??
66
-                        |
67
-   *sslEncode()         |
68
-   *sslDecode() <-------+
69
-   
70
-   *encodeSslCloseAlert()
71
-   
72
-   *write close alert buffer
73
-   **/
74
-   close(sockfd);
75
-
76
-  /**
77
-   *sslClose()
78
-   * -free connection
79
-   * -free keys
80
-   * -close pki interface
81
-   **/
82
-
83
-  return 0;
84
-}
85
-
86
-#endif

+ 0
- 487
src/crypto/matrixssl/mpi.h Näytä tiedosto

@@ -1,487 +0,0 @@
1
-/*	
2
- *	mpi.h
3
- *	Release $Name$
4
- *
5
- *	multiple-precision integer library
6
- */
7
-/*
8
- *	Copyright (c) PeerSec Networks, 2002-2006. All Rights Reserved.
9
- *	The latest version of this code is available at http://www.matrixssl.org
10
- *
11
- *	This software is open source; you can redistribute it and/or modify
12
- *	it under the terms of the GNU General Public License as published by
13
- *	the Free Software Foundation; either version 2 of the License, or
14
- *	(at your option) any later version.
15
- *
16
- *	This General Public License does NOT permit incorporating this software 
17
- *	into proprietary programs.  If you are unable to comply with the GPL, a 
18
- *	commercial license for this software may be purchased from PeerSec Networks
19
- *	at http://www.peersec.com
20
- *	
21
- *	This program is distributed in WITHOUT ANY WARRANTY; without even the 
22
- *	implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
23
- *	See the GNU General Public License for more details.
24
- *	
25
- *	You should have received a copy of the GNU General Public License
26
- *	along with this program; if not, write to the Free Software
27
- *	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
- *	http://www.gnu.org/copyleft/gpl.html
29
- */
30
-/******************************************************************************/
31
-
32
-#ifndef _h_MPI
33
-#define _h_MPI
34
-
35
-#include <stdio.h>
36
-#include <string.h>
37
-#include <stdlib.h>
38
-#include <ctype.h>
39
-#include <limits.h>
40
-
41
-#undef MIN
42
-#define MIN(x,y) ((x)<(y)?(x):(y))
43
-#undef MAX
44
-#define MAX(x,y) ((x)>(y)?(x):(y))
45
-
46
-#ifdef __cplusplus
47
-extern "C" {
48
-
49
-
50
-/*
51
-	C++ compilers don't like assigning void * to mp_digit *
52
- */
53
-#define  OPT_CAST(x)  (x *)
54
-
55
-#else
56
-
57
-/*
58
-	C on the other hand doesn't care
59
- */
60
-#define  OPT_CAST(x)
61
-
62
-#endif /* __cplusplus */
63
-
64
-/******************************************************************************/
65
-/*
66
-	some default configurations.
67
-
68
-	A "mp_digit" must be able to hold DIGIT_BIT + 1 bits
69
-	A "mp_word" must be able to hold 2*DIGIT_BIT + 1 bits
70
-
71
-	At the very least a mp_digit must be able to hold 7 bits
72
-	[any size beyond that is ok provided it doesn't overflow the data type]
73
- */
74
-#ifdef MP_8BIT
75
-	typedef unsigned char		mp_digit;
76
-	typedef unsigned short		mp_word;
77
-#elif defined(MP_16BIT)
78
-	typedef unsigned short		mp_digit;
79
-	typedef unsigned long		mp_word;
80
-#elif defined(MP_64BIT)
81
-/*
82
-	for GCC only on supported platforms
83
- */
84
-	#ifndef CRYPT
85
-		typedef unsigned long long	ulong64;
86
-		typedef signed long long	long64;
87
-	#endif /* CRYPT */
88
-
89
-	typedef ulong64				mp_digit;
90
-	typedef unsigned long		mp_word __attribute__ ((mode(TI)));
91
-
92
-	#define DIGIT_BIT			60
93
-#else  /* MP_8BIT */
94
-/*
95
-	this is the default case, 28-bit digits
96
- */
97
-	#ifndef CRYPT
98
-		#if defined(_MSC_VER) || defined(__BORLANDC__) 
99
-			typedef unsigned __int64	ulong64;
100
-			typedef signed __int64		long64;
101
-		#else
102
-			typedef unsigned long long	ulong64;
103
-			typedef signed long long	long64;
104
-		#endif
105
-	#endif /* CRYPT */
106
-
107
-	typedef unsigned long		mp_digit;
108
-	typedef ulong64				mp_word;
109
-
110
-	#ifdef MP_31BIT
111
-/*
112
-		this is an extension that uses 31-bit digits
113
- */
114
-		#define DIGIT_BIT		31
115
-	#else /* MP_31BIT */
116
-/*
117
-		default case is 28-bit digits, defines MP_28BIT as a handy macro to test
118
- */
119
-		#define DIGIT_BIT		28
120
-		#define MP_28BIT
121
-	#endif /* MP_31BIT */
122
-#endif /* MP_8BIT */
123
-
124
-/*
125
-	otherwise the bits per digit is calculated automatically from the size of
126
-	a mp_digit
127
- */
128
-#ifndef DIGIT_BIT
129
-	#define DIGIT_BIT	((int32)((CHAR_BIT * sizeof(mp_digit) - 1)))	/* bits per digit */
130
-#endif /* DIGIT_BIT */
131
-
132
-#define MP_DIGIT_BIT		DIGIT_BIT
133
-#define MP_MASK				((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1))
134
-#define MP_DIGIT_MAX		MP_MASK
135
-
136
-/******************************************************************************/
137
-/*
138
-	equalities
139
- */
140
-#define MP_LT			-1		/* less than */
141
-#define MP_EQ			0		/* equal to */
142
-#define MP_GT			1		/* greater than */
143
-
144
-#define MP_ZPOS			0		/* positive integer */
145
-#define MP_NEG			1		/* negative */
146
-
147
-#define MP_OKAY			0		/* ok result */
148
-#define MP_MEM			-2		/* out of mem */
149
-#define MP_VAL			-3		/* invalid input */
150
-#define MP_RANGE		MP_VAL
151
-
152
-#define MP_YES			1		/* yes response */
153
-#define MP_NO			0		/* no response */
154
-
155
-typedef int32				mp_err;
156
-
157
-/******************************************************************************/
158
-/*
159
-	various build options
160
- */
161
-#define MP_PREC			64		/* default digits of precision */
162
-
163
-/*
164
-	define this to use lower memory usage routines (exptmods mostly)
165
- */
166
-#define MP_LOW_MEM
167
-
168
-/*
169
-	size of comba arrays, should be at least 
170
-	2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2)
171
- */
172
-#define MP_WARRAY		(1 << (sizeof(mp_word) * CHAR_BIT - 2 * DIGIT_BIT + 1))
173
-
174
-typedef struct  {
175
-	int32 used, alloc, sign;
176
-	mp_digit *dp;
177
-} mp_int;
178
-
179
-#define USED(m)		((m)->used)
180
-#define DIGIT(m,k)	((m)->dp[(k)])
181
-#define SIGN(m)		((m)->sign)
182
-
183
-/******************************************************************************/
184
-/*
185
-	init and deinit bignum functions
186
- */
187
-
188
-/*
189
-	init a bignum
190
- */
191
-extern int32 mp_init(psPool_t *pool, mp_int *a);
192
-
193
-/*
194
-	free a bignum
195
- */
196
-extern void mp_clear(mp_int *a);
197
-
198
-/*
199
-	init a series of arguments
200
- */
201
-extern int32 _mp_init_multi(psPool_t *pool, mp_int *mp0, mp_int *mp1, mp_int *mp2, 
202
-							mp_int *mp3, mp_int *mp4, mp_int *mp5, mp_int *mp6, 
203
-							mp_int *mp7);
204
-
205
-/*
206
-	clear a  series of arguments
207
- */
208
-extern void _mp_clear_multi(mp_int *mp0, mp_int *mp1, mp_int *mp2, mp_int *mp3,
209
-					mp_int *mp4, mp_int *mp5, mp_int *mp6, mp_int *mp7);
210
-
211
-/*
212
-	exchange two ints
213
- */
214
-extern void mp_exch(mp_int *a, mp_int *b);
215
-
216
-/*
217
-	shrink ram required for a bignum
218
- */
219
-extern int32 mp_shrink(mp_int *a);
220
-
221
-/*
222
-	grow an int32 to a given size
223
- */
224
-extern int32 mp_grow(mp_int *a, int32 size);
225
-
226
-/*
227
-	init to a given number of digits
228
- */
229
-extern int32 mp_init_size(psPool_t *pool, mp_int *a, int32 size);
230
-
231
-/******************************************************************************/
232
-/*
233
-	Basic Manipulations
234
- */
235
-#define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
236
-#define mp_iseven(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO)
237
-#define mp_isodd(a)  (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO)
238
-
239
-extern int32 mp_add_d (mp_int * a, mp_digit b, mp_int * c);
240
-extern int32 mp_sub_d (mp_int * a, mp_digit b, mp_int * c);
241
-/*
242
-	set to zero
243
- */
244
-extern void mp_zero(mp_int *a);
245
-
246
-/*
247
-	set to a digit
248
- */
249
-extern void mp_set(mp_int *a, mp_digit b);
250
-
251
-/*
252
-	copy, b = a
253
- */
254
-extern int32 mp_copy(mp_int *a, mp_int *b);
255
-
256
-/*
257
-	inits and copies, a = b
258
- */
259
-extern int32 mp_init_copy(psPool_t *pool, mp_int *a, mp_int *b);
260
-
261
-/*
262
-	trim unused digits
263
- */
264
-extern void mp_clamp(mp_int *a);
265
-
266
-/******************************************************************************/
267
-/*
268
-	digit manipulation
269
-*/
270
-
271
-/*
272
-	right shift by "b" digits
273
- */
274
-extern void mp_rshd(mp_int *a, int32 b);
275
-
276
-/*
277
-	left shift by "b" digits
278
- */
279
-extern int32 mp_lshd(mp_int *a, int32 b);
280
-
281
-/*
282
-	c = a / 2**b
283
- */
284
-extern int32 mp_div_2d(psPool_t *pool, mp_int *a, int32 b, mp_int *c, mp_int *d);
285
-
286
-/*
287
-	b = a/2
288
- */
289
-extern int32 mp_div_2(mp_int *a, mp_int *b);
290
-
291
-/*
292
-	c = a * 2**b
293
- */
294
-extern int32 mp_mul_2d(mp_int *a, int32 b, mp_int *c);
295
-
296
-/*
297
-	c = a mod 2**d
298
- */
299
-extern int32 mp_mod_2d(mp_int *a, int32 b, mp_int *c);
300
-
301
-/*
302
-	computes a = 2**b
303
- */
304
-extern int32 mp_2expt(mp_int *a, int32 b);
305
-
306
-/******************************************************************************/
307
-/*
308
-	Basic arithmetic
309
- */
310
-
311
-/*
312
-	b = |a|
313
- */
314
-extern int32 mp_abs(mp_int *a, mp_int *b);
315
-
316
-/*
317
-	compare a to b
318
- */
319
-extern int32 mp_cmp(mp_int *a, mp_int *b);
320
-
321
-/*
322
-	compare |a| to |b|
323
- */
324
-extern int32 mp_cmp_mag(mp_int *a, mp_int *b);
325
-
326
-/*
327
-	c = a + b
328
- */
329
-extern int32 mp_add(mp_int *a, mp_int *b, mp_int *c);
330
-
331
-/*
332
-	c = a - b
333
- */
334
-extern int32 mp_sub(mp_int *a, mp_int *b, mp_int *c);
335
-
336
-/*
337
-	c = a * b
338
-	b = a*a
339
- */
340
-/* STEVE - moved mp_mul out of SLOW case */
341
-extern int32 mp_mul(psPool_t *pool, mp_int *a, mp_int *b, mp_int *c);
342
-#ifdef USE_SMALL_WORD
343
-extern int32 mp_sqr(psPool_t *pool, mp_int *a, mp_int *b);
344
-#endif
345
-
346
-/*
347
-	a/b => cb + d == a
348
- */
349
-extern int32 mp_div(psPool_t *pool, mp_int *a, mp_int *b, mp_int *c, mp_int *d);
350
-
351
-/*
352
-	c = a mod b, 0 <= c < b
353
- */
354
-extern int32 mp_mod(psPool_t *pool, mp_int *a, mp_int *b, mp_int *c);
355
-
356
-/******************************************************************************/
357
-/*
358
-	single digit functions
359
- */
360
-
361
-/*
362
-	compare against a single digit
363
- */
364
-extern int32 mp_cmp_d(mp_int *a, mp_digit b);
365
-
366
-/*
367
-	c = a * b
368
- */
369
-extern int32 mp_mul_d(mp_int *a, mp_digit b, mp_int *c);
370
-
371
-/******************************************************************************/
372
-/*
373
-	number theory
374
- */
375
-
376
-/*
377
-	d = a + b (mod c)
378
- */
379
-extern int32 mp_addmod(psPool_t *pool, mp_int *a, mp_int *b, mp_int *c, mp_int *d);
380
-
381
-/*
382
-	d = a * b (mod c)
383
- */
384
-extern int32 mp_mulmod(psPool_t *pool, mp_int *a, mp_int *b, mp_int *c, mp_int *d);
385
-
386
-/*
387
-	c = 1/a (mod b)
388
- */
389
-#ifdef USE_SMALL_WORD
390
-extern int32 mp_invmod(psPool_t *pool, mp_int *a, mp_int *b, mp_int *c);
391
-#endif
392
-
393
-/*
394
-	setups the montgomery reduction
395
- */
396
-extern int32 mp_montgomery_setup(mp_int *a, mp_digit *mp);
397
-
398
-/*
399
-	computes a = B**n mod b without division or multiplication useful for
400
-	normalizing numbers in a Montgomery system.
401
- */
402
-extern int32 mp_montgomery_calc_normalization(mp_int *a, mp_int *b);
403
-
404
-/*
405
-	computes x/R == x (mod N) via Montgomery Reduction
406
- */
407
-#ifdef USE_SMALL_WORD
408
-extern int32 mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp);
409
-#endif
410
-
411
-/*
412
-	d = a**b (mod c)
413
- */
414
-/* TODO - we never define this */
415
-extern int32 mp_exptmod(psPool_t *pool, mp_int *a, mp_int *b, mp_int *c, mp_int *d);
416
-
417
-/******************************************************************************/
418
-/*
419
-	If we're using 1024 or 2048 bit keys and 28 bit digits, we only need the
420
-	fast_ versions of these functions, removing the others to save space.
421
-	Otherwise, we include the slow versions as well and which version to use
422
-	is done at runtime.
423
-*/
424
-#ifdef USE_SMALL_WORD
425
-extern int32 s_mp_mul_digs(psPool_t *pool, mp_int *a, mp_int *b, mp_int *c,
426
-						   int32 digs);
427
-extern int32 s_mp_sqr(psPool_t *pool, mp_int *a, mp_int *b);
428
-#else
429
-#define mp_montgomery_reduce fast_mp_montgomery_reduce
430
-#define mp_sqr	fast_s_mp_sqr
431
-#if STEVE
432
-#define mp_mul(P, A, B, C) fast_s_mp_mul_digs(P, A, B, C, (A)->used + (B)->used + 1)
433
-#endif
434
-#define s_mp_mul_digs	fast_s_mp_mul_digs
435
-#define mp_invmod	fast_mp_invmod
436
-#endif
437
-
438
-/******************************************************************************/
439
-/*
440
-	radix conversion
441
- */
442
-extern int32 mp_count_bits(mp_int *a);
443
-
444
-extern int32 mp_unsigned_bin_size(mp_int *a);
445
-extern int32 mp_read_unsigned_bin(mp_int *a, unsigned char *b, int32 c);
446
-extern int32 mp_to_unsigned_bin(psPool_t *pool, mp_int *a, unsigned char *b);
447
-
448
-extern int32 mp_signed_bin_size(mp_int *a);
449
-
450
-/*
451
-	lowlevel functions, do not call!
452
- */
453
-#if STEVE
454
-#ifdef USE_SMALL_WORD
455
-#define s_mp_mul(P, A, B, C) s_mp_mul_digs(P, A, B, C, (A)->used + (B)->used + 1)
456
-#else
457
-#define s_mp_mul(P, A, B, C) sslAssert();
458
-#endif
459
-#endif /* STEVE */
460
-/* define this in all cases for now STEVE */
461
-#define s_mp_mul(P, A, B, C) s_mp_mul_digs(P, A, B, C, (A)->used + (B)->used + 1)
462
-
463
-
464
-/*
465
-	b = a*2
466
- */
467
-extern int32 mp_mul_2(mp_int *a, mp_int *b);
468
-
469
-extern int32 s_mp_add(mp_int *a, mp_int *b, mp_int *c);
470
-extern int32 s_mp_sub(mp_int *a, mp_int *b, mp_int *c);
471
-
472
-extern int32 fast_s_mp_mul_digs(psPool_t *pool, mp_int *a, mp_int *b, mp_int *c,
473
-								int32 digs);
474
-extern int32 fast_s_mp_sqr(psPool_t *pool, mp_int *a, mp_int *b);
475
-
476
-extern int32 fast_mp_invmod(psPool_t *pool, mp_int *a, mp_int *b, mp_int *c);
477
-extern int32 fast_mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp);
478
-
479
-extern void bn_reverse(unsigned char *s, int32 len);
480
-
481
-
482
-#ifdef __cplusplus
483
-   }
484
-#endif /* __cplusplus */
485
-
486
-#endif /* _h_MPI */
487
-

+ 0
- 661
src/crypto/matrixssl/pscrypto.h Näytä tiedosto

@@ -1,661 +0,0 @@
1
-/*
2
- *	pscrypto.h
3
- *	Release $Name$
4
- *
5
- *	Internal definitions for PeerSec Networks MatrixSSL cryptography provider
6
- */
7
-/*
8
- *	Copyright (c) PeerSec Networks, 2002-2006. All Rights Reserved.
9
- *	The latest version of this code is available at http://www.matrixssl.org
10
- *
11
- *	This software is open source; you can redistribute it and/or modify
12
- *	it under the terms of the GNU General Public License as published by
13
- *	the Free Software Foundation; either version 2 of the License, or
14
- *	(at your option) any later version.
15
- *
16
- *	This General Public License does NOT permit incorporating this software 
17
- *	into proprietary programs.  If you are unable to comply with the GPL, a 
18
- *	commercial license for this software may be purchased from PeerSec Networks
19
- *	at http://www.peersec.com
20
- *	
21
- *	This program is distributed in WITHOUT ANY WARRANTY; without even the 
22
- *	implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
23
- *	See the GNU General Public License for more details.
24
- *	
25
- *	You should have received a copy of the GNU General Public License
26
- *	along with this program; if not, write to the Free Software
27
- *	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
- *	http://www.gnu.org/copyleft/gpl.html
29
- */
30
-/******************************************************************************/
31
-
32
-#ifndef _h_PSCRYPTO
33
-#define _h_PSCRYPTO
34
-
35
-#ifdef __cplusplus
36
-extern "C" {
37
-#endif
38
-
39
-/*
40
-	PeerSec crypto-specific defines.
41
- */
42
-#define SMALL_CODE
43
-#define CLEAN_STACK
44
-/*
45
-	If Native 64 bit integers are not supported, we must set the 16 bit flag
46
-	to produce 32 bit mp_words in mpi.h
47
-	We must also include the slow MPI functions because the fast ones only
48
-	work with larger (28 bit) digit sizes.
49
-*/
50
-#ifndef USE_INT64
51
-#define MP_16BIT
52
-#define USE_SMALL_WORD
53
-#endif /* USE_INT64 */
54
-
55
-/******************************************************************************/
56
-
57
-#ifdef USE_RSA
58
-
59
-#include "mpi.h"
60
-
61
-#if LINUX
62
-	#define _stat stat
63
-#endif
64
-
65
-/* this is the "32-bit at least" data type 
66
- * Re-define it to suit your platform but it must be at least 32-bits 
67
- */
68
-typedef unsigned long ulong32;
69
-
70
-/*
71
-	Primary RSA Key struct.  Define here for crypto
72
-*/
73
-typedef struct {
74
-	mp_int		e, d, N, qP, dP, dQ, p, q;
75
-	int32			size;	/* Size of the key in bytes */
76
-	int32			optimized; /* 1 for optimized */
77
-} sslRsaKey_t;
78
-
79
-#endif /* USE_RSA */
80
-
81
-
82
-/*
83
- *	Private
84
- */
85
-extern int32 ps_base64_decode(const unsigned char *in, uint32 len, 
86
-							unsigned char *out, uint32 *outlen);
87
-
88
-/*
89
- *	Memory routines
90
- */
91
-extern void psZeromem(void *dst, size_t len);
92
-extern void psBurnStack(unsigned long len);
93
-
94
-
95
-/* max size of either a cipher/hash block or symmetric key [largest of the two] */
96
-#define MAXBLOCKSIZE			24
97
-
98
-/* ch1-01-1 */
99
-/* error codes [will be expanded in future releases] */
100
-enum {
101
-	CRYPT_OK=0,					/* Result OK */
102
-	CRYPT_ERROR,				/* Generic Error */
103
-	CRYPT_NOP,					/* Not a failure but no operation was performed */
104
-
105
-	CRYPT_INVALID_KEYSIZE,		/* Invalid key size given */
106
-	CRYPT_INVALID_ROUNDS,		/* Invalid number of rounds */
107
-	CRYPT_FAIL_TESTVECTOR,		/* Algorithm failed test vectors */
108
-
109
-	CRYPT_BUFFER_OVERFLOW,		/* Not enough space for output */
110
-	CRYPT_INVALID_PACKET,		/* Invalid input packet given */
111
-
112
-	CRYPT_INVALID_PRNGSIZE,		/* Invalid number of bits for a PRNG */
113
-	CRYPT_ERROR_READPRNG,		/* Could not read enough from PRNG */
114
-
115
-	CRYPT_INVALID_CIPHER,		/* Invalid cipher specified */
116
-	CRYPT_INVALID_HASH,			/* Invalid hash specified */
117
-	CRYPT_INVALID_PRNG,			/* Invalid PRNG specified */
118
-
119
-	CRYPT_MEM,					/* Out of memory */
120
-
121
-	CRYPT_PK_TYPE_MISMATCH,		/* Not equivalent types of PK keys */
122
-	CRYPT_PK_NOT_PRIVATE,		/* Requires a private PK key */
123
-
124
-	CRYPT_INVALID_ARG,			/* Generic invalid argument */
125
-	CRYPT_FILE_NOTFOUND,		/* File Not Found */
126
-
127
-	CRYPT_PK_INVALID_TYPE,		/* Invalid type of PK key */
128
-	CRYPT_PK_INVALID_SYSTEM,	/* Invalid PK system specified */
129
-	CRYPT_PK_DUP,				/* Duplicate key already in key ring */
130
-	CRYPT_PK_NOT_FOUND,			/* Key not found in keyring */
131
-	CRYPT_PK_INVALID_SIZE,		/* Invalid size input for PK parameters */
132
-
133
-	CRYPT_INVALID_PRIME_SIZE	/* Invalid size of prime requested */
134
-};
135
-
136
-/******************************************************************************/
137
-/*
138
-	hash defines
139
- */
140
-struct sha1_state {
141
-#ifdef USE_INT64
142
-	ulong64		length;
143
-#else
144
-	ulong32		lengthHi;
145
-	ulong32		lengthLo;
146
-#endif /* USE_INT64 */
147
-	ulong32 state[5], curlen;
148
-	unsigned char	buf[64];
149
-};
150
-
151
-struct md5_state {
152
-#ifdef USE_INT64
153
-	ulong64 length;
154
-#else
155
-	ulong32	lengthHi;
156
-	ulong32	lengthLo;
157
-#endif /* USE_INT64 */
158
-	ulong32 state[4], curlen;
159
-	unsigned char buf[64];
160
-};
161
-
162
-#ifdef USE_MD2
163
-struct md2_state {
164
-	unsigned char chksum[16], X[48], buf[16];
165
-	unsigned long curlen;
166
-};
167
-#endif /* USE_MD2 */
168
-
169
-#ifdef USE_SHA256
170
-struct sha256_state {
171
-	ulong64 length;
172
-	ulong32 state[8], curlen;
173
-	unsigned char buf[64];
174
-};
175
-#endif /* USE_SHA256 */
176
-
177
-typedef union {
178
-	struct sha1_state	sha1;
179
-	struct md5_state	md5;
180
-#ifdef USE_MD2
181
-	struct md2_state	md2;
182
-#endif /* USE_MD2 */
183
-#ifdef USE_SHA256
184
-	struct sha256_state sha256;
185
-#endif
186
-} hash_state;
187
-
188
-typedef hash_state sslSha1Context_t;
189
-typedef hash_state sslMd5Context_t;
190
-#ifdef USE_MD2
191
-typedef hash_state sslMd2Context_t;
192
-#endif /* USE_MD2 */
193
-#ifdef USE_SHA256
194
-typedef hash_state sslSha256Context_t;
195
-#endif /* USE_SHA256 */
196
-
197
-typedef struct {
198
-	unsigned char	pad[64];
199
-	union {
200
-		sslMd5Context_t		md5;
201
-		sslSha1Context_t	sha1;
202
-	} u;
203
-} sslHmacContext_t;
204
-
205
-/******************************************************************************/
206
-/*
207
-	RC4
208
- */
209
-#ifdef USE_ARC4
210
-typedef struct {
211
-	unsigned char	state[256];
212
-	uint32	byteCount;
213
-	unsigned char	x;
214
-	unsigned char	y;
215
-} rc4_key;
216
-#endif /* USE_ARC4 */
217
-
218
-#define SSL_DES3_KEY_LEN	24
219
-#define SSL_DES3_IV_LEN		8
220
-#ifdef USE_3DES
221
-
222
-typedef struct {
223
-	ulong32 ek[3][32], dk[3][32];
224
-} des3_key;
225
-
226
-/*
227
-	A block cipher CBC structure
228
- */
229
-typedef struct {
230
-	int32					blocklen;
231
-	unsigned char		IV[8];
232
-	des3_key			key;
233
-	int32					explicitIV; /* 1 if yes */
234
-} des3_CBC;
235
-
236
-extern int32 des3_setup(const unsigned char *key, int32 keylen, int32 num_rounds,
237
-		 des3_CBC *skey);
238
-extern void des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct,
239
-		 des3_CBC *key);
240
-extern void des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt,
241
-		 des3_CBC *key);
242
-extern int32 des3_keysize(int32 *desired_keysize);
243
-
244
-extern int32 des_setup(const unsigned char *key, int32 keylen, int32 num_rounds,
245
-		 des3_CBC *skey);
246
-extern void des_ecb_encrypt(const unsigned char *pt, unsigned char *ct,
247
-		 des3_CBC *key);
248
-extern void des_ecb_decrypt(const unsigned char *ct, unsigned char *pt,
249
-		 des3_CBC *key);
250
-
251
-#endif /* USE_3DES */
252
-
253
-
254
-typedef union {
255
-#ifdef USE_ARC4
256
-	rc4_key		arc4;
257
-#endif
258
-#ifdef USE_3DES
259
-	des3_CBC	des3;
260
-#endif
261
-} sslCipherContext_t;
262
-
263
-
264
-/*
265
-	Controls endianess and size of registers.  Leave uncommented to get
266
-	platform neutral [slower] code detect x86-32 machines somewhat
267
- */
268
-#if (defined(_MSC_VER) && defined(WIN32)) || (defined(__GNUC__) && (defined(__DJGPP__) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__i386__)))
269
-	#define ENDIAN_LITTLE
270
-	#define ENDIAN_32BITWORD
271
-#endif
272
-
273
-
274
-/* #define ENDIAN_LITTLE */
275
-/* #define ENDIAN_BIG */
276
-
277
-/* #define ENDIAN_32BITWORD */
278
-/* #define ENDIAN_64BITWORD */
279
-
280
-#if (defined(ENDIAN_BIG) || defined(ENDIAN_LITTLE)) && !(defined(ENDIAN_32BITWORD) || defined(ENDIAN_64BITWORD))
281
-		#error You must specify a word size as well as endianess
282
-#endif
283
-
284
-#if !(defined(ENDIAN_BIG) || defined(ENDIAN_LITTLE))
285
-	#define ENDIAN_NEUTRAL
286
-#endif
287
-
288
-/*
289
-	helper macros
290
- */
291
-#if defined (ENDIAN_NEUTRAL)
292
-
293
-#define STORE32L(x, y)                                                                     \
294
-     { (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255);   \
295
-       (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
296
-
297
-#define LOAD32L(x, y)                            \
298
-     { x = ((unsigned long)((y)[3] & 255)<<24) | \
299
-           ((unsigned long)((y)[2] & 255)<<16) | \
300
-           ((unsigned long)((y)[1] & 255)<<8)  | \
301
-           ((unsigned long)((y)[0] & 255)); }
302
-
303
-#define STORE64L(x, y)                                                                     \
304
-     { (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255);   \
305
-       (y)[5] = (unsigned char)(((x)>>40)&255); (y)[4] = (unsigned char)(((x)>>32)&255);   \
306
-       (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255);   \
307
-       (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
308
-
309
-#define LOAD64L(x, y)                                                       \
310
-     { x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48)| \
311
-           (((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32)| \
312
-           (((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16)| \
313
-           (((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); }
314
-
315
-#define STORE32H(x, y)                                                                     \
316
-     { (y)[0] = (unsigned char)(((x)>>24)&255); (y)[1] = (unsigned char)(((x)>>16)&255);   \
317
-       (y)[2] = (unsigned char)(((x)>>8)&255); (y)[3] = (unsigned char)((x)&255); }
318
-
319
-#define LOAD32H(x, y)                            \
320
-     { x = ((unsigned long)((y)[0] & 255)<<24) | \
321
-           ((unsigned long)((y)[1] & 255)<<16) | \
322
-           ((unsigned long)((y)[2] & 255)<<8)  | \
323
-           ((unsigned long)((y)[3] & 255)); }
324
-
325
-#define STORE64H(x, y)                                                                     \
326
-   { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255);     \
327
-     (y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255);     \
328
-     (y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255);     \
329
-     (y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); }
330
-
331
-#define LOAD64H(x, y)                                                      \
332
-   { x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48) | \
333
-         (((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32) | \
334
-         (((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16) | \
335
-         (((ulong64)((y)[6] & 255))<<8)|(((ulong64)((y)[7] & 255))); }
336
-
337
-#endif /* ENDIAN_NEUTRAL */
338
-
339
-#ifdef ENDIAN_LITTLE
340
-
341
-#define STORE32H(x, y)                                                                     \
342
-     { (y)[0] = (unsigned char)(((x)>>24)&255); (y)[1] = (unsigned char)(((x)>>16)&255);   \
343
-       (y)[2] = (unsigned char)(((x)>>8)&255); (y)[3] = (unsigned char)((x)&255); }
344
-
345
-#define LOAD32H(x, y)                            \
346
-     { x = ((unsigned long)((y)[0] & 255)<<24) | \
347
-           ((unsigned long)((y)[1] & 255)<<16) | \
348
-           ((unsigned long)((y)[2] & 255)<<8)  | \
349
-           ((unsigned long)((y)[3] & 255)); }
350
-
351
-#define STORE64H(x, y)                                                                     \
352
-   { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255);     \
353
-     (y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255);     \
354
-     (y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255);     \
355
-     (y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); }
356
-
357
-#define LOAD64H(x, y)                                                      \
358
-   { x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48) | \
359
-         (((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32) | \
360
-         (((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16) | \
361
-         (((ulong64)((y)[6] & 255))<<8)|(((ulong64)((y)[7] & 255))); }
362
-
363
-#ifdef ENDIAN_32BITWORD 
364
-
365
-#define STORE32L(x, y)        \
366
-     { unsigned long __t = (x); memcpy(y, &__t, 4); }
367
-
368
-#define LOAD32L(x, y)         \
369
-     memcpy(&(x), y, 4);
370
-
371
-#define STORE64L(x, y)                                                                     \
372
-     { (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255);   \
373
-       (y)[5] = (unsigned char)(((x)>>40)&255); (y)[4] = (unsigned char)(((x)>>32)&255);   \
374
-       (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255);   \
375
-       (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
376
-
377
-#define LOAD64L(x, y)                                                       \
378
-     { x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48)| \
379
-           (((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32)| \
380
-           (((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16)| \
381
-           (((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); }
382
-
383
-#else /* 64-bit words then  */
384
-
385
-#define STORE32L(x, y)        \
386
-     { unsigned long __t = (x); memcpy(y, &__t, 4); }
387
-
388
-#define LOAD32L(x, y)         \
389
-     { memcpy(&(x), y, 4); x &= 0xFFFFFFFF; }
390
-
391
-#define STORE64L(x, y)        \
392
-     { ulong64 __t = (x); memcpy(y, &__t, 8); }
393
-
394
-#define LOAD64L(x, y)         \
395
-    { memcpy(&(x), y, 8); }
396
-
397
-#endif /* ENDIAN_64BITWORD */
398
-#endif /* ENDIAN_LITTLE */
399
-
400
-#ifdef ENDIAN_BIG
401
-#define STORE32L(x, y)                                                                     \
402
-     { (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255);   \
403
-       (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
404
-
405
-#define LOAD32L(x, y)                            \
406
-     { x = ((unsigned long)((y)[3] & 255)<<24) | \
407
-           ((unsigned long)((y)[2] & 255)<<16) | \
408
-           ((unsigned long)((y)[1] & 255)<<8)  | \
409
-           ((unsigned long)((y)[0] & 255)); }
410
-
411
-#define STORE64L(x, y)                                                                     \
412
-   { (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255);     \
413
-     (y)[5] = (unsigned char)(((x)>>40)&255); (y)[4] = (unsigned char)(((x)>>32)&255);     \
414
-     (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255);     \
415
-     (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
416
-
417
-#define LOAD64L(x, y)                                                      \
418
-   { x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48) | \
419
-         (((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32) | \
420
-         (((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16) | \
421
-         (((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); }
422
-
423
-#ifdef ENDIAN_32BITWORD 
424
-
425
-#define STORE32H(x, y)        \
426
-     { unsigned long __t = (x); memcpy(y, &__t, 4); }
427
-
428
-#define LOAD32H(x, y)         \
429
-     memcpy(&(x), y, 4);
430
-
431
-#define STORE64H(x, y)                                                                     \
432
-     { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255);   \
433
-       (y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255);   \
434
-       (y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255);   \
435
-       (y)[6] = (unsigned char)(((x)>>8)&255);  (y)[7] = (unsigned char)((x)&255); }
436
-
437
-#define LOAD64H(x, y)                                                       \
438
-     { x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48)| \
439
-           (((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32)| \
440
-           (((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16)| \
441
-           (((ulong64)((y)[6] & 255))<<8)| (((ulong64)((y)[7] & 255))); }
442
-
443
-#else /* 64-bit words then  */
444
-
445
-#define STORE32H(x, y)        \
446
-     { unsigned long __t = (x); memcpy(y, &__t, 4); }
447
-
448
-#define LOAD32H(x, y)         \
449
-     { memcpy(&(x), y, 4); x &= 0xFFFFFFFF; }
450
-
451
-#define STORE64H(x, y)        \
452
-     { ulong64 __t = (x); memcpy(y, &__t, 8); }
453
-
454
-#define LOAD64H(x, y)         \
455
-    { memcpy(&(x), y, 8); }
456
-
457
-#endif /* ENDIAN_64BITWORD */
458
-#endif /* ENDIAN_BIG */
459
-
460
-/*
461
-	packet code */
462
-#if defined(USE_RSA) || defined(MDH) || defined(MECC)
463
-	#define PACKET
464
-
465
-/*
466
-	size of a packet header in bytes */
467
-	#define PACKET_SIZE				4
468
-
469
-/*
470
-	Section tags
471
- */
472
-	#define PACKET_SECT_RSA			0
473
-	#define PACKET_SECT_DH			1
474
-	#define PACKET_SECT_ECC			2
475
-	#define PACKET_SECT_DSA			3
476
-
477
-/*
478
-	Subsection Tags for the first three sections
479
- */
480
-	#define PACKET_SUB_KEY			0
481
-	#define PACKET_SUB_ENCRYPTED	1
482
-	#define PACKET_SUB_SIGNED		2
483
-	#define PACKET_SUB_ENC_KEY		3
484
-#endif
485
-
486
-/*
487
-	fix for MSVC ...evil!
488
- */
489
-#ifdef WIN32
490
-#ifdef _MSC_VER
491
-	#define CONST64(n) n ## ui64
492
-	typedef unsigned __int64 ulong64;
493
-#else
494
-	#define CONST64(n) n ## ULL
495
-	typedef unsigned long long ulong64;
496
-#endif
497
-#endif /* WIN32 */
498
-
499
-
500
-#define BSWAP(x)  ( ((x>>24)&0x000000FFUL) | ((x<<24)&0xFF000000UL)  | \
501
-                    ((x>>8)&0x0000FF00UL)  | ((x<<8)&0x00FF0000UL) )
502
-
503
-#ifdef _MSC_VER
504
-
505
-/*
506
-	instrinsic rotate
507
- */
508
-#include <stdlib.h>
509
-#pragma intrinsic(_lrotr,_lrotl)
510
-#define ROR(x,n) _lrotr(x,n)
511
-#define ROL(x,n) _lrotl(x,n)
512
-#define RORc(x,n) _lrotr(x,n)
513
-#define ROLc(x,n) _lrotl(x,n)
514
-
515
-/*
516
-#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && !defined(INTEL_CC) && !defined(PS_NO_ASM)
517
-
518
-static inline unsigned ROL(unsigned word, int32 i)
519
-{
520
-	asm ("roll %%cl,%0"
521
-		:"0" (word),"c" (i));
522
-	return word;
523
-}
524
-
525
-static inline unsigned ROR(unsigned word, int32 i)
526
-{
527
-	asm ("rorl %%cl,%0"
528
-		:"=r" (word)
529
-		:"0" (word),"c" (i));
530
-	return word;
531
-}
532
-*/
533
-/*
534
-#ifndef PS_NO_ROLC
535
-
536
-static inline unsigned ROLc(unsigned word, const int32 i)
537
-{
538
-   asm ("roll %2,%0"
539
-      :"=r" (word)
540
-      :"0" (word),"I" (i));
541
-   return word;
542
-}
543
-
544
-static inline unsigned RORc(unsigned word, const int32 i)
545
-{
546
-   asm ("rorl %2,%0"
547
-      :"=r" (word)
548
-      :"0" (word),"I" (i));
549
-   return word;
550
-}
551
-
552
-#else
553
-
554
-#define ROLc ROL
555
-#define RORc ROR
556
-
557
-#endif
558
-*/
559
-
560
-#else /* _MSC_VER */
561
-
562
-/*
563
-	rotates the hard way
564
- */
565
-#define ROL(x, y) ( (((unsigned long)(x)<<(unsigned long)((y)&31)) | (((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
566
-#define ROR(x, y) ( ((((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)((y)&31)) | ((unsigned long)(x)<<(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
567
-#define ROLc(x, y) ( (((unsigned long)(x)<<(unsigned long)((y)&31)) | (((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
568
-#define RORc(x, y) ( ((((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)((y)&31)) | ((unsigned long)(x)<<(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
569
-
570
-#endif /* _MSC_VER */
571
-
572
-/* 64-bit Rotates */
573
-#if 0
574
-
575
-#if defined(__GNUC__) && defined(__x86_64__) && !defined(PS_NO_ASM)
576
-
577
-static inline unsigned long ROL64(unsigned long word, int32 i)
578
-{
579
-   asm("rolq %%cl,%0"
580
-      :"=r" (word)
581
-      :"0" (word),"c" (i));
582
-   return word;
583
-}
584
-
585
-static inline unsigned long ROR64(unsigned long word, int32 i)
586
-{
587
-   asm("rorq %%cl,%0"
588
-      :"=r" (word)
589
-      :"0" (word),"c" (i));
590
-   return word;
591
-}
592
-
593
-#ifndef PS_NO_ROLC
594
-
595
-static inline unsigned long ROL64c(unsigned long word, const int32 i)
596
-{
597
-   asm("rolq %2,%0"
598
-      :"=r" (word)
599
-      :"0" (word),"J" (i));
600
-   return word;
601
-}
602
-
603
-static inline unsigned long ROR64c(unsigned long word, const int32 i)
604
-{
605
-   asm("rorq %2,%0"
606
-      :"=r" (word)
607
-      :"0" (word),"J" (i));
608
-   return word;
609
-}
610
-
611
-#else /* PS_NO_ROLC */
612
-
613
-#define ROL64c ROL
614
-#define ROR64c ROR
615
-
616
-#endif /* PS_NO_ROLC */
617
-#endif
618
-#endif /* commented out */
619
-
620
-#define ROL64(x, y) \
621
-    ( (((x)<<((ulong64)(y)&63)) | \
622
-      (((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)64-((y)&63)))) & CONST64(0xFFFFFFFFFFFFFFFF))
623
-
624
-#define ROR64(x, y) \
625
-    ( ((((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)(y)&CONST64(63))) | \
626
-      ((x)<<((ulong64)(64-((y)&CONST64(63)))))) & CONST64(0xFFFFFFFFFFFFFFFF))
627
-
628
-#define ROL64c(x, y) \
629
-    ( (((x)<<((ulong64)(y)&63)) | \
630
-      (((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)64-((y)&63)))) & CONST64(0xFFFFFFFFFFFFFFFF))
631
-
632
-#define ROR64c(x, y) \
633
-    ( ((((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)(y)&CONST64(63))) | \
634
-      ((x)<<((ulong64)(64-((y)&CONST64(63)))))) & CONST64(0xFFFFFFFFFFFFFFFF))
635
-
636
-#undef MAX
637
-#undef MIN
638
-#define MAX(x, y) ( ((x)>(y))?(x):(y) )
639
-#define MIN(x, y) ( ((x)<(y))?(x):(y) )
640
-
641
-/*
642
-	extract a byte portably This MSC code causes runtime errors in VS.NET,
643
-	always use the other
644
- */
645
-/*
646
-#ifdef _MSC_VER
647
-   #define byte(x, n) ((unsigned char)((x) >> (8 * (n))))
648
-#else
649
-*/
650
-   #define byte(x, n) (((x) >> (8 * (n))) & 255)
651
-/*
652
-#endif
653
-*/
654
-#ifdef __cplusplus
655
-   }
656
-#endif /* __cplusplus */
657
-
658
-#endif /* _h_PSCRYPTO */
659
-
660
-/******************************************************************************/
661
-

+ 0
- 136
src/crypto/ssl.c Näytä tiedosto

@@ -1,136 +0,0 @@
1
-#if 0
2
-
3
-#include "ssl.h"
4
-#include "ssl_constructs.h"
5
-#include <string.h> // for bcopy()
6
-#include <time.h> // for time()
7
-#include <stdlib.h> // for rand(), htons?, htonl?
8
-// note net byte order is big-endian
9
-// Need to set error codes
10
-
11
-int CreateSSLHello(SSL_t *ssl)
12
-{
13
-  printf("In CreateSSLHello()\n",ssl);
14
-
15
-  // Initalize the structure
16
-  bzero(ssl,sizeof(SSL_t));
17
-  //ssl->max_size = sizeof(ssl->buffer);
18
-  ssl->max_size = 18456;
19
-
20
-  // Declare variables
21
-  int i; void *ptr;
22
-
23
-  // Set pointers into buffer
24
-  SSLPlaintext *record = (SSLPlaintext *)ssl->buffer;
25
-  Handshake *handshake = (Handshake *)record->fragment;
26
-  // the body starts right after the handshake
27
-  printf("sizeof(Handshake) = %d\n",sizeof(Handshake));
28
-  ClientHello *hello = (ClientHello *)(handshake + 1);
29
-
30
-  printf("record->%#x, handshake->%#x, hello->%#x\n",record,handshake,hello);
31
-
32
-  // Construct ClientHello Message
33
-  hello->client_version = version;
34
-  i = htonl(time(NULL));
35
-  bcopy(&i,hello->random.gmt_unix_time,4);
36
-  for(i=0;i<28;i++){ hello->random.random_bytes[i] = (uint8)rand(); }
37
-  hello->session_id_length = 0;
38
-  hello->session_id = &hello->session_id_length;
39
-  hello->session_id_end = hello->session_id;
40
-  hello->cipher_suites_length = (CipherSuiteLength *)(hello->session_id_end + 1);
41
-  hello->cipher_suites = (hello->cipher_suites_length + 1);
42
-  hello->cipher_suites_end = hello->cipher_suites;
43
-  i = htons(2*5); // 2 bytes per Suite * 5 Suites
44
-  bcopy(&i,hello->cipher_suites_length,2);
45
-  bcopy(SSL_NULL_WITH_NULL_NULL,hello->cipher_suites_end,sizeof(CipherSuite));
46
-  *hello->cipher_suites_end++;
47
-  bcopy(SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA,hello->cipher_suites_end,sizeof(CipherSuite));
48
-  *hello->cipher_suites_end++;
49
-  bcopy(SSL_DH_DSS_WITH_DES_CBC_SHA,hello->cipher_suites_end,sizeof(CipherSuite));
50
-  *hello->cipher_suites_end++;
51
-  bcopy(SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA,hello->cipher_suites_end,sizeof(CipherSuite));
52
-  *hello->cipher_suites_end++;
53
-  bcopy(SSL_DH_anon_WITH_RC4_128_MD5,hello->cipher_suites_end,sizeof(CipherSuite));
54
-  hello->compression_methods_length = (CompressionMethodLength *)(hello->cipher_suites_end + 1);
55
-  hello->compression_methods = (hello->compression_methods_length + 1);
56
-  hello->compression_methods_end = hello->compression_methods;
57
-  *hello->compression_methods_length = 1;
58
-  *hello->compression_methods_end = compression_method_null;
59
-
60
-  // Construct Handshake Message
61
-  handshake->msg_type = handshake_type_client_hello;
62
-  i = (void *)(hello->compression_methods_end + 1) - (void *)hello;
63
-  printf("Handshake.length = %d\n", i);
64
-  handshake->length[0] = (char)*(&i+8);
65
-  handshake->length[1] = (char)*(&i+8);
66
-  handshake->length[2] = (char)i;
67
-  //bcopy((&i+1),handshake->length,3); // +1 so we copy 3 bytes
68
-
69
-  // Construct SSL Record
70
-  printf("sizeof(ContentType)=%d\n",sizeof(ContentType));
71
-  printf("sizeof(uint8)=%d\n",sizeof(uint8));
72
-  record->type = content_type_handshake;
73
-  record->version = version;
74
-  i += sizeof(Handshake);
75
-  printf("SSLPlaintext.length = %d\n",i);
76
-  record->length[0] = (char)*(&i+8);
77
-  record->length[1] = (char)i;
78
-  //bcopy(&i,record->length,4); // length of handshake
79
-
80
-  // Set total size of message
81
-  i += sizeof(ContentType) + sizeof(ProtocolVersion) + sizeof(uint16);
82
-  ssl->length = i;
83
-  printf("End of CreateSSLHello\n");
84
-  return 0;
85
-}
86
-
87
-void PrintSSLPacket(SSL_t *ssl)
88
-{
89
-  printf("Printing packet with length:%d\n", ssl->length);
90
-  char *ptr = ssl->buffer;
91
-  char *begin = ptr;
92
-  char *tmp;
93
-  char *end = ssl->buffer + ssl->length;
94
-  printf("Record Layer:\n");
95
-  printf("\tContentType: %2hhX\n",(char)*ptr++);
96
-  printf("\tVersion: %2hhX %2hhX\n", (char)*ptr++, (char)*ptr++);
97
-  printf("\tLength: %2hhX %2hhX\n", (char)*ptr++, (char)*ptr++);
98
-
99
-  printf("Handshake:\n");
100
-  printf("\tType: %2hhX\n", (char)*ptr++);
101
-  printf("\tLength: %2hhX %2hhX %2hhX\n", (char)*ptr++, (char)*ptr++, (char)*ptr++);
102
-  printf("\tVersion: %2hhX %2hhX\n", (char)*ptr++, (char)*ptr++);
103
-  printf("\tgmt_unix_time: %2hhX %2hhX %2hhX %2hhX\n", (char)*ptr++, (char)*ptr++, (char)*ptr++, (char)*ptr++);
104
-  printf("\trandom: ");
105
-  tmp = ptr + 28;
106
-  for(;ptr<tmp;ptr++){printf("%2hhX ", (char)*ptr);}
107
-
108
-  printf("\n\nHexDump:\n");
109
-
110
-  int ctr = 0;
111
-  for(;begin<end;begin++){printf("%2hhX ",(char)*begin);if(++ctr%10==0){printf("\n");}}
112
-  printf("\n\n");
113
-}
114
-
115
-int ReadSSLHello(SSL_t *ssl)
116
-{
117
-  SSLCiphertext *ct = (SSLCiphertext *)ssl->buffer;
118
-
119
-  if(ct->type == content_type_alert){
120
-    // assuming text is still plaintext
121
-    Alert *a = (Alert *)&ct->fragment;
122
-    if(a->level == alert_level_fatal){
123
-      printf("Fatal Alert %d, connection terminated\n",a->description);
124
-      return (1);
125
-    }else if(a->level == alert_level_warning){
126
-      printf("Warning Alert %d\n", a->description);
127
-    }else{
128
-      printf("Unknown alert level %d\n", a->level);
129
-    }
130
-  }else{
131
-    printf("SSL type %d\n",ct->type);
132
-  }
133
-  return (0);
134
-}
135
-
136
-#endif

+ 0
- 19
src/crypto/ssl.h Näytä tiedosto

@@ -1,19 +0,0 @@
1
-// At the moment I have hard coded one buffer. The size
2
-//  is the max size of SSLCiphertext.length (so, actually it should
3
-//  be increased to include the other information in the struct)
4
-// I might need to make a new, or split the current, buffer because
5
-//  I have to have space to read in and write out, as well as keep
6
-//  any data that has not been translated.
7
-// It works for now.
8
-typedef struct _ssl_t{
9
-  char buffer[18456];
10
-  int length;
11
-  int max_size; // can't define const here
12
-  // Current CipherSuite 
13
-  // Client random / Server random ???
14
-  // pointers to different crypto functions
15
-} SSL_t;
16
-
17
-int CreateSSLHello(SSL_t *ssl);
18
-int ReadSSLHello(SSL_t *ssl);
19
-void PrintSSLPacket(SSL_t *ssl);

+ 0
- 342
src/crypto/ssl_constructs.h Näytä tiedosto

@@ -1,342 +0,0 @@
1
-// Note: This file still needs some work.
2
-// Note: I had to redefine the enums to a set of const values,
3
-//   so that the size of the variable would be correct.
4
-
5
-// Typedefs
6
-// (As defined by the SSL v3.0 RFC Draft)
7
-// URL: http://wp.netscape.com/eng/ssl3/draft302.txt
8
-typedef unsigned char uint8;
9
-typedef uint8 uint16[2];
10
-typedef uint8 uint24[3];
11
-typedef uint8 uint32[4];
12
-typedef uint8 uint64[8];
13
-
14
-// Record layers
15
-typedef struct _ProtocolVersion{
16
-  uint8 major, minor;
17
-} ProtocolVersion;
18
-
19
-const ProtocolVersion version = { 3, 0 };
20
-
21
-typedef uint8 ContentType;
22
-const ContentType content_type_change_cipher_spec_type = 20;
23
-const ContentType content_type_alert = 21;
24
-const ContentType content_type_handshake = 22;
25
-const ContentType content_type_application_data = 23;
26
-
27
-typedef struct _SSLPlaintext{
28
-  ContentType type;
29
-  ProtocolVersion version;
30
-  uint16 length; // can not exceed 2^14 bytes
31
-  uint8 fragment[16384]; // 2^14 = 16,384 bytes
32
-} SSLPlaintext;
33
-
34
-typedef struct _SSLCompressed{
35
-  ContentType type;
36
-  ProtocolVersion version;
37
-  uint16 length; // can not exceed 2^14 + 1024
38
-  uint8 fragment[17408]; // SSLCompressed.length
39
-} SSLCompressed;
40
-
41
-typedef struct _SSLCiphertext{
42
-  ContentType type;
43
-  ProtocolVersion version;
44
-  uint16 length;
45
-  uint8 fragment; // so we have a pointer to the data, and don't have to do math
46
-  // fragment; type GenericStreamCipher or GenericBlockCipher
47
-} SSLCiphertext; // recast to get fragment
48
-
49
-typedef struct _GenericStreamCipher{
50
-  uint8 content[17408]; // SSLCompressed.length
51
-  uint8 MAC[]; // CipherSpec.hash_size
52
-} GenericStreamCipher;
53
-
54
-typedef struct _SSLStreamCiphertext{
55
-  ContentType type;
56
-  ProtocolVersion version;
57
-  uint16 length; // can not exceed 2^14 + 2048 = 18,456
58
-  GenericStreamCipher fragment;
59
-} SSLStreamCiphertext;
60
-
61
-typedef struct _GenericBlockCipher{
62
-  uint8 content[17408]; // SSLConpressed.length
63
-  uint8 MAC[0]; // CipherSpec.hash_size
64
-  // padding is used to bring the plaintext to
65
-  // a multiple of the block cipher's block length.
66
-  uint8 padding[0]; // GenericBlockCipher.padding_length
67
-  uint8 padding_length;
68
-} GenericBlockCipher;
69
-
70
-typedef struct _SSLBlockCiphertext{
71
-  ContentType type;
72
-  ProtocolVersion version;
73
-  uint16 length; // can not exceed 2^14 + 2048 = 18,456
74
-  GenericBlockCipher fragment;
75
-} SSLBlockCiphertext;
76
-
77
-// Change cipher specs message
78
-typedef struct _ChangeCipherSpec{
79
-  enum { type_change_cipher_spec=1, type_size=255 } type;
80
-} ChangeCipherSpec;
81
-
82
-// Alert messages
83
-typedef uint8 AlertLevel;
84
-const AlertLevel alert_level_warning = 1;
85
-const AlertLevel alert_level_fatal=2;
86
-
87
-typedef uint8 AlertDescription;
88
-const AlertDescription alert_description_close_notify = 0;
89
-const AlertDescription alert_description_unexpected_message = 10;
90
-const AlertDescription alert_description_bad_record_mac = 20;
91
-const AlertDescription alert_description_decompression_failure = 30;
92
-const AlertDescription alert_description_handshake_failure = 40;
93
-const AlertDescription alert_description_no_certificate = 41;
94
-const AlertDescription alert_description_bad_certificate = 42;
95
-const AlertDescription alert_description_unsupported_certificate = 43;
96
-const AlertDescription alert_description_certificate_revoked = 44;
97
-const AlertDescription alert_description_certificate_expired = 45;
98
-const AlertDescription alert_description_certificate_unknown = 46;
99
-const AlertDescription alert_description_illegal_parameter = 47;
100
-
101
-typedef struct _Alert{
102
-  AlertLevel level;
103
-  AlertDescription description;
104
-} Alert;
105
-
106
-// Handshake protocol
107
-// What is the best way to have a generic pointer to the body struct??
108
-typedef uint8 HandshakeType;
109
-const HandshakeType handshake_type_hello_request = 0;
110
-const HandshakeType handshake_type_client_hello = 1;
111
-const HandshakeType handshake_type_server_hello = 2;
112
-const HandshakeType handshake_type_certificate = 11;
113
-const HandshakeType handshake_type_server_key_exchange = 12;
114
-const HandshakeType handshake_type_certificate_request = 13;
115
-const HandshakeType handshake_type_server_done = 14;
116
-const HandshakeType handshake_type_certificate_verify = 15;
117
-const HandshakeType handshake_type_client_key_exchange = 16;
118
-const HandshakeType handshake_type_finished = 20;
119
-
120
-typedef struct _Handshake{
121
-  HandshakeType msg_type;
122
-  uint24 length;
123
-  // body; // one of HandshakeType structs
124
-} Handshake; // generic Handshake, need to recast to get body
125
-
126
-// Hello messages
127
-typedef struct _HelloRequest{} HelloRequest;
128
-
129
-typedef struct _HelloRequestHandshake{
130
-  HandshakeType msg_type;
131
-  uint24 length;
132
-  HelloRequest body;
133
-} HelloRequestHandshake;
134
-
135
-typedef struct _Random{
136
-  uint32 gmt_unix_time;
137
-  uint8 random_bytes[28];
138
-} Random;
139
-
140
-//typedef uint8 SessionID[32]; // <0..32>
141
-typedef uint8 SessionIDLength;
142
-typedef uint8 SessionID;
143
-
144
-typedef uint16 CipherSuiteLength;
145
-typedef uint8 CipherSuite[2];
146
-
147
-typedef uint8 CompressionMethodLength;
148
-typedef uint8 CompressionMethod;
149
-const CompressionMethod compression_method_null = 0;
150
-
151
-
152
-typedef struct _ClientHello{
153
-  ProtocolVersion client_version;
154
-  Random random;
155
-  SessionIDLength session_id_length;
156
-  SessionID *session_id;
157
-  SessionID *session_id_end;
158
-  CipherSuiteLength *cipher_suites_length;
159
-  CipherSuite *cipher_suites; // min size is one entry
160
-  CipherSuite *cipher_suites_end;
161
-  //CipherSuite cipher_suites[32768]; // <2..2^16-1> = 65,536 bytes and CipherSuite is 2 bytes
162
-  CompressionMethodLength *compression_methods_length;
163
-  CompressionMethod *compression_methods;
164
-  CompressionMethod *compression_methods_end;
165
-  //CompressionMethod *compression_methods; // min size is zero
166
-  //CompressionMethod compression_methods[256]; // <0..2^8-1> = 256 bytes and CompressionMethod is 1 byte
167
-} ClientHello;
168
-
169
-typedef struct _ClientHelloHandshake{
170
-  //HandshakeType msg_type;
171
-  uint8 msg_type;
172
-  uint24 length;
173
-  ClientHello body;
174
-} ClientHelloHandshake;
175
-
176
-typedef struct _ServerHello{
177
-  ProtocolVersion server_version;
178
-  Random random;
179
-  SessionID session_id;
180
-  CipherSuite cipher_suite;
181
-  CompressionMethod compression_method;
182
-} ServerHello;
183
-
184
-typedef struct _ServerHelloHandshake{
185
-  HandshakeType msg_type;
186
-  uint24 length;
187
-  ServerHello body;
188
-} ServerHelloHandshake;
189
-
190
-// Server authentication and key exchange messages
191
-typedef uint8 ASN1Cert[16777216]; // <1..2^24-1> = 16,777,216 bytes
192
-
193
-typedef struct _Certificate{
194
-  ASN1Cert certificate_list[1]; // <1..2^24-1> / ANS1Cert = 1
195
-  // for some reason the size of certificate_list and ASN1Cert is the same, so only one certificate in the list
196
-} Certificate;
197
-
198
-typedef uint8 KeyExchangeAlgorithm;
199
-const KeyExchangeAlgorithm key_exchange_algorithm_rsa = 0;
200
-const KeyExchangeAlgorithm key_exchange_algorithm_diffie_hellman = 1;
201
-const KeyExchangeAlgorithm key_exchange_algorithm_fortezza_kea = 2;
202
-
203
-typedef struct _AnonSignature{
204
-  struct {};
205
-} AnonSignature;
206
-
207
-typedef struct _RSASignature{
208
-  uint8 md5_hash[16];
209
-  uint8 sha_hash[20];
210
-} RSASignature;
211
-
212
-typedef struct _DSASignature{
213
-  uint8 sha_hash[20];
214
-} DSASignature;
215
-
216
-// use union??,  make a mess to reference, but easy to make Signature type.
217
-typedef union _Signature{ AnonSignature anon; RSASignature rsa; DSASignature dsa; } Signature;
218
-
219
-typedef struct _ServerRSAParams{
220
-  uint8 RSA_modulus[65536]; // <1..2^16-1> = 65,536
221
-  uint8 RSA_exponent[65536]; // <1..2^16-1> = 65,536
222
-} ServerRSAParams;
223
-
224
-typedef struct _ServerDHParams{
225
-  uint8 DH_p[65536]; // <1..2^16-1>
226
-  uint8 DH_g[65536]; // <1..2^16-1>
227
-  uint8 DH_Ys[65536]; // <1..2^16-1>
228
-} ServerDHParams;
229
-
230
-typedef struct _ServerDHKeyExchange{
231
-  ServerDHParams params;
232
-  Signature signed_params;
233
-} ServerDHKeyExchange;
234
-
235
-typedef struct _ServerRSAKeyExchange{
236
-  ServerRSAParams params;
237
-  Signature signed_params;
238
-} ServerRSAKeyExchange;
239
-
240
-typedef uint8 SignatureAlgorithm;
241
-const SignatureAlgorithm signature_algorithm_anonymous = 0;
242
-const SignatureAlgorithm signature_algorithm_rsa = 1;
243
-const SignatureAlgorithm signature_algorithm_dsa = 2;
244
-
245
-typedef uint8 CertificateType;
246
-const CertificateType certificate_type_RSA_sign = 1;
247
-const CertificateType certificate_type_DSS_sign = 2;
248
-const CertificateType certificate_type_RSA_fixed_DH = 3;
249
-const CertificateType certificate_type_DSS_fixed_DH = 4;
250
-const CertificateType certificate_type_RSA_ephemeral_DH = 5;
251
-const CertificateType certificate_type_DSS_ephemeral_DH = 6;
252
-const CertificateType certificate_type_FORTEZZA_MISSI = 20;
253
-
254
-typedef uint8 DistinguishedName[65536]; // <1..2^16-1> = 65,536
255
-
256
-typedef struct _CertificateRequest{
257
-  CertificateType certificate_types[256]; // <1..2^8-1>
258
-  DistinguishedName certificate_authorities[1]; // <3...2^16-1> / DistinguishedName
259
-  // this is another one that is odd with a list size of 1
260
-} CertificateRequest;
261
-
262
-typedef struct _ServerHelloDone{} ServerHelloDone;
263
-
264
-// Client authentication and key exchange messages
265
-typedef struct _PreMasterSecret{
266
-  ProtocolVersion client_version;
267
-  uint8 random[46];
268
-} PreMasterSecret;
269
-
270
-typedef struct _EncryptedPreMasterSecret{
271
-  PreMasterSecret pre_master_secret;
272
-} EncryptedPreMasterSecret;
273
-
274
-typedef struct _RSAClientKeyExchange{
275
-  EncryptedPreMasterSecret exchange_keys;
276
-} RSAClientKeyExchange;
277
-
278
-typedef uint8 PublicValueEncoding;
279
-const PublicValueEncoding public_value_encoding_implicit = 0;
280
-const PublicValueEncoding public_value_encoding_explicit = 1;
281
-
282
-typedef struct _ClientDiffieHellmanPublic{
283
-  // This is a select on PublicValueEncoding,  and I chose the larger size
284
-  uint8 dh_public[65536]; // DH_Yc<1..2^16-1>, the dh public value
285
-} ClientDiffieHellmanPublic;
286
-
287
-typedef struct _DHClientKeyExhange{
288
-  ClientDiffieHellmanPublic exchange_keys;
289
-} DHClientKeyExchange;
290
-
291
-typedef struct _CertificateVerify{
292
-  Signature signature;
293
-} CertificateVerify;
294
-
295
-// Handshake finalization message
296
-typedef struct _Finished{
297
-  uint8 md5_hash[16];
298
-  uint8 sha_hash[20];
299
-} Finished;
300
-
301
-// The CipherSuite
302
-CipherSuite SSL_NULL_WITH_NULL_NULL                     = { 0x00, 0x13 };
303
-CipherSuite SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA        = { 0x00, 0x0B };
304
-CipherSuite SSL_DH_DSS_WITH_DES_CBC_SHA                 = { 0x00, 0x0C };
305
-CipherSuite SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA       = { 0x00, 0x11 };
306
-CipherSuite SSL_DH_anon_EXPORT_WITH_RC4_40_MD5          = { 0x00, 0x17 };
307
-CipherSuite SSL_DH_anon_WITH_RC4_128_MD5                = { 0x00, 0x18 };
308
-
309
-// The CipherSpec
310
-typedef uint8 CipherType;
311
-const CipherType cipher_type_stream = 0;
312
-const CipherType cipher_type_block = 1;
313
-
314
-typedef uint8 IsExportable;
315
-const IsExportable is_exportable_true = 0;
316
-const IsExportable is_exportable_false = 1;
317
-
318
-typedef uint8 BulkCipherAlgorithm;
319
-const BulkCipherAlgorithm bulk_cipher_algorithm_null = 0;
320
-const BulkCipherAlgorithm bulk_cipher_algorithm_rc4 = 1;
321
-const BulkCipherAlgorithm bulk_cipher_algorithm_rc2 = 2;
322
-const BulkCipherAlgorithm bulk_cipher_algorithm_des = 3;
323
-const BulkCipherAlgorithm bulk_cipher_algorithm_3des = 4;
324
-const BulkCipherAlgorithm bulk_cipher_algorithm_des40 = 5;
325
-const BulkCipherAlgorithm bulk_cipher_algorithm_fortezza = 6;
326
-
327
-typedef uint8 MACAlgorithm;
328
-const MACAlgorithm mac_algorithm_null = 0;
329
-const MACAlgorithm mac_algorithm_md5 = 1;
330
-const MACAlgorithm mac_algorithm_sha = 2;
331
-
332
-typedef struct _CipherSpec{
333
-  BulkCipherAlgorithm bulk_cipher_algorithm;
334
-  MACAlgorithm mac_algorithm;
335
-  CipherType cipher_type;
336
-  IsExportable is_exportable;
337
-  uint8 hash_size;
338
-  uint8 key_material;
339
-  uint8 IV_size;
340
-} CipherSpec;
341
-
342
-

Loading…
Peruuta
Tallenna