comparison dcrypt/crypto/padding/RFC1321.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.RFC1321;
10
11 import dcrypt.crypto.BlockCipherPadding;
12
13 /**
14 * This class implements the padding described in RFC1321 (MD5 spec).
15 * Ex. [... 0x80, 0x00 ... 0x00]
16 */
17 class RFC1321 : BlockCipherPadding {
18 char[] name() {
19 return "RFC1321";
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++] = 0x80;
31 input[inOff..input.length] = 0;
32
33 return len;
34 }
35
36 uint padLength(void[] input_) {
37 ubyte[] input = cast(ubyte[]) input_;
38
39 uint len = input.length;
40
41 while (len-- > 0)
42 if (input[len] != 0) break;
43
44 if (input[len] != 0x80)
45 throw new InvalidPaddingError(
46 name()~": Incorrect padding.");
47
48 return (input.length - len);
49 }
50 }