aboutsummaryrefslogtreecommitdiff
path: root/src/cz/crcs/ectester/common/ec/CustomECFieldF2m.java
diff options
context:
space:
mode:
authordavidhofman2021-09-06 19:51:02 +0200
committerGitHub2021-09-06 19:51:02 +0200
commit69ce36e4537be52c103e8b5a314cca49cc931d8f (patch)
treea911f3c6586a00c151ed054794073bb7cece904f /src/cz/crcs/ectester/common/ec/CustomECFieldF2m.java
parentf1f6ca75524d152e347be8926fd43c98aeb504ac (diff)
downloadECTester-69ce36e4537be52c103e8b5a314cca49cc931d8f.tar.gz
ECTester-69ce36e4537be52c103e8b5a314cca49cc931d8f.tar.zst
ECTester-69ce36e4537be52c103e8b5a314cca49cc931d8f.zip
Implement StandaloneWrongSuite. (#12)
* Add StandaloneWrongSuite. * Partially implement StandaloneWrongSuite. * Add setParam method to EC_Params. * Fix new setParam method in EC_Params. * Implement StandaloneWrongSuite * Add custom classes for testing wrong curve parameters. * Update custom classes. * Add more custom classes for testing curves with wrong parameters. * Modify StandaloneWrongSuite to work with the new custom classes. * Various small cosmetic changes to new custom classes. * Add missing author information to various classes. * Fix a small mistake in CustomECFieldF2m * Add randomG test, change some variables to final. * Add option to skip certain tests + various small changes.
Diffstat (limited to 'src/cz/crcs/ectester/common/ec/CustomECFieldF2m.java')
-rw-r--r--src/cz/crcs/ectester/common/ec/CustomECFieldF2m.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/cz/crcs/ectester/common/ec/CustomECFieldF2m.java b/src/cz/crcs/ectester/common/ec/CustomECFieldF2m.java
new file mode 100644
index 0000000..24ea5aa
--- /dev/null
+++ b/src/cz/crcs/ectester/common/ec/CustomECFieldF2m.java
@@ -0,0 +1,67 @@
+package cz.crcs.ectester.common.ec;
+
+import java.math.BigInteger;
+import java.security.spec.ECFieldF2m;
+import java.util.Arrays;
+
+/**
+ * @author David Hofman
+ */
+public class CustomECFieldF2m extends ECFieldF2m {
+ private int m;
+ private int[] ks;
+ private BigInteger rp;
+
+ public CustomECFieldF2m(int m, int[] ks) {
+ //feed the constructor of the superclass some default, valid data
+ //getters will return custom parameters instead
+ super(163, new int[] {3, 2, 1});
+ this.m = m;
+ this.ks = ks.clone();
+
+ //causes ArithmeticException if m < 0 or any element of ks < 0
+ this.rp = BigInteger.ONE;
+ this.rp = this.rp.setBit(m);
+ for(int i = 0; i < this.ks.length; ++i) {
+ this.rp = this.rp.setBit(this.ks[i]);
+ }
+ }
+
+ @Override
+ public int getFieldSize() {
+ return m;
+ }
+
+ @Override
+ public int getM() {
+ return m;
+ }
+
+ @Override
+ public int[] getMidTermsOfReductionPolynomial() {
+ return ks.clone();
+ }
+
+ @Override
+ public BigInteger getReductionPolynomial() {
+ return rp;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ } else if (!(o instanceof CustomECFieldF2m)) {
+ return false;
+ } else {
+ return m == ((CustomECFieldF2m) o).m && Arrays.equals(ks, ((CustomECFieldF2m) o).ks);
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = m << 5;
+ hash += rp == null ? 0 : rp.hashCode();
+ return hash;
+ }
+}