Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spdz2k develop #398

Open
wants to merge 245 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
245 commits
Select commit Hold shift + click to select a range
9b98d43
Merge branch '266-mascot-input-mask-fix'
n1v0lg Apr 13, 2018
387283b
Arithmetic AND and XOR
n1v0lg Apr 16, 2018
9831b41
Make comps parallel
n1v0lg Apr 17, 2018
724aa64
Logical and and xor tests
n1v0lg Apr 17, 2018
80b8b5f
Stub for mod2m
n1v0lg Apr 17, 2018
a9976e3
Mod2m test skeleton
n1v0lg Apr 17, 2018
ae2f855
WIP precarry
n1v0lg Apr 17, 2018
c2205c7
Carry out tests
n1v0lg Apr 17, 2018
710dab2
Carry out cleanup
n1v0lg Apr 17, 2018
224be21
Actually use expected results
n1v0lg Apr 17, 2018
999cba1
More rigorous tests
n1v0lg Apr 17, 2018
0e78bc0
Methods don't need to be static
n1v0lg Apr 18, 2018
6fd3a8b
But they do..
n1v0lg Apr 18, 2018
3e61592
WIP BitLessThan
n1v0lg Apr 18, 2018
e8d3caa
Bit less than tests
n1v0lg Apr 18, 2018
8cf0b68
Updated sum to take DRes
n1v0lg Apr 18, 2018
4b6e15a
Use carry in in carry out and tests
n1v0lg Apr 18, 2018
2d5e878
More bit less than tests
n1v0lg Apr 19, 2018
16e73a0
Draft of mod2m
jot2re Apr 19, 2018
c68ed81
Truncate
n1v0lg Apr 19, 2018
3aa7983
Move inversion of two to big int helper
n1v0lg Apr 19, 2018
56b2cbf
Temporary dummy mod2m protocol
n1v0lg Apr 19, 2018
c8bd2dc
WIP truncate tests
n1v0lg Apr 19, 2018
fb71356
Add known(list) default to numeric
n1v0lg Apr 19, 2018
0e759d8
Update truncate description
n1v0lg Apr 19, 2018
30d4a4f
More work on truncate tests
n1v0lg Apr 19, 2018
d38d19f
Correct shift in expected result
n1v0lg Apr 19, 2018
1684023
Truncate -> LessThanZero
n1v0lg Apr 19, 2018
bcd91c8
Not working version of mod2m
jot2re Apr 19, 2018
147499a
Not working version of mod2m
jot2re Apr 19, 2018
0a45a71
Fixed carry test expected
n1v0lg Apr 19, 2018
30787ce
Use correct random bits in mod2m
n1v0lg Apr 19, 2018
96300ef
Fix less than zero protocol
n1v0lg Apr 19, 2018
a975a83
Added more mod2m tests
jot2re Apr 19, 2018
62f0816
Merge branch 'spdz2k-less-than' of https://github.com/aicis/fresco in…
jot2re Apr 19, 2018
d07cc45
Added a few more mod2m tests
jot2re Apr 19, 2018
9daf852
Clean up pre carry and fix test
n1v0lg Apr 19, 2018
27e6712
Remove dummy mod2m protocol
n1v0lg Apr 19, 2018
e7e3bfe
Less than protocol
n1v0lg Apr 20, 2018
7d9f9ca
Add less than test to spdz suite
n1v0lg Apr 20, 2018
d682f3a
Clean up carry out
n1v0lg Apr 20, 2018
d127207
TODO note
n1v0lg Apr 23, 2018
392c3dc
More todos
n1v0lg Apr 23, 2018
4c2c67b
OInt and factory
n1v0lg Apr 23, 2018
510ccdf
Add oint factory to numeric resource pool
n1v0lg Apr 23, 2018
510e760
Move oint factory to factory numeric
n1v0lg Apr 23, 2018
77ca5b6
Add oint arithmetic
n1v0lg Apr 23, 2018
097e6e6
Add oint methods to numeric comp dir
n1v0lg Apr 23, 2018
3fd6828
Update spdz and spdz2k builders
n1v0lg Apr 23, 2018
377a7d3
Use oint big int wrapper class
n1v0lg Apr 23, 2018
cea5eb9
Add constants to oint factory
n1v0lg Apr 23, 2018
cfb1438
Minor changes mod2m
n1v0lg Apr 23, 2018
c79a88c
Fix comment
n1v0lg Apr 23, 2018
b4e2d5e
Add oints to spdz2k
n1v0lg Apr 23, 2018
6a93830
Remove generic compuint
n1v0lg Apr 23, 2018
8766a34
WIP bit less than spdz2k
n1v0lg Apr 23, 2018
adc842f
Remove unused class
n1v0lg Apr 23, 2018
4b67c25
Naive compuint arithmetic
n1v0lg Apr 23, 2018
e4f7c37
OInt numeric calls spdz2k
n1v0lg Apr 23, 2018
91b4cec
Move all casts to factory
n1v0lg Apr 23, 2018
0c8a45e
uin128 testbit
n1v0lg Apr 23, 2018
ed04c05
Another testBit test
n1v0lg Apr 23, 2018
c500604
Work on advanced numeric
n1v0lg Apr 24, 2018
1a49cf8
Corrected inner prod and random bit mask protocols
n1v0lg Apr 24, 2018
3504920
Two powers list
n1v0lg Apr 24, 2018
7a0fc33
Random bit mask test
n1v0lg Apr 24, 2018
f4cfff2
Spdz2k random bit mask
n1v0lg Apr 24, 2018
1f132a6
WIP spdz2k most sig bit
n1v0lg Apr 24, 2018
902f380
More work on spdz2k most sign bit
n1v0lg Apr 24, 2018
3a149d4
Spdzk2 comparison comp dir
n1v0lg Apr 24, 2018
6f96a92
Failing comparison tests
n1v0lg Apr 24, 2018
d782aa9
Correct power in tests
n1v0lg Apr 24, 2018
3c8cd6c
Correctly handle negative values in comp uint
n1v0lg Apr 24, 2018
09e5373
More negative const tests
n1v0lg Apr 24, 2018
fffbc2b
Fix up compuin96
n1v0lg Apr 24, 2018
d763453
Run less than test for compuint96
n1v0lg Apr 24, 2018
3cbc65a
Fix up output protocols
n1v0lg Apr 24, 2018
c584125
Typo
n1v0lg Apr 25, 2018
88e220e
Remove big int references
n1v0lg Apr 25, 2018
aca095f
WIP clear above bit
n1v0lg Apr 25, 2018
920a1e3
Add clear bit tests 128
n1v0lg Apr 25, 2018
3b4b18d
uint96 clear above
n1v0lg Apr 26, 2018
e4f4969
Logical comp directory
n1v0lg Apr 26, 2018
6e65e85
Update known and/ xor tests
n1v0lg Apr 26, 2018
4cc20c5
Stray sout
n1v0lg Apr 26, 2018
0d27cee
WIP use logical ops in bit less than
n1v0lg Apr 26, 2018
3e1f2cc
Missing open as oint methods
n1v0lg Apr 26, 2018
83feebb
Fix comment
n1v0lg Apr 26, 2018
060e504
Add xor/ and on lists to logical builder
n1v0lg Apr 26, 2018
c4ac8fa
Add or of list stub
n1v0lg Apr 26, 2018
49f84cb
Moved logical tests to a logical place
n1v0lg Apr 26, 2018
2b41ddc
Refactored mod2m and added modulus operations to opened values
jot2re Apr 26, 2018
146f70b
More logical ops and tests
n1v0lg Apr 26, 2018
731255d
Merge branch 'spdz2k-less-than' of https://github.com/aicis/fresco in…
n1v0lg Apr 26, 2018
4b700af
Add logical op tests to spdz2k
n1v0lg Apr 26, 2018
eac970e
Implemented draft of EQZ from Peters thesis
jot2re Apr 26, 2018
ca7fab3
Implemented draft of OR protocol
jot2re Apr 30, 2018
ed79629
Fixed merge conflict
jot2re Apr 30, 2018
ec17316
WIP spdz2k boolean mode
n1v0lg Apr 30, 2018
f7d8e27
Merge branch 'spdz2k-less-than' of https://github.com/aicis/fresco in…
jot2re Apr 30, 2018
d5eaef2
Add bit comparison to comp dir
n1v0lg Apr 30, 2018
0a449f0
Add conversion comp dir
n1v0lg Apr 30, 2018
24d800f
Separate arithmetic and boolean spdz2ksints
n1v0lg Apr 30, 2018
773f97e
Add serialization methods to spdz2ksint
n1v0lg Apr 30, 2018
0e100b8
Use serialization methods in native protocols
n1v0lg Apr 30, 2018
f7d827f
WIP conversion
n1v0lg Apr 30, 2018
cee83b0
More work on conversion
n1v0lg Apr 30, 2018
a637692
Fix open values in dummy protocol suite
n1v0lg Apr 30, 2018
726c693
Partial implementation of list or
jot2re Apr 30, 2018
74fa590
Open as bit
n1v0lg Apr 30, 2018
9aa49df
WIP and protocol
n1v0lg Apr 30, 2018
044885d
Fixed list OR
jot2re Apr 30, 2018
a507ca0
Merge branch 'spdz2k-less-than' of https://github.com/aicis/fresco in…
jot2re Apr 30, 2018
c5a2a6c
Broken and protocol
n1v0lg Apr 30, 2018
b2945a3
Merge branch 'spdz2k-less-than' of https://github.com/aicis/fresco in…
n1v0lg Apr 30, 2018
25ad731
No mac-check for debugging
n1v0lg Apr 30, 2018
fe754ba
Draft of new equality
jot2re May 1, 2018
d2d4a67
WIP comuin128but
n1v0lg May 1, 2018
318c637
Merge branch 'spdz2k-less-than' of https://github.com/aicis/fresco in…
n1v0lg May 1, 2018
bc30b15
Semi-working zero test
n1v0lg May 1, 2018
8214770
Work on bit rep of uint
n1v0lg May 1, 2018
5e9fb05
Cleaned up a bit of equality
jot2re May 1, 2018
426fd43
Cleaned a bit of equality code
jot2re May 2, 2018
ded9fef
Fixed equality code bug
jot2re May 2, 2018
3a6311e
65-bit mult
n1v0lg May 3, 2018
a59419a
Addition
n1v0lg May 3, 2018
3c1ab88
Subtraction
n1v0lg May 3, 2018
2a77246
Restructure serialization
n1v0lg May 3, 2018
198e5a9
Refactored DefaultComparison and moved location of statistical securi…
jot2re May 3, 2018
a15bd86
And/ xor tests passing
n1v0lg May 5, 2018
acaf31d
Merge branch 'spdz2k-less-than' of https://github.com/aicis/fresco in…
n1v0lg May 5, 2018
b4def96
Spdz2k or
n1v0lg May 7, 2018
649688f
Fix incorrect close list in default collections
n1v0lg May 7, 2018
4ebd1dd
Carry out all-boolean
n1v0lg May 7, 2018
69be670
Remove unused
n1v0lg May 7, 2018
5269b16
Bit less than tests
n1v0lg May 7, 2018
7c0c19a
Less than boolean mode
n1v0lg May 7, 2018
2fc4c03
Clean up and protocol
n1v0lg May 8, 2018
9c03871
Boolean conversion as native protocol
n1v0lg May 8, 2018
ae3fd44
And known native
n1v0lg May 9, 2018
c5b0f21
Use half or in pre-carry
n1v0lg May 9, 2018
0546566
Rewrite pre-carry as while-loop
n1v0lg May 9, 2018
cf36d48
Optimize pre-carry
n1v0lg May 9, 2018
41fdeb7
Remove unnecessary reverse ops
n1v0lg May 9, 2018
501760f
WIP clean up compuin128bit
n1v0lg May 9, 2018
fccce1d
Remove subtraction and negation
n1v0lg May 9, 2018
ce4b3af
To bit rep conversion
n1v0lg May 9, 2018
0c47f64
Update conversion
n1v0lg May 9, 2018
fd03502
Native mult by public
n1v0lg May 9, 2018
b4a8185
test bit as uint
n1v0lg May 9, 2018
03c61d8
Cleaner toBits
n1v0lg May 9, 2018
5e5b404
DRes<OInt> -> OInt where it makes sense
n1v0lg May 9, 2018
b8c6b48
Zero test spdz2k
n1v0lg May 9, 2018
2fc7de4
Boolean to arithmetic conversion
n1v0lg May 10, 2018
c4d21bb
Add comment to conversion
n1v0lg May 10, 2018
4deaaab
Spdz2k equality tests and fixes
n1v0lg May 11, 2018
ae38fdc
Stray sout
n1v0lg May 11, 2018
b91dcf2
Fix comments in comparison
n1v0lg May 11, 2018
e91f6f9
Use native protocol in output
n1v0lg May 11, 2018
886ebc6
Native or protocol
n1v0lg May 11, 2018
cd5bad8
Remove uint96
n1v0lg May 15, 2018
7da613a
WIP left shift
n1v0lg May 17, 2018
b06ab0c
Small left shift
n1v0lg May 17, 2018
2a2bca5
Use left shift in conversion
n1v0lg May 17, 2018
c77afa2
Or instead of add
n1v0lg May 17, 2018
4d58fb0
Small right shift
n1v0lg May 17, 2018
80b11f8
Truncation pairs
n1v0lg Jun 15, 2018
0193926
WIP spdz2k truncation
n1v0lg Jun 15, 2018
15e16c2
Renaming
n1v0lg Jun 17, 2018
f1762a7
Spdz2k truncation fix
n1v0lg Jun 17, 2018
0320169
Right shift low tests
n1v0lg Jun 17, 2018
9406bff
Merge branch 'master' into spdz2k-develop
n1v0lg Jun 17, 2018
8ffbbe2
WIP non-floating fixed point arithmetic
n1v0lg Jun 18, 2018
f53dd1f
Fixed point mult
n1v0lg Jun 18, 2018
28abdd6
WIP fixed point mult w/o decimals tests
n1v0lg Jun 18, 2018
e4e6c73
Some fixed point mult tests
n1v0lg Jun 19, 2018
230068f
Big by small number
n1v0lg Jun 19, 2018
8c53dca
Missing fixed point methods
n1v0lg Jun 19, 2018
84358d3
Truncate in mult by open
n1v0lg Jun 19, 2018
147cf23
Ignore div-based tests for now
n1v0lg Jun 19, 2018
b1b8139
Impl fromSInt
n1v0lg Jun 19, 2018
3457ee9
Add real numeric context to spdz2k
n1v0lg Jun 19, 2018
13b88a2
Simple real arithmetic tests for spdz2k
n1v0lg Jun 19, 2018
8f55f45
Only run simple eq test with mascot
n1v0lg Jun 19, 2018
c542dbb
Generify pre-processing based truncation
n1v0lg Jun 19, 2018
507e907
Remove unused spdz2k truncation class
n1v0lg Jun 19, 2018
b26766f
Add dummy trunc pair generation
n1v0lg Jun 19, 2018
f2cbb50
Spdz truncation pair dummy pre-processing
n1v0lg Jun 19, 2018
2f7f9aa
Remove failing test for now
n1v0lg Jun 20, 2018
3e7f891
Oblivious selection
n1v0lg Jun 20, 2018
a9d7e99
Also export test jar
n1v0lg Aug 20, 2018
5763724
Logical arithmetic hack
n1v0lg Aug 20, 2018
3cfc167
Additional arithmetic and uint fixes
n1v0lg Aug 28, 2018
c17f6f9
Separate two party input protocol
n1v0lg Aug 28, 2018
34f8c71
Update dummy suite logging tests
n1v0lg Aug 28, 2018
57d0e0b
Temp fix another bit length mess
n1v0lg Aug 28, 2018
fc073bc
Another fix
n1v0lg Aug 28, 2018
2286bef
Batched bit ops
n1v0lg Aug 28, 2018
b203e84
WIP optimizing pre-carry bits
n1v0lg Aug 29, 2018
ac16728
More work on carry
n1v0lg Aug 29, 2018
37684b2
Remove old file
n1v0lg Aug 29, 2018
8914103
Pack bits
n1v0lg Aug 30, 2018
a0e3e4c
Minor fixes
n1v0lg Aug 30, 2018
69b5cf4
Merging
n1v0lg Aug 31, 2018
f64054e
Fix up some lambdas
n1v0lg Aug 31, 2018
d541c69
comp uint 64
n1v0lg Sep 3, 2018
ec17e53
64 spdz2k suite
n1v0lg Sep 3, 2018
f4369be
Update mult by bit 128
n1v0lg Sep 3, 2018
0c1248e
Bit version 64
n1v0lg Sep 3, 2018
2a95b98
Boolean mode
n1v0lg Sep 3, 2018
d774def
Random sysouts
n1v0lg Sep 3, 2018
234020a
Configurable stats security and different batches
n1v0lg Sep 12, 2018
b32db24
Clean up zero test
n1v0lg Sep 12, 2018
ac988d1
Batched or in spdz2k
n1v0lg Sep 12, 2018
df0084a
Clean up or of list
n1v0lg Sep 13, 2018
5be4b0d
Handle large packets in betch deco
n1v0lg Sep 17, 2018
4549ca8
Include comparison between neg and pos
n1v0lg Sep 18, 2018
451c50a
Remove unnecessary broadcast validation steps
n1v0lg Sep 18, 2018
8c8523e
Updated argmin
n1v0lg Sep 19, 2018
af60250
Cache powers of two
n1v0lg Sep 19, 2018
1bcb178
Updated spdz2k input
n1v0lg Sep 20, 2018
ea85055
Missing file
n1v0lg Sep 20, 2018
bb1bc57
Faster spdz2k input
n1v0lg Sep 20, 2018
265ad1d
Re-arrange mod2m protocol
n1v0lg Sep 26, 2018
a6de58f
Replace xor with halfOr
n1v0lg Sep 26, 2018
5a4ac9d
Batched operations in carry
n1v0lg Jan 11, 2019
3edb84b
Remove unused classes
n1v0lg Jan 11, 2019
04b2025
Don't used batched local ops
n1v0lg Jan 11, 2019
5415905
Spdz batched AND
n1v0lg Jan 12, 2019
94252a0
SPDZ batched OR and tests
n1v0lg Jan 15, 2019
7f14701
Merge master
n1v0lg Jan 15, 2019
804c23a
Fix off by one
n1v0lg Jan 17, 2019
eae10eb
Bring back batched local ops
n1v0lg Jan 17, 2019
b3c54e7
SPDZ batched not
n1v0lg Jan 17, 2019
63031fe
SPDZ batched XOR
n1v0lg Jan 17, 2019
12f1fcd
Batched known AND
n1v0lg Jan 17, 2019
df548d5
Various opts
n1v0lg Jan 18, 2019
8863b23
Minor
n1v0lg Jan 18, 2019
9b94a09
Fix bit length errors
n1v0lg Jan 21, 2019
2a51522
SPDZ carry
n1v0lg Jan 21, 2019
667c108
Improved serialization SPDZ
n1v0lg Jan 21, 2019
7f002cc
Native OrList
n1v0lg Jan 21, 2019
2164502
Temp
n1v0lg Jan 25, 2019
dec95c7
Fix dummy supplier test
n1v0lg Mar 11, 2019
21864ed
Added support for spdz2k in commandline utility for demos
jot2re Sep 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Commitment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import dk.alexandra.fresco.framework.DRes;
import dk.alexandra.fresco.framework.builder.ComputationDirectory;
import dk.alexandra.fresco.framework.util.Pair;
import dk.alexandra.fresco.framework.value.OInt;
import dk.alexandra.fresco.framework.value.SInt;
import dk.alexandra.fresco.lib.math.integer.binary.RandomBitMask;

import java.math.BigInteger;
import java.util.List;

Expand All @@ -16,16 +19,27 @@ public interface AdvancedNumeric extends ComputationDirectory {
* Calculates the sum of all elements in the list.
*
* @param elements the elements to sum
* @return A deferred result computing the sum of the elements
* @return A deferred result computing the sum of the elements inputs should be wrapped in {@link
* DRes}, use {@link #sum(DRes)} instead
*/
@Deprecated
DRes<SInt> sum(List<DRes<SInt>> elements);

/**
* Calculates the sum of all elements in the list.
*
* @param elements the elements to sum
* @return A deferred result computing the sum of the elements
*/
DRes<SInt> sum(DRes<List<DRes<SInt>>> elements);

/**
* Calculates the product of all elements in the list.
*
* @param elements the elements to sum
* @return A deferred result computing the product of the elements
*/
@Deprecated
DRes<SInt> product(List<DRes<SInt>> elements);

/**
Expand Down Expand Up @@ -67,7 +81,7 @@ public interface AdvancedNumeric extends ComputationDirectory {
DRes<List<SInt>> toBits(DRes<SInt> in, int maxInputLength);

/**
* Computes the exponentiation of x^e.
* Computes the exponentiation of x^e
*
* @param x The base
* @param e The exponent
Expand All @@ -77,7 +91,7 @@ public interface AdvancedNumeric extends ComputationDirectory {
DRes<SInt> exp(DRes<SInt> x, DRes<SInt> e, int maxExponentLength);

/**
* Computes the exponentiation of x^e.
* Computes the exponentiation of x^e
*
* @param x The base
* @param e The exponent
Expand All @@ -96,8 +110,6 @@ public interface AdvancedNumeric extends ComputationDirectory {
DRes<SInt> exp(DRes<SInt> x, BigInteger e);

/**
* Calculating the square root of a given input.
*
* @param input The input.
* @param maxInputLength An upper bound for <i>log<sub>2</sub>(input)</i>.
* @return A deferred result computing an approximation of the square root of the input.
Expand All @@ -119,7 +131,9 @@ public interface AdvancedNumeric extends ComputationDirectory {
* @param vectorA The first vector
* @param vectorB The second vector
* @return A deferred result computing the inner product of the two given vectors
* @deprecated inputs should be wrapped in {@link DRes}
*/
@Deprecated
DRes<SInt> innerProduct(List<DRes<SInt>> vectorA, List<DRes<SInt>> vectorB);

/**
Expand All @@ -128,55 +142,101 @@ public interface AdvancedNumeric extends ComputationDirectory {
* @param vectorA The public vector
* @param vectorB The secret vector
* @return A deferred result computing the inner product of the two given vectors
* @deprecated inputs should be wrapped in {@link DRes}, use {@link #innerProductWithPublicPart(DRes,
* DRes)} instead
*/
@Deprecated()
DRes<SInt> innerProductWithPublicPart(List<BigInteger> vectorA, List<DRes<SInt>> vectorB);

/**
* Computes the inner product between a public vector and a secret vector.
*
* @param vectorA The public vector
* @param vectorB The secret vector
* @return A deferred result computing the inner product of the two given vectors
*/
DRes<SInt> innerProductWithPublicPart(DRes<List<OInt>> vectorA,
DRes<List<DRes<SInt>>> vectorB);

/**
* Creates a string of random bits.
*
* @param noOfBits The amount of bits to create - i.e. the bit string length.
* @return A container holding the bit string once evaluated.
* @deprecated use {@link #randomBitMask(int)} instead
*/
@Deprecated
DRes<RandomAdditiveMask> additiveMask(int noOfBits);

/**
* Calculating the result of right shifting of the input by one.
* Creates a random bit mask [b0, ..., bn] along with an {@link SInt} representing the recombined
* bits, i.e., sum(2^{i} * bi).
*
* @param noOfBits The amount of bits
* @return A container holding the bit string once evaluated.
*/
DRes<RandomBitMask> randomBitMask(int noOfBits);

/**
* Takes a list of random bits [b0, ..., bn] and generates a random bit mask along with a {@link
* SInt} representing the recombined bits, i.e., sum(2^{i} * bi).
*
* @param randomBits The bits to use for the bit mask
* @return A container holding the bit mask
*/
DRes<RandomBitMask> randomBitMask(DRes<List<DRes<SInt>>> randomBits);

/**
* Right-shifts input by {@code shifts}. <p>Note that this is a probabilistic method which may
* produce an error in the least-significant bit.</p>
*
* @param input secret value to right shift
* @param shifts number of shifts
* @param useTruncationPairs indicates whether truncation pairs are available as part of
* pre-processing material (this allows for a faster protocol)
* @return shifted result
*/
DRes<SInt> truncate(DRes<SInt> input, int shifts, boolean useTruncationPairs);

default DRes<SInt> truncate(DRes<SInt> input, int shifts) {
return truncate(input, shifts, true);
}

/**
* Creates truncation pair ({@link TruncationPair}). <p>This method may rely on pre-processed
* material in which case it should be overridden by backend suits.</p>
*
* @param d number of shifts in truncation pair
*/
DRes<TruncationPair> generateTruncationPair(int d);

/**
* @param input input.
* @return A deferred result computing input >> 1
*/
DRes<SInt> rightShift(DRes<SInt> input);

/**
* Calculating the result of right shifting of the input by a given amount.
*
* @param input input.
* @param shifts Number of shifts
* @return A deferred result computing input >> shifts
*/
DRes<SInt> rightShift(DRes<SInt> input, int shifts);

/**
* Calculating the result of right shifting of the input by one, including the remainder.
*
* @param input input
* @return A deferred result computing<br>
* result: input >> 1<br>
* remainder: The <code>shifts</code> least significant bits of the input with the least
* significant having index 0.
* @return A deferred result computing<br> result: input >> 1<br> remainder: The
* <code>shifts</code> least significant bits of the input with the least significant having index
* 0.
*/
DRes<RightShiftResult> rightShiftWithRemainder(DRes<SInt> input);

/**
* Calculating the result of right shifting of the input by a given amount, including the
* remainder.
*
* @param input input
* @param shifts Number of shifts
* @return A deferred result computing <br>
* result: input >> shifts<br>
* remainder: The <code>shifts</code> least significant bits of the input with the least
* significant having index 0.
* @return A deferred result computing <br> result: input >> shifts<br> remainder: The
* <code>shifts</code> least significant bits of the input with the least significant having index
* 0.
*/
DRes<RightShiftResult> rightShiftWithRemainder(DRes<SInt> input, int shifts);

Expand All @@ -185,13 +245,13 @@ public interface AdvancedNumeric extends ComputationDirectory {
*
* @param input The number to know the bit length of
* @param maxBitLength The maximum bit length this number can have (if unknown, set this to the
* modulus bit size)
* modulus bit size)
* @return A deferred result computing the bit length of the input number.
*/
DRes<SInt> bitLength(DRes<SInt> input, int maxBitLength);

/**
* Compute the inverse of x within the field of operation.
* Compute the inverse of x within the field of operation
*
* @param x The element to take the inverse of
* @return A deferred result computing x^-1 mod p where p is the modulus of the field.
Expand All @@ -202,7 +262,7 @@ public interface AdvancedNumeric extends ComputationDirectory {
* Selects left or right based on condition.
*
* @param condition the Computation holding the condition on which to select. Must be either 0 or
* 1.
* 1.
* @param left the Computation holding the left argument.
* @param right the Computation holding the right argument.
* @return a computation holding either left or right depending on the condition.
Expand All @@ -217,7 +277,7 @@ public interface AdvancedNumeric extends ComputationDirectory {
* @param left The left argument
* @param right The right argument
* @return A deferred result computing a pair containing [left, right] if the condition is 0 and
* [right, left] if condition is 1.
* [right, left] if condition is 1.
*/
DRes<Pair<DRes<SInt>, DRes<SInt>>> swapIf(DRes<SInt> condition, DRes<SInt> left,
DRes<SInt> right);
Expand Down Expand Up @@ -246,7 +306,10 @@ public SInt getRemainder() {

/**
* Container holding a random bitvector and its SInt representation.
*
* @deprecated values should be wrapped in DRes, use {@link RandomBitMask} instead
*/
@Deprecated
class RandomAdditiveMask {

public final List<DRes<SInt>> bits;
Expand All @@ -257,4 +320,32 @@ public RandomAdditiveMask(List<DRes<SInt>> bits, SInt random) {
this.random = random;
}
}

/**
* Generic representation of a truncation pair. <p> A truncation pair is pre-processing material
* used for probabilistic truncation. A truncation pair consists of a value r and r^{prime} such
* that r^{prime} is a random element and r = r^{prime} / 2^{d}, i.e., r right-shifted by d.</p>
*/
class TruncationPair {

private final DRes<SInt> rPrime;
private final DRes<SInt> r;

public TruncationPair(
DRes<SInt> rPrime,
DRes<SInt> r) {
this.rPrime = rPrime;
this.r = r;
}

public DRes<SInt> getRPrime() {
return rPrime;
}

public DRes<SInt> getR() {
return r;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@

import dk.alexandra.fresco.framework.BuilderFactory;
import dk.alexandra.fresco.framework.builder.ComputationDirectory;
import dk.alexandra.fresco.framework.value.OIntArithmetic;
import dk.alexandra.fresco.framework.value.OIntFactory;
import dk.alexandra.fresco.lib.compare.MiscBigIntegerGenerators;
import dk.alexandra.fresco.lib.field.integer.BasicNumericContext;
import dk.alexandra.fresco.lib.real.AdvancedRealNumeric;
import dk.alexandra.fresco.lib.real.RealLinearAlgebra;
import dk.alexandra.fresco.lib.real.RealNumeric;
import dk.alexandra.fresco.lib.real.RealNumericContext;
import dk.alexandra.fresco.lib.real.fixed.AdvancedFixedNumeric;
import dk.alexandra.fresco.lib.real.fixed.DefaultFixedNumeric;
import dk.alexandra.fresco.lib.real.fixed.FixedLinearAlgebra;
import dk.alexandra.fresco.lib.real.fixed.FixedNumeric;

/**
* The core factory to implement when creating a numeric protocol. Every
* {@link ComputationDirectory} found in this factory will
* append the produced protocols to the supplied builder. Implementors must provide
* a {@link Numeric} - being directory for
* <ul>
* <li>simple, numeric operations (+, -, *)</li>
* <li>Open operations for opening a small subset of values used in the control flow (is a<b)<</li>
* <li>Factories for producing secret shared values</li>
* </ul>
* The core factory to implement when creating a numeric protocol. Every {@link
* ComputationDirectory} found in this factory will append the produced protocols to the supplied
* builder. Implementors must provide a {@link Numeric} - being directory for <ul> <li>simple,
* numeric operations (+, -, *)</li> <li>Open operations for opening a small subset of values used
* in the control flow (is a<b)<</li> <li>Factories for producing secret shared values</li> </ul>
* The other directories have defaults, based on the raw methods, but can be overridden if the
* particular protocol suite has a more efficient way of e.g. comparing two numbers than a generic
* approach would have.
Expand All @@ -31,31 +29,44 @@ public interface BuilderFactoryNumeric extends BuilderFactory<ProtocolBuilderNum
BasicNumericContext getBasicNumericContext();

RealNumericContext getRealNumericContext();

Numeric createNumeric(ProtocolBuilderNumeric builder);

Conversion createConversion(ProtocolBuilderNumeric builder);

MiscBigIntegerGenerators getBigIntegerHelper();

/**
* Returns the backend-specific implementation of {@link OIntFactory}, for converting between
* backend-suite representations of open values and native data types.
*/
OIntFactory getOIntFactory();

/**
* Returns the backend-specific implementation of open value arithmetic helper.
*/
OIntArithmetic getOIntArithmetic();

default Comparison createComparison(ProtocolBuilderNumeric builder) {
return new DefaultComparison(this, builder);
}

default AdvancedNumeric createAdvancedNumeric(ProtocolBuilderNumeric builder) {
return new DefaultAdvancedNumeric(this, builder);
}

default Collections createCollections(ProtocolBuilderNumeric builder) {
return new DefaultCollections(builder);
}

default PreprocessedValues createPreprocessedValues(ProtocolBuilderNumeric builder) {
return new DefaultPreprocessedValues(builder);
}

default RealNumeric createRealNumeric(ProtocolBuilderNumeric builder) {
return new FixedNumeric(builder);
return new DefaultFixedNumeric(builder);
}

default AdvancedRealNumeric createAdvancedRealNumeric(ProtocolBuilderNumeric builder) {
return new AdvancedFixedNumeric(builder);
}
Expand All @@ -64,7 +75,17 @@ default RealLinearAlgebra createRealLinearAlgebra(ProtocolBuilderNumeric builder
return new FixedLinearAlgebra(builder);
}


default Logical createLogical(ProtocolBuilderNumeric builder) {
return new DefaultLogical(builder);
}

// TODO this is a hack to enable logical operations over arithmetic values in Spdz2k.
// we need a way of gracefully handling protocol suites that support both arithmetic and boolean
// operations
default Logical createLogicalArithmetic(ProtocolBuilderNumeric builder) {
return new DefaultLogical(builder);
}

/**
* Returns a builder which can be helpful while developing a new protocol. Be very careful though,
* to include this in any production code since the debugging opens values to all parties.
Expand Down