bump upstream, fix cuchar warnings (#39)
This commit is contained in:
parent
88b2702fea
commit
eb5868e069
|
@ -11,7 +11,7 @@
|
|||
|
||||
import
|
||||
strformat, typetraits,
|
||||
stew/[byteutils, objects, results, ctops],
|
||||
stew/[byteutils, objects, results, ctops, ptrops],
|
||||
./secp256k1/abi
|
||||
|
||||
from nimcrypto/utils import burnMem
|
||||
|
@ -126,11 +126,8 @@ proc errorCallback(message: cstring, data: pointer) {.cdecl, raises: [].} =
|
|||
echo getStackTrace()
|
||||
quit 1
|
||||
|
||||
template ptr0(v: array|openArray): ptr cuchar =
|
||||
cast[ptr cuchar](unsafeAddr v[0])
|
||||
|
||||
template ptr0(v: SkMessage): ptr cuchar =
|
||||
ptr0(distinctBase(v))
|
||||
template baseAddr(v: SkMessage): ptr byte =
|
||||
baseAddr(distinctBase(v))
|
||||
|
||||
proc releaseThread*(T: type SkContext): T =
|
||||
if not isNil(secpContext.context):
|
||||
|
@ -196,7 +193,7 @@ proc random*(T: type SkSecretKey, rng: Rng): SkResult[T] =
|
|||
var data{.noinit.}: array[SkRawSecretKeySize, byte]
|
||||
|
||||
while rng(data):
|
||||
if secp256k1_ec_seckey_verify(secp256k1_context_no_precomp, data.ptr0) == 1:
|
||||
if secp256k1_ec_seckey_verify(secp256k1_context_no_precomp, data.baseAddr) == 1:
|
||||
return ok(T(data: data))
|
||||
|
||||
return err("secp: cannot get random bytes for key")
|
||||
|
@ -218,7 +215,7 @@ proc random*(T: type SkSecretKey, rng: FoolproofRng): T =
|
|||
|
||||
for _ in 0..1000*1000:
|
||||
rng(data)
|
||||
if secp256k1_ec_seckey_verify(secp256k1_context_no_precomp, data.ptr0) == 1:
|
||||
if secp256k1_ec_seckey_verify(secp256k1_context_no_precomp, data.baseAddr) == 1:
|
||||
return T(data: data)
|
||||
|
||||
result = T(data: default(array[32, byte])) # Silence compiler
|
||||
|
@ -230,7 +227,7 @@ func fromRaw*(T: type SkSecretKey, data: openArray[byte]): SkResult[T] =
|
|||
if len(data) < SkRawSecretKeySize:
|
||||
return err(static(&"secp: raw private key should be {SkRawSecretKeySize} bytes"))
|
||||
|
||||
if secp256k1_ec_seckey_verify(secp256k1_context_no_precomp, data.ptr0) != 1:
|
||||
if secp256k1_ec_seckey_verify(secp256k1_context_no_precomp, data.baseAddr) != 1:
|
||||
return err("secp: invalid private key")
|
||||
|
||||
ok(T(data: toArray(32, data.toOpenArray(0, SkRawSecretKeySize - 1))))
|
||||
|
@ -251,7 +248,7 @@ func toPublicKey*(key: SkSecretKey): SkPublicKey =
|
|||
## Calculate and return Secp256k1 `public key` from `private key` ``key``.
|
||||
var pubkey {.noinit.}: secp256k1_pubkey
|
||||
let res = secp256k1_ec_pubkey_create(
|
||||
getContext(), addr pubkey, key.data.ptr0)
|
||||
getContext(), addr pubkey, key.data.baseAddr)
|
||||
doAssert res == 1, "Valid private keys should always have a corresponding pub"
|
||||
|
||||
SkPublicKey(data: pubkey)
|
||||
|
@ -273,7 +270,7 @@ func fromRaw*(T: type SkPublicKey, data: openArray[byte]): SkResult[T] =
|
|||
|
||||
var key {.noinit.}: secp256k1_pubkey
|
||||
if secp256k1_ec_pubkey_parse(
|
||||
secp256k1_context_no_precomp, addr key, data.ptr0, csize_t(length)) != 1:
|
||||
secp256k1_context_no_precomp, addr key, data.baseAddr, csize_t(length)) != 1:
|
||||
return err("secp: cannot parse public key")
|
||||
|
||||
ok(SkPublicKey(data: key))
|
||||
|
@ -287,7 +284,7 @@ func toRaw*(pubkey: SkPublicKey): array[SkRawPublicKeySize, byte] =
|
|||
## Serialize Secp256k1 `public key` ``key`` to raw uncompressed form
|
||||
var length = csize_t(len(result))
|
||||
let res = secp256k1_ec_pubkey_serialize(
|
||||
secp256k1_context_no_precomp, result.ptr0, addr length,
|
||||
secp256k1_context_no_precomp, result.baseAddr, addr length,
|
||||
unsafeAddr pubkey.data, SECP256K1_EC_UNCOMPRESSED)
|
||||
doAssert res == 1, "Can't fail, per documentation"
|
||||
|
||||
|
@ -298,7 +295,7 @@ func toRawCompressed*(pubkey: SkPublicKey): array[SkRawCompressedPublicKeySize,
|
|||
## Serialize Secp256k1 `public key` ``key`` to raw compressed form
|
||||
var length = csize_t(len(result))
|
||||
let res = secp256k1_ec_pubkey_serialize(
|
||||
secp256k1_context_no_precomp, result.ptr0, addr length,
|
||||
secp256k1_context_no_precomp, result.baseAddr, addr length,
|
||||
unsafeAddr pubkey.data, SECP256K1_EC_COMPRESSED)
|
||||
doAssert res == 1, "Can't fail, per documentation"
|
||||
|
||||
|
@ -312,7 +309,7 @@ func fromRaw*(T: type SkSignature, data: openArray[byte]): SkResult[T] =
|
|||
|
||||
var sig {.noinit.}: secp256k1_ecdsa_signature
|
||||
if secp256k1_ecdsa_signature_parse_compact(
|
||||
secp256k1_context_no_precomp, addr sig, data.ptr0) != 1:
|
||||
secp256k1_context_no_precomp, addr sig, data.baseAddr) != 1:
|
||||
return err("secp: cannot parse signaure")
|
||||
|
||||
ok(T(data: sig))
|
||||
|
@ -325,7 +322,7 @@ func fromDer*(T: type SkSignature, data: openArray[byte]): SkResult[T] =
|
|||
|
||||
var sig {.noinit.}: secp256k1_ecdsa_signature
|
||||
if secp256k1_ecdsa_signature_parse_der(
|
||||
secp256k1_context_no_precomp, addr sig, data.ptr0, csize_t(len(data))) != 1:
|
||||
secp256k1_context_no_precomp, addr sig, data.baseAddr, csize_t(len(data))) != 1:
|
||||
return err("secp: cannot parse DER signature")
|
||||
|
||||
ok(T(data: sig))
|
||||
|
@ -338,7 +335,7 @@ func fromHex*(T: type SkSignature, data: string): SkResult[T] =
|
|||
func toRaw*(sig: SkSignature): array[SkRawSignatureSize, byte] =
|
||||
## Serialize signature to compact binary form
|
||||
let res = secp256k1_ecdsa_signature_serialize_compact(
|
||||
secp256k1_context_no_precomp, result.ptr0, unsafeAddr sig.data)
|
||||
secp256k1_context_no_precomp, result.baseAddr, unsafeAddr sig.data)
|
||||
doAssert res == 1, "Can't fail, per documentation"
|
||||
|
||||
func toDer*(sig: SkSignature, data: var openArray[byte]): int =
|
||||
|
@ -350,7 +347,7 @@ func toDer*(sig: SkSignature, data: var openArray[byte]): int =
|
|||
var buffer: array[SkDerSignatureMaxSize, byte]
|
||||
var plength = csize_t(len(buffer))
|
||||
let res = secp256k1_ecdsa_signature_serialize_der(
|
||||
secp256k1_context_no_precomp, buffer.ptr0, addr plength,
|
||||
secp256k1_context_no_precomp, buffer.baseAddr, addr plength,
|
||||
unsafeAddr sig.data)
|
||||
doAssert res == 1, "Can't fail, per documentation"
|
||||
result = int(plength)
|
||||
|
@ -377,7 +374,7 @@ func fromRaw*(T: type SkRecoverableSignature, data: openArray[byte]): SkResult[T
|
|||
|
||||
var sig {.noinit.}: secp256k1_ecdsa_recoverable_signature
|
||||
if secp256k1_ecdsa_recoverable_signature_parse_compact(
|
||||
secp256k1_context_no_precomp, addr sig, data.ptr0, recid) != 1:
|
||||
secp256k1_context_no_precomp, addr sig, data.baseAddr, recid) != 1:
|
||||
return err("secp: invalid recoverable signature")
|
||||
|
||||
ok(T(data: sig))
|
||||
|
@ -391,7 +388,7 @@ func toRaw*(sig: SkRecoverableSignature): array[SkRawRecoverableSignatureSize, b
|
|||
## Converts recoverable signature to compact binary form
|
||||
var recid = cint(0)
|
||||
let res = secp256k1_ecdsa_recoverable_signature_serialize_compact(
|
||||
secp256k1_context_no_precomp, result.ptr0, addr recid, unsafeAddr sig.data)
|
||||
secp256k1_context_no_precomp, result.baseAddr, addr recid, unsafeAddr sig.data)
|
||||
doAssert res == 1, "can't fail, per documentation"
|
||||
|
||||
result[64] = byte(recid)
|
||||
|
@ -433,7 +430,7 @@ func sign*(key: SkSecretKey, msg: SkMessage): SkSignature =
|
|||
## a 32-byte hash, like sha256.
|
||||
var data {.noinit.}: secp256k1_ecdsa_signature
|
||||
let res = secp256k1_ecdsa_sign(
|
||||
getContext(), addr data, msg.ptr0, key.data.ptr0, nil, nil)
|
||||
getContext(), addr data, msg.baseAddr, key.data.baseAddr, nil, nil)
|
||||
doAssert res == 1, "cannot create signature, key invalid?"
|
||||
SkSignature(data: data)
|
||||
|
||||
|
@ -441,18 +438,18 @@ func signRecoverable*(key: SkSecretKey, msg: SkMessage): SkRecoverableSignature
|
|||
## Sign message `msg` using private key `key` and return signature object.
|
||||
var data {.noinit.}: secp256k1_ecdsa_recoverable_signature
|
||||
let res = secp256k1_ecdsa_sign_recoverable(
|
||||
getContext(), addr data, msg.ptr0, key.data.ptr0, nil, nil)
|
||||
getContext(), addr data, msg.baseAddr, key.data.baseAddr, nil, nil)
|
||||
doAssert res == 1, "cannot create recoverable signature, key invalid?"
|
||||
SkRecoverableSignature(data: data)
|
||||
|
||||
func verify*(sig: SkSignature, msg: SkMessage, key: SkPublicKey): bool =
|
||||
secp256k1_ecdsa_verify(
|
||||
getContext(), unsafeAddr sig.data, msg.ptr0, unsafeAddr key.data) == 1
|
||||
getContext(), unsafeAddr sig.data, msg.baseAddr, unsafeAddr key.data) == 1
|
||||
|
||||
func recover*(sig: SkRecoverableSignature, msg: SkMessage): SkResult[SkPublicKey] =
|
||||
var data {.noinit.}: secp256k1_pubkey
|
||||
if secp256k1_ecdsa_recover(
|
||||
getContext(), addr data, unsafeAddr sig.data, msg.ptr0) != 1:
|
||||
getContext(), addr data, unsafeAddr sig.data, msg.baseAddr) != 1:
|
||||
return err("secp: cannot recover public key from signature")
|
||||
|
||||
ok(SkPublicKey(data: data))
|
||||
|
@ -461,8 +458,8 @@ func ecdh*(seckey: SkSecretKey, pubkey: SkPublicKey): SkEcdhSecret =
|
|||
## Calculate ECDH shared secret.
|
||||
var secret {.noinit.}: array[SkEdchSecretSize, byte]
|
||||
let res = secp256k1_ecdh(
|
||||
secp256k1_context_no_precomp, secret.ptr0, unsafeAddr pubkey.data,
|
||||
seckey.data.ptr0)
|
||||
secp256k1_context_no_precomp, secret.baseAddr, unsafeAddr pubkey.data,
|
||||
seckey.data.baseAddr)
|
||||
doAssert res == 1, "cannot compute ECDH secret, keys invalid?"
|
||||
|
||||
SkEcdhSecret(data: secret)
|
||||
|
@ -472,8 +469,8 @@ func ecdhRaw*(seckey: SkSecretKey, pubkey: SkPublicKey): SkEcdhRawSecret =
|
|||
# TODO - deprecate: https://github.com/status-im/nim-eth/issues/222
|
||||
var secret {.noinit.}: array[SkEcdhRawSecretSize, byte]
|
||||
let res = secp256k1_ecdh_raw(
|
||||
secp256k1_context_no_precomp, secret.ptr0, unsafeAddr pubkey.data,
|
||||
seckey.data.ptr0)
|
||||
secp256k1_context_no_precomp, secret.baseAddr, unsafeAddr pubkey.data,
|
||||
seckey.data.baseAddr)
|
||||
doAssert res == 1, "cannot compute raw ECDH secret, keys invalid?"
|
||||
|
||||
SkEcdhRawSecret(data: secret)
|
||||
|
@ -516,14 +513,16 @@ proc default*(T: type SkEcdhSecret): T {.error: "loophole".}
|
|||
proc default*(T: type SkEcdhRawSecret): T {.error: "loophole".}
|
||||
|
||||
func tweakAdd*(secretKey: var SkSecretKey, tweak: openArray[byte]): SkResult[void] =
|
||||
let res = secp256k1_ec_privkey_tweak_add(secp256k1_context_no_precomp, secretKey.data.ptr0, tweak.ptr0)
|
||||
let res = secp256k1_ec_privkey_tweak_add(
|
||||
secp256k1_context_no_precomp, secretKey.data.baseAddr, tweak.baseAddr)
|
||||
if res != 1:
|
||||
err("Tweak out of range, or invalid private key")
|
||||
else:
|
||||
ok()
|
||||
|
||||
func tweakMul*(secretKey: var SkSecretKey, tweak: openArray[byte]): SkResult[void] =
|
||||
let res = secp256k1_ec_privkey_tweak_mul(secp256k1_context_no_precomp, secretKey.data.ptr0, tweak.ptr0)
|
||||
let res = secp256k1_ec_privkey_tweak_mul(
|
||||
secp256k1_context_no_precomp, secretKey.data.baseAddr, tweak.baseAddr)
|
||||
if res != 1:
|
||||
err("Tweak out of range, or equal to zero")
|
||||
else:
|
||||
|
|
|
@ -6,7 +6,6 @@ const
|
|||
"/../secp256k1_wrapper"
|
||||
internalPath = wrapperPath & "/secp256k1"
|
||||
srcPath = internalPath & "/src"
|
||||
secpSrc = srcPath & "/secp256k1.c"
|
||||
|
||||
{.passc: "-I" & quoteShell(wrapperPath).}
|
||||
{.passc: "-I" & quoteShell(internalPath).}
|
||||
|
@ -16,7 +15,9 @@ const
|
|||
when defined(gcc) or defined(clang):
|
||||
{.passc: "-DHAVE_BUILTIN_EXPECT"}
|
||||
|
||||
{.compile: secpSrc.}
|
||||
{.compile: srcPath & "/secp256k1.c".}
|
||||
{.compile: srcPath & "/precomputed_ecmult.c".}
|
||||
{.compile: srcPath & "/precomputed_ecmult_gen.c".}
|
||||
|
||||
{.pragma: secp, importc, cdecl, raises: [].}
|
||||
|
||||
|
@ -27,13 +28,13 @@ type
|
|||
secp256k1_ecdsa_signature* = object
|
||||
data*: array[64, uint8]
|
||||
|
||||
secp256k1_nonce_function* = proc (nonce32: ptr cuchar; msg32: ptr cuchar;
|
||||
key32: ptr cuchar; algo16: ptr cuchar; data: pointer;
|
||||
secp256k1_nonce_function* = proc (nonce32: ptr byte; msg32: ptr byte;
|
||||
key32: ptr byte; algo16: ptr byte; data: pointer;
|
||||
attempt: cuint): cint {.cdecl, raises: [].}
|
||||
secp256k1_error_function* = proc (message: cstring; data: pointer) {.cdecl, raises: [].}
|
||||
|
||||
secp256k1_ecdh_hash_function* = proc (output: ptr cuchar,
|
||||
x32, y32: ptr cuchar,
|
||||
secp256k1_ecdh_hash_function* = proc (output: ptr byte,
|
||||
x32, y32: ptr byte,
|
||||
data: pointer) {.cdecl, raises: [].}
|
||||
|
||||
secp256k1_context* = object
|
||||
|
@ -118,12 +119,12 @@ proc secp256k1_scratch_space_destroy*(
|
|||
proc secp256k1_ec_pubkey_parse*(
|
||||
ctx: ptr secp256k1_context;
|
||||
pubkey: ptr secp256k1_pubkey;
|
||||
input: ptr cuchar;
|
||||
input: ptr byte;
|
||||
inputlen: csize_t): cint {.secp.}
|
||||
|
||||
proc secp256k1_ec_pubkey_serialize*(
|
||||
ctx: ptr secp256k1_context;
|
||||
output: ptr cuchar;
|
||||
output: ptr byte;
|
||||
outputlen: ptr csize_t;
|
||||
pubkey: ptr secp256k1_pubkey;
|
||||
flags: cuint): cint {.secp.}
|
||||
|
@ -131,29 +132,29 @@ proc secp256k1_ec_pubkey_serialize*(
|
|||
proc secp256k1_ecdsa_signature_parse_compact*(
|
||||
ctx: ptr secp256k1_context;
|
||||
sig: ptr secp256k1_ecdsa_signature;
|
||||
input64: ptr cuchar): cint {.secp.}
|
||||
input64: ptr byte): cint {.secp.}
|
||||
|
||||
proc secp256k1_ecdsa_signature_parse_der*(
|
||||
ctx: ptr secp256k1_context;
|
||||
sig: ptr secp256k1_ecdsa_signature;
|
||||
input: ptr cuchar;
|
||||
input: ptr byte;
|
||||
inputlen: csize_t): cint {.secp.}
|
||||
|
||||
proc secp256k1_ecdsa_signature_serialize_der*(
|
||||
ctx: ptr secp256k1_context;
|
||||
output: ptr cuchar;
|
||||
output: ptr byte;
|
||||
outputlen: ptr csize_t;
|
||||
sig: ptr secp256k1_ecdsa_signature): cint {.secp.}
|
||||
|
||||
proc secp256k1_ecdsa_signature_serialize_compact*(
|
||||
ctx: ptr secp256k1_context;
|
||||
output64: ptr cuchar;
|
||||
output64: ptr byte;
|
||||
sig: ptr secp256k1_ecdsa_signature): cint {.secp.}
|
||||
|
||||
proc secp256k1_ecdsa_verify*(
|
||||
ctx: ptr secp256k1_context;
|
||||
sig: ptr secp256k1_ecdsa_signature;
|
||||
msg32: ptr cuchar;
|
||||
msg32: ptr byte;
|
||||
pubkey: ptr secp256k1_pubkey): cint {.secp.}
|
||||
|
||||
proc secp256k1_ecdsa_signature_normalize*(
|
||||
|
@ -164,23 +165,23 @@ proc secp256k1_ecdsa_signature_normalize*(
|
|||
proc secp256k1_ecdsa_sign*(
|
||||
ctx: ptr secp256k1_context;
|
||||
sig: ptr secp256k1_ecdsa_signature;
|
||||
msg32: ptr cuchar;
|
||||
seckey: ptr cuchar;
|
||||
msg32: ptr byte;
|
||||
seckey: ptr byte;
|
||||
noncefp: secp256k1_nonce_function;
|
||||
ndata: pointer): cint {.secp.}
|
||||
|
||||
proc secp256k1_ec_seckey_verify*(
|
||||
ctx: ptr secp256k1_context;
|
||||
seckey: ptr cuchar): cint {.secp.}
|
||||
seckey: ptr byte): cint {.secp.}
|
||||
|
||||
proc secp256k1_ec_pubkey_create*(
|
||||
ctx: ptr secp256k1_context;
|
||||
pubkey: ptr secp256k1_pubkey;
|
||||
seckey: ptr cuchar): cint {.secp.}
|
||||
seckey: ptr byte): cint {.secp.}
|
||||
|
||||
proc secp256k1_ec_privkey_negate*(
|
||||
ctx: ptr secp256k1_context;
|
||||
seckey: ptr cuchar): cint {.secp.}
|
||||
seckey: ptr byte): cint {.secp.}
|
||||
|
||||
proc secp256k1_ec_pubkey_negate*(
|
||||
ctx: ptr secp256k1_context;
|
||||
|
@ -188,27 +189,27 @@ proc secp256k1_ec_pubkey_negate*(
|
|||
|
||||
proc secp256k1_ec_privkey_tweak_add*(
|
||||
ctx: ptr secp256k1_context;
|
||||
seckey: ptr cuchar;
|
||||
tweak: ptr cuchar): cint {.secp.}
|
||||
seckey: ptr byte;
|
||||
tweak: ptr byte): cint {.secp.}
|
||||
|
||||
proc secp256k1_ec_pubkey_tweak_add*(
|
||||
ctx: ptr secp256k1_context;
|
||||
pubkey: ptr secp256k1_pubkey;
|
||||
tweak: ptr cuchar): cint {.secp.}
|
||||
tweak: ptr byte): cint {.secp.}
|
||||
|
||||
proc secp256k1_ec_privkey_tweak_mul*(
|
||||
ctx: ptr secp256k1_context;
|
||||
seckey: ptr cuchar;
|
||||
tweak: ptr cuchar): cint {.secp.}
|
||||
seckey: ptr byte;
|
||||
tweak: ptr byte): cint {.secp.}
|
||||
|
||||
proc secp256k1_ec_pubkey_tweak_mul*(
|
||||
ctx: ptr secp256k1_context;
|
||||
pubkey: ptr secp256k1_pubkey;
|
||||
tweak: ptr cuchar): cint {.secp.}
|
||||
tweak: ptr byte): cint {.secp.}
|
||||
|
||||
proc secp256k1_context_randomize*(
|
||||
ctx: ptr secp256k1_context;
|
||||
seed32: ptr cuchar): cint {.secp.}
|
||||
seed32: ptr byte): cint {.secp.}
|
||||
|
||||
proc secp256k1_ec_pubkey_combine*(
|
||||
ctx: ptr secp256k1_context;
|
||||
|
@ -239,8 +240,8 @@ type
|
|||
proc secp256k1_ecdsa_sign_recoverable*(
|
||||
ctx: ptr secp256k1_context;
|
||||
sig: ptr secp256k1_ecdsa_recoverable_signature;
|
||||
msg32: ptr cuchar;
|
||||
seckey: ptr cuchar;
|
||||
msg32: ptr byte;
|
||||
seckey: ptr byte;
|
||||
noncefp: secp256k1_nonce_function;
|
||||
ndata: pointer): cint {.secp.}
|
||||
## Create a recoverable ECDSA signature.
|
||||
|
@ -259,7 +260,7 @@ proc secp256k1_ecdsa_recover*(
|
|||
ctx: ptr secp256k1_context;
|
||||
pubkey: ptr secp256k1_pubkey;
|
||||
sig: ptr secp256k1_ecdsa_recoverable_signature;
|
||||
msg32: ptr cuchar): cint {.secp.}
|
||||
msg32: ptr byte): cint {.secp.}
|
||||
## Recover an ECDSA public key from a signature.
|
||||
##
|
||||
## Returns: 1: public key successfully recovered (which guarantees a correct signature).
|
||||
|
@ -272,7 +273,7 @@ proc secp256k1_ecdsa_recover*(
|
|||
|
||||
proc secp256k1_ecdsa_recoverable_signature_serialize_compact*(
|
||||
ctx: ptr secp256k1_context;
|
||||
output64: ptr cuchar;
|
||||
output64: ptr byte;
|
||||
recid: ptr cint;
|
||||
sig: ptr secp256k1_ecdsa_recoverable_signature): cint {.secp.}
|
||||
## Serialize an ECDSA signature in compact format (64 bytes + recovery id).
|
||||
|
@ -287,11 +288,11 @@ proc secp256k1_ecdsa_recoverable_signature_serialize_compact*(
|
|||
proc secp256k1_ecdsa_recoverable_signature_parse_compact*(
|
||||
ctx: ptr secp256k1_context;
|
||||
sig: ptr secp256k1_ecdsa_recoverable_signature;
|
||||
input64: ptr cuchar, recid: cint): cint {.secp.}
|
||||
input64: ptr byte, recid: cint): cint {.secp.}
|
||||
|
||||
func secp256k1_ecdh*(ctx: ptr secp256k1_context; output32: ptr cuchar;
|
||||
func secp256k1_ecdh*(ctx: ptr secp256k1_context; output32: ptr byte;
|
||||
pubkey: ptr secp256k1_pubkey;
|
||||
privkey: ptr cuchar,
|
||||
privkey: ptr byte,
|
||||
hashfp: secp256k1_ecdh_hash_function,
|
||||
data: pointer): cint {.secp.}
|
||||
## Compute an EC Diffie-Hellman secret in constant time
|
||||
|
@ -305,15 +306,15 @@ func secp256k1_ecdh*(ctx: ptr secp256k1_context; output32: ptr cuchar;
|
|||
## privkey: a 32-byte scalar with which to multiply the point
|
||||
##
|
||||
|
||||
template secp256k1_ecdh*(ctx: ptr secp256k1_context; output32: ptr cuchar;
|
||||
template secp256k1_ecdh*(ctx: ptr secp256k1_context; output32: ptr byte;
|
||||
pubkey: ptr secp256k1_pubkey;
|
||||
privkey: ptr cuchar): cint =
|
||||
privkey: ptr byte): cint =
|
||||
secp256k1_ecdh(ctx, output32, pubkey, privkey,
|
||||
secp256k1_ecdh_hash_function_default(), nil)
|
||||
|
||||
proc secp256k1_ecdh_raw*(ctx: ptr secp256k1_context; output32: ptr cuchar;
|
||||
proc secp256k1_ecdh_raw*(ctx: ptr secp256k1_context; output32: ptr byte;
|
||||
pubkey: ptr secp256k1_pubkey;
|
||||
input32: ptr cuchar): cint {.secp.}
|
||||
input32: ptr byte): cint {.secp.}
|
||||
## Compute an EC Diffie-Hellman secret in constant time
|
||||
## Returns: 1: exponentiation was successful
|
||||
## 0: scalar was invalid (zero or overflow)
|
||||
|
|
|
@ -5,9 +5,6 @@
|
|||
|
||||
#define LIBSECP256K1_CONFIG_H
|
||||
|
||||
/* Define if building universal (internal helper macro) */
|
||||
/* #undef AC_APPLE_UNIVERSAL_BUILD */
|
||||
|
||||
/* Define this symbol to compile out all VERIFY code */
|
||||
/* #undef COVERAGE */
|
||||
|
||||
|
@ -20,14 +17,14 @@
|
|||
/* Define this symbol to enable the ECDH module */
|
||||
#define ENABLE_MODULE_ECDH 1
|
||||
|
||||
/* Define this symbol to enable the extrakeys module */
|
||||
/* #undef ENABLE_MODULE_EXTRAKEYS */
|
||||
|
||||
/* Define this symbol to enable the ECDSA pubkey recovery module */
|
||||
#define ENABLE_MODULE_RECOVERY 1
|
||||
|
||||
/* Define this symbol if OpenSSL EC functions are available */
|
||||
/* #undef ENABLE_OPENSSL_TESTS */
|
||||
|
||||
/* Define this symbol if __builtin_expect is available */
|
||||
/* #define HAVE_BUILTIN_EXPECT 1 */
|
||||
/* Define this symbol to enable the schnorrsig module */
|
||||
/* #undef ENABLE_MODULE_SCHNORRSIG */
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#define HAVE_DLFCN_H 1
|
||||
|
@ -35,18 +32,12 @@
|
|||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define this symbol if libcrypto is installed */
|
||||
#define HAVE_LIBCRYPTO 1
|
||||
|
||||
/* Define this symbol if libgmp is installed */
|
||||
/* #undef HAVE_LIBGMP */
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdio.h> header file. */
|
||||
#define HAVE_STDIO_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
|
@ -65,25 +56,9 @@
|
|||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
|
||||
#if defined(__x86_64)||defined(__x86_64__)||defined(_WIN64)
|
||||
/* Define this symbol to enable x86_64 assembly optimizations */
|
||||
#define USE_ASM_X86_64 1
|
||||
#endif
|
||||
|
||||
#if defined(_LP64)||defined(__LP64__)||defined(__64BIT__)||defined(__LLP64__)
|
||||
/* Define to 1 if the system has the type `__int128'. */
|
||||
#define HAVE___INT128 1
|
||||
/* Define this symbol to use the 4x64 scalar implementation */
|
||||
#define USE_SCALAR_4X64 1
|
||||
/* Define this symbol to use the FIELD_5X52 implementation */
|
||||
#define USE_FIELD_5X52 1
|
||||
#else
|
||||
/* Define this symbol to use the 8x32 scalar implementation */
|
||||
#define USE_SCALAR_8X32 1
|
||||
/* Define this symbol to use the FIELD_10X26 implementation */
|
||||
#define USE_FIELD_10X26 1
|
||||
#endif
|
||||
/* Define this symbol if valgrind is installed, and it supports the host
|
||||
platform */
|
||||
/* #undef HAVE_VALGRIND */
|
||||
|
||||
/* Define to the sub-directory where libtool stores uninstalled libraries. */
|
||||
#define LT_OBJDIR ".libs/"
|
||||
|
@ -92,67 +67,52 @@
|
|||
#define PACKAGE "libsecp256k1"
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT ""
|
||||
#define PACKAGE_BUGREPORT "https://github.com/bitcoin-core/secp256k1/issues"
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "libsecp256k1"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "libsecp256k1 0.1"
|
||||
#define PACKAGE_STRING "libsecp256k1 0.1.0-pre"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "libsecp256k1"
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#define PACKAGE_URL ""
|
||||
#define PACKAGE_URL "https://github.com/bitcoin-core/secp256k1"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "0.1"
|
||||
#define PACKAGE_VERSION "0.1.0-pre"
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
/* Define to 1 if all of the C90 standard headers exist (not just the ones
|
||||
required in a freestanding environment). This macro is provided for
|
||||
backward compatibility; new code need not use it. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define this symbol to use a statically generated ecmult table */
|
||||
#define USE_ECMULT_STATIC_PRECOMPUTATION 1
|
||||
|
||||
/* Define this symbol to use endomorphism optimization */
|
||||
/* #undef USE_ENDOMORPHISM */
|
||||
/* Define this symbol to enable x86_64 assembly optimizations */
|
||||
#define USE_ASM_X86_64 1
|
||||
|
||||
/* Define this symbol if an external (non-inline) assembly implementation is
|
||||
used */
|
||||
/* #undef USE_EXTERNAL_ASM */
|
||||
|
||||
/* Define this symbol to use the native field inverse implementation */
|
||||
#define USE_FIELD_INV_BUILTIN 1
|
||||
/* Define this symbol if an external implementation of the default callbacks
|
||||
is used */
|
||||
/* #undef USE_EXTERNAL_DEFAULT_CALLBACKS */
|
||||
|
||||
/* Define this symbol to use the num-based field inverse implementation */
|
||||
/* #undef USE_FIELD_INV_NUM */
|
||||
/* Define this symbol to force the use of the (unsigned) __int128 based wide
|
||||
multiplication implementation */
|
||||
/* #undef USE_FORCE_WIDEMUL_INT128 */
|
||||
|
||||
/* Define this symbol to use the gmp implementation for num */
|
||||
/* #undef USE_NUM_GMP */
|
||||
/* Define this symbol to force the use of the structure for simulating
|
||||
(unsigned) int128 based wide multiplication */
|
||||
/* #undef USE_FORCE_WIDEMUL_INT128_STRUCT */
|
||||
|
||||
/* Define this symbol to use no num implementation */
|
||||
#define USE_NUM_NONE 1
|
||||
|
||||
/* Define this symbol to use the native scalar inverse implementation */
|
||||
#define USE_SCALAR_INV_BUILTIN 1
|
||||
|
||||
/* Define this symbol to use the num-based scalar inverse implementation */
|
||||
/* #undef USE_SCALAR_INV_NUM */
|
||||
/* Define this symbol to force the use of the (u)int64_t based wide
|
||||
multiplication implementation */
|
||||
/* #undef USE_FORCE_WIDEMUL_INT64 */
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "0.1"
|
||||
|
||||
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
|
||||
significant byte first (like Motorola and SPARC, unlike Intel). */
|
||||
#if defined AC_APPLE_UNIVERSAL_BUILD
|
||||
# if defined __BIG_ENDIAN__
|
||||
# define WORDS_BIGENDIAN 1
|
||||
# endif
|
||||
#else
|
||||
# ifndef WORDS_BIGENDIAN
|
||||
/* # undef WORDS_BIGENDIAN */
|
||||
# endif
|
||||
#endif
|
||||
#define VERSION "0.1.0-pre"
|
||||
|
||||
#endif /*LIBSECP256K1_CONFIG_H*/
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 1766dc808621f8a6e91282a321ddabce4352e624
|
||||
Subproject commit c697875039954bdde415d92f3ca0af32c517309d
|
|
@ -13,20 +13,20 @@ suite "ABI tests":
|
|||
var bSecretKey: array[32, uint8]
|
||||
var aPublicKey: secp256k1_pubkey
|
||||
var bPublicKey: secp256k1_pubkey
|
||||
var data1: array[32, cuchar]
|
||||
var data2: array[32, cuchar]
|
||||
var data1: array[32, byte]
|
||||
var data2: array[32, byte]
|
||||
aSecretKey[31] = 1'u8
|
||||
bSecretKey[31] = 2'u8
|
||||
let ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN)
|
||||
check ctx != nil
|
||||
check secp256k1_ec_pubkey_create(ctx, addr aPublicKey,
|
||||
cast[ptr cuchar](addr aSecretKey[0])) == 1
|
||||
cast[ptr byte](addr aSecretKey[0])) == 1
|
||||
check secp256k1_ec_pubkey_create(ctx, addr bPublicKey,
|
||||
cast[ptr cuchar](addr bSecretKey[0])) == 1
|
||||
cast[ptr byte](addr bSecretKey[0])) == 1
|
||||
check secp256k1_ecdh(ctx, addr data1[0],
|
||||
addr bPublicKey,
|
||||
cast[ptr cuchar](addr aSecretKey[0])) == 1
|
||||
cast[ptr byte](addr aSecretKey[0])) == 1
|
||||
check secp256k1_ecdh(ctx, addr data2[0],
|
||||
addr aPublicKey,
|
||||
cast[ptr cuchar](addr bSecretKey[0])) == 1
|
||||
cast[ptr byte](addr bSecretKey[0])) == 1
|
||||
check(data1 == data2)
|
||||
|
|
Loading…
Reference in New Issue