Skip to content

Commit

Permalink
create file for common signature ops, derivePubkey for ECDSA & BLS
Browse files Browse the repository at this point in the history
Also cleans up the imports of the ECDSA file and adds the copyright header
  • Loading branch information
Vindaar committed Dec 24, 2024
1 parent d54908b commit 18425cf
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 25 deletions.
19 changes: 4 additions & 15 deletions constantine/signatures/bls_signatures.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import
constantine/named/algebras,
constantine/hash_to_curve/[hash_to_curve, h2c_hash_to_field],
constantine/hashes,
constantine/platforms/views
constantine/platforms/views,
constantine/signatures/common_signature_ops # for `derivePubkey`

export common_signature_ops

# ############################################################
#
Expand All @@ -34,20 +37,6 @@ import
{.push raises: [].} # No exceptions allowed in core cryptographic operations
{.push checks: off.} # No defects due to array bound checking or signed integer overflow allowed

func derivePubkey*[Pubkey, SecKey](pubkey: var Pubkey, seckey: SecKey) =
## Generates the public key associated with the input secret key.
##
## The secret key MUST be in range (0, curve order)
## 0 is INVALID
const Group = Pubkey.G
type Field = Pubkey.F
const EC = Field.Name

var pk {.noInit.}: EC_ShortW_Jac[Field, Group]
pk.setGenerator()
pk.scalarMul(seckey)
pubkey.affine(pk)

func coreSign*[Sig, SecKey](
signature: var Sig,
secretKey: SecKey,
Expand Down
26 changes: 26 additions & 0 deletions constantine/signatures/common_signature_ops.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Constantine
# Copyright (c) 2018-2019 Status Research & Development GmbH
# Copyright (c) 2020-Present Mamy André-Ratsimbazafy
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.

import
constantine/math/[ec_shortweierstrass],
constantine/named/zoo_generators,
constantine/named/algebras

func derivePubkey*[Pubkey, SecKey](pubkey: var Pubkey, seckey: SecKey) =
## Generates the public key associated with the input secret key.
##
## The secret key MUST be in range (0, curve order)
## 0 is INVALID
const Group = Pubkey.G
type Field = Pubkey.F
const EC = Field.Name

var pk {.noInit.}: EC_ShortW_Jac[Field, Group]
pk.setGenerator()
pk.scalarMul(seckey)
pubkey.affine(pk)
31 changes: 21 additions & 10 deletions constantine/signatures/ecdsa.nim
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
# Constantine
# Copyright (c) 2018-2019 Status Research & Development GmbH
# Copyright (c) 2020-Present Mamy André-Ratsimbazafy
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.

import
../hashes,
../named/algebras,
../math/io/[io_bigints, io_fields, io_ec],
../math/elliptic/[ec_shortweierstrass_affine, ec_shortweierstrass_jacobian, ec_scalar_mul, ec_multi_scalar_mul],
../math/[arithmetic, ec_shortweierstrass],
../platforms/[abstractions, views],
../serialization/codecs, # for fromHex and (in the future) base64 encoding
../mac/mac_hmac, # for deterministic nonce generation via RFC 6979
../named/zoo_generators, # for generator
../csprngs/sysrand
constantine/hashes,
constantine/named/algebras,
constantine/math/io/[io_bigints, io_fields, io_ec],
constantine/math/elliptic/[ec_shortweierstrass_affine, ec_shortweierstrass_jacobian, ec_scalar_mul, ec_multi_scalar_mul],
constantine/math/[arithmetic, ec_shortweierstrass],
constantine/platforms/[abstractions, views],
constantine/serialization/codecs, # for fromHex and (in the future) base64 encoding
constantine/mac/mac_hmac, # for deterministic nonce generation via RFC 6979
constantine/named/zoo_generators, # for generator
constantine/csprngs/sysrand,
constantine/signatures/common_signature_ops # for `derivePubkey`

import std / macros # for `update` convenience helper

export common_signature_ops

type
## Decides the type of sampler we use for the nonce. By default
## a simple uniform random sampler. Alternatively a deterministic
Expand Down

0 comments on commit 18425cf

Please sign in to comment.