• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • Soft
        • C
        • Bv
        • Imp-language
        • Event-macros
        • Java
        • Bitcoin
        • Ethereum
        • Yul
        • Zcash
        • ACL2-programming-language
        • Prime-fields
        • Json
        • Syntheto
        • File-io-light
        • Cryptography
          • R1cs
          • Interfaces
          • Sha-2
          • Keccak
          • Kdf
          • Mimc
          • Padding
          • Hmac
          • Elliptic-curves
          • Attachments
          • Elliptic-curve-digital-signature-algorithm
            • Secp256k1-ecdsa-attachment
            • Deterministic-ecdsa-secp256k1
              • Ecdsa-sign-deterministic-sha-256
              • Ecdsa-sign-deterministic-keccak-256
              • Ecdsa-sign-deterministic-prehashed
              • Secp256k1-ecdsa-interface
          • Number-theory
          • Lists-light
          • Axe
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Deterministic-ecdsa-secp256k1

    Ecdsa-sign-deterministic-prehashed

    Sign a prehashed message using SHA-256.

    The call

    (ecdsa-sign-deterministic-prehashed mh privkey small-x? small-s?)

    signs the already-hashed message mh using SHA-256 when applying HMAC.

    Arguments:

    1. mh -- the already-hashed message to be signed, a list of bits.
    2. privkey -- the signer's private key, which is a positive integer less than the elliptic curve order.
    3. small-x? -- a boolean flag that, when true, restricts the ephemeral public key x coordinate to be to be less than the elliptic curve order.
    4. small-s? -- a boolean flag that, when true, restricts the returned s value to be less than q/2, where q is the elliptic curve order.

    Return values (using mv):

    1. error? -- a flag indicating any sort of error was detected. Please report errors, but do not send a private key that is in use.
    2. x-index -- an index from 0 to the curve cofactor h, which can be used to recover the x coordinate of the ephemeral public key from r. If the argument small-x? is true, x-index will be 0.
    3. y-even? -- a flag indicating whether the y coordinate of the ephemeral public key was even or odd. This, along with r and x-index, can be used to recover the y coordinate of the ephemeral public key.
    4. r -- the x coordinate of the ephemeral public key, modulo the elliptic curve group order, considered the first part of the signature.
    5. s -- the second part of the signature.

    Definitions and Theorems

    Function: ecdsa-sign-deterministic-prehashed

    (defun ecdsa-sign-deterministic-prehashed
           (mh privkey small-x? small-s?)
     (declare (xargs :guard (and (true-listp mh)
                                 (all-unsigned-byte-p 1 mh)
                                 (posp privkey)
                                 (< privkey *q*)
                                 (booleanp small-x?))))
     (b* (((mv error? x-index y-even? r s)
           (ecdsa-sign-deterministic-prehashed-aux mh privkey small-x?))
          ((when error?) (mv error? 0 nil 0 0)))
       (if small-s?
           (b* (((mv x-index y-even? r s)
                 (ecdsa-ensure-s-below-q/2 x-index y-even? r s)))
             (mv nil x-index y-even? r s))
         (mv nil x-index y-even? r s))))