ECC, or Elliptic Curve Cryptography, is a cryptographic algorithm widely used in the blockchain space for creating public-private key pairs and digital signatures. It relies on the mathematical properties of elliptic curves to provide strong encryption and digital signatures.
ECC is primarily used in two key areas:
1. [[Public Key Cryptography]]: ECC forms the basis for generating public-private key pairs that are essential for secure communication and transaction verification. The private key remains secret while the corresponding public key can be freely shared with others. For example, when Alice wants to send a cryptocurrency transaction to Bob, she uses her private key (generated using ECC) to sign the transaction data. Bob can then use Alice's public key (derived from her private key) to verify that the signature is valid and ensure that only Alice could have created it.
2. [[Key Exchange Algorithms]]: ECC is also used for secure key exchange protocols, such as the Diffie-Hellman key exchange. This allows two parties to establish a shared secret key over an insecure channel without any prior communication or sharing of secrets. In blockchain systems, this is crucial for establishing secure and private communication channels between nodes or participants.
Combining ECC with [[Signature Algorithms#Digital Signature Algorithm|digital signature algorithms]], we have the [[Signature Algorithms#Elliptic Curve Digital Signature Algorithm (ECDSA)|Elliptic Curve Digital Signature Algorithm (ECDSA)]], which is used for blockchain transaction signing.
### secp256k1 curve
The `secp256k1` curve is a specific elliptic curve defined over a finite field that provides the foundation for key generation, transaction signing, and verification in Bitcoin. It was selected by Satoshi Nakamoto for use in the Bitcoin protocol, primarily due to its desirable characteristics:
1. Security: The `secp256k1` curve offers a high level of cryptographic security against various attacks such as brute-force or mathematical attacks. Its parameters are carefully chosen to resist known vulnerabilities and provide resistance against potential future advancements in cryptanalysis or quantum computers.
2. Efficiency: The `secp256k1` curve allows for fast computations on resource-constrained devices like computers or mobile phones while maintaining strong security levels.
3. Compatibility: By using the same elliptic curve across all transactions, it ensures interoperability between different implementations and wallets within the Bitcoin ecosystem.
Signature forgery or key derivation is a known risk vector, especially if an attacker can predict/influence the random values used for their generation, so robust randomness is crucial in signature generation. Standardized methods like RFC-6979 therefore provide deterministic approaches to incorporate randomness *internal to cryptographic operations* via `secp256k1`.
### RFC-6979
[RFC-6979](https://www.rfc-editor.org/rfc/rfc6979) prevents potential exposure or extraction of private keys within a `secp256k1` curve; this is done through its deterministic signature generation approach. A point is selected along the curve deterministically (via internal code), ensuring consistency and repeatability without relying on *external randomness sources*. This reduces vulnerabilities associated with random number generation during cryptographic operations. For example with private key generation, online key generators have been known to maliciously create keys with low [[Chain Concepts/Theory and Law/Entropy|entropy]], making them weak. Similarly, the randomness with which signatures are generated is an attack vector, and therefore requires randomness that is not vulnerable to malicious code injection. To address this vulnerability, RFC-6979 introduces a technique called deterministic nonce generation.
>[!info] Deterministic here means that as long as you have access to all inputs required by RFC-6979 (private key and message), you can reproduce exactly which point was selected during signing. This property ensures consistency across different implementations using RFC-6979 for generating ECDSA signatures, as the deterministic aspect lies solely in how the nonce ("k") is generated within each individual transaction signing process.
Instead of relying on an external source for randomness, internal cryptographic libraries or modules are responsible for handling digital signatures. The point selection on curve `secp256k1` is based on mathematical operations involving both public and private keys, and it varies only by the private key and message being signed. As long as these inputs remain constant, the same point will be selected during signing, ensuring the deterministic behavior across multiple executions of the signing process.
This means that given the same private key and message input, RFC-6979 will always produce the same nonce value. The function enabling this design is HMAC-SHA256, where the private key and message is being signed to deterministically generate a unique number (i.e., nonce "k") for each signature.
### HMAC-SHA256
Hash-based Message Authentication Code with SHA-256 (HMAC-SHA256) is a specific cryptographic algorithm used for generating a pseudorandom function in RFC-6979 and plays a crucial role in deterministic nonce generation for elliptic curve cryptography.
Per RFC-6979, HMAC-SHA256 is utilized to derive a unique nonce ("k") value during the signing process. The purpose of this nonce is to introduce randomness into each signature while ensuring determinism.
Here's how it works:
1. Inputs: The private key (d), the message being signed (m), and some additional parameters.
2. Initialization: HMAC-SHA256 takes as input the private key (d) concatenated with the message (m).
3. Iteration: It repeatedly applies HMAC-SHA256 on its own output until certain conditions are met.
- If at any point during iteration, the generated value falls within an acceptable range defined by secp256k1's order, it becomes the final nonce ("k").
- Otherwise, it continues iterating by feeding its previous output back into itself along with additional data derived from previous iterations until an acceptable nonce is found or termination criteria are reached.
4. Output: The final accepted value becomes the deterministic nonce ("k") used in ECDSA signature generation.
By using HMAC-SHA256 as part of this iterative process, RFC-6979 ensures that even if an attacker gains knowledge about intermediate values or partial outputs during iteration, they cannot predict or influence subsequent nonces without knowing the private key. This provides security against potential biases or vulnerabilities that may arise from relying on *external sources for random number generation* when creating signatures based on elliptic curve cryptography.