annotate dcrypt/crypto/MAC.d @ 32:2b4bccdc8387

Added version() statements to play nice with D2's current feelings about const. Changed a few methods (addEntropy and read in the base PRNG class, and the constructor for ParametersWithIV) to accept void[] in place of ubyte[].
author Thomas Dixon <reikon@reikon.us>
date Tue, 12 May 2009 22:09:33 -0400
parents b9ba770b8f16
children b9f8aa42a547
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
1 /**
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
2 * This file is part of the dcrypt project.
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
3 *
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
4 * Copyright: Copyright (C) dcrypt contributors 2008. All rights reserved.
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
5 * License: MIT
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
6 * Authors: Thomas Dixon
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
7 */
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
8
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
9 module dcrypt.crypto.MAC;
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
10
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
11 public import dcrypt.crypto.params.CipherParameters;
15
0de48552be35 Added LimitReachedError and PBKDF2. Fixed some errors with the previous commit in PRNGFromHash, etc. Re-implemented HMAC. Changed the name() format of HMAC and PBKDF2.
Thomas Dixon <reikon@reikon.us>
parents: 14
diff changeset
12 public import dcrypt.crypto.params.SymmetricKey;
4
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
13 public import dcrypt.crypto.errors.InvalidParameterError;
23
4589f8c5eb3c Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
Thomas Dixon <reikon@reikon.us>
parents: 15
diff changeset
14 import dcrypt.misc.ByteConverter;
4
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
15
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
16 /** Base MAC class */
27
8b5eaf3c2979 Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents: 23
diff changeset
17 abstract class MAC
8b5eaf3c2979 Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents: 23
diff changeset
18 {
4
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
19 /**
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
20 * Initialize a MAC.
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
21 *
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
22 * Params:
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
23 * params = Parameters to be passed to the MAC. (Key, etc.)
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
24 */
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
25 void init(CipherParameters params);
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
26
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
27 /**
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
28 * Introduce data into the MAC.
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
29 *
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
30 * Params:
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
31 * input_ = Data to be processed.
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
32 */
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
33 void update(void[] input_);
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
34
32
2b4bccdc8387 Added version() statements to play nice with D2's current feelings about const. Changed a few methods (addEntropy and read in the base PRNG class, and the constructor for ParametersWithIV) to accept void[] in place of ubyte[].
Thomas Dixon <reikon@reikon.us>
parents: 29
diff changeset
35 /** Play nice with D2's idea of const. */
2b4bccdc8387 Added version() statements to play nice with D2's current feelings about const. Changed a few methods (addEntropy and read in the base PRNG class, and the constructor for ParametersWithIV) to accept void[] in place of ubyte[].
Thomas Dixon <reikon@reikon.us>
parents: 29
diff changeset
36 version (D_Version2)
2b4bccdc8387 Added version() statements to play nice with D2's current feelings about const. Changed a few methods (addEntropy and read in the base PRNG class, and the constructor for ParametersWithIV) to accept void[] in place of ubyte[].
Thomas Dixon <reikon@reikon.us>
parents: 29
diff changeset
37 {
2b4bccdc8387 Added version() statements to play nice with D2's current feelings about const. Changed a few methods (addEntropy and read in the base PRNG class, and the constructor for ParametersWithIV) to accept void[] in place of ubyte[].
Thomas Dixon <reikon@reikon.us>
parents: 29
diff changeset
38 void update(string input_)
2b4bccdc8387 Added version() statements to play nice with D2's current feelings about const. Changed a few methods (addEntropy and read in the base PRNG class, and the constructor for ParametersWithIV) to accept void[] in place of ubyte[].
Thomas Dixon <reikon@reikon.us>
parents: 29
diff changeset
39 {
2b4bccdc8387 Added version() statements to play nice with D2's current feelings about const. Changed a few methods (addEntropy and read in the base PRNG class, and the constructor for ParametersWithIV) to accept void[] in place of ubyte[].
Thomas Dixon <reikon@reikon.us>
parents: 29
diff changeset
40 update(cast(ubyte[])input_);
2b4bccdc8387 Added version() statements to play nice with D2's current feelings about const. Changed a few methods (addEntropy and read in the base PRNG class, and the constructor for ParametersWithIV) to accept void[] in place of ubyte[].
Thomas Dixon <reikon@reikon.us>
parents: 29
diff changeset
41 }
2b4bccdc8387 Added version() statements to play nice with D2's current feelings about const. Changed a few methods (addEntropy and read in the base PRNG class, and the constructor for ParametersWithIV) to accept void[] in place of ubyte[].
Thomas Dixon <reikon@reikon.us>
parents: 29
diff changeset
42 }
2b4bccdc8387 Added version() statements to play nice with D2's current feelings about const. Changed a few methods (addEntropy and read in the base PRNG class, and the constructor for ParametersWithIV) to accept void[] in place of ubyte[].
Thomas Dixon <reikon@reikon.us>
parents: 29
diff changeset
43
4
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
44 /** Returns: The name of this MAC. */
28
ad687db713a4 Further reworked the code for hash padding. Replaced all instances of 'char[]' with 'string' and removed a few 'const' modifiers as per Glenn Haecker's patch for D2 compatibility. Updated CONTRIBUTORS file.
Thomas Dixon <reikon@reikon.us>
parents: 27
diff changeset
45 string name();
4
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
46
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
47 /** Reset MAC to its state immediately subsequent the last init. */
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
48 void reset();
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
49
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
50 /** Returns: The block size in bytes that this MAC will operate on. */
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
51 uint blockSize();
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
52
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
53 /** Returns: The output size of the MAC in bytes. */
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
54 uint macSize();
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
55
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
56 /** Returns: The computed MAC. */
14
5ce3012f1def Removed some redundancy in code. Added NotSupportedError, a base PRNG class and a class which creates a PRNG from a hash function. Changed the MAC class' finalization methods to digest and hexDigest instead of finish and hexFinish respectively. Also added a base Checksum class, crc32 and adler32 in dcrypt.misc as per request.
Thomas Dixon <reikon@reikon.us>
parents: 4
diff changeset
57 ubyte[] digest();
4
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
58
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
59 /** Returns: The computed MAC in hexadecimal. */
29
b9ba770b8f16 Second go at D2 compatibility. Changed the hexEncode method of the ByteConverter class and the hexDigest methods of various classes to return char[] instead of string.
Thomas Dixon <reikon@reikon.us>
parents: 28
diff changeset
60 char[] hexDigest()
27
8b5eaf3c2979 Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents: 23
diff changeset
61 {
23
4589f8c5eb3c Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
Thomas Dixon <reikon@reikon.us>
parents: 15
diff changeset
62 return ByteConverter.hexEncode(digest());
4
3de3a2de13a0 Added MAC base class and HMAC. Added StreamCipherWrapper as part of the work on the high-level cipher API. Running on fumes, so hopefully there isn't too much stupid mixed into the code.
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
63 }
23
4589f8c5eb3c Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
Thomas Dixon <reikon@reikon.us>
parents: 15
diff changeset
64 }