public static void crypto_sign_keypair(byte[] pk, int pkoffset, byte[] sk, int skoffset, byte[] seed, int seedoffset)
        {
            GroupElementP3 A;
            int            i;

            Array.Copy(seed, seedoffset, sk, skoffset, 32);
            byte[] h = SHA512.Hash(sk, skoffset, 32);//ToDo: Remove alloc
            ScalarOperations.sc_clamp(h, 0);

            GroupOperations.ge_scalarmult_base(out A, h, 0);
            GroupOperations.ge_p3_tobytes(pk, pkoffset, ref A);

            for (i = 0; i < 32; ++i)
            {
                sk[skoffset + 32 + i] = pk[pkoffset + i];
            }

            CryptoExtensions.Wipe(h);
        }
Exemple #2
0
        //Needs more testing
        public static void KeyExchange(ArraySegment <byte> sharedKey, ArraySegment <byte> publicKey, ArraySegment <byte> privateKey)
        {
            Throw.If(sharedKey.Array == null, "sharedKey.Array");
            Throw.If(publicKey.Array == null, "publicKey.Array");
            Throw.If(privateKey.Array == null, "privateKey");
            Throw.If(sharedKey.Count != 32, "sharedKey.Count != 32");
            Throw.If(publicKey.Count != 32, "publicKey.Count != 32");
            Throw.If(privateKey.Count != 64, "privateKey.Count != 64");

            FieldElement montgomeryX, edwardsY, edwardsZ, sharedMontgomeryX;

            FieldOperations.fe_frombytes(out edwardsY, publicKey.Array, publicKey.Offset);
            FieldOperations.fe_1(out edwardsZ);
            EdwardsToMontgomeryX(out montgomeryX, ref edwardsY, ref edwardsZ);
            byte[] h = SHA512.Hash(privateKey.Array, privateKey.Offset, 32);//ToDo: Remove alloc
            ScalarOperations.sc_clamp(h, 0);
            MontgomeryOperations.scalarmult(out sharedMontgomeryX, h, 0, ref montgomeryX);
            CryptoExtensions.Wipe(h);
            FieldOperations.fe_tobytes(sharedKey.Array, sharedKey.Offset, ref sharedMontgomeryX);
            KeyExchangeOutputHashNaCl(sharedKey.Array, sharedKey.Offset);
        }
Exemple #3
0
        public void ShouldHashFilesAsBase64()
        {
            var          tempFile   = string.Format("{0}{1}.dat", Path.GetTempPath(), Guid.NewGuid());
            const string testString = "My test content to hash with special chars 123!|\"£$%&/()=<>{}[]";

            File.WriteAllText(tempFile, testString);

            var result = _sut.Hash(new FileInfo(tempFile)).ToString(BinaryRepresentation.Base64);

            result.Should().Be.EqualTo("9hqt0jVUaA+FixoayRIm2SWM644Meqw/gpwjij/5pFM4wtA8E/umbQ1bG52YMc8K+RQ5VLzuJvzDXvzClHvfyw==");

            // Cleanup
            if (File.Exists(tempFile))
            {
                File.Delete(tempFile);
            }
        }