Esempio n. 1
0
        private byte[] EncodeBlock(byte[] inBytes, int inOff, int inLen)
        {
            var block = new byte[GetInputBlockSize() + 1 + 2 * _defHash.Length];

            //
            // copy in the message
            //
            Array.Copy(inBytes, inOff, block, block.Length - inLen, inLen);

            //
            // add sentinel
            //
            block[block.Length - inLen - 1] = 0x01;

            //
            // as the block is already zeroed - there's no need to add PS (the >= 0 pad of 0)
            //

            //
            // add the hash of the encoding params.
            //
            Array.Copy(_defHash, 0, block, _defHash.Length, _defHash.Length);

            //
            // generate the seed.
            //
            var seed = _random.GenerateSeed(_defHash.Length);

            //
            // mask the message block.
            //
            var mask = MaskGeneratorFunction1(seed, 0, seed.Length, block.Length - _defHash.Length);

            for (var i = _defHash.Length; i != block.Length; i++)
            {
                block[i] ^= mask[i - _defHash.Length];
            }

            //
            // add in the seed
            //
            Array.Copy(seed, 0, block, 0, _defHash.Length);

            //
            // mask the seed.
            //
            mask = MaskGeneratorFunction1(
                block, _defHash.Length, block.Length - _defHash.Length, _defHash.Length);

            for (var i = 0; i != _defHash.Length; i++)
            {
                block[i] ^= mask[i];
            }

            return(_engine.ProcessBlock(block, 0, block.Length));
        }
 protected virtual byte[] engineGenerateKey()
 {
     return(random.GenerateSeed(strength));
 }