Get SMK tests building and passing.
This commit is contained in:
parent
8f5e21c7cf
commit
04db4ca950
3
Podfile
3
Podfile
|
@ -12,7 +12,8 @@ def shared_pods
|
|||
# pod 'YapDatabase/SQLCipher', path: '../YapDatabase'
|
||||
pod 'YapDatabase/SQLCipher', :git => 'https://github.com/signalapp/YapDatabase.git', branch: 'signal-release'
|
||||
# pod 'AxolotlKit', git: 'https://github.com/signalapp/SignalProtocolKit.git', testspecs: ["Tests"]
|
||||
pod 'AxolotlKit', path: '../SignalProtocolKit', testspecs: ["Tests"]
|
||||
# pod 'AxolotlKit', path: '../SignalProtocolKit', testspecs: ["Tests"]
|
||||
pod 'AxolotlKit', path: '../SignalProtocolKit'
|
||||
# pod 'HKDFKit', git: 'https://github.com/signalapp/HKDFKit.git', testspecs: ["Tests"]
|
||||
pod 'HKDFKit', path: '../HKDFKit', testspecs: ["Tests"]
|
||||
# pod 'Curve25519Kit', git: 'https://github.com/signalapp/Curve25519Kit', testspecs: ["Tests"]
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
@interface NSData (messagePadding)
|
||||
|
||||
- (NSData *)removePadding;
|
||||
|
||||
- (NSData *)paddedMessageBody;
|
||||
|
||||
@end
|
|
@ -1,58 +0,0 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NSData+messagePadding.h"
|
||||
|
||||
@implementation NSData (messagePadding)
|
||||
|
||||
- (NSData *)removePadding {
|
||||
unsigned long paddingStart = self.length;
|
||||
|
||||
Byte data[self.length];
|
||||
[self getBytes:data length:self.length];
|
||||
|
||||
for (long i = (long)self.length - 1; i >= 0; i--) {
|
||||
if (data[i] == (Byte)0x80) {
|
||||
paddingStart = (unsigned long)i;
|
||||
break;
|
||||
} else if (data[i] != (Byte)0x00) {
|
||||
OWSLogWarn(@"Failed to remove padding, returning unstripped padding");
|
||||
return self;
|
||||
}
|
||||
}
|
||||
|
||||
return [self subdataWithRange:NSMakeRange(0, paddingStart)];
|
||||
}
|
||||
|
||||
|
||||
- (NSData *)paddedMessageBody {
|
||||
// From
|
||||
// https://github.com/signalapp/TextSecure/blob/master/libtextsecure/src/main/java/org/whispersystems/textsecure/internal/push/PushTransportDetails.java#L55
|
||||
// NOTE: This is dumb. We have our own padding scheme, but so does the cipher.
|
||||
// The +1 -1 here is to make sure the Cipher has room to add one padding byte,
|
||||
// otherwise it'll add a full 16 extra bytes.
|
||||
|
||||
NSUInteger paddedMessageLength = [self paddedMessageLength:(self.length + 1)] - 1;
|
||||
NSMutableData *paddedMessage = [NSMutableData dataWithLength:paddedMessageLength];
|
||||
|
||||
Byte paddingByte = 0x80;
|
||||
|
||||
[paddedMessage replaceBytesInRange:NSMakeRange(0, self.length) withBytes:[self bytes]];
|
||||
[paddedMessage replaceBytesInRange:NSMakeRange(self.length, 1) withBytes:&paddingByte];
|
||||
|
||||
return paddedMessage;
|
||||
}
|
||||
|
||||
- (NSUInteger)paddedMessageLength:(NSUInteger)messageLength {
|
||||
NSUInteger messageLengthWithTerminator = messageLength + 1;
|
||||
NSUInteger messagePartCount = messageLengthWithTerminator / 160;
|
||||
|
||||
if (messageLengthWithTerminator % 160 != 0) {
|
||||
messagePartCount++;
|
||||
}
|
||||
|
||||
return messagePartCount * 160;
|
||||
}
|
||||
|
||||
@end
|
|
@ -1,40 +0,0 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NSData+messagePadding.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import <SignalCoreKit/Cryptography.h>
|
||||
|
||||
@interface MessagePaddingTests : SSKBaseTest
|
||||
|
||||
@end
|
||||
|
||||
@implementation MessagePaddingTests
|
||||
|
||||
- (void)testV3Padding {
|
||||
for (NSUInteger i=0;i<159;i++) {
|
||||
NSData *data = [NSMutableData dataWithLength:i];
|
||||
XCTAssert([data paddedMessageBody].length == 159);
|
||||
}
|
||||
|
||||
for (NSUInteger i=159;i<319;i++) {
|
||||
NSData *data = [NSMutableData dataWithLength:i];
|
||||
XCTAssert([data paddedMessageBody].length == 319);
|
||||
}
|
||||
|
||||
for (NSUInteger i=319;i<479;i++) {
|
||||
NSData *data = [NSMutableData dataWithLength:i];
|
||||
XCTAssert([data paddedMessageBody].length == 479);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testV3RandomPadding{
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
NSData *randomMessage = [Cryptography generateRandomBytes:501];
|
||||
NSData *paddedMessage = [randomMessage paddedMessageBody];
|
||||
XCTAssert([[paddedMessage removePadding] isEqualToData:randomMessage]);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
Loading…
Reference in New Issue