/* * Copyright (c) 2018, 2021, 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
final String id; // RSA private key value associated with the corresponding test vectors final RSAPrivateKeySpec privKeySpec;
// RSA public key value associated with the corresponding test vectors final RSAPublicKeySpec pubKeySpec;
// set of test vectors final List<SigVector> testVectors;
SigRecord(String mod, String pubExp, String privExp, List<SigVector> testVectors) { if (mod == null || mod.isEmpty()) { thrownew IllegalArgumentException("Modulus n must be specified");
} if (pubExp == null || pubExp.isEmpty()) { thrownew IllegalArgumentException("Public Exponent e must be specified");
} if (privExp == null || privExp.isEmpty()) { thrownew IllegalArgumentException("Private Exponent d must be specified");
} if (testVectors == null || (testVectors.size() == 0)) { thrownew IllegalArgumentException("One or more test vectors must be specified");
}
BigInteger n = new BigInteger(1, HexFormat.of().parseHex(mod));
BigInteger e = new BigInteger(1, HexFormat.of().parseHex(pubExp));
BigInteger d = new BigInteger(1, HexFormat.of().parseHex(privExp)); this.id = ("n=" + mod + ", e=" + pubExp); this.pubKeySpec = new RSAPublicKeySpec(n, e); this.privKeySpec = new RSAPrivateKeySpec(n, d); this.testVectors = testVectors;
}
/* * Read a data file into an ArrayList. * This function will exit the program if reading the file fails * or if the file is not in the expected format.
*/ publicstatic List<SigRecord> read(String filename) throws IOException {
List<SigRecord> data = new ArrayList<>(); try (BufferedReader br = new BufferedReader( new InputStreamReader(new FileInputStream(
TEST_SRC + File.separator + filename)))) {
String line;
String mod = null;
String pubExp = null;
String privExp = null;
List<SigVector> testVectors = new ArrayList<>(); while ((line = br.readLine()) != null) { if (line.startsWith("n =")) {
mod = line.split("=")[1].trim();
} elseif (line.startsWith("e =")) {
pubExp = line.split("=")[1].trim();
} elseif (line.startsWith("d =")) {
privExp = line.split("=")[1].trim();
// now should start parsing for test vectors
String mdAlg = null;
String msg = null;
String sig = null;
String salt = null; boolean sigVectorDone = false; while ((line = br.readLine()) != null) { // we only care for lines starting with // SHAALG, Msg, S, and Salt if (line.startsWith("SHAAlg =")) {
mdAlg = line.split(" = ")[1].trim();
} elseif (line.startsWith("Msg =")) {
msg = line.split(" = ")[1].trim();
} elseif (line.startsWith("S =")) {
sig = line.split(" = ")[1].trim();
} elseif (line.startsWith("SaltVal =")) {
salt = line.split(" = ")[1].trim(); if (salt.equals("00")) {
salt = "";
}
} elseif (line.startsWith("[mod")) {
sigVectorDone = true;
}
if ((mdAlg != null) && (msg != null) && (sig != null) &&
(salt != null)) { // finish off current SigVector
testVectors.add(new SigVector(mdAlg, msg, sig, salt));
mdAlg = msg = sig = salt = null;
} if (sigVectorDone) { break;
}
} // finish off current SigRecord and clear data for next SigRecord
data.add(new SigRecord(mod, pubExp, privExp, testVectors));
mod = pubExp = privExp = null;
testVectors = new ArrayList<>();
}
}
if (data.isEmpty()) { thrownew RuntimeException("Nothing read from file "
+ filename);
}
} return data;
}
@Override public String toString() { return (id + ", " + testVectors.size() + " test vectors");
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.