Browse Questions
  • Delegate protocols must inherit from AnyObject to restrict protocol conformance to classes, allowing delegate properties to be marked with the weak keyword.
  • An Optional is a type that can hold either a value or nil.
  • 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.
  • An Xcode MVVM Feature template generates three pre-wired files for SwiftUI screens (Model with explicit state enum, ViewModel with injectable service protocol, and View with StateObject…

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.