Skip to content

Commit

Permalink
Sync with egk-ec
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnLCaron committed May 5, 2024
1 parent 30f2af1 commit fe31f88
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[![License](https://img.shields.io/github/license/JohnLCaron/egk-ec)](https://github.com/JohnLCaron/egk-ec-mixnet/blob/main/LICENSE.txt)
![GitHub branch checks state](https://img.shields.io/github/actions/workflow/status/JohnLCaron/egk-ec-mixnet/unit-tests.yml)
![Coverage](https://img.shields.io/badge/coverage-89.3%25%20LOC%20(1424/1595)-blue)
![Coverage](https://img.shields.io/badge/coverage-89.5%25%20LOC%20(1470/1642)-blue)

# Egk Elliptic Curves Mixnet

_last update 04/28/2024_
_last update 05/05/2024_

Implementation of a mixnet using the [ElectionGuard Kotlin Elliptical Curve library](https://github.com/JohnLCaron/egk-ec),
and the [Verificatum library](https://www.verificatum.org/). The mixnet uses the Terelius / Wikström (TW) mixnet
Expand Down
Binary file modified libs/egk-ec-2.1-SNAPSHOT.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/kotlin/org/cryptobiotic/maths/VectorCiphertext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ data class VectorCiphertext(val group: GroupContext, val elems: List<ElGamalCiph

fun reencrypt(publicKey: ElGamalPublicKey): Pair<VectorCiphertext, VectorQ> {
val group = publicKey.context
val nonces = List(this.nelems) { group.randomElementModQ(minimum = 1) }
val nonces = List(this.nelems) { group.randomElementModQ() }
val reencrypt = this.elems.mapIndexed { idx, text ->
text.reencrypt(publicKey, nonces[idx])
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/cryptobiotic/maths/VectorQ.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ data class VectorQ(val group: GroupContext, val elems: List<ElementModQ> ) {

companion object {
fun randomQ(group: GroupContext, n: Int): VectorQ {
val elems = List(n) { group.randomElementModQ(minimum = 1) }
val elems = List(n) { group.randomElementModQ() }
return VectorQ(group, elems)
}

Expand Down
9 changes: 4 additions & 5 deletions src/main/kotlin/org/cryptobiotic/mixnet/ShuffleProver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ fun runProof(
psi: Permutation, // nrows
nthreads: Int = 10,
): ProofOfShuffle {
// these are the deterministic nonces and generators that verifier must also be able to generate
val generators = getGeneratorsVmn(group, w.size, mixName) // CE n + 1 acc
val (pcommit, pnonces) = permutationCommitmentVmn(group, psi, generators)
val (prgSeed, e) = makeBatchingVector(group, mixName, generators, pcommit, publicKey, w, wp)
val generators = getGeneratorsVmn(group, w.size, mixName) // CE n + 1 acc // deterministic
val (pcommit, pnonces) = permutationCommitmentVmn(group, psi, generators) // not shared with Verifier
val (prgSeed, e) = makeBatchingVector(group, mixName, generators, pcommit, publicKey, w, wp) // deterministic

val prover = ProverV( // CE n acc
group,
Expand All @@ -69,7 +68,7 @@ fun runProof(
psi,
)
val pos = prover.commit(nthreads)
val challenge = makeChallenge(group, prgSeed, pos)
val challenge = makeChallenge(group, prgSeed, pos) // deterministic
return prover.reply(pos, challenge)
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/org/cryptobiotic/mixnet/ShuffleVerifier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fun runVerify(
pos: ProofOfShuffle,
nthreads: Int = 10,
):Boolean {
// these are the deterministic nonces and generators that prover must also be able to generate
// both prover and verifier must be able to generate deterministically
val generators = getGeneratorsVmn(group, w.size, pos.mixname) // CE 1 acc n exp
val (prgSeed, e) = makeBatchingVector(group, pos.mixname, generators, pos.u, publicKey, w, wp)
val d = group.randomElementModQ() // dont need d
Expand Down Expand Up @@ -176,7 +176,7 @@ class PverifyB(
val challenge: ElementModQ,
val nthreads: Int = 10,
) {
val group = h.context
val group = h.group
val nrows = proof.B.nelems
var isValid = true

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/cryptobiotic/mixnet/cli/RunMixnet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class RunMixnet {
ballotStyles = previousConfig.ballotStyles

} else {
val seed = mixnet.group.randomElementModQ(minimum = 1)
val seed = mixnet.group.randomElementModQ()
val nonces = Nonces(seed, mixName) // used for the extra ciphertexts to make even rows
val pair = mixnet.readEncryptedBallots(nonces)
inputBallots = pair.first
Expand Down
4 changes: 3 additions & 1 deletion src/test/kotlin/org/cryptobiotic/mixnet/GeneratorsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.cryptobiotic.eg.core.ecgroup.EcGroupContext
import org.cryptobiotic.eg.core.productionGroup
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class GeneratorsTest {
val groups = listOf(
Expand All @@ -24,7 +25,8 @@ class GeneratorsTest {
assertEquals(g1.nelems, g2.nelems)
g1.elems.forEachIndexed{ idx, g1elem ->
assertEquals(g1elem, g2.elems[idx])
assertEquals(group, g1elem.context)
assertEquals(group, g1elem.group)
assertTrue( g1elem.isValidElement() )
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fun commit(
generators: VectorP,
nonce: ElementModQ,
): ElementModP {
val group = nonce.context
val group = nonce.group
val exp = generators.elems.mapIndexed { idx, it -> it powP psi.of(idx).toElementModQ(group) }
val vexp = VectorP(group, exp)
return group.gPowP(nonce) * vexp.product()
Expand All @@ -101,7 +101,7 @@ fun commit(
generators: VectorP,
nonce: ElementModQ,
): ElementModP {
val group = nonce.context
val group = nonce.group
val exp = generators.elems.mapIndexed { idx, it -> it powP column[idx].toElementModQ(group) }
val vexp = VectorP(group, exp)
return group.gPowP(nonce) * vexp.product()
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/org/cryptobiotic/mixnet/TimingTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class TimingTest {

var stopwatch = Stopwatch()
repeat(times) {
val pows = bases.mapIndexed { idx, it -> it powP nonces[idx] }
val pows = bases.mapIndexed { idx, pit -> pit powP nonces[idx] }
val prod = pows.reduce { a, b -> a * b }
}
var duration = stopwatch.stop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ShuffledBallotRoundtripTest {
val testOutDir = "${Testing.testOutMixnet}/testBallotWriterFailsBinOverides"
createDirectories(testOutDir)
testBallotWriter(group, 100,34, testOutDir, false)
val ex = assertFailsWith<AssertionFailedError> {
assertFailsWith<AssertionFailedError> {
testBallotWriter(group, 100,34, testOutDir, true)
}
}
Expand Down

0 comments on commit fe31f88

Please sign in to comment.