view 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 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.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);
    }
}