diff options
author | Doug Zongker <dougz@android.com> | 2012-07-25 12:08:33 -0700 |
---|---|---|
committer | Doug Zongker <dougz@android.com> | 2012-07-25 13:09:17 -0700 |
commit | 35d9ad5ae72de846967b91aed97060f0e8558661 (patch) | |
tree | d94d48e75beabd007dbe2bf3001b933f02cac649 /libmincrypt/tools | |
parent | 237c80bf4cbc8e8fa3936ec8382b247aa4e96be2 (diff) | |
download | system_core-35d9ad5ae72de846967b91aed97060f0e8558661.zip system_core-35d9ad5ae72de846967b91aed97060f0e8558661.tar.gz system_core-35d9ad5ae72de846967b91aed97060f0e8558661.tar.bz2 |
support e=65537 for libmincrypt, DumpPublicKey
The output produced by DumpPublicKey now has a version tag on each
line (ie, each key). The existing keys are retroactively dubbed
"version 1", and we add a version 2 for 2048-bit e=65537 keys.
Change-Id: I204ec615c8f2346670220a1aeb99269e4abd5f81
Diffstat (limited to 'libmincrypt/tools')
-rw-r--r-- | libmincrypt/tools/DumpPublicKey.java | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/libmincrypt/tools/DumpPublicKey.java b/libmincrypt/tools/DumpPublicKey.java index d2935e0..b83a757 100644 --- a/libmincrypt/tools/DumpPublicKey.java +++ b/libmincrypt/tools/DumpPublicKey.java @@ -34,27 +34,42 @@ import sun.misc.BASE64Encoder; class DumpPublicKey { /** * @param key to perform sanity checks on + * @return version number of key. Supported versions are: + * 1: 2048-bit key with e=3 + * 2: 2048-bit key with e=65537 * @throws Exception if the key has the wrong size or public exponent + */ - static void check(RSAPublicKey key) throws Exception { + static int check(RSAPublicKey key) throws Exception { BigInteger pubexp = key.getPublicExponent(); BigInteger modulus = key.getModulus(); + int version; + + if (pubexp.equals(BigInteger.valueOf(3))) { + version = 1; + } else if (pubexp.equals(BigInteger.valueOf(65537))) { + version = 2; + } else { + throw new Exception("Public exponent should be 3 or 65537 but is " + + pubexp.toString(10) + "."); + } - if (!pubexp.equals(BigInteger.valueOf(3))) - throw new Exception("Public exponent should be 3 but is " + - pubexp.toString(10) + "."); - - if (modulus.bitLength() != 2048) + if (modulus.bitLength() != 2048) { throw new Exception("Modulus should be 2048 bits long but is " + modulus.bitLength() + " bits."); + } + + return version; } /** * @param key to output - * @return a C initializer representing this public key. + * @return a String representing this public key. If the key is a + * version 1 key, the string will be a C initializer; this is + * not true for newer key versions. */ static String print(RSAPublicKey key) throws Exception { - check(key); + int version = check(key); BigInteger N = key.getModulus(); @@ -62,6 +77,12 @@ class DumpPublicKey { int nwords = N.bitLength() / 32; // # of 32 bit integers in modulus + if (version > 1) { + result.append("v"); + result.append(Integer.toString(version)); + result.append(" "); + } + result.append("{"); result.append(nwords); |