Mercurial > projects > dcrypt
annotate dcrypt/crypto/padding/PKCS7.d @ 35:6b2c35b84186 0.1
Removed a D2 version statement from the BlockCipherPadding class. Minor consistency correction to the PKCS7 class. Glenn Haecker reports dcrypt now compiles successfully with D2.
author | Thomas Dixon <reikon@reikon.us> |
---|---|
date | Thu, 14 May 2009 17:46:11 -0400 |
parents | ad687db713a4 |
children |
rev | line source |
---|---|
0 | 1 /** |
2 * This file is part of the dcrypt project. | |
3 * | |
4 * Copyright: Copyright (C) dcrypt contributors 2008. All rights reserved. | |
5 * License: MIT | |
6 * Authors: Thomas Dixon | |
7 */ | |
8 | |
9 module dcrypt.crypto.padding.PKCS7; | |
10 | |
11 import dcrypt.crypto.BlockCipherPadding; | |
12 | |
13 /** | |
14 * This class implements the padding scheme described in PKCS7 | |
15 * from RSA Security. Ex. [... 0x03, 0x03, 0x03] | |
16 */ | |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
10
diff
changeset
|
17 class PKCS7 : BlockCipherPadding |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
10
diff
changeset
|
18 { |
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
|
19 string name() |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
10
diff
changeset
|
20 { |
0 | 21 return "PKCS7"; |
22 } | |
23 | |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
10
diff
changeset
|
24 ubyte[] pad(uint len) |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
10
diff
changeset
|
25 { |
10
cd376996cdb3
Renamed SymmetricCipher back to Cipher (we don't support any other kind atm, I'll deal with it when we do.). Added BlockCipherWrapper for the encryption of arbitrary streams with or without padding. Removed hashByName, and replaced it with createHash. Re-did the high-level API, and filled out Crypto. Added cipher creation via createCipher. Added dsk to the CONTRIBUTORS file for helping with the design of the high-level API.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
26 ubyte[] output = new ubyte[len]; |
cd376996cdb3
Renamed SymmetricCipher back to Cipher (we don't support any other kind atm, I'll deal with it when we do.). Added BlockCipherWrapper for the encryption of arbitrary streams with or without padding. Removed hashByName, and replaced it with createHash. Re-did the high-level API, and filled out Crypto. Added cipher creation via createCipher. Added dsk to the CONTRIBUTORS file for helping with the design of the high-level API.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
27 |
35
6b2c35b84186
Removed a D2 version statement from the BlockCipherPadding class. Minor consistency correction to the PKCS7 class. Glenn Haecker reports dcrypt now compiles successfully with D2.
Thomas Dixon <reikon@reikon.us>
parents:
28
diff
changeset
|
28 output[0..output.length] = cast(ubyte)len; |
0 | 29 |
10
cd376996cdb3
Renamed SymmetricCipher back to Cipher (we don't support any other kind atm, I'll deal with it when we do.). Added BlockCipherWrapper for the encryption of arbitrary streams with or without padding. Removed hashByName, and replaced it with createHash. Re-did the high-level API, and filled out Crypto. Added cipher creation via createCipher. Added dsk to the CONTRIBUTORS file for helping with the design of the high-level API.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
30 return output; |
0 | 31 } |
32 | |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
10
diff
changeset
|
33 uint unpad(void[] input_) |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
10
diff
changeset
|
34 { |
0 | 35 ubyte[] input = cast(ubyte[]) input_; |
36 | |
37 ubyte len = input[input.length-1]; | |
38 | |
39 if (len > input.length || len == 0) | |
40 throw new InvalidPaddingError(name()~": Incorrect padding."); | |
41 | |
42 uint limit = input.length; | |
43 for (int i = 0; i < len; i++) | |
44 if (input[--limit] != len) | |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
10
diff
changeset
|
45 throw new InvalidPaddingError(name()~": Pad value does not match pad length."); |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
10
diff
changeset
|
46 |
0 | 47 return len; |
48 } | |
49 } |