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 \), returning `None` if \( a \) and \( m \) are not coprime.

• 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, returning the resulting point.

• The code initializes parameters for elliptic curve cryptography, including setting values for \( a \) and \( d \), and generates a random private key.

• A public key is generated by applying the double-and-add method to the base point using the private key.

• The `hashing(message)` function computes a SHA-512 hash of the message and converts it into an integer.

• A signature for a message is created by calculating \( r \) and \( s \) values using elliptic curve operations and the private key.

• The signature consists of two components, \( R \) and \( s \), which are printed alongside the original message.

• The verification process checks if the computed points \( P1 \) and \( P2 \) are equal, confirming the signature's validity.

• The output indicates whether the signature is valid or if a signature violation has been detected.