Skip to content

Commit

Permalink
Cleanup TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnLCaron committed Apr 12, 2024
1 parent d9d3be0 commit 04ca3ff
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 24 deletions.
4 changes: 2 additions & 2 deletions docs/JsonSerializationSpec2.1.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Egk Election Record JSON version 2.1 serialization (proposed specification)

draft 04/04/2024
draft 04/12/2024

<!-- TOC -->
* [Egk Election Record JSON version 2.1 serialization (proposed specification)](#egk-election-record-json-version-21-serialization-proposed-specification)
Expand Down Expand Up @@ -425,7 +425,7 @@ data class SelectionVectorJson(
val encryptions: List<ElGamalCiphertextJson>, // Ej, size = nselections, in order by sequence_order
)
Note EncryptedBallotJson.primary_nonce, election_id
TODO PreEncryptionJson is not in any spec.
````

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions src/main/kotlin/org/cryptobiotic/eg/core/ElGamalCiphertext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,18 @@ fun List<ElGamalCiphertext>.add(other: List<ElGamalCiphertext>): List<ElGamalCip
return result
}

// TODO what happens if nonce is small enough to take the log of?
fun Int.encrypt(
keypair: ElGamalKeypair,
nonce: ElementModQ = keypair.context.randomElementModQ(minimum = 1)
) = this.encrypt(keypair.publicKey, nonce)

/** Encrypt an Int. */
/** Encrypt an Int. Value must be positive. */
fun Int.encrypt(
publicKey: ElGamalPublicKey,
nonce: ElementModQ = publicKey.context.randomElementModQ(minimum = 1)
): ElGamalCiphertext {
val context = compatibleContextOrFail(publicKey.key, nonce)

// LOOK: Exception
if (nonce.isZero()) {
throw ArithmeticException("Can't use a zero nonce for ElGamal encryption")
}
Expand All @@ -118,18 +116,16 @@ fun Int.encrypt(
return ElGamalCiphertext(pad, data)
}

/** Encrypt a Long. Used to encrypt serial number. */
/** Encrypt a Long. Used to encrypt serial number. Value must be positive. */
fun Long.encrypt(
publicKey: ElGamalPublicKey,
nonce: ElementModQ = publicKey.context.randomElementModQ(minimum = 1)
): ElGamalCiphertext {
val context = compatibleContextOrFail(publicKey.key, nonce)

// LOOK: Exception
if (nonce.isZero()) {
throw ArithmeticException("Can't use a zero nonce for ElGamal encryption")
}

if (this < 0) {
throw ArithmeticException("Can't encrypt a negative value")
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/cryptobiotic/eg/core/Hash.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fun HmacSha256.addToHash(element : Any) {
is ByteArray -> 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)
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 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
Expand Down Expand Up @@ -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>): ElementModQ {
val sum = cues.fold(BigInteger.ZERO) { a, b -> a.plus((b as EcElementModQ).element) }
return EcElementModQ(this, sum.mod(vecGroup.order))
Expand All @@ -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)
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/kotlin/org/cryptobiotic/eg/core/intgroup/PowRadix.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/cryptobiotic/eg/encrypt/Encryptor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fun PlaintextBallot.Contest.encryptContest(
): PendingEncryptedBallot.Contest {

val ciphertexts: List<ElGamalCiphertext> = 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<ElementModQ> = encryptedSelections.map { it.selectionNonce }
val aggNonce: ElementModQ = with(group) { nonces.addQ() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fun keyCeremonyExchange(trustees: List<KeyCeremonyTrusteeIF>, 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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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++
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<UInt256, String>()
confirmationCodes.forEach {
if (checkDuplicates[it.code] != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/org/cryptobiotic/util/DfracTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down

0 comments on commit 04ca3ff

Please sign in to comment.