Skip to content

Commit

Permalink
Merge pull request #28 from JohnLCaron/sync2
Browse files Browse the repository at this point in the history
Sync with egk-ec again.
  • Loading branch information
JohnLCaron authored May 18, 2024
2 parents f186fa1 + ba0a6af commit ef6f954
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
Binary file modified libs/egk-ec-2.1-SNAPSHOT.jar
Binary file not shown.
8 changes: 4 additions & 4 deletions src/main/kotlin/org/cryptobiotic/mixnet/Generators.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import org.cryptobiotic.eg.core.*
import org.cryptobiotic.eg.core.ecgroup.EcElementModP
import org.cryptobiotic.eg.core.ecgroup.EcGroupContext
import org.cryptobiotic.eg.core.ecgroup.VecGroup.Companion.jacobiSymbol
import org.cryptobiotic.eg.core.intgroup.ProductionElementModP
import org.cryptobiotic.eg.core.intgroup.ProductionGroupContext
import org.cryptobiotic.eg.core.intgroup.IntElementModP
import org.cryptobiotic.eg.core.intgroup.IntGroupContext
import org.cryptobiotic.eg.election.GroupType
import org.cryptobiotic.eg.election.parameterBaseHash
import org.cryptobiotic.maths.*
Expand All @@ -32,15 +32,15 @@ fun getGeneratorsIntGroup(group: GroupContext, numberOfGenerators: Int, prgSeq:
val statDistBytes = 128 / 8 // TODO what should this be?
val nbytes = group.MAX_BYTES_P + statDistBytes

val intGroup = group as ProductionGroupContext
val intGroup = group as IntGroupContext
val exp = (intGroup.p - BigInteger.ONE).div(intGroup.q) // (p-1)/q

val result = mutableListOf<ElementModP>()
while (result.size < numberOfGenerators) {
val ba = prgSeq.next(nbytes)
val bi = BigInteger(1, ba)
val ti = bi.modPow(exp, intGroup.p)
result.add(ProductionElementModP(ti, intGroup))
result.add(IntElementModP(ti, intGroup))
}
return VectorP(group, result)
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/org/cryptobiotic/mixnet/cli/RunMixnet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.cryptobiotic.eg.core.encrypt
import org.cryptobiotic.eg.election.Manifest
import org.cryptobiotic.eg.election.ManifestIF
import org.cryptobiotic.eg.publish.Consumer
import org.cryptobiotic.eg.publish.json.UInt256Json
import org.cryptobiotic.eg.publish.json.ElementModQJson
import org.cryptobiotic.eg.publish.makeConsumer
import org.cryptobiotic.eg.publish.json.publishJson
import org.cryptobiotic.util.Stopwatch
Expand Down Expand Up @@ -80,7 +80,7 @@ class RunMixnet {
var width = 0
val inputBallots: List<VectorCiphertext>
val ballotStyles: List<String>
var noncesSeed : UInt256Json? = null
var noncesSeed : ElementModQJson? = null

if (inputMixDir != null) {
val lastFilename = "$inputMixDir/$configFilename"
Expand All @@ -106,7 +106,7 @@ class RunMixnet {
inputBallots = pair.first
ballotStyles = pair.second
if (inputBallots.size > 0) width = inputBallots[0].nelems
noncesSeed = seed.toUInt256safe().publishJson()
noncesSeed = seed.publishJson()
}

try {
Expand All @@ -118,7 +118,7 @@ class RunMixnet {
writeShuffledBallotsToFile(true, outputDirMix, shuffled)
writeProofOfShuffleJsonToFile(proof, "$outputDirMix/$proofFilename")

val config = MixnetConfig(mixName, mixnet.electionId.publishJson(), ballotStyles, width, noncesSeed)
val config = MixnetConfigJson(mixName, mixnet.electionId.publishJson(), ballotStyles, width, noncesSeed)
writeMixnetConfigToFile(config, "$outputDirMix/$configFilename")
logger.info { "ShuffleProof success" }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class RunMixnetTable {
trusteeDir: String,
mixDir: String,
outputDir: String?,
config: MixnetConfig,
config: MixnetConfigJson,
noexit: Boolean
) {
val consumerIn = makeConsumer(publicDir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class RunProofOfShuffleVerifier {
logger.info { " Read ${ballots.size} input ballots" }

} else {
val seed: ElementModQ = config.nonces_seed?.import()?.toElementModQ(verifier.group)!!
val seed: ElementModQ = config.nonces_seed?.import(verifier.group)!!
val nonces = Nonces(seed, config.mix_name) // used for the extra ciphertexts to make even rows
val pair = mixnet.readEncryptedBallots(nonces)
ballots = pair.first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream
import kotlinx.serialization.json.encodeToStream
import org.cryptobiotic.eg.publish.json.ElementModQJson
import org.cryptobiotic.eg.publish.json.UInt256Json
import org.cryptobiotic.util.ErrorMessages
import java.io.FileOutputStream
Expand All @@ -18,23 +19,23 @@ import java.nio.file.Path
import java.nio.file.StandardOpenOption

@Serializable
data class MixnetConfig(
data class MixnetConfigJson(
val mix_name: String,
val election_id: UInt256Json,
val ballotStyles: List<String>, // needed ??
val width: Int,
val nonces_seed: UInt256Json?,
val nonces_seed: ElementModQJson?,
)

fun writeMixnetConfigToFile(mixnetConfig: MixnetConfig, filename: String) {
fun writeMixnetConfigToFile(mixnetConfig: MixnetConfigJson, filename: String) {
val jsonReader = Json { explicitNulls = false; ignoreUnknownKeys = true; prettyPrint = true }
FileOutputStream(filename).use { out ->
jsonReader.encodeToStream(mixnetConfig, out)
out.close()
}
}

fun readMixnetConfigFromFile(filename: String): Result<MixnetConfig, ErrorMessages> {
fun readMixnetConfigFromFile(filename: String): Result<MixnetConfigJson, ErrorMessages> {
val errs = ErrorMessages("readMixnetConfigFromFile '${filename}'")
val filepath = Path.of(filename)
if (!Files.exists(filepath)) {
Expand All @@ -44,7 +45,7 @@ fun readMixnetConfigFromFile(filename: String): Result<MixnetConfig, ErrorMessag

return try {
Files.newInputStream(filepath, StandardOpenOption.READ).use { inp ->
val mixnetConfig = jsonReader.decodeFromStream<MixnetConfig>(inp)
val mixnetConfig = jsonReader.decodeFromStream<MixnetConfigJson>(inp)
if (errs.hasErrors()) Err(errs) else Ok(mixnetConfig)
}
} catch (t: Throwable) {
Expand Down

0 comments on commit ef6f954

Please sign in to comment.