Mercurial > projects > dcrypt
view 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 |
line wrap: on
line source
/** * 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.RFC1321; import dcrypt.crypto.BlockCipherPadding; /** * This class implements the padding described in RFC1321 (MD5 spec). * Ex. [... 0x80, 0x00 ... 0x00] */ class RFC1321 : BlockCipherPadding { char[] name() { return "RFC1321"; } /* 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++] = 0x80; 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] != 0) break; if (input[len] != 0x80) throw new InvalidPaddingError( name()~": Incorrect padding."); return (input.length - len); } }