Skip to content

Commit 62dee58

Browse files
authored
Merge pull request #50 from tls-attacker/tls-testsuite
Testsuite Branch
2 parents e908817 + f90a9bc commit 62dee58

File tree

6 files changed

+96
-1
lines changed

6 files changed

+96
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ buildNumber.properties
99
.mvn/timing.properties
1010
/nbproject/
1111
*.idea/
12-
ModifiableVariable.iml
12+
ModifiableVariable.iml

src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import de.rub.nds.modifiablevariable.biginteger.BigIntegerAddModification;
1313
import de.rub.nds.modifiablevariable.biginteger.BigIntegerExplicitValueModification;
1414
import de.rub.nds.modifiablevariable.biginteger.BigIntegerInteractiveModification;
15+
import de.rub.nds.modifiablevariable.biginteger.BigIntegerMultiplyModification;
1516
import de.rub.nds.modifiablevariable.biginteger.BigIntegerShiftLeftModification;
1617
import de.rub.nds.modifiablevariable.biginteger.BigIntegerShiftRightModification;
1718
import de.rub.nds.modifiablevariable.biginteger.BigIntegerSubtractModification;
@@ -73,6 +74,7 @@ public abstract class ModifiableVariable<E> implements Serializable {
7374
@XmlElement(type = BigIntegerExplicitValueModification.class, name = "BigIntegerExplicitValueModification"),
7475
@XmlElement(type = BigIntegerAddModification.class, name = "BigIntegerAddModification"),
7576
@XmlElement(type = BigIntegerInteractiveModification.class, name = "BigIntegerInteractiveModification"),
77+
@XmlElement(type = BigIntegerMultiplyModification.class, name = "BigIntegerMultiplyModification"),
7678
@XmlElement(type = BooleanToggleModification.class, name = "BooleanToggleModification"),
7779
@XmlElement(type = BooleanExplicitValueModification.class, name = "BooleanExplicitValueModification"),
7880
@XmlElement(type = ByteArrayXorModification.class, name = "ByteArrayXorModification"),

src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ public static BigIntegerShiftRightModification shiftRight(final Integer shift) {
5858
return new BigIntegerShiftRightModification(shift);
5959
}
6060

61+
public static BigIntegerMultiplyModification multiply(final BigInteger factor) {
62+
return new BigIntegerMultiplyModification(factor);
63+
}
64+
6165
public static VariableModification<BigInteger> sub(final String subtrahend) {
6266
return sub(new BigInteger(subtrahend));
6367
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* ModifiableVariable - A Variable Concept for Runtime Modifications
3+
*
4+
* Copyright 2014-2017 Ruhr University Bochum / Hackmanit GmbH
5+
*
6+
* Licensed under Apache License 2.0
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*/
9+
10+
package de.rub.nds.modifiablevariable.biginteger;
11+
12+
import de.rub.nds.modifiablevariable.VariableModification;
13+
import java.math.BigInteger;
14+
import java.util.Objects;
15+
import java.util.Random;
16+
import javax.xml.bind.annotation.XmlAccessType;
17+
import javax.xml.bind.annotation.XmlAccessorType;
18+
import javax.xml.bind.annotation.XmlRootElement;
19+
import javax.xml.bind.annotation.XmlType;
20+
21+
@XmlRootElement
22+
@XmlType(propOrder = { "factor", "modificationFilter" })
23+
@XmlAccessorType(XmlAccessType.FIELD)
24+
public class BigIntegerMultiplyModification extends VariableModification<BigInteger> {
25+
26+
private final static int MAX_FACTOR_LENGTH = 8;
27+
28+
private BigInteger factor;
29+
30+
public BigIntegerMultiplyModification() {
31+
32+
}
33+
34+
public BigIntegerMultiplyModification(BigInteger bi) {
35+
this.factor = bi;
36+
}
37+
38+
@Override
39+
protected BigInteger modifyImplementationHook(BigInteger input) {
40+
if (input == null) {
41+
input = BigInteger.ZERO;
42+
}
43+
return input.multiply(factor);
44+
}
45+
46+
public BigInteger getFactor() {
47+
return factor;
48+
}
49+
50+
public void setFactor(BigInteger factor) {
51+
this.factor = factor;
52+
}
53+
54+
@Override
55+
public VariableModification<BigInteger> getModifiedCopy() {
56+
return new BigIntegerMultiplyModification(factor.add(new BigInteger(MAX_FACTOR_LENGTH, new Random())));
57+
}
58+
59+
@Override
60+
public int hashCode() {
61+
int hash = 5;
62+
hash = 61 * hash + Objects.hashCode(this.factor);
63+
return hash;
64+
}
65+
66+
@Override
67+
public boolean equals(Object obj) {
68+
if (this == obj) {
69+
return true;
70+
}
71+
if (obj == null) {
72+
return false;
73+
}
74+
if (getClass() != obj.getClass()) {
75+
return false;
76+
}
77+
final BigIntegerMultiplyModification other = (BigIntegerMultiplyModification) obj;
78+
if (!Objects.equals(this.factor, other.factor)) {
79+
return false;
80+
}
81+
return true;
82+
}
83+
}

src/main/java/de/rub/nds/modifiablevariable/util/ArrayConverter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ public static void makeArrayNonZero(final byte[] array) {
276276
public static byte[] bigIntegerToByteArray(BigInteger value, int blockSize, boolean removeSignByte) {
277277
if (blockSize == 0) {
278278
return new byte[0];
279+
} else if (value.equals(BigInteger.ZERO)) {
280+
return new byte[blockSize];
279281
}
280282
byte[] array = value.toByteArray();
281283
int remainder = array.length % blockSize;

src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ public static ModifiableBigInteger shiftRightBigInteger(Integer i) {
178178
return getModifiableBigIntegerWithModification(BigIntegerModificationFactory.shiftRight(i));
179179
}
180180

181+
public static ModifiableBigInteger multiplyBigInteger(BigInteger i) {
182+
return getModifiableBigIntegerWithModification(BigIntegerModificationFactory.multiply(i));
183+
}
184+
181185
public static ModifiableInteger shiftRight(Integer i) {
182186
return getModifiableIntegerWithModification(IntegerModificationFactory.shiftRight(i));
183187
}

0 commit comments

Comments
 (0)