Debian Codegraph @

Doc/src/signature/dsa.rst

raw
1 Digital Signature Algorithm (DSA and ECDSA)
2 ===========================================
3
4 DSA and ECDSA are U.S. federal standards for digital signatures, specified in `FIPS PUB 186-4`__.
5
6 Their security relies on the discrete logarithm problem in a prime finite field (the original DSA,
7 now deprecated) or in an elliptic curve field (ECDSA, faster and with smaller keys,
8 to be used in new applications).
9
10 A sender can use a *private* key (loaded from a file) to sign a message::
11
12 >>> from Crypto.Hash import SHA256
13 >>> from Crypto.PublicKey import ECC
14 >>> from Crypto.Signature import DSS
15 >>>
16 >>> message = b'I give my permission to order #4355'
17 >>> key = ECC.import_key(open('privkey.der').read())
18 >>> h = SHA256.new(message)
19 >>> signer = DSS.new(key, 'fips-186-3')
20 >>> signature = signer.sign(h)
21
22 The receiver can use the matching *public* key to verify authenticity of the received message::
23
24 >>> from Crypto.Hash import SHA256
25 >>> from Crypto.PublicKey import ECC
26 >>> from Crypto.Signature import DSS
27 >>>
28 >>> key = ECC.import_key(open('pubkey.der').read())
29 >>> h = SHA256.new(received_message)
30 >>> verifier = DSS.new(key, 'fips-186-3')
31 >>> try:
32 >>> verifier.verify(h, signature)
33 >>> print("The message is authentic.")
34 >>> except ValueError:
35 >>> print("The message is not authentic.")
36
37 .. __: http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
38
39 .. automodule:: Crypto.Signature.DSS
40 :members: