por: add hex print of PoR values
this is for debugging, not to be merged in its current form Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
64b7020549
commit
f3baf18fe7
|
@ -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)
|
||||
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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue