コード例 #1
0
ファイル: PackageFactory.cs プロジェクト: modulexcite/CEX
        /// <remarks>
        /// Encrypts the key package buffer
        /// </remarks>
        private void TransformBuffer(byte[] KeyData, byte[] Salt)
        {
            byte[] kvm = new byte[48];

            // use salt to derive key and counter vector
            using (Keccak512 digest = new Keccak512(384))
                kvm = digest.ComputeHash(Salt);

            byte[] key = new byte[32];
            byte[] iv = new byte[16];
            Buffer.BlockCopy(kvm, 0, key, 0, key.Length);
            Buffer.BlockCopy(kvm, key.Length, iv, 0, iv.Length);

            using (KeyParams keyparam = new KeyParams(key, iv))
            {
                // 40 rounds of serpent
                using (CTR cipher = new CTR(new SPX(40)))
                {
                    cipher.Initialize(true, keyparam);
                    cipher.Transform(KeyData, KeyData);
                }
            }
        }
コード例 #2
0
ファイル: CipherModeTest.cs プロジェクト: modulexcite/CEX
        private void CTRTest(byte[] Key, byte[,][] Input, byte[,][] Output)
        {
            byte[] outBytes = new byte[16];
            byte[] iv = _vectors[1];
            int index = 24;

            if (Key.Length == 24)
                index = 26;
            else if (Key.Length == 32)
                index = 28;

            using (CTR mode = new CTR(new RDX()))
            {
                mode.Initialize(true, new KeyParams(Key, iv));

                for (int i = 0; i < 4; i++)
                {
                    mode.Transform(Input[index, i], outBytes);

                    if (Compare.AreEqual(outBytes, Output[index, i]) == false)
                        throw new Exception("CTR Mode: Encrypted arrays are not equal!");
                }
            }

            index++;
            using (CTR mode = new CTR(new RDX()))
            {
                mode.Initialize(false, new KeyParams(Key, iv));

                for (int i = 0; i < 4; i++)
                {
                    mode.Transform(Input[index, i], outBytes);

                    if (Compare.AreEqual(outBytes, _output[index, i]) == false)
                        throw new Exception("CTR Mode: Decrypted arrays are not equal!");
                }
            }
        }