Mercurial > 510Connectbot
annotate app/src/main/java/ch/ethz/ssh2/crypto/cipher/CTRMode.java @ 512:e1dd1fd46e18
change connections file name and look for it in the accuspeech voice projects directory, then the downloads directory
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 10 Feb 2023 14:32:41 -0700 |
parents | d29cce60f393 |
children |
rev | line source |
---|---|
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
1 /* |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
2 * Copyright (c) 2006-2011 Christian Plattner. All rights reserved. |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
3 * Please refer to the LICENSE.txt for licensing details. |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
4 */ |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
5 package ch.ethz.ssh2.crypto.cipher; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
6 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
7 /** |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
8 * This is CTR mode as described in draft-ietf-secsh-newmodes-XY.txt |
307 | 9 * |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
10 * @author Christian Plattner |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
11 * @version 2.50, 03/15/10 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
12 */ |
307 | 13 public class CTRMode implements BlockCipher { |
14 byte[] X; | |
15 byte[] Xenc; | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
16 |
307 | 17 BlockCipher bc; |
18 int blockSize; | |
19 boolean doEncrypt; | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
20 |
307 | 21 int count = 0; |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
22 |
307 | 23 public void init(boolean forEncryption, byte[] key) { |
24 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
25 |
307 | 26 public CTRMode(BlockCipher tc, byte[] iv, boolean doEnc) throws IllegalArgumentException { |
27 bc = tc; | |
28 blockSize = bc.getBlockSize(); | |
29 doEncrypt = doEnc; | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
30 |
307 | 31 if (blockSize != iv.length) |
32 throw new IllegalArgumentException("IV must be " + blockSize + " bytes long! (currently " + iv.length + ")"); | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
33 |
307 | 34 X = new byte[blockSize]; |
35 Xenc = new byte[blockSize]; | |
36 System.arraycopy(iv, 0, X, 0, blockSize); | |
37 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
38 |
307 | 39 public final int getBlockSize() { |
40 return blockSize; | |
41 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
42 |
307 | 43 public final void transformBlock(byte[] src, int srcoff, byte[] dst, int dstoff) { |
44 bc.transformBlock(X, 0, Xenc, 0); | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
45 |
307 | 46 for (int i = 0; i < blockSize; i++) { |
47 dst[dstoff + i] = (byte)(src[srcoff + i] ^ Xenc[i]); | |
48 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
49 |
307 | 50 for (int i = (blockSize - 1); i >= 0; i--) { |
51 X[i]++; | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
52 |
307 | 53 if (X[i] != 0) |
54 break; | |
55 } | |
56 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
57 } |