Package M2Crypto :: Module DSA :: Class DSA
[frames] | no frames]

Class DSA




This class is a context supporting DSA key and parameter values, signing and verifying.

Simple example:

   from M2Crypto import EVP, DSA, util
   
   message = 'Kilroy was here!'
   md = EVP.MessageDigest('sha1')
   md.update(message)        
   digest = md.final()
   
   dsa = DSA.gen_params(1024)
   dsa.gen_key()
   r, s = dsa.sign(digest)
   good = dsa.verify(digest, r, s)
   if good:
       print '  ** success **'
   else:
       print '  ** verification failed **'
Instance Methods
 
m2_dsa_free(...)
 
__init__(self, dsa, _pyfree=0)
Use one of the factory functions to create an instance.
 
__del__(self)
int
__len__(self)
Return the key length.
str
__getattr__(self, name)
Return specified DSA parameters and key values.
 
__setattr__(self, name, value)
 
set_params(self, p, q, g)
Set new parameters.
 
gen_key(self)
Generate a key pair.
 
save_params(self, filename)
Save the DSA parameters to a file.
 
save_params_bio(self, bio)
Save DSA parameters to a BIO object.
 
save_key(self, filename, cipher='aes_128_cbc', callback=<function passphrase_callback at 0x83b2a04>)
Save the DSA key pair to a file.
 
save_key_bio(self, bio, cipher='aes_128_cbc', callback=<function passphrase_callback at 0x83b2a04>)
Save DSA key pair to a BIO object.
 
save_pub_key(self, filename)
Save the DSA public key (with parameters) to a file.
 
save_pub_key_bio(self, bio)
Save DSA public key (with parameters) to a BIO object.
tuple
sign(self, digest)
Sign the digest.
int
verify(self, digest, r, s)
Verify a newly calculated digest against the signature values r and s.
 
sign_asn1(self, digest)
 
verify_asn1(self, digest, blob)
int
check_key(self)
Check to be sure the DSA object has a valid private key.
Method Details

__len__(self)
(Length operator)

 

Return the key length.

Returns: int
the DSA key length in bits

__getattr__(self, name)
(Qualification operator)

 

Return specified DSA parameters and key values.

Parameters:
  • name (str) - name of variable to be returned. Must be one of 'p', 'q', 'g', 'pub', 'priv'.
Returns: str
value of specified variable (a "byte string")

set_params(self, p, q, g)

 

Set new parameters.

Warning: This does not change the private key, so it may be unsafe to use this method. It is better to use gen_params function to create a new DSA object.

save_params(self, filename)

 

Save the DSA parameters to a file.

Parameters:
  • filename (str) - Save the DSA parameters to this file.
Returns:
1 (true) if successful

save_params_bio(self, bio)

 

Save DSA parameters to a BIO object.

Parameters:
  • bio (M2Crypto.BIO object) - Save DSA parameters to this object.
Returns:
1 (true) if successful

save_key(self, filename, cipher='aes_128_cbc', callback=<function passphrase_callback at 0x83b2a04>)

 

Save the DSA key pair to a file.

Parameters:
  • filename (str) - Save the DSA key pair to this file.
  • cipher (str) - name of symmetric key algorithm and mode to encrypt the private key.
Returns:
1 (true) if successful

save_key_bio(self, bio, cipher='aes_128_cbc', callback=<function passphrase_callback at 0x83b2a04>)

 

Save DSA key pair to a BIO object.

Parameters:
  • bio (M2Crypto.BIO object) - Save DSA parameters to this object.
  • cipher (str) - name of symmetric key algorithm and mode to encrypt the private key.
Returns:
1 (true) if successful

save_pub_key(self, filename)

 

Save the DSA public key (with parameters) to a file.

Parameters:
  • filename (str) - Save DSA public key (with parameters) to this file.
Returns:
1 (true) if successful

save_pub_key_bio(self, bio)

 

Save DSA public key (with parameters) to a BIO object.

Parameters:
  • bio (M2Crypto.BIO object) - Save DSA public key (with parameters) to this object.
Returns:
1 (true) if successful

sign(self, digest)

 

Sign the digest.

Parameters:
  • digest (str) - SHA-1 hash of message (same as output from MessageDigest, a "byte string")
Returns: tuple
DSA signature, a tuple of two values, r and s, both "byte strings".

verify(self, digest, r, s)

 

Verify a newly calculated digest against the signature values r and s.

Parameters:
  • digest (str) - SHA-1 hash of message (same as output from MessageDigest, a "byte string")
  • r (str) - r value of the signature, a "byte string"
  • s (str) - s value of the signature, a "byte string"
Returns: int
1 (true) if verify succeeded, 0 if failed

check_key(self)

 

Check to be sure the DSA object has a valid private key.

Returns: int
1 (true) if a valid private key