Constant-Time Analysis: ppad-secp256k1
- vestigia
- no secret-dependent branch or memory access found, in 9 traced executions (aarch64, x86_64)
- censor
- 18 of 18 tests passed (aarch64-linux, x86_64-linux)
executions
| execution | verdict | aarch64 | x86_64 | ||
|---|---|---|---|---|---|
| vestigia | censor | vestigia | censor | ||
| Crypto.Curve.Secp256k1.mul
Multiplies a fixed public point by the secret scalar
|
✓ no leak found | ✓ | ✓ | ✓ | ✓ |
| Crypto.Curve.Secp256k1.mul_wnaf
Multiplies the generator by the secret scalar, through a precomputed table
|
✓ no leak found | ✓ | ✓ | ✓ | ✓ |
| Crypto.Curve.Secp256k1.derive_pub
Derives the secret key's public key
|
✓ no leak found | ✓ | ✓ | ✓ | ✓ |
| Crypto.Curve.Secp256k1.derive_pub'
Derives the secret key's public key, through a precomputed table
|
✓ no leak found | ✓ | ✓ | ✓ | ✓ |
| Crypto.Curve.Secp256k1.ecdh
Derives the shared secret of the secret key and a fixed public point
|
✓ no leak found | ✓ | ✓ | ✓ | ✓ |
| Crypto.Curve.Secp256k1.sign_schnorr
Signs a fixed message with the secret key (BIP0340)
|
✓ no leak found | ✓ | ✓ | ✓ | ✓ |
| Crypto.Curve.Secp256k1.sign_schnorr'
Signs a fixed message with the secret key (BIP0340), through a precomputed table
|
✓ no leak found | ✓ | ✓ | ✓ | ✓ |
| Crypto.Curve.Secp256k1.sign_ecdsa
Signs a fixed message with the secret key (RFC6979, low s)
|
✓ no leak found | ✓ | ✓ | ✓ | ✓ |
| Crypto.Curve.Secp256k1.sign_ecdsa'
Signs a fixed message with the secret key (RFC6979, low s), through a precomputed table
|
✓ no leak found | ✓ | ✓ | ✓ | ✓ |
✓ no leak found✗ leak? inconclusive· not run
by execution
Crypto.Curve.Secp256k1.mul
✓ no leak of scalar found| contract | vestigia | censor | |
|---|---|---|---|
|
aarch64
aarch64-linux
|
arm-dit
|
✓ 1 invariant | ✓ instructions |
|
x86_64
x86_64-linux
|
intel-doitm
|
✓ 1 invariant | ✓ instructions |
inputs
| scalar | pseudorandom in [1, n), n the secp256k1 group order |
| point | fixed, the generator times a fixed public scalar |
✓ invariant · 2 lines the secret reaches, where no run varied
Secp256k1.$wmuljne 45e82 <+0x392>branchSecp256k1.hs:615
45d89: jne 45e82 <+0x392> branch (taint)
Secp256k1.$wmul z2xkjgrlfk18haq5icbwm6vd8419a03s-source/lib/Crypto/Curve/Secp256k1.hs:615
603 loop !r !d !m 604 | zero# m = r 605 | otherwise = 606 let !nd = double# d 607 !(# nm, lsb_set #) = W.shr1_c# m 608 !nr = if CT.decide lsb_set then add_proj# r d else r 609 in loop nr nd nm 610 {-# INLINE mul_vartime# #-} 611 612 ge# :: Limb4 -> CT.Choice 613 ge# n = 614 let !(Wider q) = _CURVE_Q 615 in CT.and (W.gt# n Z) (W.lt# n q) 616 {-# INLINE ge# #-} 617 618 mul_wnaf# :: ByteArray -> Int -> Limb4 -> (# () | Proj #) 619 mul_wnaf# ctxArray ctxW ls 620 | CT.decide (CT.not (ge# ls)) = (# () | #) 621 | otherwise = 622 let !(P zx zy zz) = _CURVE_ZERO 623 in (# | loop 0 (# zx, zy, zz #) ls #) 624 where 625 !one = (# Limb 1##, Limb 0##, Limb 0##, Limb 0## #) 626 !wins = fi (256 `quot` ctxW + 1) 627 !size@(GHC.Word.W# s) = 1 .<<. (ctxW - 1)
source · Secp256k1.hs:615
611 612 ge# :: Limb4 -> CT.Choice 613 ge# n = 614 let !(Wider q) = _CURVE_Q 615 in CT.and (W.gt# n Z) (W.lt# n q) 616 {-# INLINE ge# #-} 617 618 mul_wnaf# :: ByteArray -> Int -> Limb4 -> (# () | Proj #) 619 mul_wnaf# ctxArray ctxW ls
Secp256k1.$wmulb.ne 5a8b8 <+0x558> // b.anybranch
5a7d0: b.ne 5a8b8 <+0x558> // b.any branch (taint)
test cases
| Secp.mul (non-generator base) | a valid scalar fixed vs random, times one fixed non-generator point |
| host | meter | result | p | effect (mean/pair) | jitter | clip scale | clipped |
|---|---|---|---|---|---|---|---|
| Secp.mul (non-generator base) | |||||||
| aarch64-linux | instructions | ✓ | 0.938 | [-304, 101] instr | 0.0% | 1908 instr | 11/50000 |
| x86_64-linux | instructions | ✓ | 0.402 | [-82, 246] instr | 0.0% | 1540 instr | 9/50000 |
instructions
instructions
Crypto.Curve.Secp256k1.mul_wnaf
✓ no leak of scalar found| contract | vestigia | censor | |
|---|---|---|---|
|
aarch64
aarch64-linux
|
arm-dit
|
✓ 1 invariant | ✓ instructions |
|
x86_64
x86_64-linux
|
intel-doitm
|
✓ 1 invariant | ✓ instructions |
inputs
| scalar | pseudorandom in [1, n), n the secp256k1 group order |
| generator context | precomputed once, fixed |
✓ invariant · 2 lines the secret reaches, where no run varied
Secp256k1.$wmul_wnafjne 275ce <+0xd9e>branchSecp256k1.hs:615
269cb: jne 275ce <+0xd9e> branch (taint)
Secp256k1.$wmul_wnaf z2xkjgrlfk18haq5icbwm6vd8419a03s-source/lib/Crypto/Curve/Secp256k1.hs:615
603 loop !r !d !m 604 | zero# m = r 605 | otherwise = 606 let !nd = double# d 607 !(# nm, lsb_set #) = W.shr1_c# m 608 !nr = if CT.decide lsb_set then add_proj# r d else r 609 in loop nr nd nm 610 {-# INLINE mul_vartime# #-} 611 612 ge# :: Limb4 -> CT.Choice 613 ge# n = 614 let !(Wider q) = _CURVE_Q 615 in CT.and (W.gt# n Z) (W.lt# n q) 616 {-# INLINE ge# #-} 617 618 mul_wnaf# :: ByteArray -> Int -> Limb4 -> (# () | Proj #) 619 mul_wnaf# ctxArray ctxW ls 620 | CT.decide (CT.not (ge# ls)) = (# () | #) 621 | otherwise = 622 let !(P zx zy zz) = _CURVE_ZERO 623 in (# | loop 0 (# zx, zy, zz #) ls #) 624 where 625 !one = (# Limb 1##, Limb 0##, Limb 0##, Limb 0## #) 626 !wins = fi (256 `quot` ctxW + 1) 627 !size@(GHC.Word.W# s) = 1 .<<. (ctxW - 1)
source · Secp256k1.hs:615
611 612 ge# :: Limb4 -> CT.Choice 613 ge# n = 614 let !(Wider q) = _CURVE_Q 615 in CT.and (W.gt# n Z) (W.lt# n q) 616 {-# INLINE ge# #-} 617 618 mul_wnaf# :: ByteArray -> Int -> Limb4 -> (# () | Proj #) 619 mul_wnaf# ctxArray ctxW ls
Secp256k1.$wmul_wnafb.ne 2da8c <+0x1ddc> // b.anybranch
3233c: b.ne 2da8c <+0x1ddc> // b.any branch (taint)
test cases
| Secp.mul_wnaf (precomputed generator) | a valid scalar fixed vs random, times the generator through one precomputed context |
| host | meter | result | p | effect (mean/pair) | jitter | clip scale | clipped |
|---|---|---|---|---|---|---|---|
| Secp.mul_wnaf (precomputed generator) | |||||||
| aarch64-linux | instructions | ✓ | 0.885 | [-282, 94] instr | 0.0% | 1770 instr | 11/50000 |
| x86_64-linux | instructions | ✓ | 0.996 | [-264, 88] instr | 0.0% | 1658 instr | 5/50000 |
instructions
instructions
Crypto.Curve.Secp256k1.derive_pub
✓ no leak of key found| contract | vestigia | censor | |
|---|---|---|---|
|
aarch64
aarch64-linux
|
arm-dit
|
✓ 1 invariant | ✓ instructions |
|
x86_64
x86_64-linux
|
intel-doitm
|
✓ 1 invariant | ✓ instructions |
inputs
| secret key | pseudorandom in [1, n), n the secp256k1 group order |
✓ invariant · 2 lines the secret reaches, where no run varied
Secp256k1.$wmuljne 45e82 <+0x392>branchSecp256k1.hs:615
45d89: jne 45e82 <+0x392> branch (taint)
Secp256k1.$wmul z2xkjgrlfk18haq5icbwm6vd8419a03s-source/lib/Crypto/Curve/Secp256k1.hs:615
603 loop !r !d !m 604 | zero# m = r 605 | otherwise = 606 let !nd = double# d 607 !(# nm, lsb_set #) = W.shr1_c# m 608 !nr = if CT.decide lsb_set then add_proj# r d else r 609 in loop nr nd nm 610 {-# INLINE mul_vartime# #-} 611 612 ge# :: Limb4 -> CT.Choice 613 ge# n = 614 let !(Wider q) = _CURVE_Q 615 in CT.and (W.gt# n Z) (W.lt# n q) 616 {-# INLINE ge# #-} 617 618 mul_wnaf# :: ByteArray -> Int -> Limb4 -> (# () | Proj #) 619 mul_wnaf# ctxArray ctxW ls 620 | CT.decide (CT.not (ge# ls)) = (# () | #) 621 | otherwise = 622 let !(P zx zy zz) = _CURVE_ZERO 623 in (# | loop 0 (# zx, zy, zz #) ls #) 624 where 625 !one = (# Limb 1##, Limb 0##, Limb 0##, Limb 0## #) 626 !wins = fi (256 `quot` ctxW + 1) 627 !size@(GHC.Word.W# s) = 1 .<<. (ctxW - 1)
source · Secp256k1.hs:615
611 612 ge# :: Limb4 -> CT.Choice 613 ge# n = 614 let !(Wider q) = _CURVE_Q 615 in CT.and (W.gt# n Z) (W.lt# n q) 616 {-# INLINE ge# #-} 617 618 mul_wnaf# :: ByteArray -> Int -> Limb4 -> (# () | Proj #) 619 mul_wnaf# ctxArray ctxW ls
Secp256k1.$wmulb.ne 5a8b8 <+0x558> // b.anybranch
5a7d0: b.ne 5a8b8 <+0x558> // b.any branch (taint)
test cases
| Secp.derive_pub (generator multiplication) | the secret key fixed vs random |
| host | meter | result | p | effect (mean/pair) | jitter | clip scale | clipped |
|---|---|---|---|---|---|---|---|
| Secp.derive_pub (generator multiplication) | |||||||
| aarch64-linux | instructions | ✓ | 0.461 | [-304, 101] instr | 0.0% | 1908 instr | 4/50000 |
| x86_64-linux | instructions | ✓ | 0.634 | [-246, 82] instr | 0.0% | 1542 instr | 7/50000 |
instructions
instructions
Crypto.Curve.Secp256k1.derive_pub'
✓ no leak of key found| contract | vestigia | censor | |
|---|---|---|---|
|
aarch64
aarch64-linux
|
arm-dit
|
✓ 1 invariant | ✓ instructions |
|
x86_64
x86_64-linux
|
intel-doitm
|
✓ 1 invariant | ✓ instructions |
inputs
| secret key | pseudorandom in [1, n), n the secp256k1 group order |
| generator context | precomputed once, fixed |
✓ invariant · 2 lines the secret reaches, where no run varied
Secp256k1.$wmul_wnafjne 275ce <+0xd9e>branchSecp256k1.hs:615
269cb: jne 275ce <+0xd9e> branch (taint)
Secp256k1.$wmul_wnaf z2xkjgrlfk18haq5icbwm6vd8419a03s-source/lib/Crypto/Curve/Secp256k1.hs:615
603 loop !r !d !m 604 | zero# m = r 605 | otherwise = 606 let !nd = double# d 607 !(# nm, lsb_set #) = W.shr1_c# m 608 !nr = if CT.decide lsb_set then add_proj# r d else r 609 in loop nr nd nm 610 {-# INLINE mul_vartime# #-} 611 612 ge# :: Limb4 -> CT.Choice 613 ge# n = 614 let !(Wider q) = _CURVE_Q 615 in CT.and (W.gt# n Z) (W.lt# n q) 616 {-# INLINE ge# #-} 617 618 mul_wnaf# :: ByteArray -> Int -> Limb4 -> (# () | Proj #) 619 mul_wnaf# ctxArray ctxW ls 620 | CT.decide (CT.not (ge# ls)) = (# () | #) 621 | otherwise = 622 let !(P zx zy zz) = _CURVE_ZERO 623 in (# | loop 0 (# zx, zy, zz #) ls #) 624 where 625 !one = (# Limb 1##, Limb 0##, Limb 0##, Limb 0## #) 626 !wins = fi (256 `quot` ctxW + 1) 627 !size@(GHC.Word.W# s) = 1 .<<. (ctxW - 1)
source · Secp256k1.hs:615
611 612 ge# :: Limb4 -> CT.Choice 613 ge# n = 614 let !(Wider q) = _CURVE_Q 615 in CT.and (W.gt# n Z) (W.lt# n q) 616 {-# INLINE ge# #-} 617 618 mul_wnaf# :: ByteArray -> Int -> Limb4 -> (# () | Proj #) 619 mul_wnaf# ctxArray ctxW ls
Secp256k1.$wmul_wnafb.ne 2da8c <+0x1ddc> // b.anybranch
3233c: b.ne 2da8c <+0x1ddc> // b.any branch (taint)
test cases
| Secp.derive_pub' (precomputed generator) | as derive_pub, through one precomputed context |
| host | meter | result | p | effect (mean/pair) | jitter | clip scale | clipped |
|---|---|---|---|---|---|---|---|
| Secp.derive_pub' (precomputed generator) | |||||||
| aarch64-linux | instructions | ✓ | 0.887 | [-282, 94] instr | 0.0% | 1770 instr | 10/50000 |
| x86_64-linux | instructions | ✓ | 0.142 | [-17, 50] instr | 0.0% | 316 instr | 5/50000 |
instructions
instructions
Crypto.Curve.Secp256k1.ecdh
✓ no leak of key found| contract | vestigia | censor | |
|---|---|---|---|
|
aarch64
aarch64-linux
|
arm-dit
|
✓ 2 invariant | ✓ instructions |
|
x86_64
x86_64-linux
|
intel-doitm
|
✓ 2 invariant | ✓ instructions |
inputs
| secret key | pseudorandom in [1, n), n the secp256k1 group order |
| peer | fixed, the generator times a fixed public scalar |
✓ invariant · 4 lines the secret reaches, where no run varied
Secp256k1.$wecdhjne 7e943 <+0x440b>branchSecp256k1.hs:990
7e7fd: jne 7e943 <+0x440b> branch (taint)
Secp256k1.$wecdh z2xkjgrlfk18haq5icbwm6vd8419a03s-source/lib/Crypto/Curve/Secp256k1.hs:990
978 -- >>> let secret_as_computed_by_alice = ecdh pub_bob sec_alice 979 -- >>> let secret_as_computed_by_bob = ecdh pub_alice sec_bob 980 -- >>> secret_as_computed_by_alice == secret_as_computed_by_bob 981 -- True 982 ecdh 983 :: Projective -- ^ public key 984 -> Wider -- ^ secret key 985 -> Maybe BS.ByteString -- ^ shared secret 986 ecdh pub _SECRET = do 987 pt@(P _ _ (C.Montgomery -> z)) <- mul pub _SECRET 988 let !(Affine (C.retr -> x) _) = affine pt 989 !result = SHA256.hash (unroll32 x) 990 if CT.decide (C.eq z 0) then Nothing else Just result 991 992 -- schnorr -------------------------------------------------------------------- 993 -- see https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki 994 995 -- | Create a 64-byte Schnorr signature for the provided message, using 996 -- the provided secret key. 997 -- 998 -- BIP0340 recommends that 32 bytes of fresh auxiliary entropy be 999 -- generated and added at signing time as additional protection 1000 -- against side-channel attacks (namely, to thwart so-called "fault 1001 -- injection" attacks). This entropy is /supplemental/ to security, 1002 -- and the cryptographic security of the signature scheme itself does
source · Secp256k1.hs:990
986 ecdh pub _SECRET = do 987 pt@(P _ _ (C.Montgomery -> z)) <- mul pub _SECRET 988 let !(Affine (C.retr -> x) _) = affine pt 989 !result = SHA256.hash (unroll32 x) 990 if CT.decide (C.eq z 0) then Nothing else Just result 991 992 -- schnorr -------------------------------------------------------------------- 993 -- see https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki 994
Secp256k1.$wecdhb.ne a35a4 <+0xc6c> // b.anybranch
a3518: b.ne a35a4 <+0xc6c> // b.any branch (taint)
Secp256k1.$wmuljne 45e82 <+0x392>branchSecp256k1.hs:615
45d89: jne 45e82 <+0x392> branch (taint)
Secp256k1.$wmul z2xkjgrlfk18haq5icbwm6vd8419a03s-source/lib/Crypto/Curve/Secp256k1.hs:615
603 loop !r !d !m 604 | zero# m = r 605 | otherwise = 606 let !nd = double# d 607 !(# nm, lsb_set #) = W.shr1_c# m 608 !nr = if CT.decide lsb_set then add_proj# r d else r 609 in loop nr nd nm 610 {-# INLINE mul_vartime# #-} 611 612 ge# :: Limb4 -> CT.Choice 613 ge# n = 614 let !(Wider q) = _CURVE_Q 615 in CT.and (W.gt# n Z) (W.lt# n q) 616 {-# INLINE ge# #-} 617 618 mul_wnaf# :: ByteArray -> Int -> Limb4 -> (# () | Proj #) 619 mul_wnaf# ctxArray ctxW ls 620 | CT.decide (CT.not (ge# ls)) = (# () | #) 621 | otherwise = 622 let !(P zx zy zz) = _CURVE_ZERO 623 in (# | loop 0 (# zx, zy, zz #) ls #) 624 where 625 !one = (# Limb 1##, Limb 0##, Limb 0##, Limb 0## #) 626 !wins = fi (256 `quot` ctxW + 1) 627 !size@(GHC.Word.W# s) = 1 .<<. (ctxW - 1)
source · Secp256k1.hs:615
611 612 ge# :: Limb4 -> CT.Choice 613 ge# n = 614 let !(Wider q) = _CURVE_Q 615 in CT.and (W.gt# n Z) (W.lt# n q) 616 {-# INLINE ge# #-} 617 618 mul_wnaf# :: ByteArray -> Int -> Limb4 -> (# () | Proj #) 619 mul_wnaf# ctxArray ctxW ls
Secp256k1.$wmulb.ne 5a8b8 <+0x558> // b.anybranch
5a7d0: b.ne 5a8b8 <+0x558> // b.any branch (taint)
test cases
| Secp.ecdh (fixed peer) | the secret key fixed vs random against one fixed peer point, built before the timed region |
| host | meter | result | p | effect (mean/pair) | jitter | clip scale | clipped |
|---|---|---|---|---|---|---|---|
| Secp.ecdh (fixed peer) | |||||||
| aarch64-linux | instructions | ✓ | 0.137 | [-322, 107] instr | 0.0% | 2022 instr | 79/50000 |
| x86_64-linux | instructions | ✓ | 0.154 | [-84, 253] instr | 0.0% | 1588 instr | 78/50000 |
instructions
instructions
Crypto.Curve.Secp256k1.sign_schnorr
✓ no leak of key or derived nonce found| contract | vestigia | censor | |
|---|---|---|---|
|
aarch64
aarch64-linux
|
arm-dit
|
✓ 2 invariant | ✓ instructions |
|
x86_64
x86_64-linux
|
intel-doitm
|
✓ 2 invariant | ✓ instructions |
inputs
| secret key | pseudorandom in [1, n), n the secp256k1 group order |
| message | 32 bytes, fixed |
| auxiliary randomness | 32 bytes, fixed |
✓ invariant · 4 lines the secret reaches, where no run varied
Secp256k1.$wmuljne 45e82 <+0x392>branchSecp256k1.hs:615
45d89: jne 45e82 <+0x392> branch (taint)
Secp256k1.$wmul z2xkjgrlfk18haq5icbwm6vd8419a03s-source/lib/Crypto/Curve/Secp256k1.hs:615
603 loop !r !d !m 604 | zero# m = r 605 | otherwise = 606 let !nd = double# d 607 !(# nm, lsb_set #) = W.shr1_c# m 608 !nr = if CT.decide lsb_set then add_proj# r d else r 609 in loop nr nd nm 610 {-# INLINE mul_vartime# #-} 611 612 ge# :: Limb4 -> CT.Choice 613 ge# n = 614 let !(Wider q) = _CURVE_Q 615 in CT.and (W.gt# n Z) (W.lt# n q) 616 {-# INLINE ge# #-} 617 618 mul_wnaf# :: ByteArray -> Int -> Limb4 -> (# () | Proj #) 619 mul_wnaf# ctxArray ctxW ls 620 | CT.decide (CT.not (ge# ls)) = (# () | #) 621 | otherwise = 622 let !(P zx zy zz) = _CURVE_ZERO 623 in (# | loop 0 (# zx, zy, zz #) ls #) 624 where 625 !one = (# Limb 1##, Limb 0##, Limb 0##, Limb 0## #) 626 !wins = fi (256 `quot` ctxW + 1) 627 !size@(GHC.Word.W# s) = 1 .<<. (ctxW - 1)
source · Secp256k1.hs:615
611 612 ge# :: Limb4 -> CT.Choice 613 ge# n = 614 let !(Wider q) = _CURVE_Q 615 in CT.and (W.gt# n Z) (W.lt# n q) 616 {-# INLINE ge# #-} 617 618 mul_wnaf# :: ByteArray -> Int -> Limb4 -> (# () | Proj #) 619 mul_wnaf# ctxArray ctxW ls
Secp256k1.$wmulb.ne 5a8b8 <+0x558> // b.anybranch
5a7d0: b.ne 5a8b8 <+0x558> // b.any branch (taint)
Secp256k1._sign_schnorrje 846fa <+0x27a>branchSecp256k1.hs:1056
846b4: je 846fa <+0x27a> branch (taint)
Secp256k1._sign_schnorr z2xkjgrlfk18haq5icbwm6vd8419a03s-source/lib/Crypto/Curve/Secp256k1.hs:1056
1044 _sign_schnorr _mul _SECRET m a = do 1045 p <- _mul _SECRET 1046 let Affine (C.retr -> x_p) (C.retr -> y_p) = affine p 1047 s = S.to _SECRET 1048 d = S.select s (negate s) (W.odd y_p) 1049 bytes_d = unroll32 (S.retr d) 1050 bytes_p = unroll32 x_p 1051 t = xor bytes_d (hash_aux a) 1052 rand = hash_nonce (t <> bytes_p <> m) 1053 k' = S.to (unsafe_roll32 rand) 1054 -- negligible probability, but k' is secret, so compare without 1055 -- short-circuiting and decide only on the result 1056 guard (not (CT.decide (S.eq k' 0))) 1057 pt <- _mul (S.retr k') 1058 let Affine (C.retr -> x_r) (C.retr -> y_r) = affine pt 1059 k = S.select k' (negate k') (W.odd y_r) 1060 bytes_r = unroll32 x_r 1061 rand' = hash_challenge (bytes_r <> bytes_p <> m) 1062 e = S.to (unsafe_roll32 rand') 1063 bytes_ked = unroll32 (S.retr (k + e * d)) 1064 sig = bytes_r <> bytes_ked 1065 -- NB for benchmarking we morally want to remove the precautionary 1066 -- verification check here. 1067 -- 1068 -- guard (verify_schnorr m p sig)
source · Secp256k1.hs:1056
1052 rand = hash_nonce (t <> bytes_p <> m) 1053 k' = S.to (unsafe_roll32 rand) 1054 -- negligible probability, but k' is secret, so compare without 1055 -- short-circuiting and decide only on the result 1056 guard (not (CT.decide (S.eq k' 0))) 1057 pt <- _mul (S.retr k') 1058 let Affine (C.retr -> x_r) (C.retr -> y_r) = affine pt 1059 k = S.select k' (negate k') (W.odd y_r) 1060 bytes_r = unroll32 x_r
Secp256k1._sign_schnorrb.eq b0b70 <+0x1890> // b.nonebranch
b18a0: b.eq b0b70 <+0x1890> // b.none branch (taint)
test cases
| Secp.sign_schnorr (BIP0340) | the secret key fixed vs random over a fixed 32-byte message and auxiliary randomness, so the derived nonce is fixed vs random with it |
| host | meter | result | p | effect (mean/pair) | jitter | clip scale | clipped |
|---|---|---|---|---|---|---|---|
| Secp.sign_schnorr (BIP0340) | |||||||
| aarch64-linux | instructions | ✓ | 0.484 | [-111, 334] instr | 0.0% | 2092 instr | 136/50000 |
| x86_64-linux | instructions | ✓ | 0.845 | [-312, 104] instr | 0.0% | 1958 instr | 138/50000 |
instructions
instructions
Crypto.Curve.Secp256k1.sign_schnorr'
✓ no leak of key or derived nonce found| contract | vestigia | censor | |
|---|---|---|---|
|
aarch64
aarch64-linux
|
arm-dit
|
✓ 2 invariant | ✓ instructions |
|
x86_64
x86_64-linux
|
intel-doitm
|
✓ 2 invariant | ✓ instructions |
inputs
| secret key | pseudorandom in [1, n), n the secp256k1 group order |
| message | 32 bytes, fixed |
| auxiliary randomness | 32 bytes, fixed |
| generator context | precomputed once, fixed |
✓ invariant · 4 lines the secret reaches, where no run varied
Secp256k1.$wmul_wnafjne 275ce <+0xd9e>branchSecp256k1.hs:615
269cb: jne 275ce <+0xd9e> branch (taint)
Secp256k1.$wmul_wnaf z2xkjgrlfk18haq5icbwm6vd8419a03s-source/lib/Crypto/Curve/Secp256k1.hs:615
603 loop !r !d !m 604 | zero# m = r 605 | otherwise = 606 let !nd = double# d 607 !(# nm, lsb_set #) = W.shr1_c# m 608 !nr = if CT.decide lsb_set then add_proj# r d else r 609 in loop nr nd nm 610 {-# INLINE mul_vartime# #-} 611 612 ge# :: Limb4 -> CT.Choice 613 ge# n = 614 let !(Wider q) = _CURVE_Q 615 in CT.and (W.gt# n Z) (W.lt# n q) 616 {-# INLINE ge# #-} 617 618 mul_wnaf# :: ByteArray -> Int -> Limb4 -> (# () | Proj #) 619 mul_wnaf# ctxArray ctxW ls 620 | CT.decide (CT.not (ge# ls)) = (# () | #) 621 | otherwise = 622 let !(P zx zy zz) = _CURVE_ZERO 623 in (# | loop 0 (# zx, zy, zz #) ls #) 624 where 625 !one = (# Limb 1##, Limb 0##, Limb 0##, Limb 0## #) 626 !wins = fi (256 `quot` ctxW + 1) 627 !size@(GHC.Word.W# s) = 1 .<<. (ctxW - 1)
source · Secp256k1.hs:615
611 612 ge# :: Limb4 -> CT.Choice 613 ge# n = 614 let !(Wider q) = _CURVE_Q 615 in CT.and (W.gt# n Z) (W.lt# n q) 616 {-# INLINE ge# #-} 617 618 mul_wnaf# :: ByteArray -> Int -> Limb4 -> (# () | Proj #) 619 mul_wnaf# ctxArray ctxW ls
Secp256k1.$wmul_wnafb.ne 2da8c <+0x1ddc> // b.anybranch
3233c: b.ne 2da8c <+0x1ddc> // b.any branch (taint)
Secp256k1.$wsign_schnorr'je 88c28 <+0x260>branchSecp256k1.hs:1056
88c10: je 88c28 <+0x260> branch (taint)
Secp256k1.$wsign_schnorr' z2xkjgrlfk18haq5icbwm6vd8419a03s-source/lib/Crypto/Curve/Secp256k1.hs:1056
1044 _sign_schnorr _mul _SECRET m a = do 1045 p <- _mul _SECRET 1046 let Affine (C.retr -> x_p) (C.retr -> y_p) = affine p 1047 s = S.to _SECRET 1048 d = S.select s (negate s) (W.odd y_p) 1049 bytes_d = unroll32 (S.retr d) 1050 bytes_p = unroll32 x_p 1051 t = xor bytes_d (hash_aux a) 1052 rand = hash_nonce (t <> bytes_p <> m) 1053 k' = S.to (unsafe_roll32 rand) 1054 -- negligible probability, but k' is secret, so compare without 1055 -- short-circuiting and decide only on the result 1056 guard (not (CT.decide (S.eq k' 0))) 1057 pt <- _mul (S.retr k') 1058 let Affine (C.retr -> x_r) (C.retr -> y_r) = affine pt 1059 k = S.select k' (negate k') (W.odd y_r) 1060 bytes_r = unroll32 x_r 1061 rand' = hash_challenge (bytes_r <> bytes_p <> m) 1062 e = S.to (unsafe_roll32 rand') 1063 bytes_ked = unroll32 (S.retr (k + e * d)) 1064 sig = bytes_r <> bytes_ked 1065 -- NB for benchmarking we morally want to remove the precautionary 1066 -- verification check here. 1067 -- 1068 -- guard (verify_schnorr m p sig)
source · Secp256k1.hs:1056
1052 rand = hash_nonce (t <> bytes_p <> m) 1053 k' = S.to (unsafe_roll32 rand) 1054 -- negligible probability, but k' is secret, so compare without 1055 -- short-circuiting and decide only on the result 1056 guard (not (CT.decide (S.eq k' 0))) 1057 pt <- _mul (S.retr k') 1058 let Affine (C.retr -> x_r) (C.retr -> y_r) = affine pt 1059 k = S.select k' (negate k') (W.odd y_r) 1060 bytes_r = unroll32 x_r
Secp256k1.$wsign_schnorr'b.ne b9228 <+0x25b0> // b.anybranch
b8518: b.ne b9228 <+0x25b0> // b.any branch (taint)
test cases
| Secp.sign_schnorr' (BIP0340) | as sign_schnorr, through one precomputed context |
| host | meter | result | p | effect (mean/pair) | jitter | clip scale | clipped |
|---|---|---|---|---|---|---|---|
| Secp.sign_schnorr' (BIP0340) | |||||||
| aarch64-linux | instructions | ✓ | 0.621 | [-366, 122] instr | 0.0% | 2294 instr | 135/50000 |
| x86_64-linux | instructions | ✓ | 0.060 | [-330, 110] instr | 0.0% | 2072 instr | 135/50000 |
instructions
instructions
Crypto.Curve.Secp256k1.sign_ecdsa
✓ no leak of key or deterministic nonce found| contract | vestigia | censor | |
|---|---|---|---|
|
aarch64
aarch64-linux
|
arm-dit
|
✓ 5 invariant | ✓ instructions |
|
x86_64
x86_64-linux
|
intel-doitm
|
✓ 5 invariant | ✓ instructions |
inputs
| secret key | pseudorandom in [1, n), n the secp256k1 group order |
| message | 32 bytes, fixed |
✓ invariant · 10 lines the secret reaches, where no run varied
Secp256k1.$ssign_loopjne 22f7d <+0x4d4d>branchSecp256k1.hs:1320
22e97: jne 22f7d <+0x4d4d> branch (taint)
? z2xkjgrlfk18haq5icbwm6vd8419a03s-source/lib/Crypto/Curve/Secp256k1.hs:1320
1308 d = S.to _SECRET 1309 hm = S.to (bits2int h) 1310 h = case hf of 1311 Hash -> SHA256.hash m 1312 NoHash -> m 1313 1314 sign_loop g = do 1315 k <- gen_k g 1316 let mpair = do 1317 kg <- _mul k 1318 let Affine (S.to . C.retr -> r) _ = affine kg 1319 ki = S.inv (S.to k) 1320 s = (hm + d * r) * ki 1321 pure $! (S.retr r, S.retr s) 1322 case mpair of 1323 Nothing -> do 1324 DRBG.wipe g 1325 pure Nothing 1326 Just (r, s) 1327 -- sec1-v2 4.1.3 retries on either being zero 1328 | W.eq_vartime r 0 || W.eq_vartime s 0 -> sign_loop g 1329 | otherwise -> do 1330 DRBG.wipe g 1331 let !sig = Just $! ECDSA r s 1332 pure $ case ty of
source · Secp256k1.hs:1320
1316 let mpair = do 1317 kg <- _mul k 1318 let Affine (S.to . C.retr -> r) _ = affine kg 1319 ki = S.inv (S.to k) 1320 s = (hm + d * r) * ki 1321 pure $! (S.retr r, S.retr s) 1322 case mpair of 1323 Nothing -> do 1324 DRBG.wipe g
Secp256k1.$ssign_loopjne 23689 <+0x5459>branchSecp256k1.hs:388
23572: jne 23689 <+0x5459> branch (taint)
? z2xkjgrlfk18haq5icbwm6vd8419a03s-source/lib/Crypto/Curve/Secp256k1.hs:388
376 !x2z1 = bx * az 377 !y1z2 = ay * bz 378 !y2z1 = by * az 379 in CT.decide (CT.and (C.eq x1z2 x2z1) (C.eq y1z2 y2z1)) 380 381 -- | A public key, i.e. secp256k1 point. 382 type Pub = Projective 383 384 -- Convert to affine coordinates. 385 affine :: Projective -> Affine 386 affine (Projective x y z) = 387 let !iz = C.inv z 388 in Affine (x * iz) (y * iz) 389 {-# INLINABLE affine #-} 390 391 -- Convert to projective coordinates. 392 projective :: Affine -> Projective 393 projective (Affine x y) 394 | C.eq_vartime x 0 || C.eq_vartime y 0 = _CURVE_ZERO 395 | otherwise = Projective x y 1 396 397 -- | secp256k1 generator point. 398 _CURVE_G :: Projective 399 _CURVE_G = Projective x y z where 400 !x = C.Montgomery
source · Secp256k1.hs:388
384 -- Convert to affine coordinates. 385 affine :: Projective -> Affine 386 affine (Projective x y z) = 387 let !iz = C.inv z 388 in Affine (x * iz) (y * iz) 389 {-# INLINABLE affine #-} 390 391 -- Convert to projective coordinates. 392 projective :: Affine -> Projective
Secp256k1.$ssign_loopjne 239c9 <+0x5799>branchSecp256k1.hs:356
23988: jne 239c9 <+0x5799> branch (taint)
? z2xkjgrlfk18haq5icbwm6vd8419a03s-source/lib/Crypto/Curve/Secp256k1.hs:356
344 345 -- Is field element? 346 fe :: Wider -> Bool 347 fe n = case W.cmp_vartime n 0 of 348 GT -> case W.cmp_vartime n _CURVE_P of 349 LT -> True 350 _ -> False 351 _ -> False 352 {-# INLINE fe #-} 353 354 -- Is group element? 355 ge :: Wider -> Bool 356 ge (Wider n) = CT.decide (ge# n) 357 {-# INLINE ge #-} 358 359 -- curve points --------------------------------------------------------------- 360 361 -- curve point, affine coordinates 362 data Affine = Affine !C.Montgomery !C.Montgomery 363 deriving stock (Show, Generic) 364 365 -- curve point, projective coordinates 366 data Projective = Projective { 367 px :: !C.Montgomery 368 , py :: !C.Montgomery
source · Secp256k1.hs:356
352 {-# INLINE fe #-} 353 354 -- Is group element? 355 ge :: Wider -> Bool 356 ge (Wider n) = CT.decide (ge# n) 357 {-# INLINE ge #-} 358 359 -- curve points --------------------------------------------------------------- 360
Secp256k1.$wmuljne 45e82 <+0x392>branchSecp256k1.hs:615
45d89: jne 45e82 <+0x392> branch (taint)
Secp256k1.$wmul z2xkjgrlfk18haq5icbwm6vd8419a03s-source/lib/Crypto/Curve/Secp256k1.hs:615
603 loop !r !d !m 604 | zero# m = r 605 | otherwise = 606 let !nd = double# d 607 !(# nm, lsb_set #) = W.shr1_c# m 608 !nr = if CT.decide lsb_set then add_proj# r d else r 609 in loop nr nd nm 610 {-# INLINE mul_vartime# #-} 611 612 ge# :: Limb4 -> CT.Choice 613 ge# n = 614 let !(Wider q) = _CURVE_Q 615 in CT.and (W.gt# n Z) (W.lt# n q) 616 {-# INLINE ge# #-} 617 618 mul_wnaf# :: ByteArray -> Int -> Limb4 -> (# () | Proj #) 619 mul_wnaf# ctxArray ctxW ls 620 | CT.decide (CT.not (ge# ls)) = (# () | #) 621 | otherwise = 622 let !(P zx zy zz) = _CURVE_ZERO 623 in (# | loop 0 (# zx, zy, zz #) ls #) 624 where 625 !one = (# Limb 1##, Limb 0##, Limb 0##, Limb 0## #) 626 !wins = fi (256 `quot` ctxW + 1) 627 !size@(GHC.Word.W# s) = 1 .<<. (ctxW - 1)
source · Secp256k1.hs:615
611 612 ge# :: Limb4 -> CT.Choice 613 ge# n = 614 let !(Wider q) = _CURVE_Q 615 in CT.and (W.gt# n Z) (W.lt# n q) 616 {-# INLINE ge# #-} 617 618 mul_wnaf# :: ByteArray -> Int -> Limb4 -> (# () | Proj #) 619 mul_wnaf# ctxArray ctxW ls
Secp256k1.$wmulb.ne 5a8b8 <+0x558> // b.anybranch
5a7d0: b.ne 5a8b8 <+0x558> // b.any branch (taint)
Secp256k1._sign_ecdsajne 23e0e <+0x1de>branchSecp256k1.hs:615
23dfa: jne 23e0e <+0x1de> branch (taint)
Secp256k1._sign_ecdsa z2xkjgrlfk18haq5icbwm6vd8419a03s-source/lib/Crypto/Curve/Secp256k1.hs:615
603 loop !r !d !m 604 | zero# m = r 605 | otherwise = 606 let !nd = double# d 607 !(# nm, lsb_set #) = W.shr1_c# m 608 !nr = if CT.decide lsb_set then add_proj# r d else r 609 in loop nr nd nm 610 {-# INLINE mul_vartime# #-} 611 612 ge# :: Limb4 -> CT.Choice 613 ge# n = 614 let !(Wider q) = _CURVE_Q 615 in CT.and (W.gt# n Z) (W.lt# n q) 616 {-# INLINE ge# #-} 617 618 mul_wnaf# :: ByteArray -> Int -> Limb4 -> (# () | Proj #) 619 mul_wnaf# ctxArray ctxW ls 620 | CT.decide (CT.not (ge# ls)) = (# () | #) 621 | otherwise = 622 let !(P zx zy zz) = _CURVE_ZERO 623 in (# | loop 0 (# zx, zy, zz #) ls #) 624 where 625 !one = (# Limb 1##, Limb 0##, Limb 0##, Limb 0## #) 626 !wins = fi (256 `quot` ctxW + 1) 627 !size@(GHC.Word.W# s) = 1 .<<. (ctxW - 1)
source · Secp256k1.hs:615
611 612 ge# :: Limb4 -> CT.Choice 613 ge# n = 614 let !(Wider q) = _CURVE_Q 615 in CT.and (W.gt# n Z) (W.lt# n q) 616 {-# INLINE ge# #-} 617 618 mul_wnaf# :: ByteArray -> Int -> Limb4 -> (# () | Proj #) 619 mul_wnaf# ctxArray ctxW ls
Secp256k1._sign_ecdsacbnz x9, 278fc <+0x69c>branch
27618: cbnz x9, 278fc <+0x69c> branch (taint)
Secp256k1.even_y_vartimecbnz x13, 20634 <+0x1514>branch
20270: cbnz x13, 20634 <+0x1514> branch (taint)
Secp256k1.even_y_vartimeb.ne 20348 <+0x1228> // b.anybranch
2130c: b.ne 20348 <+0x1228> // b.any branch (taint)
Secp256k1.even_y_vartimeb.ne 26590 <+0x7470> // b.anybranch
21fa4: b.ne 26590 <+0x7470> // b.any branch (taint)
test cases
| Secp.sign_ecdsa (RFC6979) | the secret key fixed vs random over a fixed 32-byte message, so the RFC6979 nonce is fixed vs random with it |
| host | meter | result | p | effect (mean/pair) | jitter | clip scale | clipped |
|---|---|---|---|---|---|---|---|
| Secp.sign_ecdsa (RFC6979) | |||||||
| aarch64-linux | instructions | ✓ | 0.138 | [-115, 345] instr | 0.0% | 2164 instr | 97/50000 |
| x86_64-linux | instructions | ✓ | 0.440 | [-95, 286] instr | 0.0% | 1796 instr | 111/50000 |
instructions
instructions
Crypto.Curve.Secp256k1.sign_ecdsa'
✓ no leak of key or deterministic nonce found| contract | vestigia | censor | |
|---|---|---|---|
|
aarch64
aarch64-linux
|
arm-dit
|
✓ 5 invariant | ✓ instructions |
|
x86_64
x86_64-linux
|
intel-doitm
|
✓ 5 invariant | ✓ instructions |
inputs
| secret key | pseudorandom in [1, n), n the secp256k1 group order |
| message | 32 bytes, fixed |
| generator context | precomputed once, fixed |
✓ invariant · 10 lines the secret reaches, where no run varied
Secp256k1.$ssign_loopjne 2b2c1 <+0x3f9>branchSecp256k1.hs:356
2b280: jne 2b2c1 <+0x3f9> branch (taint)
? z2xkjgrlfk18haq5icbwm6vd8419a03s-source/lib/Crypto/Curve/Secp256k1.hs:356
344 345 -- Is field element? 346 fe :: Wider -> Bool 347 fe n = case W.cmp_vartime n 0 of 348 GT -> case W.cmp_vartime n _CURVE_P of 349 LT -> True 350 _ -> False 351 _ -> False 352 {-# INLINE fe #-} 353 354 -- Is group element? 355 ge :: Wider -> Bool 356 ge (Wider n) = CT.decide (ge# n) 357 {-# INLINE ge #-} 358 359 -- curve points --------------------------------------------------------------- 360 361 -- curve point, affine coordinates 362 data Affine = Affine !C.Montgomery !C.Montgomery 363 deriving stock (Show, Generic) 364 365 -- curve point, projective coordinates 366 data Projective = Projective { 367 px :: !C.Montgomery 368 , py :: !C.Montgomery
source · Secp256k1.hs:356
352 {-# INLINE fe #-} 353 354 -- Is group element? 355 ge :: Wider -> Bool 356 ge (Wider n) = CT.decide (ge# n) 357 {-# INLINE ge #-} 358 359 -- curve points --------------------------------------------------------------- 360
Secp256k1.$ssign_loopjne 3023b <+0x5373>branchSecp256k1.hs:1320
30161: jne 3023b <+0x5373> branch (taint)
? z2xkjgrlfk18haq5icbwm6vd8419a03s-source/lib/Crypto/Curve/Secp256k1.hs:1320
1308 d = S.to _SECRET 1309 hm = S.to (bits2int h) 1310 h = case hf of 1311 Hash -> SHA256.hash m 1312 NoHash -> m 1313 1314 sign_loop g = do 1315 k <- gen_k g 1316 let mpair = do 1317 kg <- _mul k 1318 let Affine (S.to . C.retr -> r) _ = affine kg 1319 ki = S.inv (S.to k) 1320 s = (hm + d * r) * ki 1321 pure $! (S.retr r, S.retr s) 1322 case mpair of 1323 Nothing -> do 1324 DRBG.wipe g 1325 pure Nothing 1326 Just (r, s) 1327 -- sec1-v2 4.1.3 retries on either being zero 1328 | W.eq_vartime r 0 || W.eq_vartime s 0 -> sign_loop g 1329 | otherwise -> do 1330 DRBG.wipe g 1331 let !sig = Just $! ECDSA r s 1332 pure $ case ty of
source · Secp256k1.hs:1320
1316 let mpair = do 1317 kg <- _mul k 1318 let Affine (S.to . C.retr -> r) _ = affine kg 1319 ki = S.inv (S.to k) 1320 s = (hm + d * r) * ki 1321 pure $! (S.retr r, S.retr s) 1322 case mpair of 1323 Nothing -> do 1324 DRBG.wipe g
Secp256k1.$ssign_loopjne 2afae <+0xe6>branchSecp256k1.hs:388
30837: jne 2afae <+0xe6> branch (taint)
? z2xkjgrlfk18haq5icbwm6vd8419a03s-source/lib/Crypto/Curve/Secp256k1.hs:388
376 !x2z1 = bx * az 377 !y1z2 = ay * bz 378 !y2z1 = by * az 379 in CT.decide (CT.and (C.eq x1z2 x2z1) (C.eq y1z2 y2z1)) 380 381 -- | A public key, i.e. secp256k1 point. 382 type Pub = Projective 383 384 -- Convert to affine coordinates. 385 affine :: Projective -> Affine 386 affine (Projective x y z) = 387 let !iz = C.inv z 388 in Affine (x * iz) (y * iz) 389 {-# INLINABLE affine #-} 390 391 -- Convert to projective coordinates. 392 projective :: Affine -> Projective 393 projective (Affine x y) 394 | C.eq_vartime x 0 || C.eq_vartime y 0 = _CURVE_ZERO 395 | otherwise = Projective x y 1 396 397 -- | secp256k1 generator point. 398 _CURVE_G :: Projective 399 _CURVE_G = Projective x y z where 400 !x = C.Montgomery
source · Secp256k1.hs:388
384 -- Convert to affine coordinates. 385 affine :: Projective -> Affine 386 affine (Projective x y z) = 387 let !iz = C.inv z 388 in Affine (x * iz) (y * iz) 389 {-# INLINABLE affine #-} 390 391 -- Convert to projective coordinates. 392 projective :: Affine -> Projective
Secp256k1.$wmul_wnafjne 275ce <+0xd9e>branchSecp256k1.hs:615
269cb: jne 275ce <+0xd9e> branch (taint)
Secp256k1.$wmul_wnaf z2xkjgrlfk18haq5icbwm6vd8419a03s-source/lib/Crypto/Curve/Secp256k1.hs:615
603 loop !r !d !m 604 | zero# m = r 605 | otherwise = 606 let !nd = double# d 607 !(# nm, lsb_set #) = W.shr1_c# m 608 !nr = if CT.decide lsb_set then add_proj# r d else r 609 in loop nr nd nm 610 {-# INLINE mul_vartime# #-} 611 612 ge# :: Limb4 -> CT.Choice 613 ge# n = 614 let !(Wider q) = _CURVE_Q 615 in CT.and (W.gt# n Z) (W.lt# n q) 616 {-# INLINE ge# #-} 617 618 mul_wnaf# :: ByteArray -> Int -> Limb4 -> (# () | Proj #) 619 mul_wnaf# ctxArray ctxW ls 620 | CT.decide (CT.not (ge# ls)) = (# () | #) 621 | otherwise = 622 let !(P zx zy zz) = _CURVE_ZERO 623 in (# | loop 0 (# zx, zy, zz #) ls #) 624 where 625 !one = (# Limb 1##, Limb 0##, Limb 0##, Limb 0## #) 626 !wins = fi (256 `quot` ctxW + 1) 627 !size@(GHC.Word.W# s) = 1 .<<. (ctxW - 1)
source · Secp256k1.hs:615
611 612 ge# :: Limb4 -> CT.Choice 613 ge# n = 614 let !(Wider q) = _CURVE_Q 615 in CT.and (W.gt# n Z) (W.lt# n q) 616 {-# INLINE ge# #-} 617 618 mul_wnaf# :: ByteArray -> Int -> Limb4 -> (# () | Proj #) 619 mul_wnaf# ctxArray ctxW ls
Secp256k1.$wmul_wnafb.ne 2da8c <+0x1ddc> // b.anybranch
3233c: b.ne 2da8c <+0x1ddc> // b.any branch (taint)
Secp256k1.$wsign_ecdsa'jne 30a3e <+0x18e>branchSecp256k1.hs:1234
30a2a: jne 30a3e <+0x18e> branch (taint)
Secp256k1.$wsign_ecdsa' z2xkjgrlfk18haq5icbwm6vd8419a03s-source/lib/Crypto/Curve/Secp256k1.hs:1234
1222 -- 1223 -- You can expect about a 10x performance increase when using this 1224 -- function, compared to 'sign_ecdsa'. 1225 -- 1226 -- >>> let !tex = precompute 1227 -- >>> sign_ecdsa' tex sec msg 1228 -- Just "<ecdsa signature>" 1229 sign_ecdsa' 1230 :: Context -- ^ secp256k1 context 1231 -> Wider -- ^ secret key 1232 -> BS.ByteString -- ^ message 1233 -> Maybe ECDSA 1234 sign_ecdsa' tex = _sign_ecdsa (mul_wnaf tex) LowS Hash 1235 1236 -- | Produce an ECDSA signature for the provided message, using the 1237 -- provided private key. 1238 -- 1239 -- 'sign_ecdsa_unrestricted' produces an unrestricted ECDSA signature, 1240 -- which is less common in applications using secp256k1 due to the 1241 -- signature's inherent malleability. If you need a conventional 1242 -- "low-s" signature, use 'sign_ecdsa'. 1243 -- 1244 -- >>> sign_ecdsa_unrestricted sec msg 1245 -- Just "<ecdsa signature>" 1246 sign_ecdsa_unrestricted
source · Secp256k1.hs:1234
1230 :: Context -- ^ secp256k1 context 1231 -> Wider -- ^ secret key 1232 -> BS.ByteString -- ^ message 1233 -> Maybe ECDSA 1234 sign_ecdsa' tex = _sign_ecdsa (mul_wnaf tex) LowS Hash 1235 1236 -- | Produce an ECDSA signature for the provided message, using the 1237 -- provided private key. 1238 --
Secp256k1.$wsign_ecdsa'cbnz x13, 3a18c <+0x78b4>branch
332c0: cbnz x13, 3a18c <+0x78b4> branch (taint)
Secp256k1.$wsign_ecdsa'b.ne 33390 <+0xab8> // b.anybranch
34268: b.ne 33390 <+0xab8> // b.any branch (taint)
Secp256k1.$wsign_ecdsa'b.ne 394ec <+0x6c14> // b.anybranch
34f00: b.ne 394ec <+0x6c14> // b.any branch (taint)
Secp256k1.$wsign_ecdsa'cbnz x9, 3a900 <+0x680>branch
3a624: cbnz x9, 3a900 <+0x680> branch (taint)
test cases
| Secp.sign_ecdsa' (RFC6979) | as sign_ecdsa, through one precomputed context |
| host | meter | result | p | effect (mean/pair) | jitter | clip scale | clipped |
|---|---|---|---|---|---|---|---|
| Secp.sign_ecdsa' (RFC6979) | |||||||
| aarch64-linux | instructions | ✓ | 0.761 | [-108, 323] instr | 0.0% | 2026 instr | 107/50000 |
| x86_64-linux | instructions | ✓ | 0.026 | [-247, 82] instr | 0.0% | 1552 instr | 99/50000 |
instructions
instructions
appendix
method
This analysis assumes an adversary who can call the analysed functions any number of times, on public inputs of its choosing, and observe their execution at the architectural level, i.e.
- which instructions run, and so which branches are taken and how many instructions retire;
- which memory addresses are accessed, e.g. through a shared cache; and
- how long each instruction takes.
Under the ISA's data-independent-timing (DIT) contract, an instruction it covers takes a time independent of its data, so a clock adds no additional information there. For one it does not cover, the analysis takes the instruction's operands as a conservative stand-in for its time: where they vary with the secret, the property may fail, but the analysis cannot show that it does.
For any analysed function, the security property of concern is thus that its execution, as observed by the adversary, is constant with respect to its declared secrets. Or, put somewhat more formally: for a function f, with secret values s0, s1, and public input p, the adversary's observation O of its execution is identically distributed under (s0, p) and (s1, p), up to renaming of base pointers and stack addresses:
O(f, s0, p) ~ O(f, s1, p)
Microarchitectural concerns (including whether the mode the contract requires is set), physical concerns (e.g. power and electromagnetic emanation), and speculative execution concerns are considered out of scope.
The above security property is assumed, and then scrutinized in two ways:
vestigia v0.2.2 performs both taint and differential execution trace analyses. The former maps every branch and address computed from declared secrets on the path one secret takes through the function, and the latter compares traces, executed under emulation, that vary only in declared secrets, against a second run of one secret as a control. Any difference the control doesn't share directly negates the property.
censor v0.6.0 runs the function natively on many paired inputs, one class with the declared secrets fixed and the other drawing them fresh, and tests whether the number of instructions retired differs between the classes. A rejection whose controls pass is evidence that the security property doesn't hold.
The analysis is limited primarily by reachability, i.e. whether the variation in inputs yields satisfactory exploration of the trace space, or whether taint propagates faithfully. The analysis can thus falsify the assumed security property by finding a witness, but it cannot prove it.
Of note, an instruction outside the ISA's contract that runs on operands that vary with the secret is not a witness, as whether its time follows its operands is a microarchitectural concern, deemed out of scope. A division is taken to leak its operands, its latency being documented to depend on them.
A line is the set of instructions that one source line of one function compiled to, and is the unit by which the report reads a trace. A line varied if, between runs that differ only in the declared secrets, one of its branches had outcomes that differed in proportion or order, or one of its memory accesses had different addresses. An instruction outside the ISA's contract whose operands varied with the secret is read by what is known of its timing: a division, whose time is documented to depend on its operands, is a leak; any other leaves its line outside any DIT contract. Each line shown falls into one of three classes:
- leak: the line varied, or a division there ran on operands that varied, and it is a witness against the security property.
- outside any DIT contract: some other instruction outside the ISA's contract ran there on operands that varied with the secret. It is not a witness, but it is not cleared either; the contract says nothing about the instruction's time, so a finding of no leak holds everywhere but there.
- invariant: the taint analysis finds that the secret reaches the line, but no run varied there. It is not a witness, though a variation the compared secrets did not trigger could still hide there.
The header gives the number of distinct secret values the differential runs compared, for each execution on each system, beside a repeated run of one of them as the control: pseudorandom valid secrets, sampled deterministically from a fixed seed. What an execution's traces ran on, its secrets' domain and any input held fixed, is listed under its vestigia lane. Rare cases may thus remain undetected. Each execution's evidence table gives, per ISA, the contract its runs were recorded under.
A line opens onto its assembly, with each instruction the secret reached marked by what observed it: the analysis, what it saw (a branch, a memory address, a system call, or an operand), and how often. Under the differential runs that is how many times the instruction ran; under taint, how many times it ran on data computed from the secret. Each marked instruction opens onto its stack, and each frame onto the source around it. The assembly is the build's own disassembly, located by the digest of the object each run executed, and the source comes from the same build's line tables, so the instruction shown is the one that ran.
Each test case is one hypothesis about an execution: which declared secrets one class of inputs fixes and the other draws fresh, with any public inputs drawn alike in both. The cases are listed under each execution's censor lane. A case times the two classes on paired inputs, in random order, one pair at a time; batch is how many calls each reading spans. Under the instructions meter a reading is the number of instructions the function retired, which its code and inputs alone determine, so no host's noise enters it, and jitter, a call's interquartile range over its median, is near zero.
The test is sequential and anytime-valid. Evidence against the hypothesis of no difference accumulates pair by pair, as the log e-value plotted over pairs, and the case rejects if it crosses log(1/α). The p shown is anytime-valid too, so when the run stopped does not inflate it. Each pair's difference is clipped at a scale c (the clip scale) set during warmup, so a rare extreme reading can neither force nor mask a rejection; clipped counts the pairs that reached it. The effect is the anytime-valid confidence interval for the clipped mean difference per pair, plotted as a band narrowing over pairs; one that straddles zero is consistent with no difference.
A rejection counts only where censor's controls, rerun on it, pass: A/A and B/B runs, each class against itself, which can implicate the harness, though not exonerate it. Its driver names what the evidence rested on: a shift in the mean, an asymmetry, rare outliers, a difference in spread, or several at once. A pass means no evidence was found within the budget of pairs, on that host and meter, and is qualified (†) where censor found the evidence weak: high clipping, where many pairs reached the clip scale, or low power, where the effect interval stayed wide against it. The provenance's run totals give each run's family-wise α: a bound on the chance of any false rejection among its cases.
measure v0.6.10 checks the evidence before rendering it: every function's bindings to its cases must resolve, the censor runs must share one configuration, with one run per ISA and meter, the verdict must be the one the policy gate and its signed components imply, and each component must agree with the cells where both read the same evidence. Nothing quantitative is recomputed.
provenance
- target
- ppad-secp256k1 0.5.9 (b3494fafaebc51b991638721a2a5870138e1dc79)
- source
- https://git.ppad.tech/secp256k1
- seed
- 0x5eed5eed5eed5eed
- censor config
- alpha=1.0e-6, budget=50000, warmup=500, batch=per-case
- aarch64-linux · instructions
- Cortex-A72 (4 cores) · linux 6.18.34 · 2026-11-03T13:13:58Z
- x86_64-linux · instructions
- AMD EPYC 7713 64-Core Processor (6 cores) · linux 6.18.57 · 2026-11-03T13:29:17Z
- aarch64-linux · instructions
- 9 cases · 450000 pairs · 0 reject · α=1.0e-6 · family α=9.0e-6
- x86_64-linux · instructions
- 9 cases · 450000 pairs · 0 reject · α=1.0e-6 · family α=9.0e-6
journal
plan d9f39eba8423 · 2026-11-03 09:32–09:32 UTC · re-baselined by 21242e16734c
| 2026-11-03 UTC | ||
| 09:32:24 | plan | 2 cells · 2 runs · plan d9f39eba8423 |
plan 21242e16734c · 2026-11-03 12:11–13:35 UTC
| 2026-11-03 UTC | ||
| 12:11:41 | plan | 2 cells · 2 runs · plan 21242e16734c · re-baselined from d9f39eba8423 |
| 12:11:41 | build | ppad-secp256k1/aarch64-linux/ghc-9.10.3/ncg/O2 — 2m23s · store x8alrfsb |
| 12:14:04 | build | ppad-secp256k1/x86_64-linux/ghc-9.10.3/ncg/O2 — 1m30s · store rmf9lvhp |
| 12:15:34 | build | censor/secp256k1-secret-scalar-instructions/aarch64-linux/instructions — 24s · store kc0km5s1 |
| 12:15:58 | build | censor/secp256k1-secret-scalar-instructions/x86_64-linux/instructions — 2m12s · store 8px1r5ls |
| 12:18:11 | vestigia | derive_pub/aarch64-linux/diff/a72 — 2m · store vkm4msr9 |
| 12:20:11 | vestigia | derive_pub/aarch64-linux/taint — 1m58s · store k10dbzxn |
| 12:22:09 | vestigia | derive_pub/x86_64-linux/diff/zen3 — 1m41s · store fw93vgcy |
| 12:23:50 | vestigia | derive_pub/x86_64-linux/taint — 1m3s · store n05jwpif |
| 12:24:53 | vestigia | derive_pub_ctx/aarch64-linux/diff/a72 — 1m35s · store j4lyzqma |
| 12:26:28 | vestigia | derive_pub_ctx/aarch64-linux/taint — 1m57s · store ihxmy2mg |
| 12:28:25 | vestigia | derive_pub_ctx/x86_64-linux/diff/zen3 — 45s · store 0x032rxb |
| 12:29:10 | vestigia | derive_pub_ctx/x86_64-linux/taint — 51s · store h07r536v |
| 12:30:01 | vestigia | ecdh/aarch64-linux/diff/a72 — 1m56s · store hm0hhck8 |
| 12:31:57 | vestigia | ecdh/aarch64-linux/taint — 1m58s · store zji18jha |
| 12:33:55 | vestigia | ecdh/x86_64-linux/diff/zen3 — 51s · store 2bjmdmdk |
| 12:34:46 | vestigia | ecdh/x86_64-linux/taint — 1m24s · store 2imxj3j9 |
| 12:36:10 | vestigia | mul/aarch64-linux/diff/a72 — 1m43s · store 7l6hmbg3 |
| 12:37:53 | vestigia | mul/aarch64-linux/taint — 1m56s · store vh7r36hp |
| 12:39:49 | vestigia | mul/x86_64-linux/diff/zen3 — 50s · store 8s4y2zdf |
| 12:40:39 | vestigia | mul/x86_64-linux/taint — 52s · store raki077p |
| 12:41:31 | vestigia | mul_wnaf/aarch64-linux/diff/a72 — 1m34s · store m5q4img3 |
| 12:43:05 | vestigia | mul_wnaf/aarch64-linux/taint — 1m56s · store h8akafqd |
| 12:45:01 | vestigia | mul_wnaf/x86_64-linux/diff/zen3 — 53s · store 3bv8aqkp |
| 12:45:54 | vestigia | mul_wnaf/x86_64-linux/taint — 52s · store df73nmlb |
| 12:46:46 | vestigia | sign_ecdsa/aarch64-linux/diff/a72 — 2m14s · store qj5zxhh4 |
| 12:49:00 | vestigia | sign_ecdsa/aarch64-linux/taint — 2m31s · store nr5y5qxs |
| 12:51:31 | vestigia | sign_ecdsa/x86_64-linux/diff/zen3 — 1m · store qz3id55f |
| 12:52:31 | vestigia | sign_ecdsa/x86_64-linux/taint — 1m12s · store xbdx5q6n |
| 12:53:43 | vestigia | sign_ecdsa_ctx/aarch64-linux/diff/a72 — 2m6s · store 6cr86sp1 |
| 12:55:49 | vestigia | sign_ecdsa_ctx/aarch64-linux/taint — 2m34s · store 6dwb3s0n |
| 12:58:23 | vestigia | sign_ecdsa_ctx/x86_64-linux/diff/zen3 — 1m · store 4a1szzl1 |
| 12:59:23 | vestigia | sign_ecdsa_ctx/x86_64-linux/taint — 1m9s · store 801iwac4 |
| 13:00:32 | vestigia | sign_schnorr/aarch64-linux/diff/a72 — 2m24s · store dwb8i17k |
| 13:02:56 | vestigia | sign_schnorr/aarch64-linux/taint — 2m19s · store y1rps5ws |
| 13:05:15 | vestigia | sign_schnorr/x86_64-linux/diff/zen3 — 1m3s · store d8vmg0d4 |
| 13:06:18 | vestigia | sign_schnorr/x86_64-linux/taint — 1m · store 45zdcm4g |
| 13:07:18 | vestigia | sign_schnorr_ctx/aarch64-linux/diff/a72 — 2m6s · store rja9x1i4 |
| 13:09:24 | vestigia | sign_schnorr_ctx/aarch64-linux/taint — 2m22s · store 4bhvm3hk |
| 13:11:46 | vestigia | sign_schnorr_ctx/x86_64-linux/diff/zen3 — 1m4s · store zwmpb00h |
| 13:12:50 | vestigia | sign_schnorr_ctx/x86_64-linux/taint — 1m3s · store 06nm1lfk |
| 13:13:53 | censor | secp256k1-secret-scalar-instructions/aarch64-linux/instructions — 15m9s · clear · sealed 0b7750263eaa |
| 13:29:02 | censor | secp256k1-secret-scalar-instructions/x86_64-linux/instructions — 3m54s · clear · sealed f89e71291c70 |
| 13:32:57 | vestigia | derive_pub/aarch64-linux/diff/a72 — 5s · store vkm4msr9 |
| 13:33:02 | vestigia | derive_pub/aarch64-linux/taint — 4s · store k10dbzxn |
| 13:33:06 | vestigia | derive_pub/x86_64-linux/diff/zen3 — 4s · store fw93vgcy |
| 13:33:10 | vestigia | derive_pub/x86_64-linux/taint — 4s · store n05jwpif |
| 13:33:14 | vestigia | derive_pub_ctx/aarch64-linux/diff/a72 — 8s · store j4lyzqma |
| 13:33:22 | vestigia | derive_pub_ctx/aarch64-linux/taint — 6s · store ihxmy2mg |
| 13:33:28 | vestigia | derive_pub_ctx/x86_64-linux/diff/zen3 — 6s · store 0x032rxb |
| 13:33:34 | vestigia | derive_pub_ctx/x86_64-linux/taint — 5s · store h07r536v |
| 13:33:39 | vestigia | ecdh/aarch64-linux/diff/a72 — 4s · store hm0hhck8 |
| 13:33:43 | vestigia | ecdh/aarch64-linux/taint — 5s · store zji18jha |
| 13:33:48 | vestigia | ecdh/x86_64-linux/diff/zen3 — 5s · store 2bjmdmdk |
| 13:33:53 | vestigia | ecdh/x86_64-linux/taint — 7s · store 2imxj3j9 |
| 13:34:00 | vestigia | mul/aarch64-linux/diff/a72 — 4s · store 7l6hmbg3 |
| 13:34:04 | vestigia | mul/aarch64-linux/taint — 4s · store vh7r36hp |
| 13:34:08 | vestigia | mul/x86_64-linux/diff/zen3 — 4s · store 8s4y2zdf |
| 13:34:12 | vestigia | mul/x86_64-linux/taint — 4s · store raki077p |
| 13:34:16 | vestigia | mul_wnaf/aarch64-linux/diff/a72 — 4s · store m5q4img3 |
| 13:34:20 | vestigia | mul_wnaf/aarch64-linux/taint — 5s · store h8akafqd |
| 13:34:25 | vestigia | mul_wnaf/x86_64-linux/diff/zen3 — 4s · store 3bv8aqkp |
| 13:34:29 | vestigia | mul_wnaf/x86_64-linux/taint — 4s · store df73nmlb |
| 13:34:33 | vestigia | sign_ecdsa/aarch64-linux/diff/a72 — 4s · store qj5zxhh4 |
| 13:34:37 | vestigia | sign_ecdsa/aarch64-linux/taint — 4s · store nr5y5qxs |
| 13:34:41 | vestigia | sign_ecdsa/x86_64-linux/diff/zen3 — 4s · store qz3id55f |
| 13:34:45 | vestigia | sign_ecdsa/x86_64-linux/taint — 4s · store xbdx5q6n |
| 13:34:49 | vestigia | sign_ecdsa_ctx/aarch64-linux/diff/a72 — 4s · store 6cr86sp1 |
| 13:34:53 | vestigia | sign_ecdsa_ctx/aarch64-linux/taint — 4s · store 6dwb3s0n |
| 13:34:57 | vestigia | sign_ecdsa_ctx/x86_64-linux/diff/zen3 — 4s · store 4a1szzl1 |
| 13:35:01 | vestigia | sign_ecdsa_ctx/x86_64-linux/taint — 4s · store 801iwac4 |
| 13:35:05 | vestigia | sign_schnorr/aarch64-linux/diff/a72 — 4s · store dwb8i17k |
| 13:35:09 | vestigia | sign_schnorr/aarch64-linux/taint — 4s · store y1rps5ws |
| 13:35:13 | vestigia | sign_schnorr/x86_64-linux/diff/zen3 — 4s · store d8vmg0d4 |
| 13:35:17 | vestigia | sign_schnorr/x86_64-linux/taint — 4s · store 45zdcm4g |
| 13:35:21 | vestigia | sign_schnorr_ctx/aarch64-linux/diff/a72 — 5s · store rja9x1i4 |
| 13:35:26 | vestigia | sign_schnorr_ctx/aarch64-linux/taint — 5s · store 4bhvm3hk |
| 13:35:31 | vestigia | sign_schnorr_ctx/x86_64-linux/diff/zen3 — 4s · store zwmpb00h |
| 13:35:35 | vestigia | sign_schnorr_ctx/x86_64-linux/taint — 6s · store 06nm1lfk |
| 13:35:42 | decisions | 18 decisions signed · ledger 716e15d3337e |
| 13:35:43 | gate | pass — 0 sites · 0 violations |
| 13:35:44 | bundle | gate pass — 0 sites · 0 violations |