Mercurial > projects > dcrypt
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dcrypt/crypto/padding/NullByte.d Sun Aug 10 14:20:17 2008 -0400 @@ -0,0 +1,44 @@ +/** + * This file is part of the dcrypt project. + * + * Copyright: Copyright (C) dcrypt contributors 2008. All rights reserved. + * License: MIT + * Authors: Thomas Dixon + */ + +module dcrypt.crypto.padding.NullByte; + +import dcrypt.crypto.BlockCipherPadding; + +/** + * This class implements Null/Zero byte padding. + * Ex. [... 0x00, 0x00 ... 0x00] + */ +class NullByte : BlockCipherPadding { + char[] name() { + return "NullByte"; + } + + /* Assumes input_ is a multiple of the underlying + * block cipher's block size. + */ + uint padBlock(void[] input_, uint inOff) { + ubyte[] input = cast(ubyte[]) input_; + + uint len = (input.length - inOff); + + input[inOff..input.length] = 0; + + return len; + } + + uint padLength(void[] input_) { + ubyte[] input = cast(ubyte[]) input_; + + uint len = input.length; + while (len-- > 0) + if (input[len-1] != 0) break; + + return (input.length - len); + } +}