Index: ObjFW.xcodeproj/project.pbxproj ================================================================== --- ObjFW.xcodeproj/project.pbxproj +++ ObjFW.xcodeproj/project.pbxproj @@ -123,12 +123,12 @@ 4B23CA92133811DC0047A1D9 /* TestPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6EF684123535B60076B512 /* TestPlugin.m */; }; 4B23CA93133811E20047A1D9 /* ObjFW.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B3D23761337FBC800DD29B8 /* ObjFW.framework */; }; 4B23CA941338121C0047A1D9 /* TestPlugin.bundle in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4B23CA8A133811610047A1D9 /* TestPlugin.bundle */; }; 4B24592A19B5397C0059F271 /* OFSHA224Hash.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B24592619B5397C0059F271 /* OFSHA224Hash.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B24592B19B5397C0059F271 /* OFSHA224Hash.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B24592719B5397C0059F271 /* OFSHA224Hash.m */; }; - 4B24592C19B5397C0059F271 /* OFSHA224OrSHA256Hash.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B24592819B5397C0059F271 /* OFSHA224OrSHA256Hash.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 4B24592D19B5397C0059F271 /* OFSHA224OrSHA256Hash.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B24592919B5397C0059F271 /* OFSHA224OrSHA256Hash.m */; }; + 4B24592C19B5397C0059F271 /* OFSHA224Or256Hash.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B24592819B5397C0059F271 /* OFSHA224Or256Hash.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4B24592D19B5397C0059F271 /* OFSHA224Or256Hash.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B24592919B5397C0059F271 /* OFSHA224Or256Hash.m */; }; 4B24593019B53BC80059F271 /* OFSHA224HashTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B24592E19B53BC80059F271 /* OFSHA224HashTests.m */; }; 4B24593119B53BC80059F271 /* OFSHA256HashTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B24592F19B53BC80059F271 /* OFSHA256HashTests.m */; }; 4B29BC3F133AC4E80004B236 /* OFCreateDirectoryFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B29BC37133AC4E80004B236 /* OFCreateDirectoryFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B29BC40133AC4E80004B236 /* OFCreateDirectoryFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B29BC38133AC4E80004B236 /* OFCreateDirectoryFailedException.m */; }; 4B29BC41133AC4E80004B236 /* OFSeekFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B29BC39133AC4E80004B236 /* OFSeekFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -621,12 +621,12 @@ 4B19023A1338D6A2000374C9 /* Makefile */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.make; name = Makefile; path = src/Makefile; sourceTree = SOURCE_ROOT; }; 4B19023D1338D6D5000374C9 /* Makefile */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.make; name = Makefile; path = tests/Makefile; sourceTree = ""; }; 4B23CA8A133811610047A1D9 /* TestPlugin.bundle */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = TestPlugin.bundle; sourceTree = BUILT_PRODUCTS_DIR; }; 4B24592619B5397C0059F271 /* OFSHA224Hash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFSHA224Hash.h; path = src/OFSHA224Hash.h; sourceTree = ""; }; 4B24592719B5397C0059F271 /* OFSHA224Hash.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSHA224Hash.m; path = src/OFSHA224Hash.m; sourceTree = ""; }; - 4B24592819B5397C0059F271 /* OFSHA224OrSHA256Hash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFSHA224OrSHA256Hash.h; path = src/OFSHA224OrSHA256Hash.h; sourceTree = ""; }; - 4B24592919B5397C0059F271 /* OFSHA224OrSHA256Hash.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSHA224OrSHA256Hash.m; path = src/OFSHA224OrSHA256Hash.m; sourceTree = ""; }; + 4B24592819B5397C0059F271 /* OFSHA224Or256Hash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFSHA224Or256Hash.h; path = src/OFSHA224Or256Hash.h; sourceTree = ""; }; + 4B24592919B5397C0059F271 /* OFSHA224Or256Hash.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSHA224Or256Hash.m; path = src/OFSHA224Or256Hash.m; sourceTree = ""; }; 4B24592E19B53BC80059F271 /* OFSHA224HashTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSHA224HashTests.m; path = tests/OFSHA224HashTests.m; sourceTree = ""; }; 4B24592F19B53BC80059F271 /* OFSHA256HashTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSHA256HashTests.m; path = tests/OFSHA256HashTests.m; sourceTree = ""; }; 4B29BC37133AC4E80004B236 /* OFCreateDirectoryFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFCreateDirectoryFailedException.h; path = src/exceptions/OFCreateDirectoryFailedException.h; sourceTree = ""; }; 4B29BC38133AC4E80004B236 /* OFCreateDirectoryFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFCreateDirectoryFailedException.m; path = src/exceptions/OFCreateDirectoryFailedException.m; sourceTree = ""; }; 4B29BC39133AC4E80004B236 /* OFSeekFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFSeekFailedException.h; path = src/exceptions/OFSeekFailedException.h; sourceTree = ""; }; @@ -1351,12 +1351,12 @@ 4B8385131951BF9500D5358A /* OFSettings_INIFile.m */, 4BF1BCC411C9663F0025511F /* OFSHA1Hash.h */, 4BF1BCC511C9663F0025511F /* OFSHA1Hash.m */, 4B24592619B5397C0059F271 /* OFSHA224Hash.h */, 4B24592719B5397C0059F271 /* OFSHA224Hash.m */, - 4B24592819B5397C0059F271 /* OFSHA224OrSHA256Hash.h */, - 4B24592919B5397C0059F271 /* OFSHA224OrSHA256Hash.m */, + 4B24592819B5397C0059F271 /* OFSHA224Or256Hash.h */, + 4B24592919B5397C0059F271 /* OFSHA224Or256Hash.m */, 4B3B03E919B3F70500F70C05 /* OFSHA256Hash.h */, 4B3B03EA19B3F70500F70C05 /* OFSHA256Hash.m */, 4B141BA215FCDF74000C21A8 /* OFSortedList.h */, 4B141BA315FCDF74000C21A8 /* OFSortedList.m */, 4B0256E2172B60400062B5F1 /* OFStdIOStream.h */, @@ -1624,11 +1624,11 @@ 4B989C2F13771A3700109A30 /* OFSerialization.h in Headers */, 4B39844213D3A24600E6F825 /* OFSet.h in Headers */, 4B8385181951BF9500D5358A /* OFSettings.h in Headers */, 4B3D23D41337FCB000DD29B8 /* OFSHA1Hash.h in Headers */, 4B24592A19B5397C0059F271 /* OFSHA224Hash.h in Headers */, - 4B24592C19B5397C0059F271 /* OFSHA224OrSHA256Hash.h in Headers */, + 4B24592C19B5397C0059F271 /* OFSHA224Or256Hash.h in Headers */, 4B3B03EB19B3F70500F70C05 /* OFSHA256Hash.h in Headers */, 4B141BA415FCDF74000C21A8 /* OFSortedList.h in Headers */, 4B0256E4172B60400062B5F1 /* OFStdIOStream.h in Headers */, 4B3D23D51337FCB000DD29B8 /* OFStream.h in Headers */, 4B3D23D71337FCB000DD29B8 /* OFStreamSocket.h in Headers */, @@ -2001,11 +2001,11 @@ 4BA85BCF140ECCE800E91D51 /* OFSet_hashtable.m in Sources */, 4B8385191951BF9500D5358A /* OFSettings.m in Sources */, 4B8385171951BF9500D5358A /* OFSettings_INIFile.m in Sources */, 4B3D23A21337FC0D00DD29B8 /* OFSHA1Hash.m in Sources */, 4B24592B19B5397C0059F271 /* OFSHA224Hash.m in Sources */, - 4B24592D19B5397C0059F271 /* OFSHA224OrSHA256Hash.m in Sources */, + 4B24592D19B5397C0059F271 /* OFSHA224Or256Hash.m in Sources */, 4B3B03EC19B3F70500F70C05 /* OFSHA256Hash.m in Sources */, 4B141BA515FCDF74000C21A8 /* OFSortedList.m in Sources */, 4B0256E5172B60400062B5F1 /* OFStdIOStream.m in Sources */, 4B3D23A31337FC0D00DD29B8 /* OFStream.m in Sources */, 4B3D23A51337FC0D00DD29B8 /* OFStreamSocket.m in Sources */, Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -43,11 +43,11 @@ OFRunLoop.m \ OFSeekableStream.m \ OFSet.m \ OFSHA1Hash.m \ OFSHA224Hash.m \ - OFSHA224OrSHA256Hash.m \ + OFSHA224Or256Hash.m \ OFSHA256Hash.m \ OFSortedList.m \ OFStdIOStream.m \ OFStream.m \ OFString.m \ Index: src/OFSHA224Hash.h ================================================================== --- src/OFSHA224Hash.h +++ src/OFSHA224Hash.h @@ -12,14 +12,14 @@ * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ -#import "OFSHA224OrSHA256Hash.h" +#import "OFSHA224Or256Hash.h" /*! * @class OFSHA224Hash OFSHA224Hash.h ObjFW/OFSHA224Hash.h * * @brief A class which provides functions to create an SHA-224 hash. */ -@interface OFSHA224Hash: OFSHA224OrSHA256Hash +@interface OFSHA224Hash: OFSHA224Or256Hash @end ADDED src/OFSHA224Or256Hash.h Index: src/OFSHA224Or256Hash.h ================================================================== --- /dev/null +++ src/OFSHA224Or256Hash.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFHash.h" + +/*! + * @class OFSHA224Or256Hash OFSHA224Or256Hash.h ObjFW/OFSHA224Or256Hash.h + * + * @brief A base class for SHA-224 and SHA-256. + */ +@interface OFSHA224Or256Hash: OFObject +{ + uint32_t _state[8]; + uint64_t _bits; + union { + uint8_t bytes[64]; + uint32_t words[64]; + } _buffer; + size_t _bufferLength; + bool _calculated; +} +@end ADDED src/OFSHA224Or256Hash.m Index: src/OFSHA224Or256Hash.m ================================================================== --- /dev/null +++ src/OFSHA224Or256Hash.m @@ -0,0 +1,201 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#include +#include + +#import "OFSHA224Or256Hash.h" + +#import "OFHashAlreadyCalculatedException.h" + +static const uint32_t table[] = { + 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, + 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, + 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, + 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, + 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, + 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, + 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, + 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967, + 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, + 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, + 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, + 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, + 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, + 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, + 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, + 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2 +}; + +static void +byteSwapVectorIfLE(uint32_t *vector, uint_fast8_t length) +{ + uint_fast8_t i; + + for (i = 0; i < length; i++) + vector[i] = OF_BSWAP32_IF_LE(vector[i]); +} + +static void +processBlock(uint32_t *state, uint32_t *buffer) +{ + uint32_t new[8]; + uint_fast8_t i; + + new[0] = state[0]; + new[1] = state[1]; + new[2] = state[2]; + new[3] = state[3]; + new[4] = state[4]; + new[5] = state[5]; + new[6] = state[6]; + new[7] = state[7]; + + byteSwapVectorIfLE(buffer, 16); + + for (i = 16; i < 64; i++) { + uint32_t tmp; + + tmp = buffer[i - 2]; + buffer[i] = (OF_ROR(tmp, 17) ^ OF_ROR(tmp, 19) ^ (tmp >> 10)) + + buffer[i - 7]; + tmp = buffer[i - 15]; + buffer[i] += (OF_ROR(tmp, 7) ^ OF_ROR(tmp, 18) ^ (tmp >> 3)) + + buffer[i - 16]; + } + + for (i = 0; i < 64; i++) { + uint32_t tmp1 = new[7] + (OF_ROR(new[4], 6) ^ + OF_ROR(new[4], 11) ^ OF_ROR(new[4], 25)) + + ((new[4] & (new[5] ^ new[6])) ^ new[6]) + + table[i] + buffer[i]; + uint32_t tmp2 = (OF_ROR(new[0], 2) ^ OF_ROR(new[0], 13) ^ + OF_ROR(new[0], 22)) + + ((new[0] & (new[1] | new[2])) | (new[1] & new[2])); + + new[7] = new[6]; + new[6] = new[5]; + new[5] = new[4]; + new[4] = new[3] + tmp1; + new[3] = new[2]; + new[2] = new[1]; + new[1] = new[0]; + new[0] = tmp1 + tmp2; + } + + state[0] += new[0]; + state[1] += new[1]; + state[2] += new[2]; + state[3] += new[3]; + state[4] += new[4]; + state[5] += new[5]; + state[6] += new[6]; + state[7] += new[7]; +} + +@implementation OFSHA224Or256Hash ++ (size_t)digestSize +{ + OF_UNRECOGNIZED_SELECTOR +} + ++ (size_t)blockSize +{ + return 64; +} + ++ (instancetype)hash +{ + return [[[self alloc] init] autorelease]; +} + +- init +{ + if (object_getClass(self) == [OFSHA224Or256Hash class]) { + @try { + [self doesNotRecognizeSelector: _cmd]; + } @catch (id e) { + [self release]; + @throw e; + } + + abort(); + } + + return [super init]; +} + +- (void)updateWithBuffer: (const void*)buffer_ + length: (size_t)length +{ + const uint8_t *buffer = buffer_; + + if (_calculated) + @throw [OFHashAlreadyCalculatedException + exceptionWithHash: self]; + + _bits += (length * 8); + + while (length > 0) { + size_t min = 64 - _bufferLength; + + if (min > length) + min = length; + + memcpy(_buffer.bytes + _bufferLength, buffer, min); + _bufferLength += min; + + buffer += min; + length -= min; + + if (_bufferLength == 64) { + processBlock(_state, _buffer.words); + _bufferLength = 0; + } + } +} + +- (const uint8_t*)digest +{ + if (_calculated) + return (const uint8_t*)_state; + + _buffer.bytes[_bufferLength] = 0x80; + memset(_buffer.bytes + _bufferLength + 1, 0, 64 - _bufferLength - 1); + + if (_bufferLength >= 56) { + processBlock(_state, _buffer.words); + memset(_buffer.bytes, 0, 64); + } + + _buffer.words[14] = OF_BSWAP32_IF_LE((uint32_t)(_bits >> 32)); + _buffer.words[15] = OF_BSWAP32_IF_LE((uint32_t)(_bits & 0xFFFFFFFF)); + + processBlock(_state, _buffer.words); + memset(&_buffer, 0, sizeof(_buffer)); + byteSwapVectorIfLE(_state, 8); + _calculated = true; + + return (const uint8_t*)_state; +} + +- (bool)isCalculated +{ + return _calculated; +} +@end DELETED src/OFSHA224OrSHA256Hash.h Index: src/OFSHA224OrSHA256Hash.h ================================================================== --- src/OFSHA224OrSHA256Hash.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#import "OFHash.h" - -/*! - * @class OFSHA224OrSHA256Hash OFSHA224OrSHA256Hash.h \ - * ObjFW/OFSHA224OrSHA256Hash.h - * - * @brief A base class for SHA-224 and SHA-256. - */ -@interface OFSHA224OrSHA256Hash: OFObject -{ - uint32_t _state[8]; - uint64_t _bits; - union { - uint8_t bytes[64]; - uint32_t words[64]; - } _buffer; - size_t _bufferLength; - bool _calculated; -} -@end DELETED src/OFSHA224OrSHA256Hash.m Index: src/OFSHA224OrSHA256Hash.m ================================================================== --- src/OFSHA224OrSHA256Hash.m +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#include -#include - -#import "OFSHA224OrSHA256Hash.h" - -#import "OFHashAlreadyCalculatedException.h" - -static const uint32_t table[] = { - 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, - 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, - 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, - 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, - 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, - 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, - 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, - 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967, - 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, - 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, - 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, - 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, - 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, - 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, - 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, - 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2 -}; - -static void -byteSwapVectorIfLE(uint32_t *vector, uint_fast8_t length) -{ - uint_fast8_t i; - - for (i = 0; i < length; i++) - vector[i] = OF_BSWAP32_IF_LE(vector[i]); -} - -static void -processBlock(uint32_t *state, uint32_t *buffer) -{ - uint32_t new[8]; - uint_fast8_t i; - - new[0] = state[0]; - new[1] = state[1]; - new[2] = state[2]; - new[3] = state[3]; - new[4] = state[4]; - new[5] = state[5]; - new[6] = state[6]; - new[7] = state[7]; - - byteSwapVectorIfLE(buffer, 16); - - for (i = 16; i < 64; i++) { - uint32_t tmp; - - tmp = buffer[i - 2]; - buffer[i] = (OF_ROR(tmp, 17) ^ OF_ROR(tmp, 19) ^ (tmp >> 10)) + - buffer[i - 7]; - tmp = buffer[i - 15]; - buffer[i] += (OF_ROR(tmp, 7) ^ OF_ROR(tmp, 18) ^ (tmp >> 3)) + - buffer[i - 16]; - } - - for (i = 0; i < 64; i++) { - uint32_t tmp1 = new[7] + (OF_ROR(new[4], 6) ^ - OF_ROR(new[4], 11) ^ OF_ROR(new[4], 25)) + - ((new[4] & (new[5] ^ new[6])) ^ new[6]) + - table[i] + buffer[i]; - uint32_t tmp2 = (OF_ROR(new[0], 2) ^ OF_ROR(new[0], 13) ^ - OF_ROR(new[0], 22)) + - ((new[0] & (new[1] | new[2])) | (new[1] & new[2])); - - new[7] = new[6]; - new[6] = new[5]; - new[5] = new[4]; - new[4] = new[3] + tmp1; - new[3] = new[2]; - new[2] = new[1]; - new[1] = new[0]; - new[0] = tmp1 + tmp2; - } - - state[0] += new[0]; - state[1] += new[1]; - state[2] += new[2]; - state[3] += new[3]; - state[4] += new[4]; - state[5] += new[5]; - state[6] += new[6]; - state[7] += new[7]; -} - -@implementation OFSHA224OrSHA256Hash -+ (size_t)digestSize -{ - OF_UNRECOGNIZED_SELECTOR -} - -+ (size_t)blockSize -{ - return 64; -} - -+ (instancetype)hash -{ - return [[[self alloc] init] autorelease]; -} - -- init -{ - if (object_getClass(self) == [OFSHA224OrSHA256Hash class]) { - @try { - [self doesNotRecognizeSelector: _cmd]; - } @catch (id e) { - [self release]; - @throw e; - } - - abort(); - } - - return [super init]; -} - -- (void)updateWithBuffer: (const void*)buffer_ - length: (size_t)length -{ - const uint8_t *buffer = buffer_; - - if (_calculated) - @throw [OFHashAlreadyCalculatedException - exceptionWithHash: self]; - - _bits += (length * 8); - - while (length > 0) { - size_t min = 64 - _bufferLength; - - if (min > length) - min = length; - - memcpy(_buffer.bytes + _bufferLength, buffer, min); - _bufferLength += min; - - buffer += min; - length -= min; - - if (_bufferLength == 64) { - processBlock(_state, _buffer.words); - _bufferLength = 0; - } - } -} - -- (const uint8_t*)digest -{ - if (_calculated) - return (const uint8_t*)_state; - - _buffer.bytes[_bufferLength] = 0x80; - memset(_buffer.bytes + _bufferLength + 1, 0, 64 - _bufferLength - 1); - - if (_bufferLength >= 56) { - processBlock(_state, _buffer.words); - memset(_buffer.bytes, 0, 64); - } - - _buffer.words[14] = OF_BSWAP32_IF_LE((uint32_t)(_bits >> 32)); - _buffer.words[15] = OF_BSWAP32_IF_LE((uint32_t)(_bits & 0xFFFFFFFF)); - - processBlock(_state, _buffer.words); - memset(&_buffer, 0, sizeof(_buffer)); - byteSwapVectorIfLE(_state, 8); - _calculated = true; - - return (const uint8_t*)_state; -} - -- (bool)isCalculated -{ - return _calculated; -} -@end Index: src/OFSHA256Hash.h ================================================================== --- src/OFSHA256Hash.h +++ src/OFSHA256Hash.h @@ -12,14 +12,14 @@ * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ -#import "OFSHA224OrSHA256Hash.h" +#import "OFSHA224Or256Hash.h" /*! * @class OFSHA256Hash OFSHA256Hash.h ObjFW/OFSHA256Hash.h * * @brief A class which provides functions to create an SHA-256 hash. */ -@interface OFSHA256Hash: OFSHA224OrSHA256Hash +@interface OFSHA256Hash: OFSHA224Or256Hash @end Index: src/ObjFW.h ================================================================== --- src/ObjFW.h +++ src/ObjFW.h @@ -72,10 +72,11 @@ #endif #import "OFHash.h" #import "OFMD5Hash.h" #import "OFSHA1Hash.h" +#import "OFSHA224Hash.h" #import "OFSHA256Hash.h" #import "OFXMLAttribute.h" #import "OFXMLElement.h" #import "OFXMLAttribute.h"