SecuritySeniorMCQ

What is Secure Comparator in Themis?

Test your knowledge:

Explanation & Code

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.

Rate your understanding:

Ready to practice more Security?

Test yourself with our interactive quiz mode or browse all curated questions for this topic.