private void init(int layers, int[] heightOfTrees, int[] winternitzParameter, int[] K) throws IllegalArgumentException { boolean valid = true; String errMsg = ""; this.numOfLayers = layers; if ((numOfLayers != winternitzParameter.length) || (numOfLayers != heightOfTrees.length) || (numOfLayers != K.length)) { valid = false; errMsg = "Unexpected parameterset format"; } for (int i = 0; i < numOfLayers; i++) { if ((K[i] < 2) || ((heightOfTrees[i] - K[i]) % 2 != 0)) { valid = false; errMsg = "Wrong parameter K (K >= 2 and H-K even required)!"; } if ((heightOfTrees[i] < 4) || (winternitzParameter[i] < 2)) { valid = false; errMsg = "Wrong parameter H or w (H > 3 and w > 1 required)!"; } } if (valid) { this.heightOfTrees = Arrays.clone(heightOfTrees); this.winternitzParameter = Arrays.clone(winternitzParameter); this.K = Arrays.clone(K); } else { throw new IllegalArgumentException(errMsg); } }
private static void SMix(int[] B, int BOff, int N, int r) { int BCount = r * 32; int[] blockX1 = new int[16]; int[] blockX2 = new int[16]; int[] blockY = new int[BCount]; int[] X = new int[BCount]; int[][] V = new int[N][]; try { System.arraycopy(B, BOff, X, 0, BCount); for (int i = 0; i < N; ++i) { V[i] = Arrays.clone(X); BlockMix(X, blockX1, blockX2, blockY, r); } int mask = N - 1; for (int i = 0; i < N; ++i) { int j = X[BCount - 16] & mask; Xor(X, V[j], 0, X); BlockMix(X, blockX1, blockX2, blockY, r); } System.arraycopy(X, 0, B, BOff, BCount); } finally { ClearAll(V); ClearAll(new int[][] {X, blockX1, blockX2, blockY}); } }
/** * Returns the parameter K needed for authentication path computation * * @return The parameter K needed for authentication path computation */ public int[] getK() { return Arrays.clone(K); }
/** * Returns the array of WinternitzParameter (for each layer) of the authentication trees * * @return The array of WinternitzParameter (for each layer) of the authentication trees */ public int[] getWinternitzParameter() { return Arrays.clone(winternitzParameter); }
/** * Returns the array of height (for each layer) of the authentication trees * * @return The array of height (for each layer) of the authentication trees */ public int[] getHeightOfTrees() { return Arrays.clone(heightOfTrees); }