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

Naor-Pinkas Base OT optimization with elliptic curves #378

Merged
merged 14 commits into from
Feb 24, 2022

Conversation

Gugi264
Copy link
Contributor

@Gugi264 Gugi264 commented Mar 29, 2021

Closes #375

This PR optimizes the base Naor-Pinkas OT through the use of elliptic curves.
For this the curve p-256 is used (but can be changed easily).

The PR adds 3 new optional dependencies to the ot submodule.
1 For bouncy castle,
2 for the use of the commercial ECCelerate Library.
These dependencies are optional, the dependency and the corresponding files can be deleted if they are not wanted.

But at least one of those two is needed to use the optimization.

@Gugi264 Gugi264 force-pushed the PRNaorPinkasOTwithEcc branch 2 times, most recently from acdb912 to e4423cb Compare March 29, 2021 19:46
@Gugi264 Gugi264 closed this Mar 29, 2021
@Gugi264 Gugi264 reopened this Mar 29, 2021
@Gugi264 Gugi264 marked this pull request as ready for review March 29, 2021 19:56
Copy link
Collaborator

@jonas-lj jonas-lj left a comment

Choose a reason for hiding this comment

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

Thanks for your PR! It looks great but we have a few comments - both on smaller issues and a few larger ones. My main concern is that the old OT seems to disappear - do you think it's possible to retain the original OT and add yours as a new one to optionally use?

tools/ot/pom.xml Show resolved Hide resolved
}

}
package dk.alexandra.fresco.suite.tinytables.ot;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe you have committed files with a different line? It's odd that the diff insists that you changed all lines in the files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that was a problem with the line seperators, should be fixed now

import dk.alexandra.fresco.tools.ot.base.AbstractNaorPinkasOT;
import dk.alexandra.fresco.tools.ot.base.BouncyCastleNaorPinkas;

public class TinyTablesNaorPinkasOt implements TinyTablesOt {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you implement your OT as a new OT and keep the old TinyTablesNaorPinkasOt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TinyTablesNaorPinkasOt uses stillt the old Naor Pinkas Implementation, just with the new name (BigIntNaorPinkas)

}

@Override
public InterfaceNaorPinkasElement groupOp(InterfaceNaorPinkasElement other) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this could be done more elegantly by adding a generic parameter to InterfaceNaorPinkasElement to avoid type casting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now uses templates, no cast needed anymore

@@ -229,8 +226,7 @@ private Drbg getDrbg(int myId, int prgSeedLength) {
Map<Integer, RotList> seedOts = new HashMap<>();
for (int otherId = 1; otherId <= parties; otherId++) {
if (myId != otherId) {
DHParameterSpec dhSpec = DhParameters.getStaticDhParams();
Ot ot = new NaorPinkasOt(otherId, drbg, network, dhSpec);
AbstractNaorPinkasOT ot = new BigIntNaorPinkas(otherId, drbg, network);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

BigIntNaorPinkas has the same functionality as the old NaorPinkasOt.
The name is just different to differentiate between different NaorPinkas implementations.

Comment on lines +77 to +80
Class clazz = this.testClass;
Constructor[] constructors = clazz.getConstructors();
Ot otSender = (AbstractNaorPinkasOT) constructors[0]
.newInstance(2, rand, network);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used to get the constructor via reflection. Is not the most beautiful solution, but the best I could come up with without changing too much of the existing code

@codecov
Copy link

codecov bot commented Apr 11, 2021

Codecov Report

Merging #378 (16cda54) into master (60c2345) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##              master      #378   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity      3598      3618   +20     
===========================================
  Files            404       408    +4     
  Lines          10177     10209   +32     
  Branches         776       776           
===========================================
+ Hits           10177     10209   +32     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...lexandra/fresco/demo/cli/CmdLineProtocolSuite.java 100.00% <100.00%> (ø)
...co/suite/tinytables/ot/TinyTablesNaorPinkasOt.java 100.00% <100.00%> (ø)
...co/tools/bitTriples/BitTripleResourcePoolImpl.java 100.00% <100.00%> (ø)
...dra/fresco/tools/ot/base/AbstractNaorPinkasOT.java 100.00% <100.00%> (ø)
.../alexandra/fresco/tools/ot/base/BigIntElement.java 100.00% <100.00%> (ø)
...exandra/fresco/tools/ot/base/BigIntNaorPinkas.java 100.00% <100.00%> (ø)
...a/fresco/tools/ot/base/BouncyCastleECCElement.java 100.00% <100.00%> (ø)
...a/fresco/tools/ot/base/BouncyCastleNaorPinkas.java 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 60c2345...16cda54. Read the comment docs.

@Gugi264
Copy link
Contributor Author

Gugi264 commented Apr 11, 2021

Thanks for the review!
I changed the files you highlighted.

My main concern is that the old OT seems to disappear - do you think it's possible to retain the original OT and add yours as a new one to optionally use?

The old one doesn't disappear (at least not the functionality), I just refactored it and it is now just called BigIntNaorPinkas. If you don't want the version using elliptic curves, just use that one.

@jonas-lj jonas-lj requested a review from jot2re February 16, 2022 09:28
Copy link
Collaborator

@jot2re jot2re left a comment

Choose a reason for hiding this comment

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

Looks good, but I think in general it is better to switch to Curve25519 as it is generally regarded as safer.

public void createElement() {
Long baseNumber = 2L;
MersennePrimeFieldDefinition fieldDefintion = new MersennePrimeFieldDefinition(4, 2);
MersennePrimeFieldElement elementFromString = (MersennePrimeFieldElement) fieldDefintion.createElement(baseNumber.toString());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think something should be checked here since the code coverage says that not all versions FieldDefintion.createElement gets called.

Copy link
Contributor Author

@Gugi264 Gugi264 Feb 20, 2022

Choose a reason for hiding this comment

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

No idea why that is, as highlighted from you, it is called and should therefore be in the code coverage

Copy link
Collaborator

@jot2re jot2re left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks a lot for your contribution!

@jot2re jot2re self-requested a review February 23, 2022 09:21
Copy link
Collaborator

@jot2re jot2re left a comment

Choose a reason for hiding this comment

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

Okay, I was a bit too quick approving. I see the build service has an issue building the project. It gi ved the following error /home/runner/work/fresco/fresco/core/src/test/java/dk/alexandra/fresco/framework/builder/numeric/field/MersennePrimeFieldDefinitionTest.java:[36,39] error: cannot find symbol
However, I did not have that issue when running the branch locally.
Comparing it with what is shown here at GitHub it seems that there is an a weird whitespace symbol on this line. I tries to fix it but I am not authorised to push to your branch.

@Gugi264
Copy link
Contributor Author

Gugi264 commented Feb 23, 2022

I also didnt have the problem locally. I also dont see the whitespace problem, but I hope I fixed it.

@Gugi264
Copy link
Contributor Author

Gugi264 commented Feb 23, 2022

I tried running the github actions on a different branch on my repository, and there I didn't get the error
See https://github.com/Gugi264/fresco/runs/5304055567?check_suite_focus=true

@jonas-lj
Copy link
Collaborator

I tried running the github actions on a different branch on my repository, and there I didn't get the error See https://github.com/Gugi264/fresco/runs/5304055567?check_suite_focus=true

I haven't run the code myself, but I think it's because the extractValue method on FieldElement was renamed to toBigInteger in september last year: f128d39

@jonas-lj
Copy link
Collaborator

Looks good. Thanks for your contribution :)

1 similar comment
@jonas-lj
Copy link
Collaborator

Looks good. Thanks for your contribution :)

@jonas-lj jonas-lj merged commit fa35303 into aicis:master Feb 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Base NaorPinkasOT Optimization with Elliptic Curves
3 participants