From 04ca3ffdfcc71bcc2a36bd1a0636a160fafecad8 Mon Sep 17 00:00:00 2001 From: JohnLCaron Date: Fri, 12 Apr 2024 08:42:46 -0600 Subject: [PATCH] Cleanup TODOs --- docs/JsonSerializationSpec2.1.md | 4 ++-- .../kotlin/org/cryptobiotic/eg/cli/RunBatchEncryption.kt | 2 +- .../kotlin/org/cryptobiotic/eg/core/ElGamalCiphertext.kt | 8 ++------ src/main/kotlin/org/cryptobiotic/eg/core/Hash.kt | 2 +- .../org/cryptobiotic/eg/core/ecgroup/EcGroupContext.kt | 4 +--- .../kotlin/org/cryptobiotic/eg/core/intgroup/PowRadix.kt | 2 -- .../kotlin/org/cryptobiotic/eg/decrypt/BallotDecryptor.kt | 2 +- src/main/kotlin/org/cryptobiotic/eg/encrypt/Encryptor.kt | 2 +- .../kotlin/org/cryptobiotic/eg/keyceremony/KeyCeremony.kt | 2 +- .../kotlin/org/cryptobiotic/eg/preencrypt/PreEncryptor.kt | 2 +- .../cryptobiotic/eg/publish/json/WebappKeyCeremonyJson.kt | 2 +- .../cryptobiotic/eg/verifier/VerifyEncryptedBallots.kt | 4 ++-- .../cryptobiotic/eg/keyceremony/KeyCeremonyTrusteeTest.kt | 2 +- src/test/kotlin/org/cryptobiotic/util/DfracTest.kt | 2 +- 14 files changed, 16 insertions(+), 24 deletions(-) diff --git a/docs/JsonSerializationSpec2.1.md b/docs/JsonSerializationSpec2.1.md index 5f09b34..73bc70f 100644 --- a/docs/JsonSerializationSpec2.1.md +++ b/docs/JsonSerializationSpec2.1.md @@ -1,6 +1,6 @@ # Egk Election Record JSON version 2.1 serialization (proposed specification) -draft 04/04/2024 +draft 04/12/2024 * [Egk Election Record JSON version 2.1 serialization (proposed specification)](#egk-election-record-json-version-21-serialization-proposed-specification) @@ -425,7 +425,7 @@ data class SelectionVectorJson( val encryptions: List, // Ej, size = nselections, in order by sequence_order ) -Note EncryptedBallotJson.primary_nonce, election_id +TODO PreEncryptionJson is not in any spec. ```` diff --git a/src/main/kotlin/org/cryptobiotic/eg/cli/RunBatchEncryption.kt b/src/main/kotlin/org/cryptobiotic/eg/cli/RunBatchEncryption.kt index 48408a7..e23bab1 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/cli/RunBatchEncryption.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/cli/RunBatchEncryption.kt @@ -358,7 +358,7 @@ class RunBatchEncryption { } // coroutines allow parallel encryption at the ballot level - // LOOK not possible to do ballot chaining, since the order is indeterminate? + // TODO not possible to do ballot chaining, since the order is indeterminate? // or do we just have to work harder?? private fun CoroutineScope.launchEncryptor( id: Int, diff --git a/src/main/kotlin/org/cryptobiotic/eg/core/ElGamalCiphertext.kt b/src/main/kotlin/org/cryptobiotic/eg/core/ElGamalCiphertext.kt index d49c756..8762ed6 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/core/ElGamalCiphertext.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/core/ElGamalCiphertext.kt @@ -89,20 +89,18 @@ fun List.add(other: List): List element is UInt256 -> element.bytes is Element -> element.byteArray() - is String -> element.encodeToByteArray() // LOOK not adding size + is String -> element.encodeToByteArray() // TODO not adding size, see Issue #48 is ElGamalCiphertext -> element.pad.byteArray() + element.data.byteArray() is ElGamalPublicKey -> element.key.byteArray() is Int -> intToByteArray(element) 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 34c362e..389bf9e 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 diff of this and safe version? + // TODO whats diff of this and safe version? override fun binaryToElementModP(b: ByteArray): ElementModP? { val elem = vecGroup.elementFromByteArray(b) return if (elem != null) EcElementModP(this, elem) else null @@ -87,7 +87,6 @@ class EcGroupContext(val name: String, useNative: Boolean = true): GroupContext override fun randomElementModP(minimum: Int) = EcElementModP(this, vecGroup.randomElement()) - // TODO could these be done with just a mod at the end? fun addQQ(cues: Iterable): ElementModQ { val sum = cues.fold(BigInteger.ZERO) { a, b -> a.plus((b as EcElementModQ).element) } return EcElementModQ(this, sum.mod(vecGroup.order)) @@ -111,7 +110,6 @@ class EcGroupContext(val name: String, useNative: Boolean = true): GroupContext if (bases.isEmpty()) { return ONE_MOD_P } - // TODO seems a bit awkward.... val ec = vecGroup.prodPowers(bases, exps) return EcElementModP(this, ec) } diff --git a/src/main/kotlin/org/cryptobiotic/eg/core/intgroup/PowRadix.kt b/src/main/kotlin/org/cryptobiotic/eg/core/intgroup/PowRadix.kt index d16b23b..28a88cd 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/core/intgroup/PowRadix.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/core/intgroup/PowRadix.kt @@ -127,8 +127,6 @@ internal fun ByteArray.kBitsPerSlice( // otherwise we'd need to move up from UShortArray to UIntArray // and take a lot more intermediate space for the computation. - // TODO: support values other than the hard-coded 16, 12, and 8-bit slices? - require (this.size <= 32 || (this.size == 33 && this[0].toInt() == 0)) { "invalid input size (${this.size}), not 32 bytes" } diff --git a/src/main/kotlin/org/cryptobiotic/eg/decrypt/BallotDecryptor.kt b/src/main/kotlin/org/cryptobiotic/eg/decrypt/BallotDecryptor.kt index fce710a..32b1f38 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/decrypt/BallotDecryptor.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/decrypt/BallotDecryptor.kt @@ -106,7 +106,7 @@ class BallotDecryptor( DecryptedTallyOrBallot.Selection( eselection.selectionId, - tally?: 0, // TODO + tally?: 0, // TODO error handling T, (decryption.cipher as Ciphertext).delegate, proof diff --git a/src/main/kotlin/org/cryptobiotic/eg/encrypt/Encryptor.kt b/src/main/kotlin/org/cryptobiotic/eg/encrypt/Encryptor.kt index cd52632..f347766 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/encrypt/Encryptor.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/encrypt/Encryptor.kt @@ -187,7 +187,7 @@ fun PlaintextBallot.Contest.encryptContest( ): PendingEncryptedBallot.Contest { val ciphertexts: List = encryptedSelections.map { it.ciphertext } - val ciphertextAccumulation: ElGamalCiphertext = ciphertexts.encryptedSum()?: 0.encrypt(jointPublicKey) // LOOK deterministic? + val ciphertextAccumulation: ElGamalCiphertext = ciphertexts.encryptedSum()?: 0.encrypt(jointPublicKey) val nonces: Iterable = encryptedSelections.map { it.selectionNonce } val aggNonce: ElementModQ = with(group) { nonces.addQ() } diff --git a/src/main/kotlin/org/cryptobiotic/eg/keyceremony/KeyCeremony.kt b/src/main/kotlin/org/cryptobiotic/eg/keyceremony/KeyCeremony.kt index b254b99..e8e0abb 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/keyceremony/KeyCeremony.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/keyceremony/KeyCeremony.kt @@ -32,7 +32,7 @@ fun keyCeremonyExchange(trustees: List, allowEncryptedFail return Err("keyCeremonyExchange trustees have different quorums = ${trustees.map{it.coefficientCommitments().size}}") } - // LOOK if the trustees are not trusted, we could do other verification tests here. + // TODO if the trustees are not trusted, we could do other verification tests here. // are the public keys valid? // are the encrypted shares valid? // are the unencrypted shares valid? diff --git a/src/main/kotlin/org/cryptobiotic/eg/preencrypt/PreEncryptor.kt b/src/main/kotlin/org/cryptobiotic/eg/preencrypt/PreEncryptor.kt index 98c7308..fcb665f 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/preencrypt/PreEncryptor.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/preencrypt/PreEncryptor.kt @@ -64,7 +64,7 @@ class PreEncryptor( // In a contest with a selection limit of L, an additional L null vectors are added var nextSeqNo = sortedSelections.last().sequenceOrder + 1 for (nullVectorIdx in (1..contestLimit)) { - // TODO null labels may be in manifest, see 4.2.1. wtf? + // TODO "null labels may be in manifest", see 4.2.1. wtf? preeSelections.add( preencryptSelection(primaryNonce, this.sequenceOrder, "null${nullVectorIdx}", nextSeqNo, sortedSelectionIndices)) nextSeqNo++ } diff --git a/src/main/kotlin/org/cryptobiotic/eg/publish/json/WebappKeyCeremonyJson.kt b/src/main/kotlin/org/cryptobiotic/eg/publish/json/WebappKeyCeremonyJson.kt index 830004b..078c1ae 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/publish/json/WebappKeyCeremonyJson.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/publish/json/WebappKeyCeremonyJson.kt @@ -62,7 +62,7 @@ fun EncryptedKeyShareJson.import(group: GroupContext): EncryptedKeyShare? { ) } -/** External representation of a KeyShare LOOK */ +/** External representation of a KeyShare */ @Serializable data class KeyShareJson( val ownerXcoord : Int, diff --git a/src/main/kotlin/org/cryptobiotic/eg/verifier/VerifyEncryptedBallots.kt b/src/main/kotlin/org/cryptobiotic/eg/verifier/VerifyEncryptedBallots.kt index 72e6fe9..cd5d031 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/verifier/VerifyEncryptedBallots.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/verifier/VerifyEncryptedBallots.kt @@ -62,8 +62,8 @@ class VerifyEncryptedBallots( joinAll(*verifierJobs.toTypedArray()) } - // check duplicate confirmation codes (7.C): LOOK what if there are multiple records for the election? - // LOOK what about checking for duplicate ballot ids? + // check duplicate confirmation codes (7.C): TODO what if there are multiple records for the election? + // TODO what about checking for duplicate ballot ids? val checkDuplicates = mutableMapOf() confirmationCodes.forEach { if (checkDuplicates[it.code] != null) { diff --git a/src/test/kotlin/org/cryptobiotic/eg/keyceremony/KeyCeremonyTrusteeTest.kt b/src/test/kotlin/org/cryptobiotic/eg/keyceremony/KeyCeremonyTrusteeTest.kt index 8930012..8bc3b23 100644 --- a/src/test/kotlin/org/cryptobiotic/eg/keyceremony/KeyCeremonyTrusteeTest.kt +++ b/src/test/kotlin/org/cryptobiotic/eg/keyceremony/KeyCeremonyTrusteeTest.kt @@ -276,7 +276,7 @@ class KeyCeremonyTrusteeTest { println("result = $resultBadCoordinate") assertTrue(resultBadCoordinate.error.contains("Trustee 'id2' error validating KeyShare for missingGuardianId 'id1'")) - /* Give it a bad nonce LOOK this is disabled in KeyCeremonyTrustee.receiveKeyShare(), see notes there + /* Give it a bad nonce. This is disabled in KeyCeremonyTrustee.receiveKeyShare(), see notes there val keyShareBadNonce = keyShare12.copy(nonce = group.TWO_MOD_Q) val resultBadNonce = trustee2.receiveKeyShare(keyShareBadNonce) assertTrue(resultBadNonce is Err) diff --git a/src/test/kotlin/org/cryptobiotic/util/DfracTest.kt b/src/test/kotlin/org/cryptobiotic/util/DfracTest.kt index 23cb71b..34acce9 100644 --- a/src/test/kotlin/org/cryptobiotic/util/DfracTest.kt +++ b/src/test/kotlin/org/cryptobiotic/util/DfracTest.kt @@ -2,7 +2,7 @@ package org.cryptobiotic.util import kotlin.test.Test -// LOOK can use println("SimpleBallot %.2f encryptions / sec".format(numBallots / encryptionTime)) instead of dfrac +// Can use println("SimpleBallot %.2f encryptions / sec".format(numBallots / encryptionTime)) instead of dfrac class DfracTest {