Index: src/OFCryptoHash.h ================================================================== --- src/OFCryptoHash.h +++ src/OFCryptoHash.h @@ -32,10 +32,20 @@ #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) size_t digestSize; @property (class, readonly, nonatomic) size_t blockSize; #endif +/*! + * @brief The digest size of the cryptographic hash, in bytes. + */ +@property (readonly, nonatomic) size_t digestSize; + +/*! + * @brief The block size of the cryptographic hash, in bytes. + */ +@property (readonly, nonatomic) size_t blockSize; + /*! * @brief A boolean whether the hash has already been calculated. */ @property (readonly, nonatomic, getter=isCalculated) bool calculated; Index: src/OFHMAC.m ================================================================== --- src/OFHMAC.m +++ src/OFHMAC.m @@ -76,11 +76,11 @@ id hash = [_hashClass cryptoHash]; [hash updateWithBuffer: key length: length]; - length = [_hashClass digestSize]; + length = hash.digestSize; if OF_UNLIKELY (length > blockSize) length = blockSize; memcpy(outerKeyPadItems, hash.digest, length); memcpy(innerKeyPadItems, hash.digest, length); @@ -140,11 +140,11 @@ if (_calculated) return _outerHash.digest; [_outerHash updateWithBuffer: _innerHash.digest - length: [_hashClass digestSize]]; + length: _innerHash.digestSize]; _calculated = true; return _outerHash.digest; } Index: src/OFMD5Hash.m ================================================================== --- src/OFMD5Hash.m +++ src/OFMD5Hash.m @@ -22,10 +22,13 @@ #import "OFMD5Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" + +#define DIGEST_SIZE 16 +#define BLOCK_SIZE 64 @interface OFMD5Hash () - (void)of_resetState; @end @@ -122,16 +125,16 @@ @implementation OFMD5Hash @synthesize calculated = _calculated; + (size_t)digestSize { - return 16; + return DIGEST_SIZE; } + (size_t)blockSize { - return 64; + return BLOCK_SIZE; } + (instancetype)cryptoHash { return [[[self alloc] init] autorelease]; @@ -164,10 +167,20 @@ { [_iVarsData release]; [super dealloc]; } + +- (size_t)digestSize +{ + return DIGEST_SIZE; +} + +- (size_t)blockSize +{ + return BLOCK_SIZE; +} - (id)copy { OFMD5Hash *copy = [[OFMD5Hash alloc] of_init]; Index: src/OFRIPEMD160Hash.m ================================================================== --- src/OFRIPEMD160Hash.m +++ src/OFRIPEMD160Hash.m @@ -22,10 +22,13 @@ #import "OFRIPEMD160Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" + +#define DIGEST_SIZE 20 +#define BLOCK_SIZE 64 @interface OFRIPEMD160Hash () - (void)of_resetState; @end @@ -136,16 +139,16 @@ @implementation OFRIPEMD160Hash @synthesize calculated = _calculated; + (size_t)digestSize { - return 20; + return DIGEST_SIZE; } + (size_t)blockSize { - return 64; + return BLOCK_SIZE; } + (instancetype)cryptoHash { return [[[self alloc] init] autorelease]; @@ -178,10 +181,20 @@ { [_iVarsData release]; [super dealloc]; } + +- (size_t)digestSize +{ + return DIGEST_SIZE; +} + +- (size_t)blockSize +{ + return BLOCK_SIZE; +} - (id)copy { OFRIPEMD160Hash *copy = [[OFRIPEMD160Hash alloc] of_init]; Index: src/OFSHA1Hash.m ================================================================== --- src/OFSHA1Hash.m +++ src/OFSHA1Hash.m @@ -22,10 +22,13 @@ #import "OFSHA1Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" + +#define DIGEST_SIZE 20 +#define BLOCK_SIZE 64 @interface OFSHA1Hash () - (void)of_resetState; @end @@ -96,16 +99,16 @@ @implementation OFSHA1Hash @synthesize calculated = _calculated; + (size_t)digestSize { - return 20; + return DIGEST_SIZE; } + (size_t)blockSize { - return 64; + return BLOCK_SIZE; } + (instancetype)cryptoHash { return [[[self alloc] init] autorelease]; @@ -138,10 +141,20 @@ { [_iVarsData release]; [super dealloc]; } + +- (size_t)digestSize +{ + return DIGEST_SIZE; +} + +- (size_t)blockSize +{ + return BLOCK_SIZE; +} - (id)copy { OFSHA1Hash *copy = [[OFSHA1Hash alloc] of_init]; Index: src/OFSHA224Hash.m ================================================================== --- src/OFSHA224Hash.m +++ src/OFSHA224Hash.m @@ -16,15 +16,22 @@ */ #include "config.h" #import "OFSHA224Hash.h" + +#define DIGEST_SIZE 28 @implementation OFSHA224Hash + (size_t)digestSize { - return 28; + return DIGEST_SIZE; +} + +- (size_t)digestSize +{ + return DIGEST_SIZE; } - (void)of_resetState { _iVars->state[0] = 0xC1059ED8; Index: src/OFSHA224Or256Hash.m ================================================================== --- src/OFSHA224Or256Hash.m +++ src/OFSHA224Or256Hash.m @@ -23,10 +23,12 @@ #import "OFSHA224Or256Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" + +#define BLOCK_SIZE 64 @interface OFSHA224Or256Hash () - (void)of_resetState; @end @@ -123,11 +125,11 @@ OF_UNRECOGNIZED_SELECTOR } + (size_t)blockSize { - return 64; + return BLOCK_SIZE; } + (instancetype)cryptoHash { return [[[self alloc] init] autorelease]; @@ -165,10 +167,20 @@ { [_iVarsData release]; [super dealloc]; } + +- (size_t)digestSize +{ + OF_UNRECOGNIZED_SELECTOR +} + +- (size_t)blockSize +{ + return BLOCK_SIZE; +} - (id)copy { OFSHA224Or256Hash *copy = [[[self class] alloc] of_init]; Index: src/OFSHA256Hash.m ================================================================== --- src/OFSHA256Hash.m +++ src/OFSHA256Hash.m @@ -16,15 +16,22 @@ */ #include "config.h" #import "OFSHA256Hash.h" + +#define DIGEST_SIZE 32 @implementation OFSHA256Hash + (size_t)digestSize { - return 32; + return DIGEST_SIZE; +} + +- (size_t)digestSize +{ + return DIGEST_SIZE; } - (void)of_resetState { _iVars->state[0] = 0x6A09E667; Index: src/OFSHA384Hash.m ================================================================== --- src/OFSHA384Hash.m +++ src/OFSHA384Hash.m @@ -16,15 +16,22 @@ */ #include "config.h" #import "OFSHA384Hash.h" + +#define DIGEST_SIZE 48 @implementation OFSHA384Hash + (size_t)digestSize { - return 48; + return DIGEST_SIZE; +} + +- (size_t)digestSize +{ + return DIGEST_SIZE; } - (void)of_resetState { _iVars->state[0] = 0xCBBB9D5DC1059ED8; Index: src/OFSHA384Or512Hash.m ================================================================== --- src/OFSHA384Or512Hash.m +++ src/OFSHA384Or512Hash.m @@ -23,10 +23,12 @@ #import "OFSHA384Or512Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" + +#define BLOCK_SIZE 128 @interface OFSHA384Or512Hash () - (void)of_resetState; @end @@ -134,11 +136,11 @@ OF_UNRECOGNIZED_SELECTOR } + (size_t)blockSize { - return 128; + return BLOCK_SIZE; } + (instancetype)cryptoHash { return [[[self alloc] init] autorelease]; @@ -176,10 +178,20 @@ { [_iVarsData release]; [super dealloc]; } + +- (size_t)digestSize +{ + OF_UNRECOGNIZED_SELECTOR +} + +- (size_t)blockSize +{ + return BLOCK_SIZE; +} - (id)copy { OFSHA384Or512Hash *copy = [[[self class] alloc] of_init]; Index: src/OFSHA512Hash.m ================================================================== --- src/OFSHA512Hash.m +++ src/OFSHA512Hash.m @@ -16,15 +16,22 @@ */ #include "config.h" #import "OFSHA512Hash.h" + +#define DIGEST_SIZE 64 @implementation OFSHA512Hash + (size_t)digestSize { - return 64; + return DIGEST_SIZE; +} + +- (size_t)digestSize +{ + return DIGEST_SIZE; } - (void)of_resetState { _iVars->state[0] = 0x6A09E667F3BCC908;