secp256k1_ec_privkey_negate and invalid privkeys #488

issue dcousens openend this issue on November 29, 2017
  1. dcousens commented at 6:15 am on November 29, 2017: contributor

    For keys greater than the order, secp256k1_scalar_negate returns strange results (understandable!).

    But, as a result, secp256k1_ec_privkey_negate, when called with an invalid private key, returns 1 (OK), and a ?private key?.

    Tripped me up for a bit when generating some test fixtures for secp256k1_ec_privkey_negate.

     00000000000000000000000000000000000000000000000000000000000000000 becomes 0000000000000000000000000000000000000000000000000000000000000000
     1ff00000000000000000000000000000000000000000000000000000000000000 becomes 00fffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141
     2ffff000000000000000000000000000000000000000000000000000000000000 becomes 0000fffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141
     3ffffff0000000000000000000000000000000000000000000000000000000000 becomes 000000fffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141
     4ffffffff00000000000000000000000000000000000000000000000000000000 becomes 00000000fffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141
     5ffffffffff000000000000000000000000000000000000000000000000000000 becomes 0000000000fffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141
     6ffffffffffff0000000000000000000000000000000000000000000000000000 becomes 000000000000fffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141
     7ffffffffffffff00000000000000000000000000000000000000000000000000 becomes 00000000000000fffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141
     8ffffffffffffffff000000000000000000000000000000000000000000000000 becomes 0000000000000000fffffffffffffffebaaedce6af48a03bbfd25e8cd0364141
     9ffffffffffffffffff0000000000000000000000000000000000000000000000 becomes 000000000000000000fffffffffffffebaaedce6af48a03bbfd25e8cd0364141
    10ffffffffffffffffffff00000000000000000000000000000000000000000000 becomes 00000000000000000000fffffffffffebaaedce6af48a03bbfd25e8cd0364141
    11ffffffffffffffffffffff000000000000000000000000000000000000000000 becomes 0000000000000000000000fffffffffebaaedce6af48a03bbfd25e8cd0364141
    12ffffffffffffffffffffffff0000000000000000000000000000000000000000 becomes 000000000000000000000000fffffffebaaedce6af48a03bbfd25e8cd0364141
    13ffffffffffffffffffffffffff00000000000000000000000000000000000000 becomes 00000000000000000000000000fffffebaaedce6af48a03bbfd25e8cd0364141
    14ffffffffffffffffffffffffffff000000000000000000000000000000000000 becomes 0000000000000000000000000000fffebaaedce6af48a03bbfd25e8cd0364141
    15ffffffffffffffffffffffffffffff0000000000000000000000000000000000 becomes 000000000000000000000000000000febaaedce6af48a03bbfd25e8cd0364141
    16ffffffffffffffffffffffffffffffff00000000000000000000000000000000 becomes fffffffffffffffffffffffffffffffe755db9cd5e9140777fa4bd19a06c8282
    17ffffffffffffffffffffffffffffffffff000000000000000000000000000000 becomes fffffffffffffffffffffffffffffffd765db9cd5e9140777fa4bd19a06c8282
    18ffffffffffffffffffffffffffffffffffff0000000000000000000000000000 becomes fffffffffffffffffffffffffffffffd755eb9cd5e9140777fa4bd19a06c8282
    19ffffffffffffffffffffffffffffffffffffff00000000000000000000000000 becomes fffffffffffffffffffffffffffffffd755dbacd5e9140777fa4bd19a06c8282
    20ffffffffffffffffffffffffffffffffffffffff000000000000000000000000 becomes fffffffffffffffffffffffffffffffd755db9ce5e9140777fa4bd19a06c8282
    21ffffffffffffffffffffffffffffffffffffffffff0000000000000000000000 becomes fffffffffffffffffffffffffffffffd755db9cd5f9140777fa4bd19a06c8282
    22ffffffffffffffffffffffffffffffffffffffffffff00000000000000000000 becomes fffffffffffffffffffffffffffffffd755db9cd5e9240777fa4bd19a06c8282
    23ffffffffffffffffffffffffffffffffffffffffffffff000000000000000000 becomes fffffffffffffffffffffffffffffffd755db9cd5e9141777fa4bd19a06c8282
    24ffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000 becomes fffffffffffffffffffffffffffffffd755db9cd5e9140787fa4bd19a06c8282
    25ffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000 becomes fffffffffffffffffffffffffffffffd755db9cd5e91407780a4bd19a06c8282
    26ffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000 becomes fffffffffffffffffffffffffffffffd755db9cd5e9140777fa5bd19a06c8282
    27ffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000 becomes fffffffffffffffffffffffffffffffd755db9cd5e9140777fa4be19a06c8282
    28ffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000 becomes fffffffffffffffffffffffffffffffd755db9cd5e9140777fa4bd1aa06c8282
    29ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000 becomes fffffffffffffffffffffffffffffffd755db9cd5e9140777fa4bd19a16c8282
    30ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000 becomes fffffffffffffffffffffffffffffffd755db9cd5e9140777fa4bd19a06d8282
    31ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00 becomes fffffffffffffffffffffffffffffffd755db9cd5e9140777fa4bd19a06c8382
    
  2. dcousens commented at 6:15 am on September 24, 2018: contributor
    Is this a bug or? Do I close?
  3. apoelstra commented at 10:44 pm on September 26, 2018: contributor
    I think it’s a documentation bug. We should state clearly that secp256k1_ec_privkey_negate will work only on valid secret keys, and that mysterious things will happen otherwise.
  4. jonasnick cross-referenced this on Oct 7, 2019 from issue Return 0 if invalid seckey is given to ec_privkey_negate by jonasnick
  5. jonasnick cross-referenced this on Oct 9, 2019 from issue Make ec_ arithmetic more consistent and add documentation by jonasnick
  6. real-or-random closed this on Apr 30, 2020


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-22 20:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me