HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/thread-self/root/lib64/python3.6/site-packages/M2Crypto/__pycache__/DSA.cpython-36.pyc
3

YݧZ�7�@s�ddlmZmZddlmZmZmZejr>ddlm	Z	m
Z
mZGdd�de�Z
eje
�Gdd�de�ZGdd	�d	e�Zejfd
d�Zdd
�Zejfdd�Zejfdd�Zejfdd�Zejfdd�Zdd�Zejfdd�Zejfdd�ZdS)�)�absolute_import�print_function)�BIO�m2�util)�AnyStr�Callable�Tuplec@seZdZdS)�DSAErrorN)�__name__�
__module__�__qualname__�rr�/usr/lib64/python3.6/DSA.pyr
sr
c@s�eZdZdZejZd)dd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zdejfdd�Zdejfdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(S)*�DSAa#
    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 **')
    rcCs"tj|�std��||_||_dS)z�
        Use one of the factory functions to create an instance.
        :param dsa: binary representation of OpenSSL DSA type
        z'dsa' type errorN)r�dsa_type_check�AssertionError�dsa�_pyfree)�selfrrrrr�__init__2szDSA.__init__cCst|dd�r|j|j�dS)Nrr)�getattr�m2_dsa_freer)rrrr�__del__<szDSA.__del__cCs tj|j�std��tj|j�S)zV
        Return the key length.

        :return:  the DSA key length in bits
        z'dsa' type error)rrrrZ
dsa_keylen)rrrr�__len__AszDSA.__len__cCs>|d	kr6ttd|f�}tj|j�s,td��||j�St�dS)
z�
        Return specified DSA parameters and key values.

        :param name: name of variable to be returned.  Must be
                     one of 'p', 'q', 'g', 'pub', 'priv'.
        :return:     value of specified variable (a "byte string")
        �p�q�g�pub�privz
dsa_get_%sz'dsa' type errorN)rrrrr)rrrrr�AttributeError)r�name�methodrrr�__getattr__Ks
	
zDSA.__getattr__cCs2|dkrtd��n|d	kr$td��n
||j|<dS)
Nrrrzset (p, q, g) via set_params()rrz"generate (pub, priv) via gen_key())rrr)rr)r
�__dict__)rr!�valuerrr�__setattr__[s


zDSA.__setattr__cCstj|j|||�dS)a�
        Set new parameters.

        :param p: MPI binary representation ... format that consists of
                  the number's length in bytes represented as a 4-byte
                  big-endian number, and the number itself in big-endian
                  format, where the most significant bit signals
                  a negative number (the representation of numbers with
                  the MSB set is prefixed with null byte).
        :param q: ditto
        :param g: ditto

        @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.
        N)r�dsa_set_pqgr)rrrrrrr�
set_paramsdszDSA.set_paramscCs$tj|j�std��tj|j�dS)z&
        Generate a key pair.
        z'dsa' type errorN)rrrrZdsa_gen_key)rrrr�gen_keyxszDSA.gen_keyc
Cs.tj|d��}tj|j|j��}WdQRX|S)z�
        Save the DSA parameters to a file.

        :param filename: Save the DSA parameters to this file.
        :return:         1 (true) if successful
        �wbN)r�openfiler�dsa_write_params_bior�_ptr)r�filename�bio�retrrr�save_params�szDSA.save_paramscCstj|j|j��S)z�
        Save DSA parameters to a BIO object.

        :param bio: Save DSA parameters to this object.
        :return:    1 (true) if successful
        )rr,rr-)rr/rrr�save_params_bio�szDSA.save_params_bioZaes_128_cbccCs*tj|d��}|j|||�}WdQRX|S)a
        Save the DSA key pair to a file.

        :param filename: Save the DSA key pair to this file.
        :param cipher:   name of symmetric key algorithm and mode
                         to encrypt the private key.
        :return:         1 (true) if successful
        r*N)rr+�save_key_bio)rr.�cipher�callbackr/r0rrr�save_key�szDSA.save_keycCs^|dkrtj|j|j�|�Stt|d�}|dkr>td|��n|�}tj|j|j�||�SdS)a
        Save DSA key pair to a BIO object.

        :param bio:    Save DSA parameters to this object.
        :param cipher: name of symmetric key algorithm and mode
                       to encrypt the private key.
        :return:       1 (true) if successful
        Nzno such cipher: %s)rZdsa_write_key_bio_no_cipherrr-rr
Zdsa_write_key_bio)rr/r4r5Zciphrrrr3�szDSA.save_key_bioc	Cs&tj|d��}|j|�}WdQRX|S)z�
        Save the DSA public key (with parameters) to a file.

        :param filename: Save DSA public key (with parameters)
                         to this file.
        :return:         1 (true) if successful
        r*N)rr+�save_pub_key_bio)rr.r/r0rrr�save_pub_key�s	zDSA.save_pub_keycCstj|j|j��S)z�
        Save DSA public key (with parameters) to a BIO object.

        :param bio: Save DSA public key (with parameters)
                    to this object.
        :return:  1 (true) if successful
        )rZdsa_write_pub_key_biorr-)rr/rrrr7�s	zDSA.save_pub_key_biocCs|j�std��tj|j|�S)a
        Sign the digest.

        :param digest: SHA-1 hash of message (same as output
                       from MessageDigest, a "byte string")
        :return:       DSA signature, a tuple of two values, r and s,
                       both "byte strings".
        zkey is not initialised)�	check_keyrrZdsa_signr)r�digestrrr�sign�s
zDSA.signcCs"|j�std��tj|j|||�S)a�
        Verify a newly calculated digest against the signature
        values r and s.

        :param digest: SHA-1 hash of message (same as output
                       from MessageDigest, a "byte string")
        :param r:      r value of the signature, a "byte string"
        :param s:      s value of the signature, a "byte string"
        :return:       1 (true) if verify succeeded, 0 if failed
        zkey is not initialised)r9rrZ
dsa_verifyr)rr:�r�srrr�verify�sz
DSA.verifycCs|j�std��tj|j|�S)Nzkey is not initialised)r9rrZ
dsa_sign_asn1r)rr:rrr�	sign_asn1�sz
DSA.sign_asn1cCs |j�std��tj|j||�S)Nzkey is not initialised)r9rrZdsa_verify_asn1r)rr:Zblobrrr�verify_asn1�szDSA.verify_asn1cCs tj|j�std��tj|j�S)z}
        Check to be sure the DSA object has a valid private key.

        :return:  1 (true) if a valid private key
        z'dsa' type error)rrrrZ
dsa_check_key)rrrrr9�sz
DSA.check_keyN)r)rrr
�__doc__rZdsa_freerrrrr#r&r(r)r1r2r�passphrase_callbackr6r3r8r7r;r>r?r@r9rrrrrs,


	


rc@s0eZdZdZdd�ZeZdd�ZejZ	ej
ZdS)�DSA_pubz�
    This class is a DSA context that only supports a public key
    and verification.  It does NOT support a private key or
    signing.

    cGstd��dS)Nz!DSA_pub object has no private key)r
)r�argvrrrr;
szDSA_pub.signcCstj|j�S)z:
        :return: does DSA_pub contain a pub key?
        )rZdsa_check_pub_keyr)rrrrr9szDSA_pub.check_keyN)rrr
rAr;r?r9rr8r6r7r3rrrrrCsrCcCstj||�}t|d�S)a�
    Factory function that generates DSA parameters and
    instantiates a DSA object from the output.

    :param bits: The length of the prime to be generated. If
                 'bits' < 512, it is set to 512.
    :param callback: A Python callback object that will be
                 invoked during parameter generation; it usual
                 purpose is to provide visual feedback.
    :return:  instance of DSA.
    �)rZdsa_generate_parametersr)�bitsr5rrrr�
gen_params"s
rGcCs"tj�}tj||||�t|d�S)z�
    Factory function that instantiates a DSA object with DSA
    parameters.

    :param p: value of p, a "byte string"
    :param q: value of q, a "byte string"
    :param g: value of g, a "byte string"
    :return:  instance of DSA.
    rE)r�dsa_newr'r)rrrrrrrr(3sr(c
Cs$tj|��}t||�}WdQRX|S)a�
    Factory function that instantiates a DSA object with DSA
    parameters from a file.

    :param file:     Names the file (a path) that contains the PEM
                     representation of the DSA parameters.
    :param callback: A Python callback object that will be
                     invoked if the DSA parameters file is
                     passphrase-protected.
    :return:         instance of DSA.
    N)rr+�load_params_bio)�filer5r/r0rrr�load_paramsCs
rKcCstj|j�|�}t|d�S)a�
    Factory function that instantiates a DSA object with DSA
    parameters from a M2Crypto.BIO object.

    :param bio:      Contains the PEM representation of the DSA
                     parameters.
    :param callback: A Python callback object that will be
                     invoked if the DSA parameters file is
                     passphrase-protected.
    :return:         instance of DSA.
    rE)rZdsa_read_paramsr-r)r/r5rrrrrIVs
rIc
Cs$tj|��}t||�}WdQRX|S)a�
    Factory function that instantiates a DSA object from a
    PEM encoded DSA key pair.

    :param file:     Names the file (a path) that contains the PEM
                     representation of the DSA key pair.
    :param callback: A Python callback object that will be
                     invoked if the DSA key pair is
                     passphrase-protected.
    :return:         instance of DSA.
    N)rr+�load_key_bio)rJr5r/r0rrr�load_keygs
rMcCstj|j�|�}t|d�S)a~
    Factory function that instantiates a DSA object from a
    PEM encoded DSA key pair.

    :param bio:      Contains the PEM representation of the DSA
                     key pair.
    :param callback: A Python callback object that will be
                     invoked if the DSA key pair is
                     passphrase-protected.
    :return:         instance of DSA.
    rE)rZdsa_read_keyr-r)r/r5rrrrrLzs
rLcCs.tj�}tj||||�tj||�t|d�S)a
    Factory function that instantiates a DSA_pub object using
    the parameters and public key specified.

    :param p: value of p
    :param q: value of q
    :param g: value of g
    :param pub: value of the public key
    :return:  instance of DSA_pub.
    rE)rrHr'Zdsa_set_pubrC)rrrrrrrr�pub_key_from_params�srNc
Cs$tj|��}t||�}WdQRX|S)a
    Factory function that instantiates a DSA_pub object using
    a DSA public key contained in PEM file.  The PEM file
    must contain the parameters in addition to the public key.

    :param file:     Names the file (a path) that contains the PEM
                     representation of the DSA public key.
    :param callback: A Python callback object that will be
                     invoked should the DSA public key be
                     passphrase-protected.
    :return:         instance of DSA_pub.
    N)rr+�load_pub_key_bio)rJr5r/r0rrr�load_pub_key�srPcCstj|j�|�}t|d�S)a�
    Factory function that instantiates a DSA_pub object using
    a DSA public key contained in PEM format.  The PEM
    must contain the parameters in addition to the public key.

    :param bio:      Contains the PEM representation of the DSA
                     public key (with params).
    :param callback: A Python callback object that will be
                     invoked should the DSA public key be
                     passphrase-protected.
    :return:         instance of DSA_pub.
    rE)rZdsa_read_pub_keyr-rC)r/r5ZdsapubrrrrO�srON)Z
__future__rrZM2CryptorrrZpy27plusZtypingrrr	�	Exceptionr
Zdsa_init�objectrrCZgenparam_callbackrGr(rBrKrIrMrLrNrPrOrrrr�<module>s"
n