Link to this headingDSA
Link to this headingImplementation
= 0
=
return
#Generate Hash of message
=
#Generate ints
, , =
=
#init outputs
= 0
= 0
#check if r = 0
#Generate a Random Integer between 1, q-1
=
#Compute (g^k mod P) mod q
= %
#Compute Mod Inverse of R
=
#Check Inverse
#print("Inverse Check: {}".format((random_int_inverse * random_int) % subgroup_order))
#Compute Signature
# s:= k^-1 (H(m) + x*r)) mod q
= %
return ,
#Generate ints
, , =
=
#Generate Hash of message
=
#Generate Mod inverse of signature
=
#Check Mod inverse
#print("Inverse Check: {}".format((inverse_signature * signature) % subgroup_order))
#Generate First part of the comparison
= %
=
#Generate Second part of Comparison
= %
=
= %
#print(compare_random)
#print(random_output)
return ==
# Create a new DSA key
#public_key, private_key = generate_key_pair()
=
#print("DSA Key: {}".format(private_key))
# Hash the message
= b
#Sign the Message
, =
#Verify the Signature
=
Link to this headingSecurity
- Can have multiple signatures that are valid for the same message
- Both RAW and ASN.1 versions are valid
- While the ASN.1 encoding is supposed to be DER encoded, many libraries accept any (semi-)valid BER encoding. This means that an attacker can often use the flexibility of BER to craft an essentially infinite number of valid signatures (for the same message) once they know a single one.