ObjFW
OFHMAC.h
1 /*
2  * Copyright (c) 2008-2023 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #import "OFObject.h"
17 #import "OFCryptographicHash.h"
18 
19 OF_ASSUME_NONNULL_BEGIN
20 
26 OF_SUBCLASSING_RESTRICTED
27 @interface OFHMAC: OFObject
28 {
29  Class <OFCryptographicHash> _hashClass;
30  bool _allowsSwappableMemory;
31  id <OFCryptographicHash> _Nullable _outerHash, _innerHash;
32  id <OFCryptographicHash> _Nullable _outerHashCopy, _innerHashCopy;
33  bool _calculated;
34 }
35 
39 @property (readonly, nonatomic) Class <OFCryptographicHash> hashClass;
40 
44 @property (readonly, nonatomic) bool allowsSwappableMemory;
45 
54 @property (readonly, nonatomic) const unsigned char *digest
55  OF_RETURNS_INNER_POINTER;
56 
60 @property (readonly, nonatomic) size_t digestSize;
61 
69 + (instancetype)HMACWithHashClass: (Class <OFCryptographicHash>)hashClass
70  allowsSwappableMemory: (bool)allowsSwappableMemory;
71 
72 - (instancetype)init OF_UNAVAILABLE;
73 
82 - (instancetype)initWithHashClass: (Class <OFCryptographicHash>)hashClass
83  allowsSwappableMemory: (bool)allowsSwappableMemory
84  OF_DESIGNATED_INITIALIZER;
85 
98 - (void)setKey: (const void *)key length: (size_t)length;
99 
107 - (void)updateWithBuffer: (const void *)buffer length: (size_t)length;
108 
114 - (void)calculate;
115 
127 - (void)reset;
128 
135 - (void)zero;
136 @end
137 
138 OF_ASSUME_NONNULL_END
A class which provides methods to calculate an HMAC.
Definition: OFHMAC.h:28
The root class for all other classes inside ObjFW.
Definition: OFObject.h:688
A protocol for classes providing cryptographic hash functions.
Definition: OFCryptographicHash.h:30