To implement and understand the Digital Signature Algorithm (DSA) as per NIST standards for generating and verifying digital signatures to ensure message authenticity and integrity.
DSA is a standard for digital signatures defined by NIST (National Institute of Standards and Technology) in the FIPS 186 series. It's an asymmetric cryptographic algorithm based on modular exponentiation and discrete logarithms.
Proves that the message is from the claimed sender.
Detects any changes to the message.
Sender cannot deny signing the message.
Hash the message using a secure hash function (e.g., SHA-256)
Sign the hash using the private key
Verify the signature using the public key and the original hash
from Crypto.PublicKey import DSA
from Crypto.Signature import DSS
from Crypto.Hash import SHA256
# Generate DSA key pair
key = DSA.generate(2048)
public_key = key.publickey()
# Sign a message
message = b'GECBHARUCH DIGITAL SIGNATURE DEMO'
hash_msg = SHA256.new(message)
signer = DSS.new(key, 'fips-186-3')
signature = signer.sign(hash_msg)
print("Signature (hex):", signature.hex())
# Verifier have message and public_key
# Verify the signature
recv_message = b'GECBHARUCH DIGITAL SIGNATURE DEMO'
hash_msg_verify = SHA256.new(recv_message)
verifier = DSS.new(public_key, 'fips-186-3')
try:
verifier.verify(hash_msg_verify, signature)
print("Signature is valid.")
except ValueError:
print("Signature is invalid.")
Confirms that the message was signed by the genuine sender.
Even a single-bit change in the message will cause signature verification to fail.
The signer cannot deny creating the signature, as only they possess the private key.
Based on hard mathematical problems (discrete logarithms), making it computationally infeasible to forge a valid signature.
| Feature | Description |
|---|---|
| DSA | U.S. government digital signature standard |
| FIPS-186-3 | Updated NIST standard supporting 2048/3072-bit keys |
| Hash Required | DSA signs hashed messages, not raw messages |
| No Encryption | DSA only signs and verifies; use RSA/ECC for encryption |
| Randomness | Each signature is different even for the same message (secure design) |
After this practical, students will be able to:
This practical demonstrates the use of NIST DSA for digitally signing and verifying messages. The use of SHA-256 ensures a secure hash before signing. This mechanism is widely used in secure communications, e-governance, banking, software distribution, and legal documents, where authenticity, integrity, and non-repudiation are essential.