Mercurial > 510Connectbot
diff app/src/main/java/ch/ethz/ssh2/crypto/digest/MAC.java @ 510:7953570e5210
update to ganymed-ssh2 tag 263 and fix hmac-sha2-512
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 01 Feb 2023 17:55:29 -0700 |
parents | d29cce60f393 |
children |
line wrap: on
line diff
--- a/app/src/main/java/ch/ethz/ssh2/crypto/digest/MAC.java Sun Jan 29 10:25:21 2023 -0700 +++ b/app/src/main/java/ch/ethz/ssh2/crypto/digest/MAC.java Wed Feb 01 17:55:29 2023 -0700 @@ -20,7 +20,7 @@ public static String[] getMacList() { // Higher priority (stronger) first. Added SHA-2 algorithms as in RFC 6668 return new String[] { - // "hmac-sha2-512", // fails interop w/ centos6 + "hmac-sha2-512", "hmac-sha2-256", "hmac-sha1", "hmac-sha1-96", @@ -36,51 +36,33 @@ } public static int getKeyLen(final String type) { - if (type.equals("hmac-sha1")) { - return 20; - } - - if (type.equals("hmac-sha1-96")) { - return 20; - } - - if (type.equals("hmac-md5")) { - return 16; - } - - if (type.equals("hmac-md5-96")) { - return 16; - } - - if (type.equals("hmac-sha2-256")) { - return 32; - } - - if (type.equals("hmac-sha2-512")) { - return 64; - } - + if (type.equals("hmac-sha2-512")) return 64; + if (type.equals("hmac-sha2-256")) return 32; + if (type.equals("hmac-sha1")) return 20; + if (type.equals("hmac-sha1-96")) return 20; + if (type.equals("hmac-md5")) return 16; + if (type.equals("hmac-md5-96")) return 16; throw new IllegalArgumentException(String.format("Unknown algorithm %s", type)); } public MAC(final String type, final byte[] key) throws DigestException { - if (type.equals("hmac-sha1")) { - mac = new HMAC(new SHA1(), key, 20); + if (type.equals("hmac-sha2-512")) { + mac = new HMAC(new SHA512(), key, 64, 128); + } + else if (type.equals("hmac-sha2-256")) { + mac = new HMAC(new SHA256(), key, 32, 64); + } + else if (type.equals("hmac-sha1")) { + mac = new HMAC(new SHA1(), key, 20, 64); } else if (type.equals("hmac-sha1-96")) { - mac = new HMAC(new SHA1(), key, 12); + mac = new HMAC(new SHA1(), key, 12, 64); } else if (type.equals("hmac-md5")) { - mac = new HMAC(new MD5(), key, 16); + mac = new HMAC(new MD5(), key, 16, 64); } else if (type.equals("hmac-md5-96")) { - mac = new HMAC(new MD5(), key, 12); - } - else if (type.equals("hmac-sha2-256")) { - mac = new HMAC(new SHA256(), key, 32); - } - else if (type.equals("hmac-sha2-512")) { - mac = new HMAC(new SHA512(), key, 64); + mac = new HMAC(new MD5(), key, 12, 64); } else { throw new IllegalArgumentException(String.format("Unknown algorithm %s", type));