Пример #1
0
        /// <summary>
        /// Encryptes the login response message.
        /// </summary>
        public static byte[] SendPepperLoginResponse(ref PepperInit Init, out IEncrypter SendEncrypter, out IEncrypter ReceiveEncrypter, byte[] Data)
        {
            ++Init.State;

            Blake2BHasher Blake2 = new Blake2BHasher();

            Blake2.Update(Init.Nonce);
            Blake2.Update(Init.ClientPublicKey);
            Blake2.Update(Init.ServerPublicKey);

            byte[] M = new byte[Data.Length + 88];

            byte[] SendNonce = new byte[24];
            byte[] SecretKey = new byte[32];

            XorShift.NextBytes(SendNonce);
            XorShift.NextBytes(SecretKey);

            SendEncrypter    = new PepperEncrypter(SendNonce, SecretKey);
            ReceiveEncrypter = new PepperEncrypter(Init.Nonce, SecretKey);

            Buffer.BlockCopy(SendNonce, 0, M, 32, 24);
            Buffer.BlockCopy(SecretKey, 0, M, 56, 32);
            Buffer.BlockCopy(Data, 0, M, 88, Data.Length);

            if (Curve25519Xsalsa20Poly1305.CryptoBoxAfternm(M, M, Blake2.Finish(), Init.SharedKey) == 0)
            {
                byte[] Encrypted = new byte[M.Length - 16];
                Buffer.BlockCopy(M, 16, Encrypted, 0, M.Length - 16);
                return(Encrypted);
            }

            Logging.Error(typeof(PepperCrypto), "Unable de send pepper login response.");

            return(null);
        }
        public override void WithXorShift()
        {
            var arr = new byte[1024];

            XorShift.NextBytes(arr);
        }