Skip to content

Commit

Permalink
Use the json vectors
Browse files Browse the repository at this point in the history
- includes type system workaround: generic sandwich nim-lang/Nim#11225
- converting NimNode to typedesc: nim-lang/Nim#6785
  • Loading branch information
mratsim committed Oct 10, 2020
1 parent a5db0b0 commit e9462bc
Show file tree
Hide file tree
Showing 10 changed files with 309 additions and 1,719 deletions.
2 changes: 1 addition & 1 deletion constantine.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const testDesc: seq[tuple[path: string, useGMP: bool]] = @[

# Elliptic curve arithmetic vs Sagemath
("tests/t_ec_frobenius.nim", false),
("tests/t_ec_sage_bn254.nim", false),
("tests/t_ec_sage_bn254_snarks.nim", false),
("tests/t_ec_sage_bls12_377.nim", false),
("tests/t_ec_sage_bls12_381.nim", false),
# Edge cases highlighted by past bugs
Expand Down
2 changes: 1 addition & 1 deletion constantine/elliptic/ec_shortweierstrass_jacobian.nim
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func affineFromJacobian*[F; Tw](
aff.y.prod(jac.y, invZ)
aff.y.prod(jac.y, invZ2)

func projectiveFromJacobian*[F; Tw](
func jacobianFromAffine*[F; Tw](
jac: var ECP_ShortW_Jac[F, Tw],
aff: ECP_ShortW_Aff[F, Tw]) {.inline.} =
jac.x = aff.x
Expand Down
20 changes: 17 additions & 3 deletions constantine/io/io_bigints.nim
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func nativeEndianToHex(bytes: openarray[byte], order: static[Endianness]): strin
#
# ############################################################

func fromHex*(T: type BigInt, s: string): T {.noInit.} =
func fromHex*(a: var BigInt, s: string) =
## Convert a hex string to BigInt that can hold
## the specified number of bits
##
Expand All @@ -421,12 +421,26 @@ func fromHex*(T: type BigInt, s: string): T {.noInit.} =
## Can work at compile-time to declare curve moduli from their hex strings

# 1. Convert to canonical uint
const canonLen = (T.bits + 8 - 1) div 8
const canonLen = (BigInt.bits + 8 - 1) div 8
var bytes: array[canonLen, byte]
hexToPaddedByteArray(s, bytes, bigEndian)

# 2. Convert canonical uint to Big Int
result.fromRawUint(bytes, bigEndian)
a.fromRawUint(bytes, bigEndian)

func fromHex*(T: type BigInt, s: string): T {.noInit.} =
## Convert a hex string to BigInt that can hold
## the specified number of bits
##
## For example `fromHex(BigInt[256], "0x123456")`
##
## Hex string is assumed big-endian
##
## This API is intended for configuration and debugging purposes
## Do not pass secret or private data to it.
##
## Can work at compile-time to declare curve moduli from their hex strings
result.fromHex(s)

func appendHex*(dst: var string, big: BigInt, order: static Endianness = bigEndian) =
## Append the BigInt hex into an accumulator
Expand Down
1 change: 0 additions & 1 deletion constantine/io/io_ec.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import
./io_bigints, ./io_fields, ./io_towers,
../config/curves,
../arithmetic,
../towers,
../elliptic/[
Expand Down
1 change: 0 additions & 1 deletion tests/support/ec_reference_scalar_mult.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import
# Internals
../../constantine/config/[common, curves],
../../constantine/arithmetic,
../../constantine/io/io_bigints

Expand Down
590 changes: 24 additions & 566 deletions tests/t_ec_sage_bls12_377.nim

Large diffs are not rendered by default.

591 changes: 24 additions & 567 deletions tests/t_ec_sage_bls12_381.nim

Large diffs are not rendered by default.

Loading

0 comments on commit e9462bc

Please sign in to comment.