diff --git a/src/main/kotlin/org/cryptobiotic/eg/core/ChaumPedersen.kt b/src/main/kotlin/org/cryptobiotic/eg/core/ChaumPedersen.kt index aa9e3e1..eb596b7 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/core/ChaumPedersen.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/core/ChaumPedersen.kt @@ -75,7 +75,6 @@ internal fun ElGamalCiphertext.makeChaumPedersenWithNonces( randomCj: List, // size == R + 1 ): ChaumPedersenRangeProofKnownNonce { require(randomUj.size == randomCj.size) - // require(vote >= 0 && vote <= randomUj.size ) // TODO return Result val (alpha, beta) = this val group = compatibleContextOrFail(pad, nonce, publicKey.key, alpha, beta) @@ -223,7 +222,7 @@ fun ChaumPedersenProof.verifyDecryption( val b = (encryptedVote.pad powP this.r) * (M powP this.c) // 9.3 // 9.A The given value v is in the set Z_q. - if (!this.r.inBounds()) { // TODO why wait until now to check this? + if (!this.r.inBounds()) { return false } // The challenge value c = H(HE ; 0x30, K, A, B, a, b, M ). eq 71, 9.B. diff --git a/src/main/kotlin/org/cryptobiotic/eg/core/GroupContext.kt b/src/main/kotlin/org/cryptobiotic/eg/core/GroupContext.kt index 167bcc8..9a68f6d 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/core/GroupContext.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/core/GroupContext.kt @@ -138,7 +138,7 @@ interface GroupContext { fun randomElementModP(minimum: Int = 0) = binaryToElementModPsafe(randomBytes(MAX_BYTES_P), minimum) - /** debugging operation counts. TODO sidechannel attack? */ + /** debugging operation counts. */ fun getAndClearOpCounts(): Map } diff --git a/src/main/kotlin/org/cryptobiotic/eg/core/HashedElGamal.kt b/src/main/kotlin/org/cryptobiotic/eg/core/HashedElGamal.kt index 479303a..9e0bc43 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/core/HashedElGamal.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/core/HashedElGamal.kt @@ -114,13 +114,13 @@ fun ByteArray.encryptToHashedElGamal( // k = H(HE ; 0x22, K, C0 , β) eq 51: secret key since beta is secret since nonce is secret. val kdfKey = hashFunction(extendedBaseHash.bytes, separator, publicKey, alpha, beta) - // ki = HMAC(k, b(i, 4) ∥ Label ∥ 0x00 ∥ Context ∥ b((bD + 1) · 256, 4)) // TODO implementation correct? + // ki = HMAC(k, b(i, 4) ∥ Label ∥ 0x00 ∥ Context ∥ b((bD + 1) · 256, 4)) // LOOK implementation correct? val kdf = KDF(kdfKey, label, context, this.size * 8) val k0 = kdf[0] val c0 = alpha.byteArray() // (eq 53) val encryptedBlocks = messageBlocks.mapIndexed { i, p -> (p xor kdf[i + 1]).bytes }.toTypedArray() val c1 = concatByteArrays(*encryptedBlocks) // (eq 54) - val c2 = (c0 + c1).hmacSha256(k0) // TODO can we use hmacFunction() ?? (eq 55) + val c2 = (c0 + c1).hmacSha256(k0) // (eq 55) return HashedElGamalCiphertext(alpha, c1, c2, this.size) } diff --git a/src/main/kotlin/org/cryptobiotic/eg/core/ecgroup/EcElementModP.kt b/src/main/kotlin/org/cryptobiotic/eg/core/ecgroup/EcElementModP.kt index 635dad2..4c7f5e5 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/core/ecgroup/EcElementModP.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/core/ecgroup/EcElementModP.kt @@ -23,7 +23,7 @@ class EcElementModP(val group: EcGroupContext, val ec: VecElementP): ElementModP return EcElementModP(group, ec.mul(inv)) } - // what does it mean to be in bounds ?? + // TODO what does it mean to be in bounds ?? override fun inBounds(): Boolean = true // TODO("Not yet implemented") // TODO check this diff --git a/src/main/kotlin/org/cryptobiotic/eg/core/ecgroup/EcGroupContext.kt b/src/main/kotlin/org/cryptobiotic/eg/core/ecgroup/EcGroupContext.kt index 389bf9e..a4aeaa5 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/core/ecgroup/EcGroupContext.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/core/ecgroup/EcGroupContext.kt @@ -25,7 +25,7 @@ class EcGroupContext(val name: String, useNative: Boolean = true): GroupContext override val constants = vecGroup.constants val dlogg = DLogarithm(G_MOD_P) - // TODO whats diff of this and safe version? + // TODO whats difference with safe version? override fun binaryToElementModP(b: ByteArray): ElementModP? { val elem = vecGroup.elementFromByteArray(b) return if (elem != null) EcElementModP(this, elem) else null @@ -82,12 +82,14 @@ class EcGroupContext(val name: String, useNative: Boolean = true): GroupContext } override fun Iterable.multP(): ElementModP { + // TODO what if this.isEmpty() ? return this.reduce { a, b -> a * b } } override fun randomElementModP(minimum: Int) = EcElementModP(this, vecGroup.randomElement()) fun addQQ(cues: Iterable): ElementModQ { + // TODO what if cues.isEmpty() ? val sum = cues.fold(BigInteger.ZERO) { a, b -> a.plus((b as EcElementModQ).element) } return EcElementModQ(this, sum.mod(vecGroup.order)) } diff --git a/src/main/kotlin/org/cryptobiotic/eg/core/intgroup/IntGroup.kt b/src/main/kotlin/org/cryptobiotic/eg/core/intgroup/IntGroup.kt index 5f354db..a6e746c 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/core/intgroup/IntGroup.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/core/intgroup/IntGroup.kt @@ -135,8 +135,6 @@ class ProductionGroupContext( null } - // TODO, for an election where limit > 1, might want to cache all encryption up to limit. - override fun uIntToElementModQ(i: UInt) : ElementModQ = when (i) { 0U -> ZERO_MOD_Q 1U -> ONE_MOD_Q diff --git a/src/main/kotlin/org/cryptobiotic/eg/election/ElectionConstants.kt b/src/main/kotlin/org/cryptobiotic/eg/election/ElectionConstants.kt index 3791bff..8b3dbcd 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/election/ElectionConstants.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/election/ElectionConstants.kt @@ -8,6 +8,7 @@ import java.math.BigInteger /** * Generalization of ElectionGuard 2.0 section 3.1 "Parameter requirements" * to also describe elliptic curve groups, as well as the ElectionGuard integer group. + * Note that this class is just a container for named BigInteger parameters. */ enum class GroupType { IntegerGroup, EllipticCurve } diff --git a/src/main/kotlin/org/cryptobiotic/eg/preencrypt/Recorder.kt b/src/main/kotlin/org/cryptobiotic/eg/preencrypt/Recorder.kt index 23e4291..41323c5 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/preencrypt/Recorder.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/preencrypt/Recorder.kt @@ -103,7 +103,7 @@ class Recorder( val contestDataEncrypted = contestData.encrypt(publicKey, extendedBaseHash, preeContest.contestId, preeContest.sequenceOrder, ballotNonce, manifest.contestLimit(contestId)) - // we are going to substitute preencryptionHash (eq 94) instead of eq 57 when we validate TODO WTF? + // we are going to substitute preencryptionHash (eq 94) instead of eq 57 when we validate. ?? // χl = H(HE ; 0x23, indc (Λl ), K, α1 , β1 , α2 , β2 . . . , αm , βm ) ; spec 2.0.0 eq 57 val ciphers = mutableListOf() diff --git a/src/main/kotlin/org/cryptobiotic/eg/publish/json/ConsumerJson.kt b/src/main/kotlin/org/cryptobiotic/eg/publish/json/ConsumerJson.kt index 6c4d681..1a7871d 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/publish/json/ConsumerJson.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/publish/json/ConsumerJson.kt @@ -539,8 +539,6 @@ private class PathFilter(val prefix: String): Predicate { } fun Path.pathListNoDirs(filter: Predicate?): List { - // TODO does this sort? - // TODO "API Note: This method must be used within a try-with-resources statement" return Files.walk(this, 1).use { fileStream -> fileStream.filter { it != this && !it.isDirectory() && (filter == null || filter.test(it)) }.toList() } diff --git a/src/test/kotlin/org/cryptobiotic/eg/publish/json/ElectionConstantsTest.kt b/src/test/kotlin/org/cryptobiotic/eg/publish/json/ElectionConstantsTest.kt index 9fb6f3e..5c7ee51 100644 --- a/src/test/kotlin/org/cryptobiotic/eg/publish/json/ElectionConstantsTest.kt +++ b/src/test/kotlin/org/cryptobiotic/eg/publish/json/ElectionConstantsTest.kt @@ -18,11 +18,11 @@ class ElectionConstantsTest { } @Test - fun missingFieldsTest() { // TODO no failure - val errs = ErrorMessages("badFieldsTest") + fun anyFieldsTest() { + val errs = ErrorMessages("anyFieldsTest") var json = ElectionConstantsJson( "any", "IntegerGroup", "any", - mapOf("largePrime" to "123809afe") + mapOf("largePrime" to "123809afe", "wtf" to "42") ) val good = json.import(errs) assertFalse(errs.hasErrors()) diff --git a/src/test/kotlin/org/cryptobiotic/eg/verifier/AttackEncryptedBallotTest.kt b/src/test/kotlin/org/cryptobiotic/eg/verifier/AttackEncryptedBallotTest.kt index 879efb0..b05b97e 100644 --- a/src/test/kotlin/org/cryptobiotic/eg/verifier/AttackEncryptedBallotTest.kt +++ b/src/test/kotlin/org/cryptobiotic/eg/verifier/AttackEncryptedBallotTest.kt @@ -27,6 +27,7 @@ import kotlin.test.assertNotEquals The attacker might switch votes in precincts where they know the likely vote ratio */ +// TODO class AttackEncryptedBallotTest { private val inputDir = "src/test/data/workflow/allAvailableEc" private val trusteeDir = "$inputDir/private_data/trustees" @@ -144,7 +145,7 @@ class AttackEncryptedBallotTest { // this fails in EncryptedBallot.Selection.is_valid_encryption() because the crypto_hash includes the // selection_id and the ciphertext. - // switch the vote for the two selections TODO + // switch the vote for the two selections private fun switchVote(s1: EncryptedBallot.Selection, s2: EncryptedBallot.Selection): EncryptedBallot.Selection { return EncryptedBallot.Selection( s1.selectionId,