Anubis.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. /* Anubis.java --
  2. Copyright (C) 2001, 2002, 2003, 2006, 2010 Free Software Foundation, Inc.
  3. This file is a part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or (at
  7. your option) any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
  15. USA
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package gnu.javax.crypto.cipher;
  32. import gnu.java.security.Configuration;
  33. import gnu.java.security.Registry;
  34. import gnu.java.security.util.Util;
  35. import java.security.InvalidKeyException;
  36. import java.util.ArrayList;
  37. import java.util.Collections;
  38. import java.util.Iterator;
  39. import java.util.logging.Logger;
  40. /**
  41. * Anubis is a 128-bit block cipher that accepts a variable-length key. The
  42. * cipher is a uniform substitution-permutation network whose inverse only
  43. * differs from the forward operation in the key schedule. The design of both
  44. * the round transformation and the key schedule is based upon the Wide Trail
  45. * strategy and permits a wide variety of implementation trade-offs.
  46. * <p>
  47. * References:
  48. * <ol>
  49. * <li><a
  50. * href="http://planeta.terra.com.br/informatica/paulobarreto/AnubisPage.html">The
  51. * ANUBIS Block Cipher</a>.<br>
  52. * <a href="mailto:paulo.barreto@terra.com.br">Paulo S.L.M. Barreto</a> and <a
  53. * href="mailto:vincent.rijmen@esat.kuleuven.ac.be">Vincent Rijmen</a>.</li>
  54. * </ol>
  55. */
  56. public final class Anubis
  57. extends BaseCipher
  58. {
  59. private static final Logger log = Configuration.DEBUG ?
  60. Logger.getLogger(Anubis.class.getName()) : null;
  61. private static final int DEFAULT_BLOCK_SIZE = 16; // in bytes
  62. private static final int DEFAULT_KEY_SIZE = 16; // in bytes
  63. private static final String Sd = // p. 25 [ANUBIS]
  64. "\uBA54\u2F74\u53D3\uD24D\u50AC\u8DBF\u7052\u9A4C"
  65. + "\uEAD5\u97D1\u3351\u5BA6\uDE48\uA899\uDB32\uB7FC"
  66. + "\uE39E\u919B\uE2BB\u416E\uA5CB\u6B95\uA1F3\uB102"
  67. + "\uCCC4\u1D14\uC363\uDA5D\u5FDC\u7DCD\u7F5A\u6C5C"
  68. + "\uF726\uFFED\uE89D\u6F8E\u19A0\uF089\u0F07\uAFFB"
  69. + "\u0815\u0D04\u0164\uDF76\u79DD\u3D16\u3F37\u6D38"
  70. + "\uB973\uE935\u5571\u7B8C\u7288\uF62A\u3E5E\u2746"
  71. + "\u0C65\u6861\u03C1\u57D6\uD958\uD866\uD73A\uC83C"
  72. + "\uFA96\uA798\uECB8\uC7AE\u694B\uABA9\u670A\u47F2"
  73. + "\uB522\uE5EE\uBE2B\u8112\u831B\u0E23\uF545\u21CE"
  74. + "\u492C\uF9E6\uB628\u1782\u1A8B\uFE8A\u09C9\u874E"
  75. + "\uE12E\uE4E0\uEB90\uA41E\u8560\u0025\uF4F1\u940B"
  76. + "\uE775\uEF34\u31D4\uD086\u7EAD\uFD29\u303B\u9FF8"
  77. + "\uC613\u0605\uC511\u777C\u7A78\u361C\u3959\u1856"
  78. + "\uB3B0\u2420\uB292\uA3C0\u4462\u10B4\u8443\u93C2"
  79. + "\u4ABD\u8F2D\uBC9C\u6A40\uCFA2\u804F\u1FCA\uAA42";
  80. private static final byte[] S = new byte[256];
  81. private static final int[] T0 = new int[256];
  82. private static final int[] T1 = new int[256];
  83. private static final int[] T2 = new int[256];
  84. private static final int[] T3 = new int[256];
  85. private static final int[] T4 = new int[256];
  86. private static final int[] T5 = new int[256];
  87. /**
  88. * Anubis round constants. This is the largest possible considering that we
  89. * always use R values, R = 8 + N, and 4 &lt;= N &lt;= 10.
  90. */
  91. private static final int[] rc = new int[18];
  92. /**
  93. * KAT vector (from ecb_vk): I=83
  94. * KEY=000000000000000000002000000000000000000000000000
  95. * CT=2E66AB15773F3D32FB6C697509460DF4
  96. */
  97. private static final byte[] KAT_KEY =
  98. Util.toBytesFromString("000000000000000000002000000000000000000000000000");
  99. private static final byte[] KAT_CT =
  100. Util.toBytesFromString("2E66AB15773F3D32FB6C697509460DF4");
  101. /** caches the result of the correctness test, once executed. */
  102. private static Boolean valid;
  103. static
  104. {
  105. long time = System.currentTimeMillis();
  106. int ROOT = 0x11d; // para. 2.1 [ANUBIS]
  107. int i, s, s2, s4, s6, s8, t;
  108. char c;
  109. for (i = 0; i < 256; i++)
  110. {
  111. c = Sd.charAt(i >>> 1);
  112. s = ((i & 1) == 0 ? c >>> 8 : c) & 0xFF;
  113. S[i] = (byte) s;
  114. s2 = s << 1;
  115. if (s2 > 0xFF)
  116. s2 ^= ROOT;
  117. s4 = s2 << 1;
  118. if (s4 > 0xFF)
  119. s4 ^= ROOT;
  120. s6 = s4 ^ s2;
  121. s8 = s4 << 1;
  122. if (s8 > 0xFF)
  123. s8 ^= ROOT;
  124. T0[i] = s << 24 | s2 << 16 | s4 << 8 | s6;
  125. T1[i] = s2 << 24 | s << 16 | s6 << 8 | s4;
  126. T2[i] = s4 << 24 | s6 << 16 | s << 8 | s2;
  127. T3[i] = s6 << 24 | s4 << 16 | s2 << 8 | s;
  128. T4[i] = s << 24 | s << 16 | s << 8 | s;
  129. T5[s] = s << 24 | s2 << 16 | s6 << 8 | s8;
  130. }
  131. // compute round constant
  132. for (i = 0, s = 0; i < 18;)
  133. rc[i++] = S[(s++) & 0xFF] << 24
  134. | (S[(s++) & 0xFF] & 0xFF) << 16
  135. | (S[(s++) & 0xFF] & 0xFF) << 8
  136. | (S[(s++) & 0xFF] & 0xFF);
  137. time = System.currentTimeMillis() - time;
  138. if (Configuration.DEBUG)
  139. {
  140. log.fine("Static data");
  141. log.fine("T0[]:");
  142. StringBuilder sb;
  143. for (i = 0; i < 64; i++)
  144. {
  145. sb = new StringBuilder();
  146. for (t = 0; t < 4; t++)
  147. sb.append("0x").append(Util.toString(T0[i * 4 + t])).append(", ");
  148. log.fine(sb.toString());
  149. }
  150. log.fine("T1[]:");
  151. for (i = 0; i < 64; i++)
  152. {
  153. sb = new StringBuilder();
  154. for (t = 0; t < 4; t++)
  155. sb.append("0x").append(Util.toString(T1[i * 4 + t])).append(", ");
  156. log.fine(sb.toString());
  157. }
  158. log.fine("T2[]:");
  159. for (i = 0; i < 64; i++)
  160. {
  161. sb = new StringBuilder();
  162. for (t = 0; t < 4; t++)
  163. sb.append("0x").append(Util.toString(T2[i * 4 + t])).append(", ");
  164. log.fine(sb.toString());
  165. }
  166. log.fine("T3[]:");
  167. for (i = 0; i < 64; i++)
  168. {
  169. sb = new StringBuilder();
  170. for (t = 0; t < 4; t++)
  171. sb.append("0x").append(Util.toString(T3[i * 4 + t])).append(", ");
  172. log.fine(sb.toString());
  173. }
  174. log.fine("T4[]:");
  175. for (i = 0; i < 64; i++)
  176. {
  177. sb = new StringBuilder();
  178. for (t = 0; t < 4; t++)
  179. sb.append("0x").append(Util.toString(T4[i * 4 + t])).append(", ");
  180. log.fine(sb.toString());
  181. }
  182. log.fine("T5[]:");
  183. for (i = 0; i < 64; i++)
  184. {
  185. sb = new StringBuilder();
  186. for (t = 0; t < 4; t++)
  187. sb.append("0x").append(Util.toString(T5[i * 4 + t])).append(", ");
  188. log.fine(sb.toString());
  189. }
  190. log.fine("rc[]:");
  191. for (i = 0; i < 18; i++)
  192. log.fine("0x" + Util.toString(rc[i]));
  193. log.fine("Total initialization time: " + time + " ms.");
  194. }
  195. }
  196. /** Trivial 0-arguments constructor. */
  197. public Anubis()
  198. {
  199. super(Registry.ANUBIS_CIPHER, DEFAULT_BLOCK_SIZE, DEFAULT_KEY_SIZE);
  200. }
  201. private static void anubis(byte[] in, int i, byte[] out, int j, int[][] K)
  202. {
  203. // extract encryption round keys
  204. int R = K.length - 1;
  205. int[] Ker = K[0];
  206. // mu function + affine key addition
  207. int a0 = (in[i++] << 24
  208. | (in[i++] & 0xFF) << 16
  209. | (in[i++] & 0xFF) << 8
  210. | (in[i++] & 0xFF) ) ^ Ker[0];
  211. int a1 = (in[i++] << 24
  212. | (in[i++] & 0xFF) << 16
  213. | (in[i++] & 0xFF) << 8
  214. | (in[i++] & 0xFF) ) ^ Ker[1];
  215. int a2 = (in[i++] << 24
  216. | (in[i++] & 0xFF) << 16
  217. | (in[i++] & 0xFF) << 8
  218. | (in[i++] & 0xFF) ) ^ Ker[2];
  219. int a3 = (in[i++] << 24
  220. | (in[i++] & 0xFF) << 16
  221. | (in[i++] & 0xFF) << 8
  222. | (in[i] & 0xFF) ) ^ Ker[3];
  223. int b0, b1, b2, b3;
  224. // round function
  225. for (int r = 1; r < R; r++)
  226. {
  227. Ker = K[r];
  228. b0 = T0[ a0 >>> 24 ]
  229. ^ T1[ a1 >>> 24 ]
  230. ^ T2[ a2 >>> 24 ]
  231. ^ T3[ a3 >>> 24 ] ^ Ker[0];
  232. b1 = T0[(a0 >>> 16) & 0xFF]
  233. ^ T1[(a1 >>> 16) & 0xFF]
  234. ^ T2[(a2 >>> 16) & 0xFF]
  235. ^ T3[(a3 >>> 16) & 0xFF] ^ Ker[1];
  236. b2 = T0[(a0 >>> 8) & 0xFF]
  237. ^ T1[(a1 >>> 8) & 0xFF]
  238. ^ T2[(a2 >>> 8) & 0xFF]
  239. ^ T3[(a3 >>> 8) & 0xFF] ^ Ker[2];
  240. b3 = T0[ a0 & 0xFF]
  241. ^ T1[ a1 & 0xFF]
  242. ^ T2[ a2 & 0xFF]
  243. ^ T3[ a3 & 0xFF] ^ Ker[3];
  244. a0 = b0;
  245. a1 = b1;
  246. a2 = b2;
  247. a3 = b3;
  248. if (Configuration.DEBUG)
  249. log.fine("T" + r + "=" + Util.toString(a0) + Util.toString(a1)
  250. + Util.toString(a2) + Util.toString(a3));
  251. }
  252. // last round function
  253. Ker = K[R];
  254. int tt = Ker[0];
  255. out[j++] = (byte)(S[ a0 >>> 24 ] ^ (tt >>> 24));
  256. out[j++] = (byte)(S[ a1 >>> 24 ] ^ (tt >>> 16));
  257. out[j++] = (byte)(S[ a2 >>> 24 ] ^ (tt >>> 8));
  258. out[j++] = (byte)(S[ a3 >>> 24 ] ^ tt);
  259. tt = Ker[1];
  260. out[j++] = (byte)(S[(a0 >>> 16) & 0xFF] ^ (tt >>> 24));
  261. out[j++] = (byte)(S[(a1 >>> 16) & 0xFF] ^ (tt >>> 16));
  262. out[j++] = (byte)(S[(a2 >>> 16) & 0xFF] ^ (tt >>> 8));
  263. out[j++] = (byte)(S[(a3 >>> 16) & 0xFF] ^ tt);
  264. tt = Ker[2];
  265. out[j++] = (byte)(S[(a0 >>> 8) & 0xFF] ^ (tt >>> 24));
  266. out[j++] = (byte)(S[(a1 >>> 8) & 0xFF] ^ (tt >>> 16));
  267. out[j++] = (byte)(S[(a2 >>> 8) & 0xFF] ^ (tt >>> 8));
  268. out[j++] = (byte)(S[(a3 >>> 8) & 0xFF] ^ tt);
  269. tt = Ker[3];
  270. out[j++] = (byte)(S[ a0 & 0xFF] ^ (tt >>> 24));
  271. out[j++] = (byte)(S[ a1 & 0xFF] ^ (tt >>> 16));
  272. out[j++] = (byte)(S[ a2 & 0xFF] ^ (tt >>> 8));
  273. out[j ] = (byte)(S[ a3 & 0xFF] ^ tt);
  274. if (Configuration.DEBUG)
  275. log.fine("T=" + Util.toString(out, j - 15, 16) + "\n");
  276. }
  277. public Object clone()
  278. {
  279. Anubis result = new Anubis();
  280. result.currentBlockSize = this.currentBlockSize;
  281. return result;
  282. }
  283. public Iterator blockSizes()
  284. {
  285. ArrayList al = new ArrayList();
  286. al.add(Integer.valueOf(DEFAULT_BLOCK_SIZE));
  287. return Collections.unmodifiableList(al).iterator();
  288. }
  289. public Iterator keySizes()
  290. {
  291. ArrayList al = new ArrayList();
  292. for (int n = 4; n < 10; n++)
  293. al.add(Integer.valueOf(n * 32 / 8));
  294. return Collections.unmodifiableList(al).iterator();
  295. }
  296. /**
  297. * Expands a user-supplied key material into a session key for a designated
  298. * <i>block size</i>.
  299. *
  300. * @param uk the 32N-bit user-supplied key material; 4 &lt;= N &lt;= 10.
  301. * @param bs the desired block size in bytes.
  302. * @return an Object encapsulating the session key.
  303. * @exception IllegalArgumentException if the block size is not 16 (128-bit).
  304. * @exception InvalidKeyException if the key data is invalid.
  305. */
  306. public Object makeKey(byte[] uk, int bs) throws InvalidKeyException
  307. {
  308. if (bs != DEFAULT_BLOCK_SIZE)
  309. throw new IllegalArgumentException();
  310. if (uk == null)
  311. throw new InvalidKeyException("Empty key");
  312. if ((uk.length % 4) != 0)
  313. throw new InvalidKeyException("Key is not multiple of 32-bit.");
  314. int N = uk.length / 4;
  315. if (N < 4 || N > 10)
  316. throw new InvalidKeyException("Key is not 32N; 4 <= N <= 10");
  317. int R = 8 + N;
  318. int[][] Ke = new int[R + 1][4]; // encryption round keys
  319. int[][] Kd = new int[R + 1][4]; // decryption round keys
  320. int[] tk = new int[N];
  321. int[] kk = new int[N];
  322. int r, i, j, k, k0, k1, k2, k3, tt;
  323. // apply mu to k0
  324. for (r = 0, i = 0; r < N;)
  325. tk[r++] = uk[i++] << 24
  326. | (uk[i++] & 0xFF) << 16
  327. | (uk[i++] & 0xFF) << 8
  328. | (uk[i++] & 0xFF);
  329. for (r = 0; r <= R; r++)
  330. {
  331. if (r > 0)
  332. {
  333. // psi = key evolution function
  334. kk[0] = T0[(tk[0 ] >>> 24) ]
  335. ^ T1[(tk[N - 1] >>> 16) & 0xFF]
  336. ^ T2[(tk[N - 2] >>> 8) & 0xFF]
  337. ^ T3[ tk[N - 3] & 0xFF];
  338. kk[1] = T0[(tk[1 ] >>> 24) ]
  339. ^ T1[(tk[0 ] >>> 16) & 0xFF]
  340. ^ T2[(tk[N - 1] >>> 8) & 0xFF]
  341. ^ T3[ tk[N - 2] & 0xFF];
  342. kk[2] = T0[(tk[2 ] >>> 24) ]
  343. ^ T1[(tk[1 ] >>> 16) & 0xFF]
  344. ^ T2[(tk[0 ] >>> 8) & 0xFF]
  345. ^ T3[ tk[N - 1] & 0xFF];
  346. kk[3] = T0[(tk[3 ] >>> 24) ]
  347. ^ T1[(tk[2 ] >>> 16) & 0xFF]
  348. ^ T2[(tk[1 ] >>> 8) & 0xFF]
  349. ^ T3[ tk[0 ] & 0xFF];
  350. for (i = 4; i < N; i++)
  351. kk[i] = T0[ tk[i ] >>> 24 ]
  352. ^ T1[(tk[i - 1] >>> 16) & 0xFF]
  353. ^ T2[(tk[i - 2] >>> 8) & 0xFF]
  354. ^ T3[ tk[i - 3] & 0xFF];
  355. // apply sigma (affine addition) to round constant
  356. tk[0] = rc[r - 1] ^ kk[0];
  357. for (i = 1; i < N; i++)
  358. tk[i] = kk[i];
  359. }
  360. // phi = key selection function
  361. tt = tk[N - 1];
  362. k0 = T4[ tt >>> 24 ];
  363. k1 = T4[(tt >>> 16) & 0xFF];
  364. k2 = T4[(tt >>> 8) & 0xFF];
  365. k3 = T4[ tt & 0xFF];
  366. for (k = N - 2; k >= 0; k--)
  367. {
  368. tt = tk[k];
  369. k0 = T4[ tt >>> 24 ]
  370. ^ (T5[(k0 >>> 24) & 0xFF] & 0xFF000000)
  371. ^ (T5[(k0 >>> 16) & 0xFF] & 0x00FF0000)
  372. ^ (T5[(k0 >>> 8) & 0xFF] & 0x0000FF00)
  373. ^ (T5 [k0 & 0xFF] & 0x000000FF);
  374. k1 = T4[(tt >>> 16) & 0xFF]
  375. ^ (T5[(k1 >>> 24) & 0xFF] & 0xFF000000)
  376. ^ (T5[(k1 >>> 16) & 0xFF] & 0x00FF0000)
  377. ^ (T5[(k1 >>> 8) & 0xFF] & 0x0000FF00)
  378. ^ (T5[ k1 & 0xFF] & 0x000000FF);
  379. k2 = T4[(tt >>> 8) & 0xFF]
  380. ^ (T5[(k2 >>> 24) & 0xFF] & 0xFF000000)
  381. ^ (T5[(k2 >>> 16) & 0xFF] & 0x00FF0000)
  382. ^ (T5[(k2 >>> 8) & 0xFF] & 0x0000FF00)
  383. ^ (T5[ k2 & 0xFF] & 0x000000FF);
  384. k3 = T4[ tt & 0xFF]
  385. ^ (T5[(k3 >>> 24) & 0xFF] & 0xFF000000)
  386. ^ (T5[(k3 >>> 16) & 0xFF] & 0x00FF0000)
  387. ^ (T5[(k3 >>> 8) & 0xFF] & 0x0000FF00)
  388. ^ (T5[ k3 & 0xFF] & 0x000000FF);
  389. }
  390. Ke[r][0] = k0;
  391. Ke[r][1] = k1;
  392. Ke[r][2] = k2;
  393. Ke[r][3] = k3;
  394. if (r == 0 || r == R)
  395. {
  396. Kd[R - r][0] = k0;
  397. Kd[R - r][1] = k1;
  398. Kd[R - r][2] = k2;
  399. Kd[R - r][3] = k3;
  400. }
  401. else
  402. {
  403. Kd[R - r][0] = T0[S[ k0 >>> 24 ] & 0xFF]
  404. ^ T1[S[(k0 >>> 16) & 0xFF] & 0xFF]
  405. ^ T2[S[(k0 >>> 8) & 0xFF] & 0xFF]
  406. ^ T3[S[ k0 & 0xFF] & 0xFF];
  407. Kd[R - r][1] = T0[S[ k1 >>> 24 ] & 0xFF]
  408. ^ T1[S[(k1 >>> 16) & 0xFF] & 0xFF]
  409. ^ T2[S[(k1 >>> 8) & 0xFF] & 0xFF]
  410. ^ T3[S[ k1 & 0xFF] & 0xFF];
  411. Kd[R - r][2] = T0[S[ k2 >>> 24 ] & 0xFF]
  412. ^ T1[S[(k2 >>> 16) & 0xFF] & 0xFF]
  413. ^ T2[S[(k2 >>> 8) & 0xFF] & 0xFF]
  414. ^ T3[S[ k2 & 0xFF] & 0xFF];
  415. Kd[R - r][3] = T0[S[ k3 >>> 24 ] & 0xFF]
  416. ^ T1[S[(k3 >>> 16) & 0xFF] & 0xFF]
  417. ^ T2[S[(k3 >>> 8) & 0xFF] & 0xFF]
  418. ^ T3[S[ k3 & 0xFF] & 0xFF];
  419. }
  420. }
  421. if (Configuration.DEBUG)
  422. {
  423. log.fine("Key schedule");
  424. log.fine("Ke[]:");
  425. StringBuilder sb;
  426. for (r = 0; r < R + 1; r++)
  427. {
  428. sb = new StringBuilder("#").append(r).append(": ");
  429. for (j = 0; j < 4; j++)
  430. sb.append("0x").append(Util.toString(Ke[r][j])).append(", ");
  431. log.fine(sb.toString());
  432. }
  433. log.fine("Kd[]:");
  434. for (r = 0; r < R + 1; r++)
  435. {
  436. sb = new StringBuilder("#").append(r).append(": ");
  437. for (j = 0; j < 4; j++)
  438. sb.append("0x").append(Util.toString(Kd[r][j])).append(", ");
  439. log.fine(sb.toString());
  440. }
  441. }
  442. return new Object[] { Ke, Kd };
  443. }
  444. public void encrypt(byte[] in, int i, byte[] out, int j, Object k, int bs)
  445. {
  446. if (bs != DEFAULT_BLOCK_SIZE)
  447. throw new IllegalArgumentException();
  448. int[][] K = (int[][])((Object[]) k)[0];
  449. anubis(in, i, out, j, K);
  450. }
  451. public void decrypt(byte[] in, int i, byte[] out, int j, Object k, int bs)
  452. {
  453. if (bs != DEFAULT_BLOCK_SIZE)
  454. throw new IllegalArgumentException();
  455. int[][] K = (int[][])((Object[]) k)[1];
  456. anubis(in, i, out, j, K);
  457. }
  458. public boolean selfTest()
  459. {
  460. if (valid == null)
  461. {
  462. boolean result = super.selfTest(); // do symmetry tests
  463. if (result)
  464. result = testKat(KAT_KEY, KAT_CT);
  465. valid = Boolean.valueOf(result);
  466. }
  467. return valid.booleanValue();
  468. }
  469. }