8237218: Support NIST Curves verification in java implementation

Reviewed-by: ascarpino
This commit is contained in:
Weijun Wang 2020-02-22 08:10:21 +08:00
parent 2596e83a34
commit 533649b8ca
5 changed files with 378 additions and 39 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -34,6 +34,17 @@ import java.util.Arrays;
public final class ECUtil {
// Used by SunEC
public static byte[] sArray(BigInteger s, ECParameterSpec params) {
byte[] arr = s.toByteArray();
ArrayUtil.reverse(arr);
int byteLength = (params.getOrder().bitLength() + 7) / 8;
byte[] arrayS = new byte[byteLength];
int length = Math.min(byteLength, arr.length);
System.arraycopy(arr, 0, arrayS, 0, length);
return arrayS;
}
// Used by SunPKCS11 and SunJSSE.
public static ECPoint decodePoint(byte[] data, EllipticCurve curve)
throws IOException {