Mercurial > 510Connectbot
comparison src/ch/ethz/ssh2/crypto/KeyMaterial.java @ 307:071eccdff8ea ganymed
fix java formatting
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 30 Jul 2014 14:16:58 -0700 |
parents | 91a31873c42a |
children |
comparison
equal
deleted
inserted
replaced
305:d2b303406d63 | 307:071eccdff8ea |
---|---|
24 public byte[] integrity_key_server_to_client; | 24 public byte[] integrity_key_server_to_client; |
25 | 25 |
26 private static byte[] calculateKey(HashForSSH2Types sh, BigInteger K, byte[] H, byte type, byte[] SessionID, | 26 private static byte[] calculateKey(HashForSSH2Types sh, BigInteger K, byte[] H, byte type, byte[] SessionID, |
27 int keyLength) throws IOException { | 27 int keyLength) throws IOException { |
28 byte[] res = new byte[keyLength]; | 28 byte[] res = new byte[keyLength]; |
29 | |
30 int dglen = sh.getDigestLength(); | 29 int dglen = sh.getDigestLength(); |
31 int numRounds = (keyLength + dglen - 1) / dglen; | 30 int numRounds = (keyLength + dglen - 1) / dglen; |
32 | |
33 byte[][] tmp = new byte[numRounds][]; | 31 byte[][] tmp = new byte[numRounds][]; |
34 | |
35 sh.reset(); | 32 sh.reset(); |
36 sh.updateBigInt(K); | 33 sh.updateBigInt(K); |
37 sh.updateBytes(H); | 34 sh.updateBytes(H); |
38 sh.updateByte(type); | 35 sh.updateByte(type); |
39 sh.updateBytes(SessionID); | 36 sh.updateBytes(SessionID); |
40 | |
41 tmp[0] = sh.getDigest(); | 37 tmp[0] = sh.getDigest(); |
42 | |
43 int off = 0; | 38 int off = 0; |
44 int produced = Math.min(dglen, keyLength); | 39 int produced = Math.min(dglen, keyLength); |
45 | |
46 System.arraycopy(tmp[0], 0, res, off, produced); | 40 System.arraycopy(tmp[0], 0, res, off, produced); |
47 | |
48 keyLength -= produced; | 41 keyLength -= produced; |
49 off += produced; | 42 off += produced; |
50 | 43 |
51 for(int i = 1; i < numRounds; i++) { | 44 for (int i = 1; i < numRounds; i++) { |
52 sh.updateBigInt(K); | 45 sh.updateBigInt(K); |
53 sh.updateBytes(H); | 46 sh.updateBytes(H); |
54 | 47 |
55 for(int j = 0; j < i; j++) { | 48 for (int j = 0; j < i; j++) { |
56 sh.updateBytes(tmp[j]); | 49 sh.updateBytes(tmp[j]); |
57 } | 50 } |
58 | 51 |
59 tmp[i] = sh.getDigest(); | 52 tmp[i] = sh.getDigest(); |
60 | |
61 produced = Math.min(dglen, keyLength); | 53 produced = Math.min(dglen, keyLength); |
62 System.arraycopy(tmp[i], 0, res, off, produced); | 54 System.arraycopy(tmp[i], 0, res, off, produced); |
63 keyLength -= produced; | 55 keyLength -= produced; |
64 off += produced; | 56 off += produced; |
65 } | 57 } |
67 return res; | 59 return res; |
68 } | 60 } |
69 | 61 |
70 public static KeyMaterial create(String hashType, byte[] H, BigInteger K, byte[] SessionID, int keyLengthCS, | 62 public static KeyMaterial create(String hashType, byte[] H, BigInteger K, byte[] SessionID, int keyLengthCS, |
71 int blockSizeCS, int macLengthCS, int keyLengthSC, int blockSizeSC, int macLengthSC) | 63 int blockSizeCS, int macLengthCS, int keyLengthSC, int blockSizeSC, int macLengthSC) |
72 throws IOException { | 64 throws IOException { |
73 KeyMaterial km = new KeyMaterial(); | 65 KeyMaterial km = new KeyMaterial(); |
74 | |
75 HashForSSH2Types sh = new HashForSSH2Types(hashType); | 66 HashForSSH2Types sh = new HashForSSH2Types(hashType); |
76 | |
77 km.initial_iv_client_to_server = calculateKey(sh, K, H, (byte) 'A', SessionID, blockSizeCS); | 67 km.initial_iv_client_to_server = calculateKey(sh, K, H, (byte) 'A', SessionID, blockSizeCS); |
78 | |
79 km.initial_iv_server_to_client = calculateKey(sh, K, H, (byte) 'B', SessionID, blockSizeSC); | 68 km.initial_iv_server_to_client = calculateKey(sh, K, H, (byte) 'B', SessionID, blockSizeSC); |
80 | |
81 km.enc_key_client_to_server = calculateKey(sh, K, H, (byte) 'C', SessionID, keyLengthCS); | 69 km.enc_key_client_to_server = calculateKey(sh, K, H, (byte) 'C', SessionID, keyLengthCS); |
82 | |
83 km.enc_key_server_to_client = calculateKey(sh, K, H, (byte) 'D', SessionID, keyLengthSC); | 70 km.enc_key_server_to_client = calculateKey(sh, K, H, (byte) 'D', SessionID, keyLengthSC); |
84 | |
85 km.integrity_key_client_to_server = calculateKey(sh, K, H, (byte) 'E', SessionID, macLengthCS); | 71 km.integrity_key_client_to_server = calculateKey(sh, K, H, (byte) 'E', SessionID, macLengthCS); |
86 | |
87 km.integrity_key_server_to_client = calculateKey(sh, K, H, (byte) 'F', SessionID, macLengthSC); | 72 km.integrity_key_server_to_client = calculateKey(sh, K, H, (byte) 'F', SessionID, macLengthSC); |
88 | |
89 return km; | 73 return km; |
90 } | 74 } |
91 } | 75 } |