-
Notifications
You must be signed in to change notification settings - Fork 55
/
BasicNumericContext.java
114 lines (101 loc) · 3.54 KB
/
BasicNumericContext.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package dk.alexandra.fresco.lib.field.integer;
import dk.alexandra.fresco.framework.builder.numeric.field.FieldDefinition;
import dk.alexandra.fresco.framework.util.ValidationUtils;
import java.math.BigInteger;
import java.util.Objects;
/**
* Holds the most crucial properties about the finite field we are working within.
*/
public class BasicNumericContext {
// TODO temporary hardcoded statistical security parameter
private static final int DEFAULT_STATISTICAL_SECURITY = 40;
private final int statisticalSecurityParam;
private final int maxBitLength;
private final int myId;
private final int noOfParties;
private final FieldDefinition fieldDefinition;
private final int defaultFixedPointPrecision;
/**
* Construct a new BasicNumericContext.
*
* @param maxBitLength The maximum length in bits that the numbers in the application will
* have.
* @param myId my party id
* @param noOfParties number of parties in computation
* @param fieldDefinition the field definition used in the application. Nullable.
* @param defaultFixedPointPrecision the fixed point precision when using the fixed point library
* @param statisticalSecurityParam the statistical security parameter
*/
public BasicNumericContext(int maxBitLength, int myId, int noOfParties,
FieldDefinition fieldDefinition, int defaultFixedPointPrecision, int statisticalSecurityParam) {
ValidationUtils.assertValidId(myId, noOfParties);
this.maxBitLength = maxBitLength;
this.myId = myId;
this.noOfParties = noOfParties;
this.fieldDefinition = fieldDefinition;
this.defaultFixedPointPrecision = defaultFixedPointPrecision;
this.statisticalSecurityParam = statisticalSecurityParam;
}
/**
* Construct a new BasicNumericContext.
*
* @param maxBitLength The maximum length in bits that the numbers in the application will
* have.
* @param myId my party id
* @param noOfParties number of parties in computation
* @param fieldDefinition the field definition used in the application
* @param defaultFixedPointPrecision the fixed point precision when using the fixed point library
*/
public BasicNumericContext(int maxBitLength, int myId, int noOfParties,
FieldDefinition fieldDefinition, int defaultFixedPointPrecision) {
this(maxBitLength, myId, noOfParties, fieldDefinition, defaultFixedPointPrecision,
DEFAULT_STATISTICAL_SECURITY);
}
/**
* Returns the maximum number of bits a number in the field can contain.
*/
public int getMaxBitLength() {
return this.maxBitLength;
}
/**
* Returns the field definition used in the underlying arithmetic protocol suite.
*
* @return The field definition used.
*/
public FieldDefinition getFieldDefinition() {
return fieldDefinition;
}
/**
* Returns the modulus used in the underlying arithmetic protocol suite.
*
* @return The modulus used.
*/
public BigInteger getModulus() {
return fieldDefinition.getModulus();
}
/**
* Returns the id of the party.
*/
public int getMyId() {
return myId;
}
/**
* Returns the number of players.
*/
public int getNoOfParties() {
return noOfParties;
}
/**
* Returns the fixed point precision used, e.g. the number of bits used to represent the fractional
* part of a fixed point number.
*/
public int getDefaultFixedPointPrecision() {
return defaultFixedPointPrecision;
}
/**
* Returns the statistical security parameter.
*/
public int getStatisticalSecurityParam() {
return this.statisticalSecurityParam;
}
}