ó
ñ1Mc           @   s  d  Z  d d l Z d d l Z d d l Z d e f d „  ƒ  YZ e j e ƒ e j Z e j Z e j	 Z	 e j
 Z
 e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z e j  Z  e j! Z! e j" Z" e j# Z# e j$ Z$ e j% Z% e j& Z& e j' Z' e j( Z( e j) Z) e j* Z* e j+ Z+ e j, Z, e j- Z- e j. Z. e j/ Z/ e j0 Z0 e j1 Z1 e j2 Z2 e j3 Z3 e j4 Z4 e j5 Z5 e j6 Z6 e j7 Z7 e j8 Z8 e j9 Z9 e j: Z: e j; Z; e j< Z< e j= Z= e j> Z> e j? Z? e j@ Z@ e jA ZA e jB ZB e jC ZC e jD ZD e jE ZE e jF ZF e jG ZG d d d „  ƒ  YZH d eH f d „  ƒ  YZI d	 „  ZJ e jK d
 „ ZL e jK d „ ZM d „  ZN d „  ZO d „  ZP d „  ZQ d S(   sä   
M2Crypto wrapper for OpenSSL ECDH/ECDSA API.

@requires: OpenSSL 0.9.8 or newer

Copyright (c) 1999-2003 Ng Pheng Siong. All rights reserved.

Portions copyright (c) 2005-2006 Vrije Universiteit Amsterdam. 
All rights reserved.iÿÿÿÿNt   ECErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyR       s    t   ECc           B   s¼   e  Z d  Z e j Z d d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d e j d „ Z d e j d „ Z d „  Z d „  Z d „  Z d „  Z RS(   s,   
    Object interface to a EC key pair.
    i    c         C   s   | |  _  | |  _ d  S(   N(   t   ect   _pyfree(   t   selfR   R   (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyt   __init__i   s    	c         C   s)   t  |  d d ƒ r% |  j |  j ƒ n  d  S(   NR   i    (   t   getattrt   m2_ec_key_freeR   (   R   (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyt   __del__n   s    c         C   s   t  j |  j ƒ S(   N(   t   m2t   ec_key_keylenR   (   R   (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyt   __len__r   s    c         C   s   t  j |  j ƒ d S(   s®   
        Generates the key pair from its parameters. Use::
            keypair = EC.gen_params(curve)
            keypair.gen_key()
        to create an EC key pair.
        N(   R   t   ec_key_gen_keyR   (   R   (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyt   gen_keyv   s    c         C   s   t  |  j d ƒ S(   Ni    (   t   EC_pubR   (   R   (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyt   pub€   s    c         C   s   t  j |  j | ƒ S(   sw   
        Sign the given digest using ECDSA. Returns a tuple (r,s), the two
        ECDSA signature parameters.
        (   R   t
   ecdsa_signR   (   R   t   digest(    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyt   sign_dsa„   s    c         C   s   t  j |  j | | | ƒ S(   sj   
        Verify the given digest using ECDSA. r and s are the ECDSA
        signature parameters.
        (   R   t   ecdsa_verifyR   (   R   R   t   rt   s(    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyt
   verify_dsaŒ   s    c         C   s   t  j |  j | ƒ S(   N(   R   t   ecdsa_sign_asn1R   (   R   R   (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyt   sign_dsa_asn1”   s    c         C   s   t  j |  j | | ƒ S(   N(   R   t   ecdsa_verify_asn1R   (   R   R   t   blob(    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyt   verify_dsa_asn1˜   s    c         C   s   t  j |  j | j ƒ S(   sù   
        Compute the ECDH shared key of this key pair and the given public 
        key object. They must both use the same curve. Returns the 
        shared key in binary as a buffer object. No Key Derivation Function is 
        applied.
        (   R   t   ecdh_compute_keyR   (   R   t   pub_key(    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyt   compute_dh_keyœ   s    t   aes_128_cbcc         C   s   | d k r( t j |  j | j ƒ  | ƒ St t | d ƒ } | d k rY t d | ƒ ‚ n  t j |  j | j ƒ  | ƒ  | ƒ Sd S(   sR  
        Save the key pair to an M2Crypto.BIO.BIO object in PEM format.

        @type bio: M2Crypto.BIO.BIO
        @param bio: M2Crypto.BIO.BIO object to save key to.

        @type cipher: string
        @param cipher: Symmetric cipher to protect the key. The default
        cipher is 'aes_128_cbc'. If cipher is None, then the key is saved
        in the clear.

        @type callback: Python callable
        @param callback: A Python callable object that is invoked
        to acquire a passphrase with which to protect the key.
        The default is util.passphrase_callback.
        s   not such cipher %sN(   t   NoneR   t   ec_key_write_bio_no_cipherR   t   _ptrR   t
   ValueErrort   ec_key_write_bio(   R   t   biot   ciphert   callbackt   ciph(    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyt   save_key_bio¦   s    c         C   s%   t  j | d ƒ } |  j | | | ƒ S(   s+  
        Save the key pair to a file in PEM format.

        @type file: string
        @param file: Name of file to save key to.

        @type cipher: string
        @param cipher: Symmetric cipher to protect the key. The default
        cipher is 'aes_128_cbc'. If cipher is None, then the key is saved
        in the clear.

        @type callback: Python callable
        @param callback: A Python callable object that is invoked
        to acquire a passphrase with which to protect the key.
        The default is util.passphrase_callback.
        t   wb(   t   BIOt   openfileR+   (   R   t   fileR(   R)   R'   (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyt   save_key¿   s    c         C   s   t  j |  j | j ƒ  ƒ S(   s³   
        Save the public key to an M2Crypto.BIO.BIO object in PEM format.

        @type bio: M2Crypto.BIO.BIO
        @param bio: M2Crypto.BIO.BIO object to save key to.
        (   R   t   ec_key_write_pubkeyR   R$   (   R   R'   (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyt   save_pub_key_bioÓ   s    c         C   s+   t  j | d ƒ } t j |  j | j ƒ  ƒ S(   sŒ   
        Save the public key to a file in PEM format.

        @type file: string
        @param file: Name of file to save key to.
        R,   (   R-   R.   R   R1   R   R$   (   R   R/   R'   (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyt   save_pub_keyÜ   s    c         C   s   t  j |  j ƒ S(   N(   R   t   ec_key_type_checkR   (   R   (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyt   _check_key_typeæ   s    c         C   s   t  j |  j ƒ S(   N(   R   t   ec_key_check_keyR   (   R   (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyt	   check_keyé   s    (   R   R   t   __doc__R   t   ec_key_freeR	   R   R
   R   R   R   R   R   R   R   R    t   utilt   passphrase_callbackR+   R0   R2   R3   R5   R7   (    (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyR   a   s$   				
						
			
	R   c           B   s5   e  Z d  Z d d „ Z d „  Z e j Z e j Z	 RS(   sc   
    Object interface to an EC public key. 
    ((don't like this implementation inheritance))
    i    c         C   s    t  j |  | | ƒ d  |  _ d  S(   N(   R   R   R"   t   der(   R   R   R   (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyR   ô   s    c         C   s.   |  j  d k r' t j |  j ƒ |  _  n  |  j  S(   sJ   
        Returns the public key in DER format as a buffer object.
        N(   R<   R"   R   t   ec_key_get_public_derR   (   R   (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyt   get_derø   s    (
   R   R   R8   R   R>   R   R3   R0   R2   R+   (    (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyR   î   s
   			c         C   s   t  t j |  ƒ d ƒ S(   s«   
    Factory function that generates EC parameters and 
    instantiates a EC object from the output.

    @param curve: This is the OpenSSL nid of the curve to use. 
    i   (   R   R   t   ec_key_new_by_curve_name(   t   curve(    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyt
   gen_params  s    c         C   s   t  j |  ƒ } t | | ƒ S(   s  
    Factory function that instantiates a EC object.

    @param file: Names the file that contains the PEM representation 
    of the EC key pair.

    @param callback: Python callback object that will be invoked 
    if the EC key pair is passphrase-protected.
    (   R-   R.   t   load_key_bio(   R/   R)   R'   (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyt   load_key  s    
c         C   s   t  t j |  j ƒ  | ƒ d ƒ S(   s  
    Factory function that instantiates a EC object.

    @param bio: M2Crypto.BIO object that contains the PEM
    representation of the EC key pair. 

    @param callback: Python callback object that will be invoked 
    if the EC key pair is passphrase-protected.
    i   (   R   R   t   ec_key_read_bioR$   (   R'   R)   (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyRB     s    
c         C   s   t  j |  ƒ } t | ƒ S(   sÐ   
    Load an EC public key from file.

    @type file: string
    @param file: Name of file containing EC public key in PEM format.

    @rtype: M2Crypto.EC.EC_pub
    @return: M2Crypto.EC.EC_pub object.
    (   R-   R.   t   load_pub_key_bio(   R/   R'   (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyt   load_pub_key*  s    
c         C   s8   t  j |  j ƒ  ƒ } | d k r+ t ƒ  n  t | d ƒ S(   sý   
    Load an EC public key from an M2Crypto.BIO.BIO object.

    @type bio: M2Crypto.BIO.BIO
    @param bio: M2Crypto.BIO.BIO object containing EC public key in PEM
    format.

    @rtype: M2Crypto.EC.EC_pub
    @return: M2Crypto.EC.EC_pub object.
    i   N(   R   t   ec_key_read_pubkeyR$   R"   t   ec_errorR   (   R'   R   (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyRE   8  s    
c           C   s   t  t j t j ƒ  ƒ ‚ d  S(   N(   R    R   t   err_reason_error_stringt   err_get_error(    (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyRH   H  s    c         C   s   t  t j |  ƒ d ƒ S(   s!   
    Create EC_pub from DER.
    i   (   R   R   t   ec_key_from_pubkey_der(   R<   (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyt   pub_key_from_derK  s    (    (R   R8   R:   R-   R   t	   ExceptionR    t   ec_initt   NID_secp112r1t   NID_secp112r2t   NID_secp128r1t   NID_secp128r2t   NID_secp160k1t   NID_secp160r1t   NID_secp160r2t   NID_secp192k1t   NID_secp224k1t   NID_secp224r1t   NID_secp256k1t   NID_secp384r1t   NID_secp521r1t   NID_sect113r1t   NID_sect113r2t   NID_sect131r1t   NID_sect131r2t   NID_sect163k1t   NID_sect163r1t   NID_sect163r2t   NID_sect193r1t   NID_sect193r2t   NID_sect233k1t   NID_sect233r1t   NID_sect239k1t   NID_sect283k1t   NID_sect283r1t   NID_sect409k1t   NID_sect409r1t   NID_sect571k1t   NID_sect571r1t   NID_X9_62_prime192v1t   NID_X9_62_prime192v2t   NID_X9_62_prime192v3t   NID_X9_62_prime239v1t   NID_X9_62_prime239v2t   NID_X9_62_prime239v3t   NID_X9_62_prime256v1t   NID_X9_62_c2pnb163v1t   NID_X9_62_c2pnb163v2t   NID_X9_62_c2pnb163v3t   NID_X9_62_c2pnb176v1t   NID_X9_62_c2tnb191v1t   NID_X9_62_c2tnb191v2t   NID_X9_62_c2tnb191v3t   NID_X9_62_c2pnb208w1t   NID_X9_62_c2tnb239v1t   NID_X9_62_c2tnb239v2t   NID_X9_62_c2tnb239v3t   NID_X9_62_c2pnb272w1t   NID_X9_62_c2pnb304w1t   NID_X9_62_c2tnb359v1t   NID_X9_62_c2pnb368w1t   NID_X9_62_c2tnb431r1t   NID_wap_wsg_idm_ecid_wtls1t   NID_wap_wsg_idm_ecid_wtls3t   NID_wap_wsg_idm_ecid_wtls4t   NID_wap_wsg_idm_ecid_wtls5t   NID_wap_wsg_idm_ecid_wtls6t   NID_wap_wsg_idm_ecid_wtls7t   NID_wap_wsg_idm_ecid_wtls8t   NID_wap_wsg_idm_ecid_wtls9t   NID_wap_wsg_idm_ecid_wtls10t   NID_wap_wsg_idm_ecid_wtls11t   NID_wap_wsg_idm_ecid_wtls12R   R   RA   R;   RC   RB   RF   RE   RH   RL   (    (    (    s1   /usr/lib64/python2.7/site-packages/M2Crypto/EC.pyt   <module>	   sš   $																																																																		
			