This project is a C implementation of the Elliptic Curve Digital Signature Algorithm (ECDSA), a widely used cryptographic algorithm for digital signatures. The implementation includes key generation, signing, and verification processes, and it uses PEM files for storing keys and signatures.
To compile and run this project, you need the following:
- GCC (GNU Compiler Collection)
- GMP (GNU Multiple Precision Arithmetic Library)
- OpenSSL (for cryptographic functions and base64 encoding/decoding)
You can install these dependencies on a Debian-based system using:
sudo apt-get install build-essential libgmp-dev libssl-devTo compile the project, navigate to the directory containing the source code and run:
gcc -o ecdsa ecdsa.c -lgmp -lcryptoThis will generate an executable named ecdsa.
The program provides a menu-driven interface for key generation, signing, and verification. Below are the steps to use the program.
- Run the program:
./ecdsa
- Select option
1to generate a key pair. - Follow the prompts to enter the elliptic curve parameters (
p,a,b,q) and the generator pointG. - The program will generate a private key (
ecdsa_private_key.pem) and a public key (ecdsa_public_key.pem).
- Run the program:
./ecdsa
- Select option
2to sign a file. - Enter the path to the file you want to sign.
- The program will generate a signature file (
ecdsa_signature.txt).
- Run the program:
./ecdsa
- Select option
3to verify a signature. - Enter the path to the file you want to verify.
- The program will check the signature against the file and the public key, and it will output whether the signature is valid or not.
Here is an example of how to use the program:
-
Generate keys:
./ecdsa
- Select option
1. - Enter the elliptic curve parameters and generator point.
- Select option
-
Sign a file:
./ecdsa
- Select option
2. - Enter the path to the file you want to sign (e.g.,
example.txt).
- Select option
-
Verify the signature:
./ecdsa
- Select option
3. - Enter the path to the file you want to verify (e.g.,
example.txt). - The program will output whether the signature is valid.
- Select option
- The private key is stored in
ecdsa_private_key.pem, and the public key is stored inecdsa_public_key.pem. - The signature is stored in
ecdsa_signature.txt. - The program uses SHA-256 for hashing the files before signing or verifying.
This implementation is designed to be a practical example of how ECDSA works, and it can be used as a reference for understanding digital signatures in elliptic curve cryptography.