/[rdesktop]/sourceforge.net/trunk/rdesktop/secure.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/rdesktop/secure.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 24 by matty, Sat Jan 6 03:12:10 2001 UTC revision 25 by matty, Sat Jan 6 03:47:04 2001 UTC
# Line 45  static uint8 sec_crypted_random[64]; Line 45  static uint8 sec_crypted_random[64];
45   * a client and server salt) and a global salt value used for padding.   * a client and server salt) and a global salt value used for padding.
46   * Both SHA1 and MD5 algorithms are used.   * Both SHA1 and MD5 algorithms are used.
47   */   */
48  void sec_hash_48(uint8 *out, uint8 *in, uint8 *salt1, uint8 *salt2,  void
49                   uint8 salt)  sec_hash_48(uint8 *out, uint8 *in, uint8 *salt1, uint8 *salt2, uint8 salt)
50  {  {
51          uint8 shasig[20];          uint8 shasig[20];
52          uint8 pad[4];          uint8 pad[4];
# Line 76  void sec_hash_48(uint8 *out, uint8 *in, Line 76  void sec_hash_48(uint8 *out, uint8 *in,
76   * Weaker 16-byte transformation, also using two 32-byte salts, but   * Weaker 16-byte transformation, also using two 32-byte salts, but
77   * only using a single round of MD5.   * only using a single round of MD5.
78   */   */
79  void sec_hash_16(uint8 *out, uint8 *in, uint8 *salt1, uint8 *salt2)  void
80    sec_hash_16(uint8 *out, uint8 *in, uint8 *salt1, uint8 *salt2)
81  {  {
82          MD5_CTX md5;          MD5_CTX md5;
83    
# Line 88  void sec_hash_16(uint8 *out, uint8 *in, Line 89  void sec_hash_16(uint8 *out, uint8 *in,
89  }  }
90    
91  /* Reduce key entropy from 64 to 40 bits */  /* Reduce key entropy from 64 to 40 bits */
92  static void sec_make_40bit(uint8 *key)  static void
93    sec_make_40bit(uint8 *key)
94  {  {
95          key[0] = 0xd1;          key[0] = 0xd1;
96          key[1] = 0x26;          key[1] = 0x26;
# Line 96  static void sec_make_40bit(uint8 *key) Line 98  static void sec_make_40bit(uint8 *key)
98  }  }
99    
100  /* Generate a session key and RC4 keys, given client and server randoms */  /* Generate a session key and RC4 keys, given client and server randoms */
101  static void sec_generate_keys(uint8 *client_key, uint8 *server_key,  static void
102                                int rc4_key_size)  sec_generate_keys(uint8 *client_key, uint8 *server_key, int rc4_key_size)
103  {  {
104          uint8 session_key[48];          uint8 session_key[48];
105          uint8 temp_hash[48];          uint8 temp_hash[48];
# Line 145  static void sec_generate_keys(uint8 *cli Line 147  static void sec_generate_keys(uint8 *cli
147    
148  static uint8 pad_54[40] = {  static uint8 pad_54[40] = {
149          54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54,          54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54,
150                  54, 54, 54,          54, 54, 54,
151          54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54,          54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54,
152                  54, 54, 54          54, 54, 54
153  };  };
154    
155  static uint8 pad_92[48] = {  static uint8 pad_92[48] = {
156          92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92,          92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92,
157                  92, 92, 92, 92, 92, 92, 92,          92, 92, 92, 92, 92, 92, 92,
158          92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92,          92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92,
159                  92, 92, 92, 92, 92, 92, 92          92, 92, 92, 92, 92, 92, 92
160  };  };
161    
162  /* Output a uint32 into a buffer (little-endian) */  /* Output a uint32 into a buffer (little-endian) */
163  void buf_out_uint32(uint8 *buffer, uint32 value)  void
164    buf_out_uint32(uint8 *buffer, uint32 value)
165  {  {
166          buffer[0] = (value) & 0xff;          buffer[0] = (value) & 0xff;
167          buffer[1] = (value >> 8) & 0xff;          buffer[1] = (value >> 8) & 0xff;
# Line 167  void buf_out_uint32(uint8 *buffer, uint3 Line 170  void buf_out_uint32(uint8 *buffer, uint3
170  }  }
171    
172  /* Generate a signature hash, using a combination of SHA1 and MD5 */  /* Generate a signature hash, using a combination of SHA1 and MD5 */
173  void sec_sign(uint8 *signature, uint8 *session_key, int length,  void
174                uint8 *data, int datalen)  sec_sign(uint8 *signature, uint8 *session_key, int length,
175             uint8 *data, int datalen)
176  {  {
177          uint8 shasig[20];          uint8 shasig[20];
178          uint8 md5sig[16];          uint8 md5sig[16];
# Line 195  void sec_sign(uint8 *signature, uint8 *s Line 199  void sec_sign(uint8 *signature, uint8 *s
199  }  }
200    
201  /* Update an encryption key - similar to the signing process */  /* Update an encryption key - similar to the signing process */
202  static void sec_update(uint8 *key, uint8 *update_key)  static void
203    sec_update(uint8 *key, uint8 *update_key)
204  {  {
205          uint8 shasig[20];          uint8 shasig[20];
206          SHA_CTX sha;          SHA_CTX sha;
# Line 222  static void sec_update(uint8 *key, uint8 Line 227  static void sec_update(uint8 *key, uint8
227  }  }
228    
229  /* Encrypt data using RC4 */  /* Encrypt data using RC4 */
230  static void sec_encrypt(uint8 *data, int length)  static void
231    sec_encrypt(uint8 *data, int length)
232  {  {
233          static int use_count;          static int use_count;
234    
# Line 238  static void sec_encrypt(uint8 *data, int Line 244  static void sec_encrypt(uint8 *data, int
244  }  }
245    
246  /* Decrypt data using RC4 */  /* Decrypt data using RC4 */
247  static void sec_decrypt(uint8 *data, int length)  static void
248    sec_decrypt(uint8 *data, int length)
249  {  {
250          static int use_count;          static int use_count;
251    
# Line 254  static void sec_decrypt(uint8 *data, int Line 261  static void sec_decrypt(uint8 *data, int
261  }  }
262    
263  /* Read in a NUMBER from a buffer */  /* Read in a NUMBER from a buffer */
264  static void sec_read_number(NUMBER * num, uint8 *buffer, int len)  static void
265    sec_read_number(NUMBER * num, uint8 *buffer, int len)
266  {  {
267          INT *data = num->n_part;          INT *data = num->n_part;
268          int i, j;          int i, j;
# Line 266  static void sec_read_number(NUMBER * num Line 274  static void sec_read_number(NUMBER * num
274  }  }
275    
276  /* Write a NUMBER to a buffer */  /* Write a NUMBER to a buffer */
277  static void sec_write_number(NUMBER * num, uint8 *buffer, int len)  static void
278    sec_write_number(NUMBER * num, uint8 *buffer, int len)
279  {  {
280          INT *data = num->n_part;          INT *data = num->n_part;
281          int i, j;          int i, j;
# Line 279  static void sec_write_number(NUMBER * nu Line 288  static void sec_write_number(NUMBER * nu
288  }  }
289    
290  /* Perform an RSA public key encryption operation */  /* Perform an RSA public key encryption operation */
291  static void sec_rsa_encrypt(uint8 *out, uint8 *in, int len,  static void
292                              uint8 *modulus, uint8 *exponent)  sec_rsa_encrypt(uint8 *out, uint8 *in, int len,
293                    uint8 *modulus, uint8 *exponent)
294  {  {
295          NUMBER data, key;          NUMBER data, key;
296    
# Line 296  static void sec_rsa_encrypt(uint8 *out, Line 306  static void sec_rsa_encrypt(uint8 *out,
306  }  }
307    
308  /* Initialise secure transport packet */  /* Initialise secure transport packet */
309  STREAM sec_init(uint32 flags, int maxlen)  STREAM
310    sec_init(uint32 flags, int maxlen)
311  {  {
312          int hdrlen;          int hdrlen;
313          STREAM s;          STREAM s;
# Line 309  STREAM sec_init(uint32 flags, int maxlen Line 320  STREAM sec_init(uint32 flags, int maxlen
320  }  }
321    
322  /* Transmit secure transport packet */  /* Transmit secure transport packet */
323  void sec_send(STREAM s, uint32 flags)  void
324    sec_send(STREAM s, uint32 flags)
325  {  {
326          int datalen;          int datalen;
327    
# Line 334  void sec_send(STREAM s, uint32 flags) Line 346  void sec_send(STREAM s, uint32 flags)
346  }  }
347    
348  /* Transfer the client random to the server */  /* Transfer the client random to the server */
349  static void sec_establish_key()  static void
350    sec_establish_key()
351  {  {
352          uint32 length = SEC_MODULUS_SIZE + SEC_PADDING_SIZE;          uint32 length = SEC_MODULUS_SIZE + SEC_PADDING_SIZE;
353          uint32 flags = SEC_CLIENT_RANDOM;          uint32 flags = SEC_CLIENT_RANDOM;
# Line 351  static void sec_establish_key() Line 364  static void sec_establish_key()
364  }  }
365    
366  /* Output connect initial data blob */  /* Output connect initial data blob */
367  static void sec_out_mcs_data(STREAM s)  static void
368    sec_out_mcs_data(STREAM s)
369  {  {
370          int hostlen = 2 * strlen(hostname);          int hostlen = 2 * strlen(hostname);
371    
# Line 403  static void sec_out_mcs_data(STREAM s) Line 417  static void sec_out_mcs_data(STREAM s)
417  }  }
418    
419  /* Parse a public key structure */  /* Parse a public key structure */
420  static BOOL sec_parse_public_key(STREAM s, uint8 **modulus, uint8 **exponent)  static BOOL
421    sec_parse_public_key(STREAM s, uint8 **modulus, uint8 **exponent)
422  {  {
423          uint32 magic, modulus_len;          uint32 magic, modulus_len;
424    
# Line 430  static BOOL sec_parse_public_key(STREAM Line 445  static BOOL sec_parse_public_key(STREAM
445  }  }
446    
447  /* Parse a crypto information structure */  /* Parse a crypto information structure */
448  static BOOL sec_parse_crypt_info(STREAM s, uint32 *rc4_key_size,  static BOOL
449                                   uint8 **server_random, uint8 **modulus,  sec_parse_crypt_info(STREAM s, uint32 *rc4_key_size,
450                                   uint8 **exponent)                       uint8 **server_random, uint8 **modulus, uint8 **exponent)
451  {  {
452          uint32 crypt_level, random_len, rsa_info_len;          uint32 crypt_level, random_len, rsa_info_len;
453          uint16 tag, length;          uint16 tag, length;
# Line 490  static BOOL sec_parse_crypt_info(STREAM Line 505  static BOOL sec_parse_crypt_info(STREAM
505  }  }
506    
507  /* Process crypto information blob */  /* Process crypto information blob */
508  static void sec_process_crypt_info(STREAM s)  static void
509    sec_process_crypt_info(STREAM s)
510  {  {
511          uint8 *server_random, *modulus, *exponent;          uint8 *server_random, *modulus, *exponent;
512          uint8 client_random[SEC_RANDOM_SIZE];          uint8 client_random[SEC_RANDOM_SIZE];
# Line 508  static void sec_process_crypt_info(STREA Line 524  static void sec_process_crypt_info(STREA
524  }  }
525    
526  /* Process connect response data blob */  /* Process connect response data blob */
527  static void sec_process_mcs_data(STREAM s)  static void
528    sec_process_mcs_data(STREAM s)
529  {  {
530          uint16 tag, length;          uint16 tag, length;
531          uint8 *next_tag;          uint8 *next_tag;
# Line 544  static void sec_process_mcs_data(STREAM Line 561  static void sec_process_mcs_data(STREAM
561  }  }
562    
563  /* Receive secure transport packet */  /* Receive secure transport packet */
564  STREAM sec_recv()  STREAM
565    sec_recv()
566  {  {
567          uint32 sec_flags;          uint32 sec_flags;
568          STREAM s;          STREAM s;
# Line 572  STREAM sec_recv() Line 590  STREAM sec_recv()
590  }  }
591    
592  /* Establish a secure connection */  /* Establish a secure connection */
593  BOOL sec_connect(char *server)  BOOL
594    sec_connect(char *server)
595  {  {
596          struct stream mcs_data;          struct stream mcs_data;
597    
# Line 590  BOOL sec_connect(char *server) Line 609  BOOL sec_connect(char *server)
609  }  }
610    
611  /* Disconnect a connection */  /* Disconnect a connection */
612  void sec_disconnect()  void
613    sec_disconnect()
614  {  {
615          mcs_disconnect();          mcs_disconnect();
616  }  }

Legend:
Removed from v.24  
changed lines
  Added in v.25

  ViewVC Help
Powered by ViewVC 1.1.26