ObjFW
OFHMAC.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
3  * Jonathan Schleifer <js@heap.zone>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #import "OFObject.h"
18 #import "OFCryptoHash.h"
19 
20 OF_ASSUME_NONNULL_BEGIN
21 
27 @interface OFHMAC: OFObject
28 {
29  Class <OFCryptoHash> _hashClass;
30  id <OFCryptoHash> _outerHash, _innerHash;
31  id <OFCryptoHash> _outerHashCopy, _innerHashCopy;
32  bool _calculated;
33 }
34 
36 @property (readonly, nonatomic) Class <OFCryptoHash> hashClass;
37 
44 + (instancetype)HMACWithHashClass: (Class <OFCryptoHash>)hashClass;
45 
46 - init OF_UNAVAILABLE;
47 
55 - initWithHashClass: (Class <OFCryptoHash>)hashClass OF_DESIGNATED_INITIALIZER;
56 
69 - (void)setKey: (const void *)key
70  length: (size_t)length;
71 
78 - (void)updateWithBuffer: (const void *)buffer
79  length: (size_t)length;
80 
89 - (const unsigned char *)digest OF_RETURNS_INNER_POINTER;
90 
96 - (size_t)digestSize;
97 
109 - (void)reset;
110 
117 - (void)zero;
118 @end
119 
120 OF_ASSUME_NONNULL_END
void reset()
Resets the HMAC so that it can be calculated for a new message.
Definition: OFHMAC.m:142
Class< OFCryptoHash > hashClass
Definition: OFHMAC.h:36
id init()
Initializes an already allocated object.
Definition: OFObject.m:488
A protocol for classes providing cryptographic hash functions.
A class which provides methods to calculate an HMAC.
Definition: OFHMAC.h:27
const unsigned char * digest()
Returns a buffer containing the HMAC.
Definition: OFHMAC.m:122
void zero()
This is like reset, but also zeroes the hashed key and all state.
Definition: OFHMAC.m:154
The root class for all other classes inside ObjFW.
Definition: OFObject.h:379
size_t digestSize()
Returns the size of the digest.
Definition: OFHMAC.m:137