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.
		
		
		
		
		
			
		
			
				
	
	
		
			65 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Objective-C
		
	
			
		
		
	
	
			65 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Objective-C
		
	
| //
 | |
| //  Copyright (c) 2018 Open Whisper Systems. All rights reserved.
 | |
| //
 | |
| 
 | |
| #import "RootKey.h"
 | |
| #import "ChainKey.h"
 | |
| #import "RKCK.h"
 | |
| #import "TSDerivedSecrets.h"
 | |
| #import <Curve25519Kit/Curve25519.h>
 | |
| #import <SignalCoreKit/OWSAsserts.h>
 | |
| 
 | |
| static NSString* const kCoderData      = @"kCoderData";
 | |
| 
 | |
| @implementation RootKey
 | |
| 
 | |
| +(BOOL)supportsSecureCoding{
 | |
|     return YES;
 | |
| }
 | |
| 
 | |
| - (void)encodeWithCoder:(NSCoder *)aCoder{
 | |
|     [aCoder encodeObject:_keyData forKey:kCoderData];
 | |
| }
 | |
| 
 | |
| - (id)initWithCoder:(NSCoder *)aDecoder{
 | |
|     self = [super init];
 | |
| 
 | |
|     if (self) {
 | |
|         _keyData = [aDecoder decodeObjectOfClass:[NSData class] forKey:kCoderData];
 | |
|     }
 | |
| 
 | |
|     return self;
 | |
| }
 | |
| 
 | |
| - (instancetype)initWithData:(NSData *)data{
 | |
|     self = [super init];
 | |
| 
 | |
|     OWSAssert(data.length == 32);
 | |
| 
 | |
|     if (self) {
 | |
|         _keyData = data;
 | |
|     }
 | |
| 
 | |
|     return self;
 | |
| }
 | |
| 
 | |
| - (RKCK *)throws_createChainWithTheirEphemeral:(NSData *)theirEphemeral ourEphemeral:(ECKeyPair *)ourEphemeral
 | |
| {
 | |
|     OWSAssert(theirEphemeral);
 | |
|     OWSAssert(ourEphemeral);
 | |
| 
 | |
|     NSData *sharedSecret = [Curve25519 throws_generateSharedSecretFromPublicKey:theirEphemeral andKeyPair:ourEphemeral];
 | |
|     OWSAssert(sharedSecret.length == 32);
 | |
| 
 | |
|     TSDerivedSecrets *secrets =
 | |
|         [TSDerivedSecrets throws_derivedRatchetedSecretsWithSharedSecret:sharedSecret rootKey:_keyData];
 | |
|     OWSAssert(secrets);
 | |
| 
 | |
|     RKCK *newRKCK = [[RKCK alloc] initWithRK:[[RootKey alloc]  initWithData:secrets.cipherKey]
 | |
|                                           CK:[[ChainKey alloc] initWithData:secrets.macKey index:0]];
 | |
| 
 | |
|     return newRKCK;
 | |
| }
 | |
| 
 | |
| @end
 |