Mercurial > 510Connectbot
comparison 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 |
comparison
equal
deleted
inserted
replaced
509:2eb4fa13b9ef | 510:7953570e5210 |
---|---|
18 private int size; | 18 private int size; |
19 | 19 |
20 public static String[] getMacList() { | 20 public static String[] getMacList() { |
21 // Higher priority (stronger) first. Added SHA-2 algorithms as in RFC 6668 | 21 // Higher priority (stronger) first. Added SHA-2 algorithms as in RFC 6668 |
22 return new String[] { | 22 return new String[] { |
23 // "hmac-sha2-512", // fails interop w/ centos6 | 23 "hmac-sha2-512", |
24 "hmac-sha2-256", | 24 "hmac-sha2-256", |
25 "hmac-sha1", | 25 "hmac-sha1", |
26 "hmac-sha1-96", | 26 "hmac-sha1-96", |
27 "hmac-md5", | 27 "hmac-md5", |
28 "hmac-md5-96" | 28 "hmac-md5-96" |
34 getKeyLen(m); | 34 getKeyLen(m); |
35 } | 35 } |
36 } | 36 } |
37 | 37 |
38 public static int getKeyLen(final String type) { | 38 public static int getKeyLen(final String type) { |
39 if (type.equals("hmac-sha1")) { | 39 if (type.equals("hmac-sha2-512")) return 64; |
40 return 20; | 40 if (type.equals("hmac-sha2-256")) return 32; |
41 } | 41 if (type.equals("hmac-sha1")) return 20; |
42 | 42 if (type.equals("hmac-sha1-96")) return 20; |
43 if (type.equals("hmac-sha1-96")) { | 43 if (type.equals("hmac-md5")) return 16; |
44 return 20; | 44 if (type.equals("hmac-md5-96")) return 16; |
45 } | |
46 | |
47 if (type.equals("hmac-md5")) { | |
48 return 16; | |
49 } | |
50 | |
51 if (type.equals("hmac-md5-96")) { | |
52 return 16; | |
53 } | |
54 | |
55 if (type.equals("hmac-sha2-256")) { | |
56 return 32; | |
57 } | |
58 | |
59 if (type.equals("hmac-sha2-512")) { | |
60 return 64; | |
61 } | |
62 | |
63 throw new IllegalArgumentException(String.format("Unknown algorithm %s", type)); | 45 throw new IllegalArgumentException(String.format("Unknown algorithm %s", type)); |
64 } | 46 } |
65 | 47 |
66 public MAC(final String type, final byte[] key) throws DigestException { | 48 public MAC(final String type, final byte[] key) throws DigestException { |
67 if (type.equals("hmac-sha1")) { | 49 if (type.equals("hmac-sha2-512")) { |
68 mac = new HMAC(new SHA1(), key, 20); | 50 mac = new HMAC(new SHA512(), key, 64, 128); |
51 } | |
52 else if (type.equals("hmac-sha2-256")) { | |
53 mac = new HMAC(new SHA256(), key, 32, 64); | |
54 } | |
55 else if (type.equals("hmac-sha1")) { | |
56 mac = new HMAC(new SHA1(), key, 20, 64); | |
69 } | 57 } |
70 else if (type.equals("hmac-sha1-96")) { | 58 else if (type.equals("hmac-sha1-96")) { |
71 mac = new HMAC(new SHA1(), key, 12); | 59 mac = new HMAC(new SHA1(), key, 12, 64); |
72 } | 60 } |
73 else if (type.equals("hmac-md5")) { | 61 else if (type.equals("hmac-md5")) { |
74 mac = new HMAC(new MD5(), key, 16); | 62 mac = new HMAC(new MD5(), key, 16, 64); |
75 } | 63 } |
76 else if (type.equals("hmac-md5-96")) { | 64 else if (type.equals("hmac-md5-96")) { |
77 mac = new HMAC(new MD5(), key, 12); | 65 mac = new HMAC(new MD5(), key, 12, 64); |
78 } | |
79 else if (type.equals("hmac-sha2-256")) { | |
80 mac = new HMAC(new SHA256(), key, 32); | |
81 } | |
82 else if (type.equals("hmac-sha2-512")) { | |
83 mac = new HMAC(new SHA512(), key, 64); | |
84 } | 66 } |
85 else { | 67 else { |
86 throw new IllegalArgumentException(String.format("Unknown algorithm %s", type)); | 68 throw new IllegalArgumentException(String.format("Unknown algorithm %s", type)); |
87 } | 69 } |
88 | 70 |