Skip to content

Commit fd28aad

Browse files
author
Anthony Scarpino
committedMay 18, 2020
8166597: Crypto support for the EdDSA Signature Algorithm
Reviewed-by: weijun, mullan, wetmore
1 parent 02293da commit fd28aad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4697
-155
lines changed
 

‎make/jdk/src/classes/build/tools/intpoly/FieldGen.java

+67-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,7 +21,6 @@
2121
* questions.
2222
*/
2323

24-
2524
/*
2625
* This file is used to generated optimized finite field implementations.
2726
*/
@@ -170,6 +169,19 @@ private static List<CarryReduce> P521CrSequence() {
170169
o521crSequence(19), orderFieldSmallCrSequence(19)
171170
);
172171

172+
static FieldParams O25519 = new FieldParams(
173+
"Curve25519OrderField", 26, 10, 1, 252,
174+
"1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed",
175+
orderFieldCrSequence(10), orderFieldSmallCrSequence(10)
176+
);
177+
178+
static FieldParams O448 = new FieldParams(
179+
"Curve448OrderField", 28, 16, 1, 446,
180+
"3fffffffffffffffffffffffffffffffffffffffffffffffffffffff7cca23e9c44edb49aed63690216cc2728dc58f552378c292ab5844f3",
181+
//"ffffffffffffffffffffffffffffffffffffffffffffffffffffffff7cca23e9c44edb49aed63690216cc2728dc58f552378c292ab5844f3",
182+
orderFieldCrSequence(16), orderFieldSmallCrSequence(16)
183+
);
184+
173185
private static List<CarryReduce> o521crSequence(int numLimbs) {
174186

175187
// split the full reduce in half, with a carry in between
@@ -212,7 +224,8 @@ private static List<CarryReduce> orderFieldSmallCrSequence(int numLimbs) {
212224
}
213225

214226
static final FieldParams[] ALL_FIELDS = {
215-
P256, P384, P521, O256, O384, O521,
227+
Curve25519, Curve448,
228+
P256, P384, P521, O256, O384, O521, O25519, O448
216229
};
217230

218231
public static class Term {
@@ -322,6 +335,11 @@ public FieldParams(String className, int bitsPerLimb, int numLimbs,
322335
private Iterable<Term> buildTerms(BigInteger sub) {
323336
// split a large subtrahend into smaller terms
324337
// that are aligned with limbs
338+
boolean negate = false;
339+
if (sub.compareTo(BigInteger.ZERO) < 0) {
340+
negate = true;
341+
sub = sub.negate();
342+
}
325343
List<Term> result = new ArrayList<Term>();
326344
BigInteger mod = BigInteger.valueOf(1 << bitsPerLimb);
327345
int termIndex = 0;
@@ -332,6 +350,9 @@ private Iterable<Term> buildTerms(BigInteger sub) {
332350
coef = coef - (1 << bitsPerLimb);
333351
plusOne = true;
334352
}
353+
if (negate) {
354+
coef = 0 - coef;
355+
}
335356
if (coef != 0) {
336357
int pow = termIndex * bitsPerLimb;
337358
result.add(new Term(pow, -coef));
@@ -619,6 +640,14 @@ private String generate(FieldParams params) throws IOException {
619640
result.appendLine();
620641
result.appendLine("}");
621642

643+
StringBuilder coqTerms = new StringBuilder("//");
644+
for (Term t : params.getTerms()) {
645+
coqTerms.append("(" + t.getPower() + "%nat,");
646+
coqTerms.append(t.getCoefficient() + ")::");
647+
}
648+
coqTerms.append("nil.");
649+
result.appendLine(coqTerms.toString());
650+
622651
result.appendLine("private static BigInteger evaluateModulus() {");
623652
result.incrIndent();
624653
result.appendLine("BigInteger result = BigInteger.valueOf(2).pow("
@@ -650,6 +679,41 @@ private String generate(FieldParams params) throws IOException {
650679
result.decrIndent();
651680
result.appendLine("}");
652681

682+
result.appendLine("@Override");
683+
result.appendLine("protected void reduceIn(long[] limbs, long v, int i) {");
684+
result.incrIndent();
685+
String c = "v";
686+
for (Term t : params.getTerms()) {
687+
int reduceBits = params.getPower() - t.getPower();
688+
int coefficient = -1 * t.getCoefficient();
689+
690+
String x = coefficient + " * " + c;
691+
String accOp = "+=";
692+
String temp = null;
693+
if (coefficient == 1) {
694+
x = c;
695+
} else if (coefficient == -1) {
696+
x = c;
697+
accOp = "-=";
698+
} else {
699+
temp = result.getTemporary("long", x);
700+
x = temp;
701+
}
702+
703+
if (reduceBits % params.getBitsPerLimb() == 0) {
704+
int pos = reduceBits / params.getBitsPerLimb();
705+
result.appendLine("limbs[i - " + pos + "] " + accOp + " " + x + ";");
706+
} else {
707+
int secondPos = reduceBits / params.getBitsPerLimb();
708+
int bitOffset = (secondPos + 1) * params.getBitsPerLimb() - reduceBits;
709+
int rightBitOffset = params.getBitsPerLimb() - bitOffset;
710+
result.appendLine("limbs[i - " + (secondPos + 1) + "] " + accOp + " (" + x + " << " + bitOffset + ") & LIMB_MASK;");
711+
result.appendLine("limbs[i - " + secondPos + "] " + accOp + " " + x + " >> " + rightBitOffset + ";");
712+
}
713+
}
714+
result.decrIndent();
715+
result.appendLine("}");
716+
653717
result.appendLine("@Override");
654718
result.appendLine("protected void finalCarryReduceLast(long[] limbs) {");
655719
result.incrIndent();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package java.security.interfaces;
26+
27+
import java.security.spec.NamedParameterSpec;
28+
29+
/**
30+
* An interface for an elliptic curve public/private key as defined by
31+
* <a href="https://tools.ietf.org/html/rfc8032">RFC 8032: Edwards-Curve
32+
* Digital Signature Algorithm (EdDSA)</a>. These keys are distinct from the
33+
* keys represented by {@code ECKey}, and they are intended for use with
34+
* algorithms based on RFC 8032 such as the EdDSA {@code Signature} algorithm.
35+
* This interface allows access to the algorithm parameters associated with
36+
* the key.
37+
*
38+
* @since 15
39+
*/
40+
public interface EdECKey {
41+
/**
42+
* Returns the algorithm parameters associated with the key.
43+
*
44+
* @return the associated algorithm parameters.
45+
*/
46+
NamedParameterSpec getParams();
47+
}

0 commit comments

Comments
 (0)
Please sign in to comment.