comparison dcrypt/crypto/padding/NullByte.d @ 0:0e08791a1418

Initial import.
author Thomas Dixon <reikon@reikon.us>
date Sun, 10 Aug 2008 14:20:17 -0400
parents
children cd376996cdb3
comparison
equal deleted inserted replaced
-1:000000000000 0:0e08791a1418
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.NullByte;
10
11 import dcrypt.crypto.BlockCipherPadding;
12
13 /**
14 * This class implements Null/Zero byte padding.
15 * Ex. [... 0x00, 0x00 ... 0x00]
16 */
17 class NullByte : BlockCipherPadding {
18 char[] name() {
19 return "NullByte";
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 uint len = (input.length - inOff);
29
30 input[inOff..input.length] = 0;
31
32 return len;
33 }
34
35 uint padLength(void[] input_) {
36 ubyte[] input = cast(ubyte[]) input_;
37
38 uint len = input.length;
39 while (len-- > 0)
40 if (input[len-1] != 0) break;
41
42 return (input.length - len);
43 }
44 }