1
1
package com .github .pvriel .oprf4j .nroprf .semihonest .KISS17 ;
2
2
3
+ import com .github .pvriel .mpcutils4j .stream .StreamUtils ;
3
4
import com .github .pvriel .oblivioustransfer4j .precomputed .PrecomputedObliviousTransferReceiver ;
4
- import com .github .pvriel .oblivioustransfer4j .utils .StreamUtils ;
5
5
import com .github .pvriel .oprf4j .nroprf .NROPRFEvaluator ;
6
6
import com .github .pvriel .oprf4j .precomputed .PrecomputedOPRFEvaluator ;
7
7
import org .apache .commons .lang3 .tuple .Triple ;
10
10
import java .io .InputStream ;
11
11
import java .io .OutputStream ;
12
12
import java .math .BigInteger ;
13
+ import java .util .stream .IntStream ;
13
14
14
15
/**
15
16
* Class representing the <a href="https://www.semanticscholar.org/paper/Private-Set-Intersection-for-Unequal-Set-Sizes-with-Kiss-Liu/ef148d510ce6fd445b73584a238f6244660efbe6">KISS17</a> variant of the
16
17
* {@link NROPRFEvaluator} protocol.
17
18
*/
18
- public class KISS17NROPRFEvaluator extends NROPRFEvaluator implements PrecomputedOPRFEvaluator <Triple <boolean [], BigInteger , Object >> {
19
+ public class KISS17NROPRFEvaluator extends NROPRFEvaluator implements PrecomputedOPRFEvaluator <Triple <boolean [], BigInteger [] , Object >> {
19
20
20
21
private final PrecomputedObliviousTransferReceiver <Object > precomputedObliviousTransferReceiver ;
21
22
private final int bitLengthRandomValues ;
@@ -31,6 +32,8 @@ public class KISS17NROPRFEvaluator extends NROPRFEvaluator implements Precompute
31
32
* The (not-null) prime number that is used for the group (the result of applying the PRF is always part of F_{p}).
32
33
* @param q
33
34
* The (not-null) prime number, for which q | p - 1 holds. This prime number is used to apply mod operations with the exponents.
35
+ * @param <T>
36
+ * The type of the elements that are used in the oblivious transfer.
34
37
*/
35
38
public <T > KISS17NROPRFEvaluator (int bitLengthRandomValues , PrecomputedObliviousTransferReceiver <T > precomputedObliviousTransferReceiver ,
36
39
BigInteger p , BigInteger q ) {
@@ -41,25 +44,31 @@ public <T> KISS17NROPRFEvaluator(int bitLengthRandomValues, PrecomputedOblivious
41
44
}
42
45
43
46
@ Override
44
- public Triple <boolean [], BigInteger , Object > executeOfflinePhase (BigInteger element , int bitLength , InputStream inputStream , OutputStream outputStream ) throws IOException {
45
- boolean [] choices = new boolean [bitLength ];
46
- for (int i = 0 ; i < bitLength ; i ++) choices [i ] = element .testBit (i );
47
+ public Triple <boolean [], BigInteger [] , Object > executeOfflinePhase (BigInteger [] elements , int bitLength , InputStream inputStream , OutputStream outputStream ) throws IOException {
48
+ boolean [] choices = new boolean [elements . length * bitLength ];
49
+ for (int i = 0 ; i < elements . length ; i ++) for ( int j = 0 ; j < bitLength ; j ++) choices [i * bitLength + j ] = elements [ i ] .testBit (j );
47
50
48
- BigInteger g_modded = StreamUtils .readBigIntegerFromInputStream (inputStream );
51
+ BigInteger [] g_modded = new BigInteger [elements .length ];
52
+ for (int i = 0 ; i < g_modded .length ; i ++) g_modded [i ] = StreamUtils .readBigIntegerFromInputStream (inputStream );
49
53
var resultOfflinePhaseOTs = precomputedObliviousTransferReceiver .executeOfflinePhase (choices , bitLengthRandomValues , inputStream , outputStream );
50
54
return Triple .of (choices , g_modded , resultOfflinePhaseOTs );
51
55
}
52
56
53
57
@ Override
54
- public BigInteger executeOnlinePhase (Triple <boolean [], BigInteger , Object > resultOfflinePhase , BigInteger element , int bitLength , InputStream inputStream , OutputStream outputStream ) throws IOException {
58
+ public BigInteger [] executeOnlinePhase (Triple <boolean [], BigInteger [] , Object > resultOfflinePhase , BigInteger [] elements , int bitLength , InputStream inputStream , OutputStream outputStream ) throws IOException {
55
59
boolean [] choices = resultOfflinePhase .getLeft ();
56
- BigInteger g_modded = resultOfflinePhase .getMiddle ();
60
+ BigInteger [] g_modded = resultOfflinePhase .getMiddle ();
57
61
Object resultOfflinePhaseOTs = resultOfflinePhase .getRight ();
58
62
59
63
BigInteger [] R_s = precomputedObliviousTransferReceiver .executeOnlinePhase (resultOfflinePhaseOTs , choices , bitLengthRandomValues , inputStream , outputStream );
60
64
61
- BigInteger exponent = BigInteger .ONE ;
62
- for (BigInteger r : R_s ) exponent = exponent .multiply (r ).mod (getQ ());
63
- return g_modded .modPow (exponent , getP ());
65
+ BigInteger [] result = new BigInteger [elements .length ];
66
+ IntStream .range (0 , elements .length ).parallel ().forEach (i -> {
67
+ BigInteger g_modded_i = g_modded [i ];
68
+ BigInteger exponent = BigInteger .ONE ;
69
+ for (int j = 0 ; j < bitLength ; j ++) exponent = exponent .multiply (R_s [i * bitLength + j ]).mod (getQ ());
70
+ result [i ] = g_modded_i .modPow (exponent , getP ());
71
+ });
72
+ return result ;
64
73
}
65
74
}
0 commit comments