Coverage Summary for Class: Blake2b (org.ethereum.crypto.cryptohash)

Class Class, % Method, % Line, %
Blake2b 0% (0/1) 0% (0/4) 0% (0/33)


1 package org.ethereum.crypto.cryptohash; 2  3 public class Blake2b { 4  5  /** 6  * IV is an initialization vector for BLAKE2b 7  */ 8  private static final long[] IV = { 9  0x6a09e667f3bcc908L, 0xbb67ae8584caa73bL, 0x3c6ef372fe94f82bL, 0xa54ff53a5f1d36f1L, 10  0x510e527fade682d1L, 0x9b05688c2b3e6c1fL, 0x1f83d9abfb41bd6bL, 0x5be0cd19137e2179L, 11  }; 12  13  /** 14  * the PRECOMPUTED values for BLAKE2b 15  * there are 10 16-byte arrays - one for each round 16  * the entries are calculated from the sigma constants. 17  */ 18  private static final byte[][] PRECOMPUTED = { 19  {0, 2, 4, 6, 1, 3, 5, 7, 8, 10, 12, 14, 9, 11, 13, 15}, 20  {14, 4, 9, 13, 10, 8, 15, 6, 1, 0, 11, 5, 12, 2, 7, 3}, 21  {11, 12, 5, 15, 8, 0, 2, 13, 10, 3, 7, 9, 14, 6, 1, 4}, 22  {7, 3, 13, 11, 9, 1, 12, 14, 2, 5, 4, 15, 6, 10, 0, 8}, 23  {9, 5, 2, 10, 0, 7, 4, 15, 14, 11, 6, 3, 1, 12, 8, 13}, 24  {2, 6, 0, 8, 12, 10, 11, 3, 4, 7, 15, 1, 13, 5, 14, 9}, 25  {12, 1, 14, 4, 5, 15, 13, 10, 0, 6, 9, 8, 7, 3, 2, 11}, 26  {13, 7, 12, 3, 11, 14, 1, 9, 5, 15, 8, 2, 0, 4, 6, 10}, 27  {6, 14, 11, 0, 15, 9, 3, 8, 12, 13, 1, 10, 2, 7, 4, 5}, 28  {10, 8, 7, 1, 2, 4, 6, 5, 15, 9, 3, 13, 11, 14, 12, 0}, 29  }; 30  31  private Blake2b() { 32  throw new IllegalStateException("Utility class"); 33  } 34  35  /** 36  * F is a compression function for BLAKE2b. The state vector 37  * provided as the first parameter is modified by the function. 38  * 39  * @param h the state vector 40  * @param m the message block vector 41  * @param c offset counter 42  * @param f final block indicator flag 43  * @param rounds number of rounds 44  */ 45  public static void functionF(long[] h, long[] m, long[] c, boolean f, long rounds) { 46  long t0 = c[0]; 47  long t1 = c[1]; 48  49  long[] v = new long[16]; 50  System.arraycopy(h, 0, v, 0, 8); 51  System.arraycopy(IV, 0, v, 8, 8); 52  53  v[12] ^= t0; 54  v[13] ^= t1; 55  56  if (f) { 57  v[14] ^= 0xffffffffffffffffL; 58  } 59  60  for (long j = 0; j < rounds; ++j) { 61  byte[] s = PRECOMPUTED[(int) (j % 10)]; 62  63  mix(v, m[s[0]], m[s[4]], 0, 4, 8, 12); 64  mix(v, m[s[1]], m[s[5]], 1, 5, 9, 13); 65  mix(v, m[s[2]], m[s[6]], 2, 6, 10, 14); 66  mix(v, m[s[3]], m[s[7]], 3, 7, 11, 15); 67  mix(v, m[s[8]], m[s[12]], 0, 5, 10, 15); 68  mix(v, m[s[9]], m[s[13]], 1, 6, 11, 12); 69  mix(v, m[s[10]], m[s[14]], 2, 7, 8, 13); 70  mix(v, m[s[11]], m[s[15]], 3, 4, 9, 14); 71  } 72  73  // update h: 74  for (int offset = 0; offset < h.length; offset++) { 75  h[offset] ^= v[offset] ^ v[offset + 8]; 76  } 77  } 78  79  private static void mix(long[] v, final long a, final long b, final int i, final int j, final int k, final int l) { 80  v[i] += a + v[j]; 81  v[l] = Long.rotateLeft(v[l] ^ v[i], -32); 82  v[k] += v[l]; 83  v[j] = Long.rotateLeft(v[j] ^ v[k], -24); 84  85  v[i] += b + v[j]; 86  v[l] = Long.rotateLeft(v[l] ^ v[i], -16); 87  v[k] += v[l]; 88  v[j] = Long.rotateLeft(v[j] ^ v[k], -63); 89  } 90 }