ObjFW  Diff

Differences From Artifact [e332bfebbc]:

To Artifact [43577ec262]:

  • File src/OFSHA384Or512Hash.m — part of check-in [951f530aee] at 2016-07-24 00:06:30 on branch trunk — Rename OFHash to OFCryptoHash

    OFHash is too generic, as this protocol is for cryptographic hashes. It
    also solves the ambiguity of the +[hash] method (which is now
    +[cryptoHash]), which conflicted with -[hash] on the class itself,
    resulting in classes conforming to OFHash not being able to be used as a
    key in an OFDictionary. (user: js, size: 5670) [annotate] [blame] [check-ins using]


12
13
14
15
16
17
18

19
20
21
22
23
24
25
 * 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 <string.h>

#import "OFSHA384Or512Hash.h"

#import "OFHashAlreadyCalculatedException.h"

static const uint64_t table[] = {







>







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 * 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 <stdlib.h>
#include <string.h>

#import "OFSHA384Or512Hash.h"

#import "OFHashAlreadyCalculatedException.h"

static const uint64_t table[] = {
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142






143




144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
}

+ (size_t)blockSize
{
	return 128;
}

+ (instancetype)hash
{
	return [[[self alloc] init] autorelease];
}

- init
{
	self = [super init];







	[self OF_resetState];





	return self;
}

- (void)updateWithBuffer: (const void*)buffer_
		  length: (size_t)length
{
	const uint8_t *buffer = buffer_;

	if (_calculated)
		@throw [OFHashAlreadyCalculatedException
		    exceptionWithHash: self];

	if (UINT64_MAX - _bits[0] < (length * 8))
		_bits[1]++;
	_bits[0] += (length * 8);

	while (length > 0) {
		size_t min = 128 - _bufferLength;







|








>
>
>
>
>
>
|
>
>
>
>











|







128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
}

+ (size_t)blockSize
{
	return 128;
}

+ (instancetype)cryptoHash
{
	return [[[self alloc] init] autorelease];
}

- init
{
	self = [super init];

	@try {
		if ([self class] == [OFSHA384Or512Hash class]) {
			[self doesNotRecognizeSelector: _cmd];
			abort();
		}

		[self OF_resetState];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)updateWithBuffer: (const void*)buffer_
		  length: (size_t)length
{
	const uint8_t *buffer = buffer_;

	if (_calculated)
		@throw [OFHashAlreadyCalculatedException
		    exceptionWithObject: self];

	if (UINT64_MAX - _bits[0] < (length * 8))
		_bits[1]++;
	_bits[0] += (length * 8);

	while (length > 0) {
		size_t min = 128 - _bufferLength;