Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add opCounts to EcGroup #53

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading