comparison dcrypt/crypto/padding/RFC1321.d @ 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.
author Thomas Dixon <reikon@reikon.us>
date Wed, 20 Aug 2008 20:08:07 -0400
parents 0e08791a1418
children 8b5eaf3c2979
comparison
equal deleted inserted replaced
9:29b910949588 10:cd376996cdb3
16 */ 16 */
17 class RFC1321 : BlockCipherPadding { 17 class RFC1321 : BlockCipherPadding {
18 char[] name() { 18 char[] name() {
19 return "RFC1321"; 19 return "RFC1321";
20 } 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 21
28 uint len = (input.length - inOff); 22 ubyte[] pad(uint len) {
23 ubyte[] output = new ubyte[len];
29 24
30 input[inOff++] = 0x80; 25 output[0] = 0x80;
31 input[inOff..input.length] = 0; 26 output[1..output.length] = 0;
32 27
33 return len; 28 return output;
34 } 29 }
35 30
36 uint padLength(void[] input_) { 31 uint unpad(void[] input_) {
37 ubyte[] input = cast(ubyte[]) input_; 32 ubyte[] input = cast(ubyte[]) input_;
38 33
39 uint len = input.length; 34 uint len = input.length;
40 35
41 while (len-- > 0) 36 while (len-- > 0)