public static boolean sequenceEqualConstantTime ( byte [ ] self , byte [ ] other ) { if ( self == null ) { throw new IllegalArgumentException ( "self" ) ; } if ( other == null ) { throw new IllegalArgumentException ( "other" ) ; } // Constant time comparison of two byte arrays long difference = ( self . length & 0xffffffff L ) ^ ( other . length & 0xffffffff L ) ; for ( int i = 0 ; i < self . length && i < other . length ; i ++ ) { difference |= ( self [ i ] ^ other [ i ] ) & 0xffffffff L ; } return difference == 0 ; }
Compares two byte arrays in constant time .