Differences From Artifact [e382c5ef41]:
- File src/OFSHA384Or512Hash.m — part of check-in [27103855c2] at 2021-04-25 11:05:52 on branch new-naming-convention — A few last renames (user: js, size: 7211) [annotate] [blame] [check-ins using] [more...]
To Artifact [f0d2e79fad]:
- File
src/OFSHA384Or512Hash.m
— part of check-in
[82801897d3]
at
2022-03-25 10:22:55
on branch trunk
— OFCryptographicHash: Add -[calculate]
Before, -[digest] would do the final calculation, however, this would
mean a property modifies state, which is bad. (user: js, size: 7391) [annotate] [blame] [check-ins using] [more...]
1 | /* | | | 1 2 3 4 5 6 7 8 9 | /* * Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im> * * 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. * |
︙ | ︙ | |||
18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <stdlib.h> #include <string.h> #import "OFSHA384Or512Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t blockSize = 128; @interface OFSHA384Or512Hash () - (void)of_resetState; @end | > | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include <stdlib.h> #include <string.h> #import "OFSHA384Or512Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFHashNotCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t blockSize = 128; @interface OFSHA384Or512Hash () - (void)of_resetState; @end |
︙ | ︙ | |||
243 244 245 246 247 248 249 | _iVars->bufferLength = 0; } } } - (const unsigned char *)digest { | | > > | > > > > > > > < < | 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | _iVars->bufferLength = 0; } } } - (const unsigned char *)digest { if (!_calculated) @throw [OFHashNotCalculatedException exceptionWithObject: self]; return (const unsigned char *)_iVars->state; } - (void)calculate { if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; _iVars->buffer.bytes[_iVars->bufferLength] = 0x80; OFZeroMemory(_iVars->buffer.bytes + _iVars->bufferLength + 1, 128 - _iVars->bufferLength - 1); if (_iVars->bufferLength >= 112) { processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(_iVars->buffer.bytes, 128); } _iVars->buffer.words[14] = OFToBigEndian64(_iVars->bits[1]); _iVars->buffer.words[15] = OFToBigEndian64(_iVars->bits[0]); processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); byteSwapVectorIfLE(_iVars->state, 8); _calculated = true; } - (void)reset { [self of_resetState]; OFZeroMemory(_iVars->bits, sizeof(_iVars->bits)); OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); |
︙ | ︙ |