Commit graph

10 commits

Author SHA1 Message Date
Hanjun Kim
7cbf95675a btcec: add a comment indicating where curve name taken from
Related with #1565
2020-09-08 09:37:33 -04:00
Hanjun Kim
8facfdd04d btcec: set curve name in CurveParams
Set curve name(secp256k1) in KoblitzCurve.CurveParams

Fixes #1564
2020-09-08 09:37:33 -04:00
Conner Fromknecht
2340ad388c
btcec/btcec: deprecate QPlus1Div4() in favor of Q()
The previous naming suggested that the value ((P+1)/4+1)/4 was being
returned, when in fact the returned value is simply (P+1)/4. The old
method is superseded by Q().
2019-10-02 18:22:17 -07:00
Conner Fromknecht
c7d523f83c
btcec/pubkey: optimize decompressPoint using fieldVals
This commit optimizes the decompressPoint subroutine, used in extracting
compressed pubkeys and performing pubkey recovery. We do so by replacing
the use of big.Int.Exp with with square-and-multiply exponentiation of
btcec's more optimized fieldVals, reducing the overall latency and
memory requirements of decompressPoint.

Instead of operating on bits of Q = (P+1)/4, the exponentiation applies
the square-and-multiply operations on full bytes of Q.  Compared to the
original speedup. Compared the bit-wise version, the improvement is
roughly 10%.

A new pair fieldVal methods called Sqrt and SqrtVal are added, which
applies the square-and-multiply exponentiation using precomputed
byte-slice of the value Q.

Comparison against big.Int sqrt and SAM sqrt over bytes of Q:

benchmark                            old ns/op     new ns/op     delta
BenchmarkParseCompressedPubKey-8     35545         23119         -34.96%

benchmark                            old allocs     new allocs     delta
BenchmarkParseCompressedPubKey-8     35             6            -82.86%

benchmark                            old bytes     new bytes     delta
BenchmarkParseCompressedPubKey-8     2777          256           -90.78%
2019-10-02 18:21:59 -07:00
Steven Roose
79445fbd97 btcec: Prevent static initialization of S256
This is achieved by introducing a new variable `halfOrder` on the
KoblitzCurve struct that is half the order.
2017-10-13 03:37:29 -05:00
Jimmy Song
1bdb713285 btcec: Slightly optimize NAF and add several tests.
This slightly optimizes the NAF function by avoiding returning the
unused bit when there is not a carry.

It also adds a bunch of additional unit tests which I made while
debugging.
2017-06-07 20:43:48 -05:00
Dave Collins
6e402deb35 Relicense to the btcsuite developers.
This commit relicenses all code in this repository to the btcsuite
developers.
2015-05-01 12:00:56 -05:00
Dave Collins
2713c8528d Consistency and general cleanup in btcec.
This commit contains various modifications for code and comment
consistency in the btcec package:
- Call out references at the top and reference them by their identifier in
  the other comments
- Remove a TODO that no longer applies
- Add comments to the fields in the KoblitzCurve struct and reorder them
  slightly
- Make comments wrap to 80
- Cleanup code that was far exceeding col 80 (only function declarations
  typically do this)
- Extend block comments to use as much of the 80 cols as available
- Add a bit more explanation in a couple of places
- Update copyright year on secp256k1.go
- Fix a couple of typos in the comments
2015-02-06 16:55:34 -06:00
Dave Collins
555778e9d5 Don't ignore errs setting consts in btcec init.
This commit converts the initialization of the constants to use a function
which panics on error instead of just ignoring the error.  This is
acceptable since they are hard-coded constants and should never fail.
2015-02-06 12:57:06 -06:00
Dave Collins
87968edb1d Import btcec repo into btcec directory. 2015-02-06 10:09:24 -06:00
Renamed from btcec.go (Browse further)