Blockchain - Elliptic Curve Digital Signature Algorithm ...…

metamitya ·

Blockchain - Elliptic Curve Digital Signature Algorithm ...

• The code establishes a prime number \( p \) and defines a base point for elliptic curve cryptography with specific large integer coordinates.

• A function `findPositiveModulus(a, p)` is created to ensure that the modulus of \( a \) with respect to \( p \) is non-negative.

• The `textToInt(text)` function converts a string into an integer by encoding it in UTF-8 and transforming the hexadecimal representation into an integer.

• The `gcd(a, b)` function calculates the greatest common divisor of two integers using the Euclidean algorithm.

• The `findModInverse(a, m)` function computes the modular inverse of \( a \) modulo \( m \) if \( a \) and \( m \) are coprime; it returns None otherwise.

• The `applyDoubleAndAddMethod(P, k, a, d, mod)` function performs scalar multiplication on an elliptic curve point \( P \) using the double-and-add method based on the binary representation of \( k \).

• The `pointAddition(P, Q, a, d, mod)` function adds two points \( P \) and \( Q \) on an elliptic curve defined by parameters \( a \) and \( d \), returning the resulting point.

• The code initializes parameters for elliptic curve cryptography, including setting the value of \( a \) and calculating \( d \) using a specific formula.

• A random private key is generated, and a corresponding public key is computed using the `applyDoubleAndAddMethod`.

• The message "Hello, world!" is converted into an integer for the purpose of signing.

• A `hashing(message)` function is defined to create a SHA-512 hash of the message, returning it as an integer.

• The signing process involves generating a random value \( r \), computing a point \( R \), and deriving a signature \( s \) based on the private key and the hash of the message.

• The verification process checks the validity of the signature by comparing two computed points \( P1 \) and \( P2 \) derived from the signature and the public key.

• The result of the verification is printed, indicating whether the signature is valid or if a violation has occurred.