src/protocols/sametime/meanwhile/session.c

changeset 12261
672e2d392a73
parent 11943
81ee4bc13c28
child 12311
ee0f62f4fcd4
equal deleted inserted replaced
12260:4b2e29383b0e 12261:672e2d392a73
17 License along with this library; if not, write to the Free 17 License along with this library; if not, write to the Free
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 19 */
20 20
21 #include <glib.h> 21 #include <glib.h>
22 #include <gmp.h>
23 #include <string.h> 22 #include <string.h>
24 23
25 #include "mw_channel.h" 24 #include "mw_channel.h"
26 #include "mw_cipher.h" 25 #include "mw_cipher.h"
27 #include "mw_debug.h" 26 #include "mw_debug.h"
369 368
370 char iv[8]; 369 char iv[8];
371 struct mwOpaque a, b, c; 370 struct mwOpaque a, b, c;
372 struct mwPutBuffer *p; 371 struct mwPutBuffer *p;
373 372
374 mpz_t private, public; 373 struct mwMpi *private, *public;
375 mpz_t remote; 374 struct mwMpi *remote;
376 mpz_t shared; 375 struct mwMpi *shared;
377 376
378 mpz_init(private); 377 private = mwMpi_new();
379 mpz_init(public); 378 public = mwMpi_new();
380 mpz_init(remote); 379 remote = mwMpi_new();
381 mpz_init(shared); 380 shared = mwMpi_new();
382 381
383 mwIV_init(iv); 382 mwIV_init(iv);
384 383
385 mwDHRandKeypair(private, public); 384 mwMpi_randDHKeypair(private, public);
386 mwDHImportKey(remote, rkey); 385 mwMpi_import(remote, rkey);
387 mwDHCalculateShared(shared, remote, private); 386 mwMpi_calculateDHShared(shared, remote, private);
388 387
389 /* put the password in opaque a */ 388 /* put the password in opaque a */
390 p = mwPutBuffer_new(); 389 p = mwPutBuffer_new();
391 guint32_put(p, magic); 390 guint32_put(p, magic);
392 mwString_put(p, pass); 391 mwString_put(p, pass);
393 mwPutBuffer_finalize(&a, p); 392 mwPutBuffer_finalize(&a, p);
394 393
395 /* put the shared key in opaque b */ 394 /* put the shared key in opaque b */
396 mwDHExportKey(shared, &b); 395 mwMpi_export(shared, &b);
397 396
398 /* encrypt the password (a) using the shared key (b), put the result 397 /* encrypt the password (a) using the shared key (b), put the result
399 in opaque c */ 398 in opaque c */
400 mwEncrypt(b.data+(b.len-16), 16, iv, &a, &c); 399 mwEncrypt(b.data+(b.len-16), 16, iv, &a, &c);
401 400
402 /* don't need the shared key anymore, re-use opaque (b) as the 401 /* don't need the shared key anymore, re-use opaque (b) as the
403 export of the public key */ 402 export of the public key */
404 mwOpaque_clear(&b); 403 mwOpaque_clear(&b);
405 mwDHExportKey(public, &b); 404 mwMpi_export(public, &b);
406 405
407 p = mwPutBuffer_new(); 406 p = mwPutBuffer_new();
408 guint16_put(p, 0x0001); /* XXX: unknown */ 407 guint16_put(p, 0x0001); /* XXX: unknown */
409 mwOpaque_put(p, &b); 408 mwOpaque_put(p, &b);
410 mwOpaque_put(p, &c); 409 mwOpaque_put(p, &c);
412 411
413 mwOpaque_clear(&a); 412 mwOpaque_clear(&a);
414 mwOpaque_clear(&b); 413 mwOpaque_clear(&b);
415 mwOpaque_clear(&c); 414 mwOpaque_clear(&c);
416 415
417 mpz_clear(private); 416 mwMpi_free(private);
418 mpz_clear(public); 417 mwMpi_free(public);
419 mpz_clear(remote); 418 mwMpi_free(remote);
420 mpz_clear(shared); 419 mwMpi_free(shared);
421 } 420 }
422 421
423 422
424 /** handle the receipt of a handshake_ack message by sending the login 423 /** handle the receipt of a handshake_ack message by sending the login
425 message */ 424 message */

mercurial