public unsafe void Compare_Sha512Hpt_Test(PrvToPubComparer comp, byte[] key, bool expected)
        {
            ulong *hPt = stackalloc ulong[8];

            Helper.WriteToHpt32(key, hPt);
            bool actual = comp.Compare(hPt);

            Assert.Equal(expected, actual);
        }
예제 #2
0
        public void CompareTest()
        {
            var comp1 = new PrvToPubComparer();
            var comp2 = new PrvToPubComparer();

            Assert.True(comp1.Init(KeyHelper.Pub1CompHex));
            Assert.True(comp2.Init(KeyHelper.Pub1UnCompHex));

            byte[] key = KeyHelper.Prv1.ToBytes();
            key[0]++;

            bool b1 = comp1.Compare(key);
            bool b2 = comp2.Compare(key);

            Assert.False(b1);
            Assert.False(b2);

            key[0]--;
            b1 = comp1.Compare(key);
            b2 = comp2.Compare(key);
            Assert.True(b1);
            Assert.True(b2);
        }
예제 #3
0
        public void CloneTest()
        {
            var original = new PrvToPubComparer();

            Assert.True(original.Init(KeyHelper.Pub1CompHex)); // Make sure it is successfully initialized
            var cloned = original.Clone();

            // Change original field value to make sure it is cloned not a reference copy
            Assert.True(original.Init(KeyHelper.Pub2CompHex));

            byte[] key = KeyHelper.Prv1.ToBytes();

            // Since the original was changed it should fail when comparing
            Assert.False(original.Compare(key));
            Assert.True(cloned.Compare(key));
        }
예제 #4
0
        public unsafe void Compare_Sha256HashStateTest()
        {
            var comp = new PrvToPubComparer();

            using Sha256Fo sha = new();
            sha.ComputeHash(new byte[1]);
            fixed(uint *hPt = sha.hashState)
            {
                var key = new Scalar(hPt, out int overflow);

                Assert.Equal(0, overflow);
                var    calc   = new Calc();
                string pubHex = calc.GetPubkey(key, true).ToArray().ToBase16();
                bool   b      = comp.Init(pubHex);

                Assert.True(b);

                bool actual = comp.Compare(hPt);

                Assert.True(actual);
            }
        }