mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			46 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Objective-C
		
	
			
		
		
	
	
			46 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Objective-C
		
	
#import <XCTest/XCTest.h>
 | 
						|
#import "TestUtil.h"
 | 
						|
 | 
						|
@interface EC25AgreerTest : XCTestCase
 | 
						|
@end
 | 
						|
 | 
						|
@implementation EC25AgreerTest
 | 
						|
 | 
						|
-(void) testKeyExchangeMatchesPeerButNotOthers {
 | 
						|
    EC25KeyAgreementProtocol* protocol = [EC25KeyAgreementProtocol protocol];
 | 
						|
    
 | 
						|
    id<KeyAgreementParticipant> ec1 = [protocol generateParticipantWithNewKeys];
 | 
						|
    id<KeyAgreementParticipant> ec2 = [protocol generateParticipantWithNewKeys];
 | 
						|
    id<KeyAgreementParticipant> ec3 = [protocol generateParticipantWithNewKeys];
 | 
						|
    
 | 
						|
    NSData* pub_1 = ec1.getPublicKeyData;
 | 
						|
    NSData* pub_2 = ec2.getPublicKeyData;
 | 
						|
    
 | 
						|
    NSData* shared_1 = [ec1 calculateKeyAgreementAgainstRemotePublicKey:pub_2];
 | 
						|
    NSData* shared_2 = [ec2 calculateKeyAgreementAgainstRemotePublicKey:pub_1];
 | 
						|
    
 | 
						|
    test([shared_1 isEqualToData:shared_2]);
 | 
						|
    
 | 
						|
    NSData* shared_3 = [ec3 calculateKeyAgreementAgainstRemotePublicKey:pub_1];
 | 
						|
    
 | 
						|
    test(![shared_3 isEqualToData:shared_1]);
 | 
						|
}
 | 
						|
 | 
						|
-(void) testKeyExchangeSucceedsConsistently {
 | 
						|
    EC25KeyAgreementProtocol* protocol = [EC25KeyAgreementProtocol protocol];
 | 
						|
    for (int i = 0; i < 1000; i++) {
 | 
						|
        id<KeyAgreementParticipant> ec1 = [protocol generateParticipantWithNewKeys];
 | 
						|
        id<KeyAgreementParticipant> ec2 = [protocol generateParticipantWithNewKeys];
 | 
						|
 | 
						|
        NSData* pub_1 = ec1.getPublicKeyData;
 | 
						|
        NSData* pub_2 = ec2.getPublicKeyData;
 | 
						|
    
 | 
						|
        NSData* shared_1 = [ec1 calculateKeyAgreementAgainstRemotePublicKey:pub_2];
 | 
						|
        NSData* shared_2 = [ec2 calculateKeyAgreementAgainstRemotePublicKey:pub_1];
 | 
						|
    
 | 
						|
        test([shared_1 isEqualToData:shared_2]);
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
@end
 |