예제 #1
0
파일: UBI.cs 프로젝트: sriramk/nskein
        internal void Update(UInt64[] message, Tweak tweak)
        {
            //
            // Takes encoded tweak value and message, encrypts using current state as key and XORs
            // result with message. The block size is determined by looking at input message length
            // TODO: Reuse block cipher instance
            //

            if (_Hi.Length != message.Length){
                throw new InvalidOperationException("Can't change block size in mid flight");

            }
            Threefish threeFish = new Threefish(_Hi, tweak, _blockSize);
            threeFish.Encrypt(message, _Hi);

            for (int i = 0; i < _Hi.Length; i++){

                _Hi[i] ^= message[i];
            }
        }
예제 #2
0
파일: Program.cs 프로젝트: sriramk/nskein
        static bool ThreefishTest(string hexKey, string hexTweak, string hexMessage, string hexExpectedCipherText, Threefish.ThreeFishBlockSize blockSize)
        {
            UInt64[] plainText = Util.ConvertLSBFirstToUInt64(Util.ByteArrayfromHex(hexMessage));
            UInt64[] key = Util.ConvertLSBFirstToUInt64(Util.ByteArrayfromHex(hexKey));
            UInt64[] tweak = Util.ConvertLSBFirstToUInt64(Util.ByteArrayfromHex(hexTweak));
            UInt64[] cipherText = new UInt64[plainText.Length];
            Threefish threefish = new Threefish(key, new Tweak { low64 = tweak[0], high64 = tweak[1] }, blockSize);
            threefish.Encrypt(plainText, cipherText);
            string hexObtainedCipherText = Util.HexStringFromByteArray(Util.ConvertUInt64ToLSBFirst(cipherText));
            if (String.Compare(hexObtainedCipherText.ToLower(), hexExpectedCipherText.ToLower(), true) != 0)
            {
                System.Diagnostics.Debugger.Break();
                Console.WriteLine("\n\n!!!Test failed!!!");
                Console.WriteLine(" \n Key: {0} \n Tweak: {1} \n Message: {2} \n ExpectedCipher: {3}\n GotCipher: {4}", hexKey, hexTweak, hexMessage, hexExpectedCipherText, hexObtainedCipherText);
                return false;
            }

            return true;
        }