mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-15 12:36:48 +00:00
Updates the libsecp256k1 dependency to commit: c0d9480fbbf8eccbd4be23ed27f6f2af6f3b211e PR: ``` BenchmarkSign-24 57756 21214 ns/op 164 B/op 3 allocs/op BenchmarkRecover-24 37156 33044 ns/op 80 B/op 1 allocs/op BenchmarkEcrecoverSignature-24 36889 32935 ns/op 80 B/op 1 allocs/op BenchmarkVerifySignature-24 41163 29207 ns/op 0 B/op 0 allocs/op BenchmarkDecompressPubkey-24 318624 4062 ns/op 304 B/op 6 allocs/op ``` Master: ``` BenchmarkSign-24 34509 35330 ns/op 164 B/op 3 allocs/op BenchmarkRecover-24 25418 47725 ns/op 80 B/op 1 allocs/op BenchmarkEcrecoverSignature-24 25735 47591 ns/op 80 B/op 1 allocs/op BenchmarkVerifySignature-24 29108 41097 ns/op 0 B/op 0 allocs/op BenchmarkDecompressPubkey-24 294747 4143 ns/op 304 B/op 6 allocs/op ``` Performance seems to be improved significantly: ``` Sign-24 34.86µ ± 3% 21.66µ ± 2% -37.86% (p=0.000 n=10) Recover-24 46.14µ ± 3% 33.24µ ± 2% -27.95% (p=0.000 n=10) ```
57 lines
2.3 KiB
C
57 lines
2.3 KiB
C
/***********************************************************************
|
|
* Copyright (c) 2013, 2014 Pieter Wuille *
|
|
* Distributed under the MIT software license, see the accompanying *
|
|
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
|
|
***********************************************************************/
|
|
|
|
#ifndef SECP256K1_FIELD_REPR_H
|
|
#define SECP256K1_FIELD_REPR_H
|
|
|
|
#include <stdint.h>
|
|
|
|
/** This field implementation represents the value as 10 uint32_t limbs in base
|
|
* 2^26. */
|
|
typedef struct {
|
|
/* A field element f represents the sum(i=0..9, f.n[i] << (i*26)) mod p,
|
|
* where p is the field modulus, 2^256 - 2^32 - 977.
|
|
*
|
|
* The individual limbs f.n[i] can exceed 2^26; the field's magnitude roughly
|
|
* corresponds to how much excess is allowed. The value
|
|
* sum(i=0..9, f.n[i] << (i*26)) may exceed p, unless the field element is
|
|
* normalized. */
|
|
uint32_t n[10];
|
|
/*
|
|
* Magnitude m requires:
|
|
* n[i] <= 2 * m * (2^26 - 1) for i=0..8
|
|
* n[9] <= 2 * m * (2^22 - 1)
|
|
*
|
|
* Normalized requires:
|
|
* n[i] <= (2^26 - 1) for i=0..8
|
|
* sum(i=0..9, n[i] << (i*26)) < p
|
|
* (together these imply n[9] <= 2^22 - 1)
|
|
*/
|
|
SECP256K1_FE_VERIFY_FIELDS
|
|
} secp256k1_fe;
|
|
|
|
/* Unpacks a constant into a overlapping multi-limbed FE element. */
|
|
#define SECP256K1_FE_CONST_INNER(d7, d6, d5, d4, d3, d2, d1, d0) { \
|
|
(d0) & 0x3FFFFFFUL, \
|
|
(((uint32_t)d0) >> 26) | (((uint32_t)(d1) & 0xFFFFFUL) << 6), \
|
|
(((uint32_t)d1) >> 20) | (((uint32_t)(d2) & 0x3FFFUL) << 12), \
|
|
(((uint32_t)d2) >> 14) | (((uint32_t)(d3) & 0xFFUL) << 18), \
|
|
(((uint32_t)d3) >> 8) | (((uint32_t)(d4) & 0x3UL) << 24), \
|
|
(((uint32_t)d4) >> 2) & 0x3FFFFFFUL, \
|
|
(((uint32_t)d4) >> 28) | (((uint32_t)(d5) & 0x3FFFFFUL) << 4), \
|
|
(((uint32_t)d5) >> 22) | (((uint32_t)(d6) & 0xFFFFUL) << 10), \
|
|
(((uint32_t)d6) >> 16) | (((uint32_t)(d7) & 0x3FFUL) << 16), \
|
|
(((uint32_t)d7) >> 10) \
|
|
}
|
|
|
|
typedef struct {
|
|
uint32_t n[8];
|
|
} secp256k1_fe_storage;
|
|
|
|
#define SECP256K1_FE_STORAGE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{ (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }}
|
|
#define SECP256K1_FE_STORAGE_CONST_GET(d) d.n[7], d.n[6], d.n[5], d.n[4],d.n[3], d.n[2], d.n[1], d.n[0]
|
|
|
|
#endif /* SECP256K1_FIELD_REPR_H */
|