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

Mascot preprocessing #214

Merged
merged 527 commits into from
Jan 25, 2018
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
527 commits
Select commit Hold shift + click to select a range
475d7e6
Merging fun
n1v0lg Dec 21, 2017
ef1ae3b
Use new network constructor in demo
n1v0lg Dec 21, 2017
80fea70
Changed names so it is not implied to be secure, rather a subsystem i…
pffrandsen Dec 21, 2017
6410b47
Merge remote-tracking branch 'origin/mascot-preprocessing' into masco…
pffrandsen Dec 21, 2017
5a75335
Fixed visibilty
pffrandsen Dec 21, 2017
0fb5f37
Removed unneeded getmod
pffrandsen Dec 21, 2017
0b0ef78
Renamed FrescoSerializer to ByteSerializer
pffrandsen Dec 21, 2017
f6d6130
Encapsulated fields
pffrandsen Dec 21, 2017
d1ef72c
Remove dead code and outdated TODOs
n1v0lg Dec 21, 2017
2628bad
Don't package mascot
n1v0lg Dec 21, 2017
cddf71b
Killed some unused imports
n1v0lg Dec 21, 2017
77293d3
Merge branch 'develop' into mascot-preprocessing
Dec 22, 2017
441faf1
Better naming
pffrandsen Dec 22, 2017
a4b0f7f
Merge remote-tracking branch 'origin/mascot-preprocessing' into masco…
pffrandsen Dec 22, 2017
fee5111
Smaller, co-prime modulus for spdz-mascot tests
n1v0lg Dec 22, 2017
d29319b
Nice prime
n1v0lg Dec 22, 2017
c885ef0
Mascot input mask gen
n1v0lg Dec 22, 2017
ab27b7e
Spdz input mask tests
n1v0lg Dec 22, 2017
cde82cd
Use random element gen in supplier
n1v0lg Dec 22, 2017
521683f
Fixed class cast exception
pffrandsen Dec 22, 2017
3017f70
Mindre netværk i test
pffrandsen Dec 22, 2017
2be3d88
Removed dummy override version
pffrandsen Jan 2, 2018
eba224d
Spdz is always spdz
pffrandsen Jan 2, 2018
a33e9d0
Spdz is always spdz
pffrandsen Jan 2, 2018
0dc900b
Added javadoc and used the interface where intended
pffrandsen Jan 2, 2018
39c9d0e
Excessive logging removed and cleanup of BatchedProtocolEvaluator
pffrandsen Jan 2, 2018
9f0aa75
Changed loglevel for triplework
pffrandsen Jan 2, 2018
bcc7f97
Cleaned javadoc
pffrandsen Jan 2, 2018
e5664d7
Code style fixed
pffrandsen Jan 2, 2018
1e71e63
Trivial optimization
pffrandsen Jan 2, 2018
f49ce5a
JAvadoc
pffrandsen Jan 2, 2018
a695da0
Tried to remove dependency on scapi, no longer needed with OT fully i…
pffrandsen Jan 3, 2018
d6843a3
Reverted
pffrandsen Jan 3, 2018
2bec9f7
intellij code style
n1v0lg Jan 4, 2018
7764a89
Again
n1v0lg Jan 4, 2018
ba4cea6
Modulus finder
n1v0lg Jan 4, 2018
53aa0d1
Set bit length on tests
n1v0lg Jan 4, 2018
ad1f0dc
Some fixes and tests
n1v0lg Jan 4, 2018
7a268ee
Redundant exceptions removed
pffrandsen Jan 5, 2018
7e4bd14
Equality edge case tests
n1v0lg Jan 5, 2018
2075162
Equality tests for negative numbers
n1v0lg Jan 5, 2018
9ad92d6
Added massive test of Mascot to test it under realistic terms
pffrandsen Jan 5, 2018
a766dc8
Merge remote-tracking branch 'origin/mascot-preprocessing' into masco…
pffrandsen Jan 5, 2018
b9ac7c7
Made the invoker busy wait
pffrandsen Jan 5, 2018
25cd81a
Basic style fixes and documentation.
Jan 5, 2018
592c79d
Basic style fixes, also computes byte size from bitsize.
Jan 5, 2018
8bbe016
Merge branch 'mascot-preprocessing' of https://github.com/aicis/fresc…
Jan 5, 2018
6fee855
Merge remote-tracking branch 'origin/mascot-preprocessing' into masco…
pffrandsen Jan 5, 2018
b10cd9a
Added progress in the test
pffrandsen Jan 6, 2018
b657cbb
Merged with develop. Fixed conflicts
Jan 8, 2018
9973510
Changed Spdz mac check and input protocol to throw malicious exceptio…
Jan 8, 2018
7dccfbb
Configurable max bit length and mod bit length
n1v0lg Jan 9, 2018
8a61bd5
Bit length params to fix LP
n1v0lg Jan 9, 2018
4d570de
Increase blocking queue size in kry net
n1v0lg Jan 10, 2018
0411b01
Adjust parameters in net manager and parallel mascot test
n1v0lg Jan 10, 2018
3df34e7
Make max len in dummy test suite configurable and tests
n1v0lg Jan 10, 2018
3e787c7
Remove long running mascot LP test
n1v0lg Jan 10, 2018
a09619d
Fix modulus finder test
n1v0lg Jan 10, 2018
0c60216
Fixed kryonet test after change to limit within personal queue
Jan 11, 2018
70b1cc0
Organized imports.
Jan 11, 2018
d768dd2
Moved seed OTs out of extension
jot2re Jan 11, 2018
42ff6d3
Merge branch 'mascot-preprocessing' of https://github.com/aicis/fresc…
jot2re Jan 11, 2018
72c079b
Some style and formatting fixes.
Jan 11, 2018
8720fb7
Merge branch 'mascot-preprocessing' of https://github.com/aicis/fresc…
Jan 11, 2018
c14b09a
Some style and comment fixes.
Jan 11, 2018
3393d4d
Attempt at fixing the kryonet errors on travis
Jan 11, 2018
1767295
Added seedOts to Otextension resources
jot2re Jan 11, 2018
7207137
Unoptimized square root mod p
n1v0lg Jan 11, 2018
76a77ae
Merge branch 'mascot-preprocessing' of https://github.com/aicis/fresc…
n1v0lg Jan 11, 2018
0597689
Make exponents ints
n1v0lg Jan 11, 2018
25c401b
Improved coverage
jot2re Jan 11, 2018
78a9a18
Clearned up demo classes
jot2re Jan 11, 2018
8674811
Cleaned up unit tests
jot2re Jan 11, 2018
d5a27be
Cleaned up Ot extension test context
jot2re Jan 11, 2018
4200ed7
Partially Cleaned up Bristol OT functest
jot2re Jan 11, 2018
d4a348f
Get next bit
n1v0lg Jan 11, 2018
a3a723c
Merge branch 'mascot-preprocessing' of https://github.com/aicis/fresc…
n1v0lg Jan 11, 2018
8386976
Fixed compile error
jot2re Jan 12, 2018
66b3704
Fix build
n1v0lg Jan 12, 2018
5abc572
Remove old test
n1v0lg Jan 12, 2018
7aad14d
Also remove calls to test
n1v0lg Jan 12, 2018
a592856
Move dummy ot back into main and make tests compile
n1v0lg Jan 12, 2018
818d7f3
Added online multiplication protocol
n1v0lg Jan 12, 2018
71701c9
In-mascot random bit generation
n1v0lg Jan 12, 2018
d3ed1de
Field element inverse and sqrt tests
n1v0lg Jan 12, 2018
1dbd682
Online multiplication tests
n1v0lg Jan 12, 2018
8e33202
Bit converter tests
n1v0lg Jan 12, 2018
afc916a
Correct test name
n1v0lg Jan 12, 2018
b545f66
Plug random bit gen into data supplier
n1v0lg Jan 12, 2018
ecbe998
Important todo
n1v0lg Jan 12, 2018
d76a04c
Fixed some issues with Mascot tests after refactoring
jot2re Jan 12, 2018
14cbe15
Merge branch 'mascot-preprocessing' of https://github.com/aicis/fresc…
jot2re Jan 12, 2018
2926656
Fixed triple generation bug
jot2re Jan 15, 2018
f7a1bf9
Modulus related test changes and fixes
n1v0lg Jan 15, 2018
8eff04f
Fix online mult protocol
n1v0lg Jan 15, 2018
b51e7a3
Kill some sysouts
n1v0lg Jan 15, 2018
72ce3c2
Fixed bit converter protocol
n1v0lg Jan 15, 2018
d7c65fb
Refactored code so input and output to protocols are clearly seen
pffrandsen Jan 15, 2018
3b006ea
Merge remote-tracking branch 'origin/mascot-preprocessing' into masco…
pffrandsen Jan 15, 2018
90dd89e
Fix createRot test
n1v0lg Jan 15, 2018
6f51b29
Kill dummy mascot resource poll
n1v0lg Jan 15, 2018
3670904
Cleaned up OT tests
jot2re Jan 15, 2018
f664779
Use real ot in demo
n1v0lg Jan 15, 2018
77a1284
Merge remote-tracking branch 'origin/mascot-preprocessing' into masco…
pffrandsen Jan 15, 2018
97a73e4
Changed the test system to fail fast if any thread fails
pffrandsen Jan 15, 2018
316877c
Refactored to be based on Lazy protocol constructions
pffrandsen Jan 15, 2018
fd164bc
Fixed OT bug
jot2re Jan 15, 2018
4a35d27
Merge remote-tracking branch 'origin/mascot-preprocessing' into masco…
pffrandsen Jan 15, 2018
1f1a98f
First stab at fixing mascot parallel
n1v0lg Jan 15, 2018
d894e9f
Cleaned up OT extension classes
jot2re Jan 15, 2018
a706b02
Add seed ot initialization to data supplier
n1v0lg Jan 15, 2018
bc8d0e1
Merge branch 'mascot-preprocessing' of https://github.com/aicis/fresc…
n1v0lg Jan 15, 2018
a5f81d8
Remove slow lt test and adjust params
n1v0lg Jan 15, 2018
ff34421
Removed author tag from OT extension files
jot2re Jan 15, 2018
5304bca
Fixed small problem in BristolRotBatch
jot2re Jan 15, 2018
302c1ee
Small readability changes
n1v0lg Jan 15, 2018
582e4d0
Another not equals
n1v0lg Jan 15, 2018
7d2730f
Added description to the MaliciousException class
jot2re Jan 15, 2018
df12821
Updated description of the MaliciousException class
jot2re Jan 15, 2018
474d959
Removed usages of MPCException
pffrandsen Jan 15, 2018
2f8b599
Removed deprecated, dangerous, unused methods
pffrandsen Jan 15, 2018
4ddc7ee
Fixed tests
pffrandsen Jan 15, 2018
57beda6
Fix exp pipe test
n1v0lg Jan 15, 2018
c6e7acd
Fixed tests
pffrandsen Jan 15, 2018
26ee9fe
Merge remote-tracking branch 'origin/mascot-preprocessing' into masco…
pffrandsen Jan 15, 2018
700f39f
Added another IllegalArugment
pffrandsen Jan 15, 2018
8ef1bfc
Moved ot init out of data supplier
n1v0lg Jan 15, 2018
767ccdf
More illegal args
n1v0lg Jan 15, 2018
8ded3d4
Removed MPC exception and replaced it - best estimate - of either a r…
pffrandsen Jan 15, 2018
a565a36
Do not catch exceptions to rethrow them
pffrandsen Jan 16, 2018
dafa76b
Temporary ignore test
pffrandsen Jan 16, 2018
9504f54
Removed dead code from BitVector
jot2re Jan 16, 2018
8a9fc0d
Added documentation to BitVector
jot2re Jan 16, 2018
62b4cd8
Move secret-sharing in el gen to match paper
n1v0lg Jan 16, 2018
0ef3293
Adressed review comments in StrictBitVectorSerializer
jot2re Jan 16, 2018
822e277
Clean up padding prg
n1v0lg Jan 16, 2018
6558b52
Merge branch 'mascot-preprocessing' of https://github.com/aicis/fresc…
n1v0lg Jan 16, 2018
ed39ade
Use serializer instead of toByteArray
n1v0lg Jan 16, 2018
be95f5b
Renaming in element generation
n1v0lg Jan 16, 2018
1004436
Removed dead code - round based exceptions never occurs
pffrandsen Jan 16, 2018
ed0deb3
Merge remote-tracking branch 'origin/mascot-preprocessing' into masco…
pffrandsen Jan 16, 2018
36a12df
Added tests of error conditions
pffrandsen Jan 16, 2018
7cbc4e1
Remove send and receive diff methods for mult classes
n1v0lg Jan 16, 2018
355d257
Adressed issues with StrictBitVetor
jot2re Jan 16, 2018
433a70b
Merge branch 'mascot-preprocessing' of https://github.com/aicis/fresc…
jot2re Jan 16, 2018
d834519
Abstract classes where appropriate and docs
n1v0lg Jan 16, 2018
e47def4
Removed redundant code
pffrandsen Jan 16, 2018
884bded
Merge remote-tracking branch 'origin/mascot-preprocessing' into masco…
pffrandsen Jan 16, 2018
bf548fe
Cleaned NOT protocol
pffrandsen Jan 16, 2018
8714c68
Added tests to StrictBitVectorSerializer
jot2re Jan 16, 2018
3660d44
Removed redundant code in preprocess AND
pffrandsen Jan 16, 2018
7a3ea70
Cleaned up AND
pffrandsen Jan 16, 2018
4bc08be
Merge remote-tracking branch 'origin/mascot-preprocessing' into masco…
pffrandsen Jan 16, 2018
00db1e6
Docs and clean-up in element generation
n1v0lg Jan 16, 2018
ac09a69
Fixed ssk generation in mascot data supplier
n1v0lg Jan 16, 2018
ae27bec
Clean-up and document arithmetic collection utils
n1v0lg Jan 16, 2018
08f1df9
Mascot test cov back to 100
n1v0lg Jan 16, 2018
013b563
Reverted changes, the test is written in a broken manner for windows …
pffrandsen Jan 16, 2018
962f22b
Merge remote-tracking branch 'origin/mascot-preprocessing' into masco…
pffrandsen Jan 16, 2018
aa49d75
Reverted changes, the test is written in a broken manner for windows …
pffrandsen Jan 16, 2018
6cf5b41
Refactor multiplication protocols
n1v0lg Jan 16, 2018
cf5defc
More multiplication-related clean-up
n1v0lg Jan 16, 2018
7d902d6
Dead code removed
pffrandsen Jan 16, 2018
72f0ce1
Merge remote-tracking branch 'origin/mascot-preprocessing' into masco…
pffrandsen Jan 16, 2018
8edb13d
Add instance id to data supplier
n1v0lg Jan 16, 2018
75a9af3
Add createRot exception test
n1v0lg Jan 17, 2018
87e7df7
Unused import
n1v0lg Jan 17, 2018
8a77b1a
Correct test names
n1v0lg Jan 17, 2018
a139279
Refactoring and documentation.
Jan 17, 2018
4827507
Update strict bit vector equals method and more tests
n1v0lg Jan 17, 2018
251f992
Merge branch 'mascot-preprocessing' of https://github.com/aicis/fresc…
Jan 17, 2018
c4f8d58
Data supplier docs
n1v0lg Jan 17, 2018
e480087
Merge branch 'mascot-preprocessing' of https://github.com/aicis/fresc…
Jan 17, 2018
18e2e06
More documentation of el gen and link to paper
n1v0lg Jan 17, 2018
5409fd7
Add refs to paper to el gen
n1v0lg Jan 17, 2018
134c7d4
Rename tests
n1v0lg Jan 17, 2018
3ffb976
Added mechanism for running mac checks during online phase
n1v0lg Jan 17, 2018
5225e32
Clean up broadcast validation
n1v0lg Jan 17, 2018
4bbc40d
More cleanup
n1v0lg Jan 17, 2018
2c47876
Multi-party coin tossing test etc
n1v0lg Jan 17, 2018
c4e7bb8
Add prg produces non-zero test etc
n1v0lg Jan 17, 2018
d2d95b5
Renamed tests to make codeCov happy
jot2re Jan 18, 2018
e24a032
Documented triple generation
n1v0lg Jan 18, 2018
4adac97
Merge branch 'mascot-preprocessing' of https://github.com/aicis/fresc…
n1v0lg Jan 18, 2018
3721287
Minor formatting el gen
n1v0lg Jan 18, 2018
6fa0fa0
Various javadoc and refactoring.
Jan 18, 2018
8959d7a
Merge branch 'mascot-preprocessing' of https://github.com/aicis/fresc…
Jan 18, 2018
661ca23
Renamed tests to make codeCov happy
jot2re Jan 18, 2018
8442274
Get rid off numLeftFactors in mult classes
n1v0lg Jan 18, 2018
fe39de3
Merge branch 'mascot-preprocessing' of https://github.com/aicis/fresc…
n1v0lg Jan 18, 2018
4f9ddc7
Moved multiply classes into triple package
n1v0lg Jan 18, 2018
60bc41b
Formatting javadoc.
Jan 18, 2018
d97bbbc
Cleaned up Xor and tiny tables values
pffrandsen Jan 18, 2018
b690354
Merge remote-tracking branch 'origin/mascot-preprocessing' into masco…
pffrandsen Jan 18, 2018
09a5e1c
Cleaned up preprocess and tiny tables values
pffrandsen Jan 18, 2018
777058e
Remove party ids
n1v0lg Jan 18, 2018
eb0e283
Remove mod bit length from prg
n1v0lg Jan 18, 2018
207793e
Merge branch 'mascot-preprocessing' of https://github.com/aicis/fresc…
Jan 18, 2018
1dacaf0
Made the dependency on Rot runtime rather than compile time in Bristo…
pffrandsen Jan 18, 2018
37f83f5
Merge remote-tracking branch 'origin/mascot-preprocessing' into masco…
pffrandsen Jan 18, 2018
d67a139
Made the dependency on Rot runtime rather than compile time in BristolOt
pffrandsen Jan 18, 2018
6f5165c
Remove mod bit length argument from field element
n1v0lg Jan 18, 2018
437ba26
Merge branch 'mascot-preprocessing' of https://github.com/aicis/fresc…
n1v0lg Jan 18, 2018
75d5f85
Remove bit length from authenticated element
n1v0lg Jan 18, 2018
b553665
More reasonable toString methods
n1v0lg Jan 18, 2018
1c536b9
FEUtils clean-up
n1v0lg Jan 18, 2018
4a5bed9
Address more of psn comments
n1v0lg Jan 18, 2018
292824a
Merge branch 'mascot-preprocessing' of https://github.com/aicis/fresc…
Jan 18, 2018
880ca0f
Fixed compile error.
Jan 18, 2018
01e9333
Introduced interfaces to allow users of the framework to change behav…
pffrandsen Jan 18, 2018
a77dd25
Merge remote-tracking branch 'origin/mascot-preprocessing' into masco…
pffrandsen Jan 18, 2018
69dbf23
Authenticated element docs
n1v0lg Jan 19, 2018
386af02
otherId now an int
n1v0lg Jan 19, 2018
22a0dda
Removed shared classes and delegation from base protocol
n1v0lg Jan 19, 2018
6ae5248
Remove base and two party protocol
n1v0lg Jan 19, 2018
6b0b324
Handled PFFs comments
jot2re Jan 19, 2018
17bf5b8
First stab at cleaning up mascot res pool
n1v0lg Jan 19, 2018
3352ffd
Merge branch 'mascot-preprocessing' of https://github.com/aicis/fresc…
n1v0lg Jan 19, 2018
c9ba991
Docs for mascot res pool impl
n1v0lg Jan 19, 2018
cb5ed62
Mascot demo
n1v0lg Jan 19, 2018
5f1d1d6
Temp fix for corr error in build
n1v0lg Jan 19, 2018
fb3f3a7
Fixed parallel Mascot problem
jot2re Jan 21, 2018
c407521
Fix coin tossing double init test
n1v0lg Jan 22, 2018
b976d0a
Remove mascot makefile
n1v0lg Jan 22, 2018
3a44eb5
Changed issue with constructor in Naor-Pinkas
jot2re Jan 22, 2018
32c4d6c
Made more variables in NaotPinkasOT
jot2re Jan 22, 2018
6000178
Removed much of the shared classes from OT extension
jot2re Jan 22, 2018
a57251a
Use sec params and no of parties in test runtime
n1v0lg Jan 22, 2018
21e9cb2
Added more comments to Naor Pinkas
jot2re Jan 22, 2018
094104c
Added reference to Bristol OT
jot2re Jan 22, 2018
bf10664
Fixes to pom
n1v0lg Jan 22, 2018
1c181bf
Merge branch 'mascot-preprocessing' of https://github.com/aicis/fresc…
n1v0lg Jan 22, 2018
2714818
Changed naming of Rot and Cote to contain factory
jot2re Jan 22, 2018
2c242e1
Changed Naor-Pinkas tests to securely generate DH parameters
jot2re Jan 22, 2018
c7636d4
Inline private fields
n1v0lg Jan 23, 2018
aa33a06
Remove ArithmeticCollectionUtils
n1v0lg Jan 23, 2018
dddb173
Minor changed to Bit vector classes according to review comments
jot2re Jan 23, 2018
5451ba6
Fixed merge conflict
jot2re Jan 23, 2018
c13540a
Dead code
pffrandsen Jan 23, 2018
5f83849
Merge remote-tracking branch 'origin/mascot-preprocessing' into masco…
pffrandsen Jan 23, 2018
2a93dfd
Dead code
pffrandsen Jan 23, 2018
d258a94
final field
pffrandsen Jan 23, 2018
06f4731
Renamed things and added comments to Naor Pinkas OT
jot2re Jan 23, 2018
c901c59
Changed Boolean to boolean
jot2re Jan 23, 2018
6bd02da
Minor changes according to review
jot2re Jan 23, 2018
8ad218e
Implement mod finder and misc tests
n1v0lg Jan 24, 2018
3e61953
Removed redundant interface and made the RotFactory the actual (Abstr…
pffrandsen Jan 24, 2018
0515efa
Addresed minor review comments
jot2re Jan 24, 2018
faa7e12
Handled minor review comments
jot2re Jan 24, 2018
fcc0a55
Added missing parens.
Jan 25, 2018
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,97 @@
package dk.alexandra.fresco.commitment;

import dk.alexandra.fresco.framework.MaliciousException;
import dk.alexandra.fresco.framework.util.Drbg;
import dk.alexandra.fresco.framework.util.ExceptionConverter;
import java.security.MessageDigest;
import java.util.Arrays;

/**
* Class representing a hash-based commitment. Secure assuming that SHA-256 is a
* random oracle. An instantiated object represents a commitment by itself and
* does <b>not</b> contain any secret information. An object gets instantiated
* by calling the commit command. <br/>
* The scheme itself is based on the ROM folklore scheme where the message to
* commit to is concatenated with a random string and then hashed. The hash
* digest serves as the commitment itself and the opening is the randomness and
* the message committed to.
*
* @author jot2re
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We decided at some point that all author tags be removed. Some are still remaining, but I guess we should be consistent on new files

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed all author tags from the OT package.

*/
public class HashBasedCommitment {

private static final String HASH_ALGORITHM = "SHA-256";
/**
* The length of the hash digest along with the randomness used.
*/
public static final int DIGEST_LENGTH = 32; // 256 / 8 bytes
/**
* The actual value representing the commitment.
*/
byte[] commitmentVal = null;
private final MessageDigest digest;

/**
* Constructs a new commitment, not yet committed to any value.
*/
public HashBasedCommitment() {
digest = ExceptionConverter.safe(
() -> MessageDigest.getInstance(HASH_ALGORITHM),
"Missing secure, hash function which is dependent in this library");
}

/**
* Initializes the commitment to commit to a specific value and returns the opening information.
*
* @param rand
* A cryptographically secure randomness generator.
* @param value
* The element to commit to.
* @return The opening information needed to open the commitment.
*/
public byte[] commit(Drbg rand, byte[] value) {
if (commitmentVal != null) {
throw new IllegalStateException("Already committed");
}
// Sample a sufficient amount of random bits
byte[] randomness = new byte[DIGEST_LENGTH];
rand.nextBytes(randomness);
// Construct an array to contain the bytes to hash
byte[] openingInfo = new byte[value.length + randomness.length];
System.arraycopy(value, 0, openingInfo, 0, value.length);
System.arraycopy(randomness, 0, openingInfo, value.length,
randomness.length);
commitmentVal = digest.digest(openingInfo);
return openingInfo;
}

/**
* Opens a committed object using information returned from the {@code commit} command.
*
* @param openingInfo
* The data needed to open this given commitment.
* @return The value that was committed to.
*/
public byte[] open(byte[] openingInfo) {
if (commitmentVal == null) {
throw new IllegalStateException("No commitment to open");
}
if (openingInfo.length < DIGEST_LENGTH) {
throw new MaliciousException(
"The opening info is too small to be a commitment.");
}
// Hash the opening info and verify that it matches the value stored in
// "commitmentValue"
byte[] digestValue = digest.digest(openingInfo);
if (Arrays.equals(digestValue, commitmentVal)) {
// Extract the randomness and the value committed to from the openingInfo
// The value comes first
byte[] value = new byte[openingInfo.length - DIGEST_LENGTH];
System.arraycopy(openingInfo, 0, value, 0,
openingInfo.length - DIGEST_LENGTH);
return value;
} else {
throw new MaliciousException("The opening info does not match the commitment.");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package dk.alexandra.fresco.commitment;

import dk.alexandra.fresco.framework.network.serializers.ByteSerializer;

import java.util.ArrayList;
import java.util.List;

public class HashBasedCommitmentSerializer implements ByteSerializer<HashBasedCommitment> {

@Override
public byte[] serialize(HashBasedCommitment comm) {
return comm.commitmentVal;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Encapsulate using a package local getter

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed to use package accessible getter and setter

}

@Override
public byte[] serialize(List<HashBasedCommitment> elements) {
if (elements.isEmpty()) {
return new byte[] {};
}
// A serialized commitment only consists of its internal digest
byte[] commList = new byte[elements.size() * HashBasedCommitment.DIGEST_LENGTH];
// Ensure all field elements are in the same field and have same bit length
for (int i = 0; i < elements.size(); i++) {
System.arraycopy(elements.get(i).commitmentVal, 0, commList,
i * HashBasedCommitment.DIGEST_LENGTH, HashBasedCommitment.DIGEST_LENGTH);
}
return commList;
}

@Override
public HashBasedCommitment deserialize(byte[] data) {
if (data.length != HashBasedCommitment.DIGEST_LENGTH) {
throw new IllegalArgumentException(
"The length of the byte array to deserialize is wrong.");
}
HashBasedCommitment comm = new HashBasedCommitment();
comm.commitmentVal = data.clone();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Encapsulate - by the way, it could be allowed just to use the array directly

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed to use package accessible getter and setter

return comm;
}

@Override
public List<HashBasedCommitment> deserializeList(byte[] data) {
if (data.length % HashBasedCommitment.DIGEST_LENGTH != 0) {
throw new IllegalArgumentException(
"The length of the byte array to deserialize is wrong.");
}
if (data.length == 0) {
return new ArrayList<>();
}
// A serialized commitment only consists of its internal digest
List<HashBasedCommitment> res = new ArrayList<>(data.length / HashBasedCommitment.DIGEST_LENGTH);
for (int i = 0; i < data.length / HashBasedCommitment.DIGEST_LENGTH; i++) {
HashBasedCommitment comm = new HashBasedCommitment();
byte[] commVal = new byte[HashBasedCommitment.DIGEST_LENGTH];
System.arraycopy(data, i * HashBasedCommitment.DIGEST_LENGTH,
commVal, 0, HashBasedCommitment.DIGEST_LENGTH);
comm.commitmentVal = commVal;
res.add(comm);
}
return res;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dk.alexandra.fresco.framework;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ought to have some documentation of how to interpret this type exception.

Copy link
Collaborator

@jot2re jot2re Jan 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been added in commit 7d2730f and df12821

public class MaliciousException extends MPCException {

public MaliciousException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ public DRes<List<DRes<SInt>>> getExponentiationPipe(int pipeLength) {
List<DRes<SInt>> values = new ArrayList<>(state.value);
values.add(seq.numeric().mult(last, r));
return () -> new IterationState(state.round + 1, values);
}).seq((seq, state) -> {
return () -> state.value;
});
}).seq((seq, state) -> () -> state.value);
}

private static final class IterationState {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package dk.alexandra.fresco.framework.builder.numeric;

import dk.alexandra.fresco.framework.network.serializers.ByteSerializer;
import dk.alexandra.fresco.framework.sce.resources.ResourcePool;
import java.math.BigInteger;
import java.security.MessageDigest;

public interface NumericResourcePool extends ResourcePool {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interface missing javadoc. Which might help for me in understanding exactly what it is. In my world, resource pools are specific to protocol suites, and I don't think all numeric protocol suites needs access to e.g. a hash algorithm?


/**
* Gets the modulus.
*
* @return modulus
*/
BigInteger getModulus();

/**
* Gets a serializer for big integer that is aligned with the current system settings in this
* invocation - hence byte length of big integer.
*
* @return the serializer
*/
ByteSerializer<BigInteger> getSerializer();

/**
* Gets the message digest for this protocol suite invocation.
*
* @return the message digest
*/
MessageDigest getMessageDigest();

/**
* Takes a unsigned BigInteger and converts it (reasonable) to a signed version.
*
* @param b the unsigned BigInteger
* @return the signed BigInteger
*/
default BigInteger convertRepresentation(BigInteger b) {
BigInteger modulus = getModulus();
BigInteger actual = b.mod(modulus);
if (actual.compareTo(modulus.divide(BigInteger.valueOf(2))) > 0) {
actual = actual.subtract(modulus);
}
return actual;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,35 +1,65 @@
package dk.alexandra.fresco.framework.network.serializers;

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

/**
* Serializes {@link BigInteger} to byte arrays using knowledge about the length
* of the BigInteger.
*/
public class BigIntegerWithFixedLengthSerializer implements BigIntegerSerializer {
public class BigIntegerWithFixedLengthSerializer implements ByteSerializer<BigInteger> {

private int byteLength;

/**
* Creates a new instance that adhere to the interface.
*
* @param byteLength the amount of bytes inteded to be serialized
*/
public BigIntegerWithFixedLengthSerializer(int byteLength) {
this.byteLength = byteLength;
}

@Override
public byte[] toBytes(BigInteger bigInteger) {
public byte[] serialize(BigInteger obj) {
byte[] bytes = new byte[byteLength];
byte[] bb = bigInteger.toByteArray();
System.arraycopy(bb, 0, bytes, byteLength - bb.length, bb.length);
return produceBytes(obj, bytes, 0);
}

@Override
public BigInteger deserialize(byte[] data) {
return new BigInteger(data);
}

@Override
public byte[] serialize(List<BigInteger> objs) {
byte[] bytes = new byte[byteLength * objs.size()];
int offset = 0;
for (BigInteger bigInteger : objs) {
produceBytes(bigInteger, bytes, offset);
offset += byteLength;
}
return bytes;
}

@Override
public BigInteger toBigInteger(byte[] bytes) {
return new BigInteger(bytes);
public List<BigInteger> deserializeList(byte[] data) {
int offset = 0;
List<BigInteger> result = new ArrayList<>();
while (offset < data.length) {
byte[] subArray = new byte[byteLength];
System.arraycopy(data, offset, subArray, 0, byteLength);
result.add(new BigInteger(subArray));
offset += byteLength;
}
return result;
}

/**
* Creates a new instance that adhere to the interface.
*
* @param byteLength the amount of bytes inteded to be serialized
*/
public BigIntegerWithFixedLengthSerializer(int byteLength) {
this.byteLength = byteLength;
private byte[] produceBytes(BigInteger bigInteger, byte[] bytes, int offset) {
byte[] bb = bigInteger.toByteArray();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the right way to do it for general BigInteger serialization. However, it may be worth noting that serializing BigIntegers this way will include a sign bit. For most applications the BigIntegers we serialize will represent numbers in some Z_p, i.e., they are in the range 0, ..., p-1. Thus, for byte-aligned values of p we use one redundant zero-byte. Most often we would actually like p to have this property. Not sure if we should do something about it or just accept the overhead.

System.arraycopy(bb, 0, bytes, byteLength - bb.length + offset, bb.length);
return bytes;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package dk.alexandra.fresco.framework.network.serializers;

import java.util.List;

/**
* A generic serializer, allows serialization and deserialization of elements with the
* corresponding type, T.
*
* @param <T> the type to serialize.
*/
public interface ByteSerializer<T> {

/**
* Converts an element of type T to an array of bytes
*
* @param object the object to convert
* @return the resulting byte array
*/
byte[] serialize(T object);

/**
* Converts a list of elements of type T to an array of bytes
*
* @param objects the objects to convert
* @return the resulting byte array
*/
byte[] serialize(List<T> objects);


/**
* Reads an element of type T from a byte array.
*
* @param bytes the data
* @return the converted element.
*/
T deserialize(byte[] bytes);


/**
* Reads a list of elements of type T from a byte array.
*
* @param bytes the data
* @return the converted elements.
*/
List<T> deserializeList(byte[] bytes);

}