Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More TODO cleanup #67

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/main/kotlin/org/cryptobiotic/eg/core/ChaumPedersen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ internal fun ElGamalCiphertext.makeChaumPedersenWithNonces(
randomCj: List<ElementModQ>, // 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)
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/cryptobiotic/eg/core/GroupContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Int>
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/org/cryptobiotic/eg/core/HashedElGamal.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -82,12 +82,14 @@ class EcGroupContext(val name: String, useNative: Boolean = true): GroupContext
}

override fun Iterable<ElementModP>.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>): 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))
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/kotlin/org/cryptobiotic/eg/core/intgroup/IntGroup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/cryptobiotic/eg/preencrypt/Recorder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<ElementModP>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,6 @@ private class PathFilter(val prefix: String): Predicate<Path> {
}

fun Path.pathListNoDirs(filter: Predicate<Path>?): List<Path> {
// 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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
Loading