SASDerivation.kt

543 B · raw

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