1
2
3
4
5
6
7
8
9
10
11
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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.
*
|
<
<
|
|
1
2
3
4
5
6
7
8
9
|
/*
* Copyright (c) 2008-2021 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.
*
|
︙ | | | ︙ | |
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
[_innerHash release];
[_outerHashCopy release];
[_innerHashCopy release];
[super dealloc];
}
- (void)setKey: (const void *)key
length: (size_t)length
{
void *pool = objc_autoreleasePoolPush();
size_t blockSize = [_hashClass blockSize];
OFSecureData *outerKeyPad = [OFSecureData
dataWithCount: blockSize
allowsSwappableMemory: _allowsSwappableMemory];
OFSecureData *innerKeyPad = [OFSecureData
|
|
<
|
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
[_innerHash release];
[_outerHashCopy release];
[_innerHashCopy release];
[super dealloc];
}
- (void)setKey: (const void *)key length: (size_t)length
{
void *pool = objc_autoreleasePoolPush();
size_t blockSize = [_hashClass blockSize];
OFSecureData *outerKeyPad = [OFSecureData
dataWithCount: blockSize
allowsSwappableMemory: _allowsSwappableMemory];
OFSecureData *innerKeyPad = [OFSecureData
|
︙ | | | ︙ | |
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
_outerHash = _innerHash = _outerHashCopy = _innerHashCopy = nil;
@try {
if (length > blockSize) {
id <OFCryptoHash> hash = [_hashClass
cryptoHashWithAllowsSwappableMemory:
_allowsSwappableMemory];
[hash updateWithBuffer: key
length: length];
length = hash.digestSize;
if OF_UNLIKELY (length > blockSize)
length = blockSize;
memcpy(outerKeyPadItems, hash.digest, length);
memcpy(innerKeyPadItems, hash.digest, length);
|
<
|
<
|
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
_outerHash = _innerHash = _outerHashCopy = _innerHashCopy = nil;
@try {
if (length > blockSize) {
id <OFCryptoHash> hash = [_hashClass
cryptoHashWithAllowsSwappableMemory:
_allowsSwappableMemory];
[hash updateWithBuffer: key length: length];
length = hash.digestSize;
if OF_UNLIKELY (length > blockSize)
length = blockSize;
memcpy(outerKeyPadItems, hash.digest, length);
memcpy(innerKeyPadItems, hash.digest, length);
|
︙ | | | ︙ | |
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
|
_outerHashCopy = [_outerHash copy];
_innerHashCopy = [_innerHash copy];
_calculated = false;
}
- (void)updateWithBuffer: (const void *)buffer
length: (size_t)length
{
if (_innerHash == nil)
@throw [OFInvalidArgumentException exception];
if (_calculated)
@throw [OFHashAlreadyCalculatedException
exceptionWithObject: self];
[_innerHash updateWithBuffer: buffer
length: length];
}
- (const unsigned char *)digest
{
if (_outerHash == nil || _innerHash == nil)
@throw [OFInvalidArgumentException exception];
|
|
<
|
<
|
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
_outerHashCopy = [_outerHash copy];
_innerHashCopy = [_innerHash copy];
_calculated = false;
}
- (void)updateWithBuffer: (const void *)buffer length: (size_t)length
{
if (_innerHash == nil)
@throw [OFInvalidArgumentException exception];
if (_calculated)
@throw [OFHashAlreadyCalculatedException
exceptionWithObject: self];
[_innerHash updateWithBuffer: buffer length: length];
}
- (const unsigned char *)digest
{
if (_outerHash == nil || _innerHash == nil)
@throw [OFInvalidArgumentException exception];
|
︙ | | | ︙ | |