diff --git a/src/main/kotlin/org/cryptobiotic/eg/core/GroupContext.kt b/src/main/kotlin/org/cryptobiotic/eg/core/GroupContext.kt index de85d9b..167bcc8 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/core/GroupContext.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/core/GroupContext.kt @@ -275,5 +275,15 @@ fun GroupContext.addQ(vararg elements: ElementModQ) = elements.asIterable().addQ */ fun GroupContext.multP(vararg elements: ElementModP) = elements.asIterable().multP() +fun GroupContext.showOpCountResults(where: String): String { + val opCounts = this.getAndClearOpCounts() + return buildString { + appendLine("$where:") + opCounts.toSortedMap().forEach { (key, value) -> + appendLine(" $key : $value") + } + } +} + diff --git a/src/main/kotlin/org/cryptobiotic/eg/core/ecgroup/EcElementModP.kt b/src/main/kotlin/org/cryptobiotic/eg/core/ecgroup/EcElementModP.kt index dae5483..635dad2 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/core/ecgroup/EcElementModP.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/core/ecgroup/EcElementModP.kt @@ -1,6 +1,7 @@ package org.cryptobiotic.eg.core.ecgroup import org.cryptobiotic.eg.core.* +import java.util.concurrent.atomic.AtomicInteger class EcElementModP(val group: EcGroupContext, val ec: VecElementP): ElementModP { override val context: GroupContext = group @@ -36,6 +37,7 @@ class EcElementModP(val group: EcGroupContext, val ec: VecElementP): ElementModP override fun powP(exp: ElementModQ): ElementModP { require (exp is EcElementModQ) + group.opCounts.getOrPut("exp") { AtomicInteger(0) }.incrementAndGet() return EcElementModP(group, ec.exp(exp.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 85783c0..34c362e 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/core/ecgroup/EcGroupContext.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/core/ecgroup/EcGroupContext.kt @@ -3,6 +3,7 @@ package org.cryptobiotic.eg.core.ecgroup import org.cryptobiotic.eg.core.* import java.math.BigInteger +import java.util.concurrent.atomic.AtomicInteger class EcGroupContext(val name: String, useNative: Boolean = true): GroupContext { val vecGroup: VecGroup = VecGroups.getEcGroup(name, useNative) @@ -52,8 +53,12 @@ class EcGroupContext(val name: String, useNative: Boolean = true): GroupContext return EcElementModP(this, vecGroup.g.exp(exp.element)) } + var opCounts: HashMap = HashMap() override fun getAndClearOpCounts(): Map { - return emptyMap() + val result = HashMap() + opCounts.forEach { (key, value) -> result[key] = value.get() } + opCounts = HashMap() + return result.toSortedMap() } override fun isCompatible(ctx: GroupContext): Boolean { diff --git a/src/test/data/workflow/allAvailableEc.zip b/src/test/data/workflow/allAvailableEc.zip index e3b184c..30b3a09 100644 Binary files a/src/test/data/workflow/allAvailableEc.zip and b/src/test/data/workflow/allAvailableEc.zip differ diff --git a/src/test/kotlin/org/cryptobiotic/eg/core/GroupTest.kt b/src/test/kotlin/org/cryptobiotic/eg/core/GroupTest.kt index 50a54e5..4441e6f 100644 --- a/src/test/kotlin/org/cryptobiotic/eg/core/GroupTest.kt +++ b/src/test/kotlin/org/cryptobiotic/eg/core/GroupTest.kt @@ -336,14 +336,4 @@ class GroupTest { assertEquals(expected, prodpow) } } -} - -fun GroupContext.showOpCountResults(where: String): String { - val opCounts = this.getAndClearOpCounts() - return buildString { - appendLine("$where:") - opCounts.toSortedMap().forEach { (key, value) -> - appendLine(" $key : $value") - } - } } \ No newline at end of file diff --git a/src/test/kotlin/org/cryptobiotic/eg/workflow/RunEncryptBallotTiming.kt b/src/test/kotlin/org/cryptobiotic/eg/workflow/RunEncryptBallotTiming.kt index fbaed18..6c07e98 100644 --- a/src/test/kotlin/org/cryptobiotic/eg/workflow/RunEncryptBallotTiming.kt +++ b/src/test/kotlin/org/cryptobiotic/eg/workflow/RunEncryptBallotTiming.kt @@ -73,17 +73,14 @@ class RunEncryptBallotTiming { val encryptedBallot = encryptor.encrypt(ballot, ByteArray(0), ErrorMessages("testEncryption")) requireNotNull(encryptedBallot) } - val opCounts = group.getAndClearOpCounts() + group.getAndClearOpCounts() val nencryptions = ncontests + ncontests * nselections println("Encryption ${stopwatch.tookPer(nballots, "ballots")}") println(" ${stopwatch.tookPer(nencryptions, "encryptions")}") println() if (showOperations) { - println("operations:") - println(buildString { - opCounts.forEach { key, value -> println(" $key = $value") } - }) + println(group.showOpCountResults("operations")) println("expect: ${6 * nencryptions * nballots + 2 * nballots}") } }