diff --git a/dagger/por/backends/backend_blst.nim b/dagger/por/backends/backend_blst.nim index 1c27109a..9efc5547 100644 --- a/dagger/por/backends/backend_blst.nim +++ b/dagger/por/backends/backend_blst.nim @@ -13,6 +13,7 @@ import blscurve import blscurve/blst/blst_abi +import stew/byteutils # for toHex type ec_SecretKey* = blscurve.SecretKey @@ -108,4 +109,27 @@ func ec_verify*[T: byte|char]( publicKey: PublicKey, message: openarray[T], signature: Signature) : bool = - verify(publicKey, message, signature) \ No newline at end of file + verify(publicKey, message, signature) + +func toHex*( + obj: blst_p1|blst_p2|ec_scalar, + ): string = + ## Return the hex representation of a BLS object + ## They are serialized in compressed form + when obj is blst_p1: + const size = 48 + var bytes{.noInit.}: array[size, byte] + bytes.blst_p1_compress(obj) + elif obj is blst_p2: + const size = 96 + var bytes{.noInit.}: array[size, byte] + bytes.blst_p2_compress(obj) + elif obj is blst_scalar: + const size = 32 + var bytes{.noInit.}: array[size, byte] + bytes.blst_bendian_from_scalar(obj) + + result = bytes.toHex() + +proc `$`*(x: ec_p1|ec_p2|ec_scalar): string = + result &= toHex(x) diff --git a/dagger/por/backends/backend_constantine.nim b/dagger/por/backends/backend_constantine.nim index 2218c79a..d7b25843 100644 --- a/dagger/por/backends/backend_constantine.nim +++ b/dagger/por/backends/backend_constantine.nim @@ -22,6 +22,7 @@ import # constantine/math/pairing/cyclotomic_subgroup, # constantine/math/io/io_extfields, constantine/math/io/io_bigints, + constantine/math/io/io_ec, # constantine/math/config/[curves_declaration, type_ff], constantine/math/config/type_ff, constantine/blssig_pop_on_bls12381_g2, @@ -187,3 +188,6 @@ func ec_verify*( message: openarray[char], signature: Signature) : bool = publicKey.verify(message, signature) == cttBLS_Success + +proc `$`*(x: ec_p1|ec_p2|ec_scalar): string = + result &= toHex(x) diff --git a/dagger/por/por.nim b/dagger/por/por.nim index 2b71aa69..68318840 100644 --- a/dagger/por/por.nim +++ b/dagger/por/por.nim @@ -83,10 +83,13 @@ # - constantine is more experimental, supports BLS and BN curves as well # As of now configuration of backends is in the backend_* file itself import ./backends/backend_blst +export backend_blst.`$` #import ./backends/backend_constantine +#export backend_constantine.`$` import ../rng import endians +import pkg/stew/byteutils # sector size in bytes. Must be smaller than the subgroup order r # which is 255 bits long for BLS12-381 @@ -361,3 +364,11 @@ proc verifyProof*(tau: Tau, q: openArray[QElement], mus: openArray[ec_scalar], s g.ec_p2_from_affine(EC_G2) return verifyPairings(sum, spk.key, sigma, g) + +proc `$`*(t0: TauZero): string = + result &= "\nname: " & toHex(t0.name) + result &= "\nn: " & $t0.n + result &= "\nu: " & $t0.u + +proc `$`*(x: array[96, byte]): string = + result &= toHex(x) diff --git a/dagger/por/testpor.nim b/dagger/por/testpor.nim index 718ee9d7..a8468ece 100644 --- a/dagger/por/testpor.nim +++ b/dagger/por/testpor.nim @@ -20,15 +20,16 @@ proc testbls() : bool = benchmark "Auth generation (s=" & $sectorsperblock & ")": let (tau, authenticators) = por.setup(ssk, sectorsperblock, "example.txt") - #echo "Auth: ", authenticators + echo "tau: ", tau + echo "Auth: ", authenticators benchmark "Generating challenge (q=" & $querylen & ")": let q = por.generateQuery(tau, spk, querylen) - #echo "Generated!" #, " q:", q + echo "Generated!", "\nq:", q benchmark "Issuing proof": let (mu, sigma) = por.generateProof(q, authenticators, spk, sectorsperblock, "example.txt") - #echo "Issued!" #, " mu:", mu, " sigma:", sigma + echo "Issued!", "\nmu:", mu, "\nsigma:", sigma benchmark "Verifying proof": result = por.verifyProof(tau, q, mu, sigma, spk)