Skip to content

Commit

Permalink
Add opCounts to EcGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnLCaron committed Apr 10, 2024
1 parent 4507d8d commit 4e38dee
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
10 changes: 10 additions & 0 deletions src/main/kotlin/org/cryptobiotic/eg/core/GroupContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}



Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -52,8 +53,12 @@ class EcGroupContext(val name: String, useNative: Boolean = true): GroupContext
return EcElementModP(this, vecGroup.g.exp(exp.element))
}

var opCounts: HashMap<String, AtomicInteger> = HashMap()
override fun getAndClearOpCounts(): Map<String, Int> {
return emptyMap()
val result = HashMap<String, Int>()
opCounts.forEach { (key, value) -> result[key] = value.get() }
opCounts = HashMap()
return result.toSortedMap()
}

override fun isCompatible(ctx: GroupContext): Boolean {
Expand Down
Binary file modified src/test/data/workflow/allAvailableEc.zip
Binary file not shown.
10 changes: 0 additions & 10 deletions src/test/kotlin/org/cryptobiotic/eg/core/GroupTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
}
}
Expand Down

0 comments on commit 4e38dee

Please sign in to comment.