aboutsummaryrefslogtreecommitdiff
path: root/assets/ECExample.java
diff options
context:
space:
mode:
authorJ08nY2018-01-21 19:22:06 +0100
committerJ08nY2018-01-21 19:22:06 +0100
commit757b968e8609b031a653e824719d5b8248c5597b (patch)
tree5fe7974ad9a4ab51983765f7bc74fe97299c880f /assets/ECExample.java
parent6d23864444b7f781a44b23a15da01ce16218bbea (diff)
downloadECTester-757b968e8609b031a653e824719d5b8248c5597b.tar.gz
ECTester-757b968e8609b031a653e824719d5b8248c5597b.tar.zst
ECTester-757b968e8609b031a653e824719d5b8248c5597b.zip
Style the page a bit.
Diffstat (limited to 'assets/ECExample.java')
-rw-r--r--assets/ECExample.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/assets/ECExample.java b/assets/ECExample.java
index a45f028..c817547 100644
--- a/assets/ECExample.java
+++ b/assets/ECExample.java
@@ -1288,12 +1288,30 @@ public class ECExample {
return curve <= FP_CURVES ? KeyPair.ALG_EC_FP : KeyPair.ALG_EC_F2M;
}
+ /**
+ * Generate a new EC KeyPair, uses SECG curves.
+ *
+ * @param keyLength The size of the KeyPair in bits.
+ * @param keyClass The type of te KeyPair, one of KeyPair.ALG_EC_FP, KeyPair.ALG_EC_F2M.
+ * @param buffer A byte buffer(in RAM preferrably), this method will use to copy the domain parameters into the keypair.
+ * @param offset An offset in the buffer, from which it's contents will get overridden.
+ * @throws ISOException: - SW_FUNC_NOT_SUPPORTED if no SECG curve for given size and type can be found.
+ * - SW_WRONG_LENGTH if the usable buffer length after offset is shorter than necessary.
+ * @return the generated KeyPair
+ */
public static KeyPair generatKeyPair(short keyLength, short keyClass, byte[] buffer, short offset) {
byte curve = getCurve(keyLength, keyClass);
if (curve == 0) {
+ // No SECG curve for given size and type.
ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED);
}
+ short byteLength = (short) ((keyLength / 8) + keyLength % 8 == 0 ? 0 : 1);
+ if (buffer.length - offset < 2 * byteLength + 1) {
+ // The curve data will not fit in the provided buffer.
+ ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
+ }
+
KeyPair result = new KeyPair(keyClass, keyLength);
if (result.getPrivate() == null || result.getPublic() == null) {
// Sometimes cards require this so we have the keyparts, to