+ /**
+ * Compute a binary "Adler-32" checksum as defined by LibXDiff, i.e. with
+ * the bytes backwards and initialised with 0 instead of 1. See bug 34428.
+ *
+ * Returns false if no hashing library is available
+ */
+ function xdiffAdler32( $s ) {
+ static $init;
+ if ( $init === null ) {
+ $init = str_repeat( "\xf0", 205 ) . "\xee" . str_repeat( "\xf0", 67 ) . "\x02";
+ }
+ // The real Adler-32 checksum of $init is zero, so it initialises the
+ // state to zero, as it is at the start of LibXDiff's checksum
+ // algorithm. Appending the subject string then simulates LibXDiff.
+ if ( function_exists( 'hash' ) ) {
+ $hash = hash( 'adler32', $init . $s, true );
+ } elseif ( function_exists( 'mhash' ) ) {
+ $hash = mhash( MHASH_ADLER32, $init . $s );
+ } else {
+ return false;
+ }
+ return strrev( $hash );
+ }
+