package com.peachpasswords.sync import java.math.BigInteger object SASDerivation { fun derive(handshakeHash: ByteArray): String { require(handshakeHash.size >= 8) { "Handshake hash too short for SAS" } // Use 64 PRF-output bits so modulo bias at the 1e8 boundary is // negligible. Browser pins the identical big-endian rule. val value = BigInteger(1, handshakeHash.copyOfRange(0, 8)) return value.mod(BigInteger.valueOf(100_000_000L)) .toString() .padStart(8, '0') } }