@@ -375,4 +375,323 @@ - (void)testSessionInitializationAndRatcheting {
375
375
376
376
}
377
377
378
+ - (void )testOutOfOrderReceives {
379
+
380
+ Byte aliceIdentityPrivateKey [] = {(Byte) 0x58 , (Byte) 0x20 , (Byte) 0xD9 , (Byte) 0x2B ,
381
+ (Byte) 0xBF , (Byte) 0x3E , (Byte) 0x74 , (Byte) 0x80 ,
382
+ (Byte) 0x68 , (Byte) 0x01 , (Byte) 0x94 , (Byte) 0x90 ,
383
+ (Byte) 0xC3 , (Byte) 0xAA , (Byte) 0x94 , (Byte) 0x50 ,
384
+ (Byte) 0x21 , (Byte) 0xFA , (Byte) 0xA6 , (Byte) 0xD2 ,
385
+ (Byte) 0x43 , (Byte) 0xE4 , (Byte) 0x86 , (Byte) 0x49 ,
386
+ (Byte) 0xF6 , (Byte) 0x6B , (Byte) 0xD6 , (Byte) 0xA4 ,
387
+ (Byte) 0x45 , (Byte) 0x99 , (Byte) 0x17 , (Byte) 0x63 };
388
+ NSData *aliceIdentityPrivateKeyData = [NSData dataWithBytes: aliceIdentityPrivateKey length: 32 ];
389
+
390
+ Byte aliceIdentityPublicKey [] = {(Byte) 0x05 , (Byte) 0x6F , (Byte) 0xEC , (Byte) 0xDE ,
391
+ (Byte) 0xE2 , (Byte) 0x7F , (Byte) 0x67 , (Byte) 0x36 ,
392
+ (Byte) 0xA7 , (Byte) 0xC6 , (Byte) 0xA2 , (Byte) 0x77 ,
393
+ (Byte) 0x9C , (Byte) 0x5A , (Byte) 0xDC , (Byte) 0x26 ,
394
+ (Byte) 0x35 , (Byte) 0x22 , (Byte) 0x2A , (Byte) 0xBB ,
395
+ (Byte) 0x26 , (Byte) 0x01 , (Byte) 0xCB , (Byte) 0x93 ,
396
+ (Byte) 0x7B , (Byte) 0xA9 , (Byte) 0x0F , (Byte) 0xD8 ,
397
+ (Byte) 0x6E , (Byte) 0x56 , (Byte) 0x2C , (Byte) 0x76 ,
398
+ (Byte) 0x1C };
399
+ NSData *aliceIdentityPublicKeyData = [NSData dataWithBytes: aliceIdentityPublicKey length: 33 ];
400
+
401
+ Byte aliceBasePublicKey [] = {(Byte) 0x05 , (Byte) 0x7B , (Byte) 0xB2 , (Byte) 0x6A ,
402
+ (Byte) 0xAF , (Byte) 0x25 , (Byte) 0x3C , (Byte) 0x7C ,
403
+ (Byte) 0x2F , (Byte) 0xFB , (Byte) 0x99 , (Byte) 0x42 ,
404
+ (Byte) 0xED , (Byte) 0x5F , (Byte) 0xDA , (Byte) 0x93 ,
405
+ (Byte) 0x77 , (Byte) 0xF5 , (Byte) 0xD2 , (Byte) 0x3E ,
406
+ (Byte) 0x25 , (Byte) 0x95 , (Byte) 0x67 , (Byte) 0x5D ,
407
+ (Byte) 0x62 , (Byte) 0x14 , (Byte) 0xBB , (Byte) 0x3B ,
408
+ (Byte) 0x40 , (Byte) 0xC7 , (Byte) 0xBE , (Byte) 0xAC ,
409
+ (Byte) 0x56 };
410
+ NSData *aliceBasePublicKeyData = [NSData dataWithBytes: aliceBasePublicKey length: 33 ];
411
+
412
+ Byte aliceBasePrivateKey [] = {(Byte) 0x28 , (Byte) 0xD3 , (Byte) 0x04 , (Byte) 0xA2 ,
413
+ (Byte) 0xEB , (Byte) 0x00 , (Byte) 0xFB , (Byte) 0x63 ,
414
+ (Byte) 0xF8 , (Byte) 0x5E , (Byte) 0x6D , (Byte) 0x4C ,
415
+ (Byte) 0xEF , (Byte) 0xC6 , (Byte) 0xBF , (Byte) 0x13 ,
416
+ (Byte) 0x1B , (Byte) 0x5E , (Byte) 0xE5 , (Byte) 0x62 ,
417
+ (Byte) 0xB4 , (Byte) 0x6B , (Byte) 0xD5 , (Byte) 0x2C ,
418
+ (Byte) 0xCB , (Byte) 0x52 , (Byte) 0x8A , (Byte) 0x84 ,
419
+ (Byte) 0x61 , (Byte) 0xDD , (Byte) 0xC3 , (Byte) 0x65 };
420
+ NSData *aliceBasePrivateKeyData = [NSData dataWithBytes: aliceBasePrivateKey length: 32 ];
421
+
422
+ Byte bobIdentityPublicKey [] = {(Byte) 0x05 , (Byte) 0x01 , (Byte) 0x6A , (Byte) 0x60 ,
423
+ (Byte) 0xFC , (Byte) 0xCF , (Byte) 0x33 , (Byte) 0xB6 ,
424
+ (Byte) 0xF0 , (Byte) 0x9A , (Byte) 0x1E , (Byte) 0x9B ,
425
+ (Byte) 0x54 , (Byte) 0x77 , (Byte) 0x78 , (Byte) 0x42 ,
426
+ (Byte) 0xDD , (Byte) 0xE6 , (Byte) 0xC4 , (Byte) 0xF6 ,
427
+ (Byte) 0x30 , (Byte) 0xAE , (Byte) 0x35 , (Byte) 0x95 ,
428
+ (Byte) 0x67 , (Byte) 0xB3 , (Byte) 0x74 , (Byte) 0x20 ,
429
+ (Byte) 0xCF , (Byte) 0x2D , (Byte) 0x93 , (Byte) 0xF1 ,
430
+ (Byte) 0x45 };
431
+ NSData *bobIdentityPublicKeyData = [NSData dataWithBytes: bobIdentityPublicKey length: 33 ];
432
+
433
+ Byte bobIdentityPrivateKey [] = {(Byte) 0xC8 , (Byte) 0xF3 , (Byte) 0xA6 , (Byte) 0x39 ,
434
+ (Byte) 0x34 , (Byte) 0xCE , (Byte) 0xDE , (Byte) 0xEE ,
435
+ (Byte) 0x37 , (Byte) 0x07 , (Byte) 0xFF , (Byte) 0x79 ,
436
+ (Byte) 0x71 , (Byte) 0x05 , (Byte) 0x0D , (Byte) 0x58 ,
437
+ (Byte) 0x3B , (Byte) 0x63 , (Byte) 0x7D , (Byte) 0xD2 ,
438
+ (Byte) 0x21 , (Byte) 0x15 , (Byte) 0xE3 , (Byte) 0xFD ,
439
+ (Byte) 0x2B , (Byte) 0x1D , (Byte) 0x41 , (Byte) 0x22 ,
440
+ (Byte) 0x2C , (Byte) 0x29 , (Byte) 0x24 , (Byte) 0x65 };
441
+ NSData *bobIdentityPrivateKeyData = [NSData dataWithBytes: bobIdentityPrivateKey length: 32 ];
442
+
443
+ Byte bobBasePrivateKey [] = {(Byte) 0x70 , (Byte) 0xCC , (Byte) 0x77 , (Byte) 0x0A ,
444
+ (Byte) 0x82 , (Byte) 0x74 , (Byte) 0x70 , (Byte) 0x99 ,
445
+ (Byte) 0xB7 , (Byte) 0xCC , (Byte) 0x05 , (Byte) 0xCC ,
446
+ (Byte) 0x69 , (Byte) 0x73 , (Byte) 0x58 , (Byte) 0x78 ,
447
+ (Byte) 0x41 , (Byte) 0x3E , (Byte) 0xCF , (Byte) 0xEE ,
448
+ (Byte) 0xFE , (Byte) 0x85 , (Byte) 0xB5 , (Byte) 0xF7 ,
449
+ (Byte) 0x14 , (Byte) 0xFF , (Byte) 0x85 , (Byte) 0x36 ,
450
+ (Byte) 0x8C , (Byte) 0x98 , (Byte) 0x70 , (Byte) 0x52 };
451
+ NSData *bobBasePrivateKeyData = [NSData dataWithBytes: bobBasePrivateKey length: 32 ];
452
+
453
+ Byte bobBasePublicKey [] = {(Byte) 0x05 , (Byte) 0x18 , (Byte) 0x3A , (Byte) 0x6E ,
454
+ (Byte) 0xC2 , (Byte) 0xC7 , (Byte) 0x4A , (Byte) 0x21 ,
455
+ (Byte) 0xF3 , (Byte) 0xDE , (Byte) 0xB3 , (Byte) 0x70 ,
456
+ (Byte) 0x4C , (Byte) 0x3D , (Byte) 0x32 , (Byte) 0x45 ,
457
+ (Byte) 0xE0 , (Byte) 0xA5 , (Byte) 0xD5 , (Byte) 0x5F ,
458
+ (Byte) 0xDC , (Byte) 0xC9 , (Byte) 0x9A , (Byte) 0x26 ,
459
+ (Byte) 0x9D , (Byte) 0x64 , (Byte) 0x68 , (Byte) 0xA6 ,
460
+ (Byte) 0x7C , (Byte) 0xAE , (Byte) 0xEF , (Byte) 0x59 ,
461
+ (Byte) 0x12 };
462
+ NSData *bobBasePublicKeyData = [NSData dataWithBytes: bobBasePublicKey length: 33 ];
463
+
464
+ Byte bobPreKeyPrivateKey [] = {(Byte) 0x78 , (Byte) 0x0D , (Byte) 0x5D , (Byte) 0x26 ,
465
+ (Byte) 0xF7 , (Byte) 0x6A , (Byte) 0x24 , (Byte) 0xAD ,
466
+ (Byte) 0x65 , (Byte) 0x9C , (Byte) 0xF5 , (Byte) 0xCE ,
467
+ (Byte) 0xD5 , (Byte) 0x2B , (Byte) 0x0E , (Byte) 0x5C ,
468
+ (Byte) 0xEA , (Byte) 0x3D , (Byte) 0x42 , (Byte) 0xA2 ,
469
+ (Byte) 0x05 , (Byte) 0x40 , (Byte) 0xE0 , (Byte) 0xD8 ,
470
+ (Byte) 0x45 , (Byte) 0xDF , (Byte) 0xA2 , (Byte) 0xF0 ,
471
+ (Byte) 0x78 , (Byte) 0x1E , (Byte) 0xBA , (Byte) 0x42 };
472
+ NSData *bobPreKeyPrivateKeyData = [NSData dataWithBytes: bobPreKeyPrivateKey length: 32 ];
473
+
474
+
475
+ Byte bobPreKeyPublicKey [] = {(Byte) 0x05 , (Byte) 0x52 , (Byte) 0x02 , (Byte) 0xA7 ,
476
+ (Byte) 0xDE , (Byte) 0x5D , (Byte) 0x6C , (Byte) 0x23 ,
477
+ (Byte) 0x87 , (Byte) 0x6D , (Byte) 0x43 , (Byte) 0x24 ,
478
+ (Byte) 0x3D , (Byte) 0x75 , (Byte) 0x68 , (Byte) 0xAE ,
479
+ (Byte) 0x27 , (Byte) 0x3B , (Byte) 0x27 , (Byte) 0x76 ,
480
+ (Byte) 0x4B , (Byte) 0x01 , (Byte) 0xCE , (Byte) 0x15 ,
481
+ (Byte) 0xDF , (Byte) 0x51 , (Byte) 0x38 , (Byte) 0xA5 ,
482
+ (Byte) 0xFC , (Byte) 0xD9 , (Byte) 0xB6 , (Byte) 0xC8 ,
483
+ (Byte) 0x44 };
484
+ NSData *bobPreKeyPublicKeyData = [NSData dataWithBytes: bobPreKeyPublicKey length: 33 ];
485
+
486
+ Byte aliceSendingRatchetPrivate [] = {(Byte) 0x98 , (Byte) 0x04 , (Byte) 0x0B , (Byte) 0xAE ,
487
+ (Byte) 0x6B , (Byte) 0x3D , (Byte) 0x02 , (Byte) 0x9C ,
488
+ (Byte) 0xF1 , (Byte) 0x25 , (Byte) 0xDC , (Byte) 0x8E ,
489
+ (Byte) 0xD8 , (Byte) 0x07 , (Byte) 0xCE , (Byte) 0x33 ,
490
+ (Byte) 0xFC , (Byte) 0xE0 , (Byte) 0x07 , (Byte) 0xD8 ,
491
+ (Byte) 0x2F , (Byte) 0x67 , (Byte) 0x6D , (Byte) 0x7B ,
492
+ (Byte) 0xC7 , (Byte) 0x1A , (Byte) 0x5B , (Byte) 0x91 ,
493
+ (Byte) 0x3B , (Byte) 0x60 , (Byte) 0x3B , (Byte) 0x67 };
494
+ NSData *aliceSendingRatchetPrivateData = [NSData dataWithBytes: aliceSendingRatchetPrivate length: 32 ];
495
+
496
+ Byte aliceSendingRatchetPublic [] = {(Byte) 0x05 , (Byte) 0xB6 , (Byte) 0x2A , (Byte) 0xE0 ,
497
+ (Byte) 0x25 , (Byte) 0xB8 , (Byte) 0xFF , (Byte) 0xEE ,
498
+ (Byte) 0x3A , (Byte) 0xEB , (Byte) 0x01 , (Byte) 0x1B ,
499
+ (Byte) 0xF7 , (Byte) 0x78 , (Byte) 0xE6 , (Byte) 0x26 ,
500
+ (Byte) 0x22 , (Byte) 0x56 , (Byte) 0x17 , (Byte) 0x30 ,
501
+ (Byte) 0x7A , (Byte) 0x95 , (Byte) 0x87 , (Byte) 0x91 ,
502
+ (Byte) 0x31 , (Byte) 0xD9 , (Byte) 0x9D , (Byte) 0x27 ,
503
+ (Byte) 0x49 , (Byte) 0x06 , (Byte) 0xEE , (Byte) 0x57 ,
504
+ (Byte) 0x6A };
505
+ NSData *aliceSendingRatchetPublicData = [NSData dataWithBytes: aliceSendingRatchetPublic length: 33 ];
506
+
507
+ Byte aliceRootKey [] = {(Byte) 0xC3 , (Byte) 0x5A , (Byte) 0xF1 , (Byte) 0x81 ,
508
+ (Byte) 0xB0 , (Byte) 0xBF , (Byte) 0xEA , (Byte) 0xB5 ,
509
+ (Byte) 0xD9 , (Byte) 0x71 , (Byte) 0x12 , (Byte) 0x20 ,
510
+ (Byte) 0xC1 , (Byte) 0x60 , (Byte) 0xD6 , (Byte) 0x43 ,
511
+ (Byte) 0xF6 , (Byte) 0xE8 , (Byte) 0x1C , (Byte) 0x00 ,
512
+ (Byte) 0x11 , (Byte) 0xBF , (Byte) 0xA1 , (Byte) 0xAA ,
513
+ (Byte) 0x16 , (Byte) 0xAE , (Byte) 0xF3 , (Byte) 0x6A ,
514
+ (Byte) 0x91 , (Byte) 0xCD , (Byte) 0x1A , (Byte) 0x9B };
515
+ NSData *aliceRootKeyData = [NSData dataWithBytes: aliceRootKey length: 32 ];
516
+
517
+ Byte aliceSendingChainKey [] = {(Byte) 0x8A , (Byte) 0xA2 , (Byte) 0x05 , (Byte) 0xEA ,
518
+ (Byte) 0x17 , (Byte) 0x00 , (Byte) 0xC0 , (Byte) 0x85 ,
519
+ (Byte) 0xB6 , (Byte) 0x43 , (Byte) 0xE9 , (Byte) 0x68 ,
520
+ (Byte) 0x4F , (Byte) 0x6A , (Byte) 0x53 , (Byte) 0x74 ,
521
+ (Byte) 0x88 , (Byte) 0xBD , (Byte) 0x9F , (Byte) 0x3E ,
522
+ (Byte) 0xA0 , (Byte) 0x1D , (Byte) 0x00 , (Byte) 0xF9 ,
523
+ (Byte) 0x58 , (Byte) 0x55 , (Byte) 0xE1 , (Byte) 0x8F ,
524
+ (Byte) 0xAB , (Byte) 0x9F , (Byte) 0xBE , (Byte) 0x51 };
525
+ NSData *aliceSendingChainKeyData = [NSData dataWithBytes: aliceSendingChainKey length: 32 ];
526
+
527
+ Byte aliceSendingCipherKey [] = {(Byte) 0xDD , (Byte) 0x61 , (Byte) 0x0E , (Byte) 0xEE ,
528
+ (Byte) 0x8F , (Byte) 0x33 , (Byte) 0x02 , (Byte) 0x25 ,
529
+ (Byte) 0x63 , (Byte) 0x48 , (Byte) 0x8A , (Byte) 0xED ,
530
+ (Byte) 0xE0 , (Byte) 0x94 , (Byte) 0xAB , (Byte) 0x6C ,
531
+ (Byte) 0x72 , (Byte) 0xAF , (Byte) 0x39 , (Byte) 0x69 ,
532
+ (Byte) 0xF7 , (Byte) 0xCF , (Byte) 0xA6 , (Byte) 0x5F ,
533
+ (Byte) 0x09 , (Byte) 0x5F , (Byte) 0xEE , (Byte) 0x59 ,
534
+ (Byte) 0xC4 , (Byte) 0xEA , (Byte) 0xE7 , (Byte) 0x3D };
535
+ NSData *aliceSendingCipherKeyData = [NSData dataWithBytes: aliceSendingCipherKey length: 32 ];
536
+
537
+ Byte aliceSendingIVKey [] = {(Byte) 0xF3 , (Byte) 0xF0 , (Byte) 0x25 , (Byte) 0x58 ,
538
+ (Byte) 0x43 , (Byte) 0xDA , (Byte) 0x3A , (Byte) 0x81 ,
539
+ (Byte) 0x6C , (Byte) 0x78 , (Byte) 0xD7 , (Byte) 0x65 ,
540
+ (Byte) 0xCE , (Byte) 0xBD , (Byte) 0xBA , (Byte) 0x0B };
541
+ NSData *aliceSendingIVKeyData = [NSData dataWithBytes: aliceSendingIVKey length: 16 ];
542
+
543
+ Byte aliceSendingMacKey [] = {(Byte) 0xAC , (Byte) 0xC6 , (Byte) 0x30 , (Byte) 0x4D ,
544
+ (Byte) 0xC0 , (Byte) 0xCC , (Byte) 0x20 , (Byte) 0xE5 ,
545
+ (Byte) 0x8F , (Byte) 0xCE , (Byte) 0xA4 , (Byte) 0x60 ,
546
+ (Byte) 0xDA , (Byte) 0xC1 , (Byte) 0x67 , (Byte) 0x55 ,
547
+ (Byte) 0x4E , (Byte) 0x89 , (Byte) 0xA9 , (Byte) 0xB2 ,
548
+ (Byte) 0x5E , (Byte) 0xBD , (Byte) 0xA5 , (Byte) 0xA3 ,
549
+ (Byte) 0xBA , (Byte) 0xBE , (Byte) 0x15 , (Byte) 0xCF ,
550
+ (Byte) 0x8B , (Byte) 0x71 , (Byte) 0xE7 , (Byte) 0x9A };
551
+ NSData *aliceSendingMacKeyData = [NSData dataWithBytes: aliceSendingMacKey length: 32 ];
552
+
553
+ Byte bobRootKey [] = {(Byte) 0x89 , (Byte) 0xF9 , (Byte) 0x57 , (Byte) 0x60 ,
554
+ (Byte) 0x37 , (Byte) 0xC1 , (Byte) 0x07 , (Byte) 0x6C ,
555
+ (Byte) 0x19 , (Byte) 0x22 , (Byte) 0x11 , (Byte) 0xFB ,
556
+ (Byte) 0x22 , (Byte) 0x61 , (Byte) 0xE4 , (Byte) 0xC4 ,
557
+ (Byte) 0x44 , (Byte) 0x58 , (Byte) 0x51 , (Byte) 0x44 ,
558
+ (Byte) 0xC2 , (Byte) 0x8C , (Byte) 0x1C , (Byte) 0x6E ,
559
+ (Byte) 0x7C , (Byte) 0x48 , (Byte) 0xB6 , (Byte) 0x91 ,
560
+ (Byte) 0x26 , (Byte) 0x9B , (Byte) 0xF2 , (Byte) 0xE6 };
561
+ NSData *bobRootKeyData = [NSData dataWithBytes: bobRootKey length: 32 ];
562
+
563
+ Byte aliceSessionRecordRootKey [] = {(Byte) 0xC3 , (Byte) 0x5A , (Byte) 0xF1 , (Byte) 0x81 ,
564
+ (Byte) 0xB0 , (Byte) 0xBF , (Byte) 0xEA , (Byte) 0xB5 ,
565
+ (Byte) 0xD9 , (Byte) 0x71 , (Byte) 0x12 , (Byte) 0x20 ,
566
+ (Byte) 0xC1 , (Byte) 0x60 , (Byte) 0xD6 , (Byte) 0x43 ,
567
+ (Byte) 0xF6 , (Byte) 0xE8 , (Byte) 0x1C , (Byte) 0x00 ,
568
+ (Byte) 0x11 , (Byte) 0xBF , (Byte) 0xA1 , (Byte) 0xAA ,
569
+ (Byte) 0x16 , (Byte) 0xAE , (Byte) 0xF3 , (Byte) 0x6A ,
570
+ (Byte) 0x91 , (Byte) 0xCD , (Byte) 0x1A , (Byte) 0x9B };
571
+ NSData *aliceSessionRecordRootKeyData = [NSData dataWithBytes: aliceSessionRecordRootKey length: 32 ];
572
+
573
+ Byte bobSessionRecordRootKey [] = {(Byte) 0x89 , (Byte) 0xF9 , (Byte) 0x57 , (Byte) 0x60 ,
574
+ (Byte) 0x37 , (Byte) 0xC1 , (Byte) 0x07 , (Byte) 0x6C ,
575
+ (Byte) 0x19 , (Byte) 0x22 , (Byte) 0x11 , (Byte) 0xFB ,
576
+ (Byte) 0x22 , (Byte) 0x61 , (Byte) 0xE4 , (Byte) 0xC4 ,
577
+ (Byte) 0x44 , (Byte) 0x58 , (Byte) 0x51 , (Byte) 0x44 ,
578
+ (Byte) 0xC2 , (Byte) 0x8C , (Byte) 0x1C , (Byte) 0x6E ,
579
+ (Byte) 0x7C , (Byte) 0x48 , (Byte) 0xB6 , (Byte) 0x91 ,
580
+ (Byte) 0x26 , (Byte) 0x9B , (Byte) 0xF2 , (Byte) 0xE6 };
581
+ NSData *bobSessionRecordRootKeyData = [NSData dataWithBytes: bobSessionRecordRootKey length: 32 ];
582
+
583
+ Byte alicePlaintext [] = {(Byte) 0x54 , (Byte) 0x68 , (Byte) 0x69 , (Byte) 0x73 ,
584
+ (Byte) 0x20 , (Byte) 0x69 , (Byte) 0x73 , (Byte) 0x20 ,
585
+ (Byte) 0x61 , (Byte) 0x20 , (Byte) 0x70 , (Byte) 0x6C ,
586
+ (Byte) 0x61 , (Byte) 0x69 , (Byte) 0x6E , (Byte) 0x74 ,
587
+ (Byte) 0x65 , (Byte) 0x78 , (Byte) 0x74 , (Byte) 0x20 ,
588
+ (Byte) 0x6D , (Byte) 0x65 , (Byte) 0x73 , (Byte) 0x73 ,
589
+ (Byte) 0x61 , (Byte) 0x67 , (Byte) 0x65 , (Byte) 0x2E };
590
+ NSData *alicePlaintextData = [NSData dataWithBytes: alicePlaintext length: 28 ];
591
+
592
+ Byte AliceSerializedWhisperMessage [] = {(Byte) 0x33 , (Byte) 0x0A , (Byte) 0x21 , (Byte) 0x05 ,
593
+ (Byte) 0xB6 , (Byte) 0x2A , (Byte) 0xE0 , (Byte) 0x25 ,
594
+ (Byte) 0xB8 , (Byte) 0xFF , (Byte) 0xEE , (Byte) 0x3A ,
595
+ (Byte) 0xEB , (Byte) 0x01 , (Byte) 0x1B , (Byte) 0xF7 ,
596
+ (Byte) 0x78 , (Byte) 0xE6 , (Byte) 0x26 , (Byte) 0x22 ,
597
+ (Byte) 0x56 , (Byte) 0x17 , (Byte) 0x30 , (Byte) 0x7A ,
598
+ (Byte) 0x95 , (Byte) 0x87 , (Byte) 0x91 , (Byte) 0x31 ,
599
+ (Byte) 0xD9 , (Byte) 0x9D , (Byte) 0x27 , (Byte) 0x49 ,
600
+ (Byte) 0x06 , (Byte) 0xEE , (Byte) 0x57 , (Byte) 0x6A ,
601
+ (Byte) 0x10 , (Byte) 0x00 , (Byte) 0x18 , (Byte) 0x00 ,
602
+ (Byte) 0x22 , (Byte) 0x20 , (Byte) 0x9E , (Byte) 0xF2 ,
603
+ (Byte) 0xD0 , (Byte) 0xE1 , (Byte) 0x30 , (Byte) 0x4C ,
604
+ (Byte) 0x01 , (Byte) 0xE0 , (Byte) 0x68 , (Byte) 0x7B ,
605
+ (Byte) 0x44 , (Byte) 0x5A , (Byte) 0x27 , (Byte) 0x64 ,
606
+ (Byte) 0x79 , (Byte) 0x51 , (Byte) 0xD4 , (Byte) 0xC7 ,
607
+ (Byte) 0x0B , (Byte) 0xF3 , (Byte) 0xD3 , (Byte) 0xAC ,
608
+ (Byte) 0x23 , (Byte) 0xA5 , (Byte) 0x8D , (Byte) 0xF7 ,
609
+ (Byte) 0x22 , (Byte) 0xDC , (Byte) 0x22 , (Byte) 0x76 ,
610
+ (Byte) 0xC3 , (Byte) 0xA6 , (Byte) 0x96 , (Byte) 0x06 ,
611
+ (Byte) 0xAB , (Byte) 0xBE , (Byte) 0x2E , (Byte) 0x31 ,
612
+ (Byte) 0x63 , (Byte) 0x88 };
613
+ NSData *AliceSerializedWhisperMessageData = [NSData dataWithBytes: AliceSerializedWhisperMessage length: 82 ];
614
+
615
+ Byte aliceCipherText [] = {(Byte) 0x9E , (Byte) 0xF2 , (Byte) 0xD0 , (Byte) 0xE1 ,
616
+ (Byte) 0x30 , (Byte) 0x4C , (Byte) 0x01 , (Byte) 0xE0 ,
617
+ (Byte) 0x68 , (Byte) 0x7B , (Byte) 0x44 , (Byte) 0x5A ,
618
+ (Byte) 0x27 , (Byte) 0x64 , (Byte) 0x79 , (Byte) 0x51 ,
619
+ (Byte) 0xD4 , (Byte) 0xC7 , (Byte) 0x0B , (Byte) 0xF3 ,
620
+ (Byte) 0xD3 , (Byte) 0xAC , (Byte) 0x23 , (Byte) 0xA5 ,
621
+ (Byte) 0x8D , (Byte) 0xF7 , (Byte) 0x22 , (Byte) 0xDC ,
622
+ (Byte) 0x22 , (Byte) 0x76 , (Byte) 0xC3 , (Byte) 0xA6 };
623
+ NSData *aliceCipherTextData = [NSData dataWithBytes: aliceCipherText length: 32 ];
624
+
625
+
626
+ ECKeyPair *aliceIdentityKey = [ECKeyPair keyPairWithPrivateKey: aliceIdentityPrivateKeyData publicKey: aliceIdentityPublicKeyData];
627
+
628
+ ECKeyPair *bobIdentityKey = [ECKeyPair keyPairWithPrivateKey: bobIdentityPrivateKeyData publicKey: bobIdentityPublicKeyData];
629
+
630
+ ECKeyPair *aliceBaseKey = [ECKeyPair keyPairWithPrivateKey: aliceBasePrivateKeyData publicKey: aliceBasePublicKeyData];
631
+
632
+ ECKeyPair *bobBaseKey = [ECKeyPair keyPairWithPrivateKey: bobBasePrivateKeyData publicKey: bobBasePublicKeyData];
633
+
634
+ ECKeyPair *aliceSendingRatchet = [ECKeyPair keyPairWithPrivateKey: aliceSendingRatchetPrivateData publicKey: aliceSendingRatchetPublicData];
635
+
636
+ // ---
637
+
638
+ AxolotlInMemoryStore *aliceStore = [AxolotlInMemoryStore new ];
639
+ AxolotlInMemoryStore *bobStore = [AxolotlInMemoryStore new ];
640
+
641
+ SessionRecord *aliceSessionRecord = [SessionRecord new ];
642
+ SessionRecord *bobSessionRecord = [SessionRecord new ];
643
+
644
+ AliceAxolotlParameters *aliceAxolotlParams = [[AliceAxolotlParameters alloc ] initWithIdentityKey: aliceIdentityKey theirIdentityKey: bobIdentityKey.publicKey ourBaseKey: aliceBaseKey theirSignedPreKey: bobBaseKey.publicKey theirOneTimePreKey: nil theirRatchetKey: bobBaseKey.publicKey];
645
+
646
+ BobAxolotlParameters *bobAxolotlParams = [[BobAxolotlParameters alloc ] initWithMyIdentityKeyPair: bobIdentityKey theirIdentityKey: aliceIdentityKey.publicKey ourSignedPrekey: bobBaseKey ourRatchetKey: bobBaseKey ourOneTimePrekey: nil theirBaseKey: aliceBaseKey.publicKey];
647
+
648
+ [RatchetingSession initializeSession: aliceSessionRecord.sessionState sessionVersion: 3 AliceParameters: aliceAxolotlParams senderRatchet: aliceSendingRatchet];
649
+
650
+ [RatchetingSession initializeSession: bobSessionRecord.sessionState sessionVersion: 3 BobParameters: bobAxolotlParams];
651
+
652
+ NSString *aliceIdentifier = @" +483294823482" ;
653
+ NSString *bobIdentifier = @" +389424728942" ;
654
+
655
+ // Logging Alice's Session initialization and first message encryption
656
+ XCTAssert ([[@" This is a plaintext message." dataUsingEncoding: NSUTF8StringEncoding] isEqualToData: alicePlaintextData], @" Encoding is not correct" );
657
+ XCTAssert ([aliceSessionRecord.sessionState.rootKey.keyData isEqualToData: aliceSessionRecordRootKeyData]);
658
+ XCTAssert ([aliceSessionRecord.sessionState.senderChainKey.key isEqualToData: aliceSendingChainKeyData]);
659
+ XCTAssert ([aliceSendingCipherKeyData isEqualToData: aliceSessionRecord.sessionState.senderChainKey.messageKeys.cipherKey]);
660
+ XCTAssert ([aliceSendingIVKeyData isEqualToData: aliceSessionRecord.sessionState.senderChainKey.messageKeys.iv]);
661
+ XCTAssert ([aliceSendingMacKeyData isEqualToData: aliceSessionRecord.sessionState.senderChainKey.messageKeys.macKey]);
662
+
663
+ [aliceStore storeSession: bobIdentifier deviceId: 1 session: aliceSessionRecord];
664
+ SessionCipher *aliceSessionCipher = [[SessionCipher alloc ] initWithAxolotlStore: aliceStore recipientId: bobIdentifier deviceId: 1 ];
665
+
666
+ WhisperMessage *message = [aliceSessionCipher encryptMessage: alicePlaintextData];
667
+ XCTAssert ([aliceCipherTextData isEqualToData: message.cipherText]);
668
+
669
+ // Logging's Bob's Session initialization and first message decryption
670
+
671
+ XCTAssert ([bobRootKeyData isEqualToData: bobSessionRecord.sessionState.rootKey.keyData]);
672
+
673
+ [bobStore storeSession: aliceIdentifier deviceId: 1 session: bobSessionRecord];
674
+
675
+ SessionCipher *bobSessionCipher = [[SessionCipher alloc ] initWithAxolotlStore: bobStore recipientId: aliceIdentifier deviceId: 1 ];
676
+
677
+ NSData *plainData = [bobSessionCipher decrypt: message];
678
+
679
+ XCTAssert ([plainData isEqualToData: alicePlaintextData]);
680
+
681
+
682
+ NSMutableArray *plainTexts = [NSMutableArray new ];
683
+ NSMutableArray *cipherMessages = [NSMutableArray new ];
684
+
685
+ for (int i = 0 ; i < 30 ; i++) {
686
+ NSData *message = [[NSString stringWithFormat: @" Message: %i " , i] dataUsingEncoding: NSUTF8StringEncoding];
687
+ [plainTexts addObject: message];
688
+ [cipherMessages addObject: [bobSessionCipher encryptMessage: message]];
689
+ }
690
+
691
+ for (NSUInteger i = plainTexts.count -1 ; i > 0 ; i--) {
692
+ XCTAssert ([[aliceSessionCipher decrypt: [cipherMessages objectAtIndex: i]] isEqualToData: [plainTexts objectAtIndex: i]]);
693
+ }
694
+
695
+ }
696
+
378
697
@end
0 commit comments