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.X923;
|
|
10
|
|
11 import dcrypt.crypto.BlockCipherPadding;
|
|
12
|
|
13 /**
|
|
14 * This class implements the Null/Zero byte padding described in ANSI X.923.
|
|
15 * Ex. [... 0x00, 0x00, 0x03]
|
|
16 */
|
|
17 class X923 : BlockCipherPadding {
|
|
18 char[] name() {
|
|
19 return "X923";
|
|
20 }
|
|
21
|
|
22 /* Assumes input_ is a multiple of the underlying
|
|
23 * block cipher's block size.
|
|
24 */
|
|
25 uint padBlock(void[] input_, uint inOff) {
|
|
26 ubyte[] input = cast(ubyte[]) input_;
|
|
27
|
|
28 ubyte len = (input.length - inOff);
|
|
29
|
|
30 input[inOff..input.length-1] = 0;
|
|
31 input[input.length-1] = len;
|
|
32
|
|
33 return len;
|
|
34 }
|
|
35
|
|
36 uint padLength(void[] input_) {
|
|
37 ubyte[] input = cast(ubyte[]) input_;
|
|
38
|
|
39 ubyte len = input[input.length-1];
|
|
40
|
|
41 if (len > input.length || len == 0)
|
|
42 throw new InvalidPaddingError(name()~": Incorrect padding.");
|
|
43
|
|
44 return len;
|
|
45 }
|
|
46 }
|