@@ -23,26 +23,32 @@ #import "OFHashAlreadyCalculatedException.h" #import "OFInvalidArgumentException.h" @implementation OFHMAC @synthesize hashClass = _hashClass; +@synthesize allowsSwappableMemory = _allowsSwappableMemory; + (instancetype)HMACWithHashClass: (Class )class + allowsSwappableMemory: (bool)allowsSwappableMemory { - return [[[self alloc] initWithHashClass: class] autorelease]; + return [[[self alloc] initWithHashClass: class + allowsSwappableMemory: allowsSwappableMemory] + autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithHashClass: (Class )class + allowsSwappableMemory: (bool)allowsSwappableMemory { self = [super init]; _hashClass = class; + _allowsSwappableMemory = allowsSwappableMemory; return self; } - (void)dealloc @@ -58,12 +64,16 @@ - (void)setKey: (const void *)key length: (size_t)length { void *pool = objc_autoreleasePoolPush(); size_t blockSize = [_hashClass blockSize]; - OFSecureData *outerKeyPad = [OFSecureData dataWithCount: blockSize]; - OFSecureData *innerKeyPad = [OFSecureData dataWithCount: blockSize]; + OFSecureData *outerKeyPad = [OFSecureData + dataWithCount: blockSize + allowsSwappableMemory: _allowsSwappableMemory]; + OFSecureData *innerKeyPad = [OFSecureData + dataWithCount: blockSize + allowsSwappableMemory: _allowsSwappableMemory]; unsigned char *outerKeyPadItems = outerKeyPad.mutableItems; unsigned char *innerKeyPadItems = innerKeyPad.mutableItems; [_outerHash release]; [_innerHash release]; @@ -71,11 +81,13 @@ [_innerHashCopy release]; _outerHash = _innerHash = _outerHashCopy = _innerHashCopy = nil; @try { if (length > blockSize) { - id hash = [_hashClass cryptoHash]; + id hash = [_hashClass + cryptoHashWithAllowsSwappableMemory: + _allowsSwappableMemory]; [hash updateWithBuffer: key length: length]; length = hash.digestSize; @@ -95,12 +107,14 @@ for (size_t i = 0; i < blockSize; i++) { outerKeyPadItems[i] ^= 0x5C; innerKeyPadItems[i] ^= 0x36; } - _outerHash = [[_hashClass cryptoHash] retain]; - _innerHash = [[_hashClass cryptoHash] retain]; + _outerHash = [[_hashClass cryptoHashWithAllowsSwappableMemory: + _allowsSwappableMemory] retain]; + _innerHash = [[_hashClass cryptoHashWithAllowsSwappableMemory: + _allowsSwappableMemory] retain]; [_outerHash updateWithBuffer: outerKeyPadItems length: blockSize]; [_innerHash updateWithBuffer: innerKeyPadItems length: blockSize];