Here you can find the source of constantTimeAreEqual(byte[] a, byte[] b)
Parameter | Description |
---|---|
a | first array |
b | second array |
public static boolean constantTimeAreEqual(byte[] a, byte[] b)
//package com.java2s; public class Main { /**/*w w w . jav a 2 s.c o m*/ * A constant time equals comparison - does not terminate early if * test will fail. * * @param a first array * @param b second array * @return true if arrays equal, false otherwise. */ public static boolean constantTimeAreEqual(byte[] a, byte[] b) { if (a == b) { return true; } if (a == null || b == null) { return false; } if (a.length != b.length) { return false; } int nonEqual = 0; for (int i = 0; i != a.length; i++) { nonEqual |= (a[i] ^ b[i]); } return nonEqual == 0; } }