diff options
author | Kenny Root <kenny@the-b.org> | 2013-04-12 00:13:42 -0700 |
---|---|---|
committer | Kenny Root <kenny@the-b.org> | 2013-04-12 00:33:11 -0700 |
commit | 1adfa1979549740665d0e6d845d7575ebad5faae (patch) | |
tree | 8d05c69145cbe584f161935513b696524f5891a1 /lib/src/main/java/com/trilead/ssh2/signature | |
parent | 3359a7f6d20f4d799140e304f646491863735028 (diff) | |
download | sshlib-1adfa1979549740665d0e6d845d7575ebad5faae.tar.gz sshlib-1adfa1979549740665d0e6d845d7575ebad5faae.tar.bz2 sshlib-1adfa1979549740665d0e6d845d7575ebad5faae.zip |
Add EC pubkey to UI
Diffstat (limited to 'lib/src/main/java/com/trilead/ssh2/signature')
-rw-r--r-- | lib/src/main/java/com/trilead/ssh2/signature/ECDSASHA2Verify.java | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/lib/src/main/java/com/trilead/ssh2/signature/ECDSASHA2Verify.java b/lib/src/main/java/com/trilead/ssh2/signature/ECDSASHA2Verify.java index 4f3bae2..7b4f6af 100644 --- a/lib/src/main/java/com/trilead/ssh2/signature/ECDSASHA2Verify.java +++ b/lib/src/main/java/com/trilead/ssh2/signature/ECDSASHA2Verify.java @@ -55,6 +55,23 @@ public class ECDSASHA2Verify { CURVE_SIZES.put(521, NISTP521); } + public static int[] getCurveSizes() { + int[] keys = new int[CURVE_SIZES.size()]; + int i = 0; + for (Integer n : CURVE_SIZES.keySet().toArray(new Integer[keys.length])) { + keys[i++] = n; + } + return keys; + } + + public static ECParameterSpec getCurveForSize(int size) { + final String name = CURVE_SIZES.get(size); + if (name == null) { + return null; + } + return CURVES.get(name); + } + public static ECPublicKey decodeSSHECDSAPublicKey(byte[] key) throws IOException { TypesReader tr = new TypesReader(key); @@ -112,21 +129,30 @@ public class ECDSASHA2Verify { tw.writeString(curveName); - tw.writeBytes(encodeECPoint(key.getW(), key.getParams().getCurve())); + byte[] encoded = encodeECPoint(key.getW(), key.getParams().getCurve()); + tw.writeString(encoded, 0, encoded.length); return tw.getBytes(); } - private static String getCurveName(ECParameterSpec params) throws IOException { + public static String getCurveName(ECParameterSpec params) throws IOException { int fieldSize = getCurveSize(params); + final String curveName = getCurveName(fieldSize); + if (curveName == null) { + throw new IOException("invalid curve size " + fieldSize); + } + return curveName; + } + + public static String getCurveName(int fieldSize) { String curveName = CURVE_SIZES.get(fieldSize); if (curveName == null) { - throw new IOException("Unsupported curve field size: " + fieldSize); + return null; } return curveName; } - private static int getCurveSize(ECParameterSpec params) { + public static int getCurveSize(ECParameterSpec params) { return params.getCurve().getField().getFieldSize(); } @@ -258,7 +284,8 @@ public class ECDSASHA2Verify { TypesWriter rsWriter = new TypesWriter(); rsWriter.writeMPInt(r); rsWriter.writeMPInt(s); - tw.writeBytes(rsWriter.getBytes()); + byte[] encoded = rsWriter.getBytes(); + tw.writeString(encoded, 0, encoded.length); return tw.getBytes(); } |