comparison dcrypt/crypto/padding/X923.d @ 27:8b5eaf3c2979

Fixed error in hash message padding reported by Glenn Haecker.
author Thomas Dixon <reikon@reikon.us>
date Sat, 09 May 2009 23:29:20 -0400
parents cd376996cdb3
children ad687db713a4
comparison
equal deleted inserted replaced
26:176c933827a8 27:8b5eaf3c2979
12 12
13 /** 13 /**
14 * This class implements the Null/Zero byte padding described in ANSI X.923. 14 * This class implements the Null/Zero byte padding described in ANSI X.923.
15 * Ex. [... 0x00, 0x00, 0x03] 15 * Ex. [... 0x00, 0x00, 0x03]
16 */ 16 */
17 class X923 : BlockCipherPadding { 17 class X923 : BlockCipherPadding
18 char[] name() { 18 {
19 char[] name()
20 {
19 return "X923"; 21 return "X923";
20 } 22 }
21 23
22 /* Assumes input_ is a multiple of the underlying 24 /* Assumes input_ is a multiple of the underlying
23 * block cipher's block size. 25 * block cipher's block size.
24 */ 26 */
25 ubyte[] pad(uint len) { 27 ubyte[] pad(uint len)
28 {
26 ubyte[] output = new ubyte[len]; 29 ubyte[] output = new ubyte[len];
27 30
28 output[0..len-1] = 0; 31 output[0..len-1] = 0;
29 output[output.length-1] = cast(ubyte)len; 32 output[output.length-1] = cast(ubyte)len;
30 33
31 return output; 34 return output;
32 } 35 }
33 36
34 uint unpad(void[] input_) { 37 uint unpad(void[] input_)
38 {
35 ubyte[] input = cast(ubyte[]) input_; 39 ubyte[] input = cast(ubyte[]) input_;
36 40
37 ubyte len = input[input.length-1]; 41 ubyte len = input[input.length-1];
38 42
39 if (len > input.length || len == 0) 43 if (len > input.length || len == 0)