示例#1
0
        private void Encode(NTRUParameters param)
        {
            NTRUKeyPair kp;

            using (NTRUKeyGenerator kg = new NTRUKeyGenerator(param))
                kp = (NTRUKeyPair)kg.GenerateKeyPair();

            // encode to byte[] and reconstruct
            byte[]      enc = kp.ToBytes();
            NTRUKeyPair kp2 = new NTRUKeyPair(enc);

            if (!Evaluate.Equals(kp, kp2))
            {
                throw new Exception("NtruKeyPair encoding test failed!");
            }

            // encode to OutputStream and reconstruct
            MemoryStream bos = new MemoryStream();

            kp.WriteTo(bos);
            MemoryStream bis = new MemoryStream(bos.ToArray());
            NTRUKeyPair  kp3 = new NTRUKeyPair(bis);

            if (!Evaluate.Equals(kp, kp3))
            {
                throw new Exception("NtruKeyPair encoding test failed!");
            }
        }
示例#2
0
        private void GetOutputLength()
        {
            NTRUParameters[] paramSets = new NTRUParameters[]
            {
                (NTRUParameters)NTRUParamSets.APR2011439.DeepCopy(),
                (NTRUParameters)NTRUParamSets.APR2011439FAST.DeepCopy(),
                (NTRUParameters)NTRUParamSets.APR2011743.DeepCopy(),
                (NTRUParameters)NTRUParamSets.APR2011743FAST.DeepCopy(),
                (NTRUParameters)NTRUParamSets.EES1087EP2.DeepCopy(),
                (NTRUParameters)NTRUParamSets.EES1171EP1.DeepCopy(),
                (NTRUParameters)NTRUParamSets.EES1499EP1.DeepCopy(),
            };

            byte[] plainText = ByteUtils.GetBytes("secret encrypted text");

            foreach (NTRUParameters param in paramSets)
            {
                NTRUKeyPair kp;
                using (NTRUKeyGenerator kg = new NTRUKeyGenerator(param))
                    kp = (NTRUKeyPair)kg.GenerateKeyPair();

                NTRUEncrypt ntru = new NTRUEncrypt(param);
                ntru.Initialize(kp.PublicKey);
                byte[] encrypted = ntru.Encrypt(plainText);
                if (!Evaluate.Equals(param.GetOutputLength(), encrypted.Length))
                {
                    throw new Exception("NtruEncryptTest: output length test failed!");
                }
            }
        }
示例#3
0
        public void Equals_BothNull_ReturnsTrue()
        {
            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            // ReSharper disable once EqualExpressionComparison
            var actual = Evaluate.Equals(null, null);

            Assert.IsTrue(actual);
        }
示例#4
0
        public void Equals_RightNullWithParameters_ReturnsFalse()
        {
            var valueA = new FakeTestItem {
                TestDateTime = DateTime.Now, TestInt = 290, TestString = "blah"
            };
            var actual = Evaluate.Equals(valueA, null, item => item.TestDateTime, item => item.TestInt, item => item.TestString);

            Assert.IsFalse(actual);
        }
示例#5
0
        public void Equals_LeftNull_ReturnsFalse()
        {
            var valueB = new FakeTestItem {
                TestDateTime = DateTime.Now, TestInt = 290, TestString = "blah"
            };
            var actual = Evaluate.Equals(null, valueB);

            Assert.IsFalse(actual);
        }
示例#6
0
 /// <summary>
 /// Determines whether two <see cref="EntityLocation"/> values represent the same location.
 /// </summary>
 /// <returns>
 /// true if the specified objects are equal; otherwise, false.
 /// </returns>
 /// <param name="x">
 /// The first object to compare.
 /// </param>
 /// <param name="y">
 /// The second object to compare.
 /// </param>
 public override bool Equals(EntityLocation x, EntityLocation y)
 {
     return(Evaluate.Equals(
                x,
                y,
                location => location.EntityType,
                location => location.Alias,
                location => location.Name,
                location => location.Container));
 }
示例#7
0
        public void Equals_TestObjectsWithEqualProperties_ReturnsTrue()
        {
            var valueA = new FakeTestItem {
                TestString = "test", TestInt = 1
            };
            var valueB = new FakeTestItem {
                TestString = "test", TestInt = 1
            };
            var actual = Evaluate.Equals(valueA, valueB);

            Assert.IsTrue(actual);
        }
示例#8
0
        public void Equals_TestObjectsWithSpecificEqualProperties_ReturnsTrue()
        {
            var valueA = new FakeTestItem {
                TestString = "test", TestInt = 1, TestDateTime = DateTime.MinValue
            };
            var valueB = new FakeTestItem {
                TestString = "test", TestInt = 4, TestDateTime = DateTime.MinValue
            };
            var actual = Evaluate.Equals(valueA, valueB, o => o.TestString, o => o.TestDateTime);

            Assert.AreEqual(true, actual);
        }
示例#9
0
        private void Encode(NTRUParameters param)
        {
            NTRUKeyGenerator ntru = new NTRUKeyGenerator(param);
            NTRUKeyPair      kp   = (NTRUKeyPair)ntru.GenerateKeyPair();

            byte[]      priv = ((NTRUPrivateKey)kp.PrivateKey).ToBytes();
            byte[]      pub  = ((NTRUPublicKey)kp.PublicKey).ToBytes();
            NTRUKeyPair kp2  = new NTRUKeyPair(new NTRUPublicKey(pub), new NTRUPrivateKey(priv));

            if (!Evaluate.Equals(kp.PublicKey, kp2.PublicKey))
            {
                throw new Exception("EncryptionKey: public key comparison test failed!");
            }
            if (kp.PublicKey.GetHashCode() != kp2.PublicKey.GetHashCode())
            {
                throw new Exception("EncryptionKey: public key hash test failed!");
            }
            if (!Evaluate.Equals(kp.PrivateKey, kp2.PrivateKey))
            {
                throw new Exception("EncryptionKey: private key comparison test failed!");
            }
            if (kp.PrivateKey.GetHashCode() != kp2.PrivateKey.GetHashCode())
            {
                throw new Exception("EncryptionKey: private key hash test failed!");
            }

            MemoryStream bos1 = new MemoryStream();
            MemoryStream bos2 = new MemoryStream();

            ((NTRUPrivateKey)kp.PrivateKey).WriteTo(bos1);
            ((NTRUPublicKey)kp.PublicKey).WriteTo(bos2);
            MemoryStream bis1 = new MemoryStream(bos1.ToArray());
            MemoryStream bis2 = new MemoryStream(bos2.ToArray());
            NTRUKeyPair  kp3  = new NTRUKeyPair(new NTRUPublicKey(bis2), new NTRUPrivateKey(bis1));

            if (!Evaluate.Equals(kp.PublicKey, kp3.PublicKey))
            {
                throw new Exception("EncryptionKey: public key comparison test failed!");
            }
            if (kp.PublicKey.GetHashCode() != kp3.PublicKey.GetHashCode())
            {
                throw new Exception("EncryptionKey: public key hash test failed!");
            }
            if (!Evaluate.Equals(kp.PrivateKey, kp3.PrivateKey))
            {
                throw new Exception("EncryptionKey: private key comparison test failed!");
            }
            if (kp.PrivateKey.GetHashCode() != kp3.PrivateKey.GetHashCode())
            {
                throw new Exception("EncryptionKey: private key hash test failed!");
            }
        }
示例#10
0
        public void LoadSave()
        {
            NTRUParameters param = (NTRUParameters)NTRUParamSets.EES1499EP1.DeepCopy();
            MemoryStream   os    = new MemoryStream();

            param.WriteTo(os);
            MemoryStream ins = new MemoryStream(os.ToArray());

            if (!Evaluate.Equals(param, new NTRUParameters(ins)))
            {
                throw new Exception("NtruParameters: load and save test failed!");
            }
        }
示例#11
0
        public void Clone()
        {
            NTRUParameters param  = NTRUParamSets.APR2011439;
            NTRUParameters param2 = (NTRUParameters)param.DeepCopy();

            if (!Evaluate.Equals(param, param2))
            {
                throw new Exception("NtruParameters: cloned copy is not equal!");
            }
            if (param.GetHashCode() != param.GetHashCode())
            {
                throw new Exception("Parameters: parameters hash test failed!");
            }

            param  = NTRUParamSets.APR2011439FAST;
            param2 = (NTRUParameters)param.DeepCopy();

            if (!Evaluate.Equals(param, param2))
            {
                throw new Exception("NtruParameters: cloned copy is not equal!");
            }
            if (param.GetHashCode() != param.GetHashCode())
            {
                throw new Exception("Parameters: parameters hash test failed!");
            }

            param2.Digest = Digests.Blake2B512;
            if (Evaluate.Equals(param, param2))
            {
                throw new Exception("NtruParameters: cloned copy is not equal!");
            }
            if (param.GetHashCode() != param.GetHashCode())
            {
                throw new Exception("Parameters: parameters hash test failed!");
            }
        }
示例#12
0
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">
 /// An object to compare with this object.
 /// </param>
 public bool Equals(UnifiedField other)
 {
     return(Evaluate.Equals(this, other, ComparisonProperties));
 }
示例#13
0
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">An object to compare with this object.</param>
 public bool Equals(DependentRow other)
 {
     return(Evaluate.Equals(this, other, ComparisonProperties));
 }
示例#14
0
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">An object to compare with this object.</param>
 public bool Equals(Template other)
 {
     return(Evaluate.Equals(this, other, ComparisonProperties));
 }
示例#15
0
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">
 /// An object to compare with this object.
 /// </param>
 public bool Equals(ResultPage other)
 {
     return(Evaluate.Equals(this, other, ComparisonProperties));
 }
示例#16
0
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">An object to compare with this object.</param>
 public bool Equals(SignatureOptionRow other)
 {
     return(Evaluate.Equals(this, other, ComparisonProperties));
 }
示例#17
0
 /// <summary>
 /// Compares the equality of two values of the same type.
 /// </summary>
 /// <param name="valueA">
 /// The first value to compare.
 /// </param>
 /// <param name="valueB">
 /// The second value to compare.
 /// </param>
 /// <returns>
 /// <c>true</c> if the values are equal; otherwise, <c>false</c>.
 /// </returns>
 public static bool operator ==(EntityLocation valueA, EntityLocation valueB)
 {
     return(Evaluate.Equals(valueA, valueB));
 }
示例#18
0
 /// <summary>
 /// Determines whether the specified object is equal to the current object.
 /// </summary>
 /// <returns>
 /// true if the specified object  is equal to the current object; otherwise, false.
 /// </returns>
 /// <param name="obj">
 /// The object to compare with the current object.
 /// </param>
 /// <filterpriority>2</filterpriority>
 public override bool Equals(object obj)
 {
     return(Evaluate.Equals(this, obj));
 }
示例#19
0
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">
 /// An object to compare with this object.
 /// </param>
 public bool Equals(DocumentVersion other)
 {
     return(Evaluate.Equals(this, other, ComparisonProperties));
 }
示例#20
0
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">
 /// An object to compare with this object.
 /// </param>
 public bool Equals(FieldValueElement other)
 {
     return(Evaluate.Equals(this, other, ComparisonProperties));
 }
示例#21
0
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">An object to compare with this object.</param>
 public bool Equals(SubEntity other)
 {
     return(Evaluate.Equals(this, other, ComparisonProperties));
 }
示例#22
0
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">An object to compare with this object.</param>
 public bool Equals(InstanceSection other)
 {
     return(Evaluate.Equals(this, other, ComparisonProperties));
 }
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">An object to compare with this object.</param>
 public bool Equals(OverriddenColumnNameRow other)
 {
     return(Evaluate.Equals(this, other, ComparisonProperties));
 }
示例#24
0
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">An object to compare with this object.</param>
 public bool Equals(MultiReferenceRow other)
 {
     return(Evaluate.Equals(this, other, ComparisonProperties));
 }
示例#25
0
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">
 /// An object to compare with this object.
 /// </param>
 public bool Equals(FakeTestItem other)
 {
     return(Evaluate.Equals(this, other, ComparisonProperties));
 }
示例#26
0
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">An object to compare with this object.</param>
 public bool Equals(RelatedRow other)
 {
     return(Evaluate.Equals(this, other, ComparisonProperties));
 }
示例#27
0
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">
 /// An object to compare with this object.
 /// </param>
 public bool Equals(AttributeLocation other)
 {
     return(Evaluate.Equals(this, other, ComparisonProperties));
 }
示例#28
0
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">
 /// An object to compare with this object.
 /// </param>
 public bool Equals(SubContainerRow other)
 {
     return(Evaluate.Equals(this, other, ComparisonProperties));
 }
示例#29
0
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">
 /// An object to compare with this object.
 /// </param>
 public bool Equals(UnifiedFieldValue other)
 {
     return(Evaluate.Equals(this, other, ComparisonProperties) && this.FieldValues.SequenceEqual(other?.FieldValues ?? new List <object>()));
 }
示例#30
0
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">
 /// An object to compare with this object.
 /// </param>
 public bool Equals(DomainIdentityRow other)
 {
     return(Evaluate.Equals(this, other, ComparisonProperties));
 }