Package Crypto :: Package PublicKey :: Module DSA :: Class DSAImplementation
[frames] | no frames]

Class DSAImplementation

object --+
         |
        DSAImplementation

A DSA key factory.

This class is only internally used to implement the methods of the Crypto.PublicKey.DSA module.

Instance Methods
 
__init__(self, **kwargs)
Create a new DSA key factory.
 
generate(self, bits, randfunc=None, progress_func=None)
Randomly generate a fresh, new DSA key.
 
construct(self, tup)
Construct a DSA key from a tuple of valid DSA components.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties

Inherited from object: __class__

Method Details

__init__(self, **kwargs)
(Constructor)

 
Create a new DSA key factory.
Parameters:
  • use_fast_math (bool) - Specify which mathematic library to use:

    • None (default). Use fastest math available.
    • True . Use fast math.
    • False . Use slow math.
  • default_randfunc (callable) - Specify how to collect random data:

    • None (default). Use Random.new().read().
    • not None . Use the specified function directly.
Raises:
  • RuntimeError - When use_fast_math =True but fast math is not available.
Overrides: object.__init__

generate(self, bits, randfunc=None, progress_func=None)

 
Randomly generate a fresh, new DSA key.
Parameters:
  • bits (int) - Key length, or size (in bits) of the DSA modulus p. It must be a multiple of 64, in the closed interval [512,1024].
  • randfunc (callable) - Random number generation function; it should accept a single integer N and return a string of random data N bytes long. If not specified, a new one will be instantiated from Crypto.Random.
  • progress_func (callable) - Optional function that will be called with a short string containing the key parameter currently being generated; it's useful for interactive applications where a user is waiting for a key to be generated.
Returns:
A DSA key object (_DSAobj).
Raises:
  • ValueError - When bits is too little, too big, or not a multiple of 64.

Attention: You should always use a cryptographically secure random number generator, such as the one defined in the Crypto.Random module; don't just use the current time and the random module.

construct(self, tup)

 

Construct a DSA key from a tuple of valid DSA components.

The modulus p must be a prime.

The following equations must apply:

  • p-1 = 0 mod q
  • g^x = y mod p
  • 0 < x < q
  • 1 < g < p
Parameters:
  • tup (tuple) - A tuple of long integers, with 4 or 5 items in the following order:

    1. Public key (y).
    2. Sub-group generator (g).
    3. Modulus, finite field order (p).
    4. Sub-group order (q).
    5. Private key (x). Optional.
Returns:
A DSA key object (_DSAobj).