Skip to content

Commit

Permalink
Changed the initial code seed for ballot chaining to be consistend wi…
Browse files Browse the repository at this point in the history
…th the specification
  • Loading branch information
frog711 committed Oct 10, 2024
1 parent c3f9e1f commit 610ee34
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class AddEncryptedBallot(

val publisher = makePublisher(outputDir, false, isJson)
val sink: EncryptedBallotSinkIF = publisher.encryptedBallotSink(deviceName)
val baux0: ByteArray

private val ballotIds = mutableListOf<String>()
private val pending = mutableMapOf<UInt256, CiphertextBallot>() // key = ccode.toHex()
Expand All @@ -63,17 +62,15 @@ class AddEncryptedBallot(
// this is a restart on an existing chain
val chain: EncryptedBallotChain = chainResult.unwrap()
require(configChaining == chain.chaining) { "mismatched chaining config=$configChaining ouputDir=${chain.chaining}" }
baux0 = chain.baux0
ballotIds.addAll(chain.ballotIds)
this.lastConfirmationCode = chain.lastConfirmationCode
first = false

// hmmm you could check EncryptedBallotChain each time, in case of crash

} else {
baux0 = if (!configChaining) configBaux0 else
// H0 = H(HE ; 0x24, Baux,0 ), eq (59)
hashFunction(extendedBaseHash.bytes, 0x24.toByte(), configBaux0).bytes
// H0 = H(HE ; 0x24, Baux,0 ), eq (59)
this.lastConfirmationCode = hashFunction(extendedBaseHash.bytes, 0x24.toByte(), configBaux0)
}
}

Expand All @@ -91,7 +88,7 @@ class AddEncryptedBallot(
}

// Baux,j = Hj−1 ∥ Baux,0 eq (60)
val bauxj: ByteArray = if (!configChaining || first) baux0 else lastConfirmationCode.bytes + configBaux0
val bauxj: ByteArray = if (!configChaining) configBaux0 else lastConfirmationCode.bytes + configBaux0
first = false

val ciphertextBallot = encryptor.encrypt(ballot, bauxj, errs)
Expand Down Expand Up @@ -178,8 +175,8 @@ class AddEncryptedBallot(
submit(it, EncryptedBallot.BallotState.UNKNOWN)
}
}
val closing =
EncryptedBallotChain(deviceName, baux0, ballotIds, this.lastConfirmationCode, configChaining, closeChain())
val closing = EncryptedBallotChain(
deviceName, configBaux0, ballotIds, this.lastConfirmationCode, configChaining, closeChain())
publisher.writeEncryptedBallotChain(closing)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,8 @@ actual class VerifyEncryptedBallots actual constructor(
// (7.E) For all 1 ≤ j ≤ ℓ, the additional input byte array used to compute Hj = H(Bj) is equal to
// Baux,j = H(Bj−1) ∥ Baux,0 .
var prevCC = H0
var first = true
ballots.forEach { ballot ->
val expectedBaux = if (first) H0 else prevCC + config.configBaux0 // eq 7.D and 7.E
first = false
val expectedBaux = prevCC + config.configBaux0 // eq 7.D and 7.E
if (!expectedBaux.contentEquals(ballot.codeBaux)) {
errs.add(" 7.E. additional input byte array Baux != H(Bj−1 ) ∥ Baux,0 for ballot=${ballot.ballotId}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,8 @@ actual class VerifyEncryptedBallots actual constructor(
// (7.E) For all 1 ≤ j ≤ ℓ, the additional input byte array used to compute Hj = H(Bj) is equal to
// Baux,j = H(Bj−1) ∥ Baux,0 .
var prevCC = H0
var first = true
ballots.forEach { ballot ->
val expectedBaux = if (first) H0 else prevCC + config.configBaux0 // eq 7.D and 7.E
first = false
val expectedBaux = prevCC + config.configBaux0 // eq 7.D and 7.E
if (!expectedBaux.contentEquals(ballot.codeBaux)) {
errs.add(" 7.E. additional input byte array Baux != H(Bj−1 ) ∥ Baux,0 for ballot=${ballot.ballotId}")
}
Expand Down

0 comments on commit 610ee34

Please sign in to comment.