Mercurial > 510Connectbot
comparison app/src/main/java/ch/ethz/ssh2/crypto/digest/HMAC.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 |
---|---|
19 | 19 |
20 byte[] tmp; | 20 byte[] tmp; |
21 | 21 |
22 int size; | 22 int size; |
23 | 23 |
24 public HMAC(Digest md, byte[] key, int size) throws DigestException { | 24 public HMAC(Digest md, byte[] key, int digestsize, int blocksize) throws DigestException { |
25 this.md = md; | 25 this.md = md; |
26 this.size = size; | 26 this.size = digestsize; |
27 tmp = new byte[md.getDigestLength()]; | 27 tmp = new byte[md.getDigestLength()]; |
28 final int BLOCKSIZE = 64; | 28 k_xor_ipad = new byte[blocksize]; |
29 k_xor_ipad = new byte[BLOCKSIZE]; | 29 k_xor_opad = new byte[blocksize]; |
30 k_xor_opad = new byte[BLOCKSIZE]; | |
31 | 30 |
32 if (key.length > BLOCKSIZE) { | 31 if (key.length > blocksize) { |
33 md.reset(); | 32 md.reset(); |
34 md.update(key); | 33 md.update(key); |
35 md.digest(tmp); | 34 md.digest(tmp); |
36 key = tmp; | 35 key = tmp; |
37 } | 36 } |
38 | 37 |
39 System.arraycopy(key, 0, k_xor_ipad, 0, key.length); | 38 System.arraycopy(key, 0, k_xor_ipad, 0, key.length); |
40 System.arraycopy(key, 0, k_xor_opad, 0, key.length); | 39 System.arraycopy(key, 0, k_xor_opad, 0, key.length); |
41 | 40 |
42 for (int i = 0; i < BLOCKSIZE; i++) { | 41 for (int i = 0; i < blocksize; i++) { |
43 k_xor_ipad[i] ^= 0x36; | 42 k_xor_ipad[i] ^= 0x36; |
44 k_xor_opad[i] ^= 0x5C; | 43 k_xor_opad[i] ^= 0x5C; |
45 } | 44 } |
46 | 45 |
47 md.update(k_xor_ipad); | 46 md.update(k_xor_ipad); |