Browse Questions
  • SwiftUI compares the new view tree with the previous one on every state change.
  • A property wrapper adds custom logic around getting and setting a property.
  • Unstructured Task { ...
  • Secure Comparator is a zero-knowledge protocol that lets two parties confirm they hold the same secret without either side transmitting it, or leaking anything usable when the secrets differ.

Answer: Secure Comparator is a zero-knowledge protocol that lets two parties confirm they hold the same secret without either side transmitting it, or leaking anything usable when the secrets differ. It is built on a Socialist Millionaire Problem construction and runs as a multi-step exchange rather than a single call.

The practical benefit over "hash it and compare" is that a hash sent over the wire is still an offline brute-force target for a low-entropy secret like a PIN. Secure Comparator gives an attacker who records the entire exchange nothing to grind against.

Code Example:

let comparator = TSComparator(messageToCompare: sharedSecret.data(using: .utf8)!)!
var data = try comparator.beginCompare()

while comparator.status() == TSComparatorStateType.notReady {
    let reply = try transport.exchange(data)      // send to peer, get its response
    data = try comparator.proceedCompare(reply)
}

switch comparator.status() {
case .match:    proceed()
case .notMatch: reject()
default:        abort()
}

Key Points:

  • Multi-round: loop until the status leaves .notReady.
  • Reveals a single bit — match or not — and nothing about the secret.
  • Never treat .notReady as success; check for .match explicitly.