status-im / nim-blscurve

Nim implementation of BLS signature scheme (Boneh-Lynn-Shacham) over Barreto-Lynn-Scott (BLS) curve BLS12-381
Apache License 2.0
26 stars 11 forks source link

Fix secretKey bigger than curve order and stack smashing in ECP mul #41

Closed mratsim closed 4 years ago

mratsim commented 4 years ago

This PR changes 2 things:

  1. it uses a DBIG_384 (double BIG_384) in to hold the raw bytes coming from HKDF-expand. Some of the raw outputs require more than 381-bit With a BIG the fromBytes procedure doesn't fail, the resulting BIG can be printed but calling norm or mod on it gives incorrect result and this creates an invalid secret key that causes stack smashing issues: https://github.com/status-im/nim-blscurve/issues/40#issuecomment-597573079, https://github.com/status-im/nim-beacon-chain/pull/780

  2. In the process of debugging, I changed HKDF to use openarray thinking that the rootcause was hidden in some raw pointers