AnonSec Shell
Server IP : 85.193.89.191  /  Your IP : 3.141.21.185
Web Server : Apache
System : Linux 956367-cx40159.tmweb.ru 3.10.0-1160.105.1.el7.x86_64 #1 SMP Thu Dec 7 15:39:45 UTC 2023 x86_64
User : bitrix ( 600)
PHP Version : 8.1.27
Disable Function : NONE
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python2.7/site-packages/keyczar/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /lib/python2.7/site-packages/keyczar/keys.pyc
�
N�Pc@s{dZddlZddlZddlZyddlmZWnek
r]ddlZnXddlm	Z	ddl
mZddl
mZyddl
ZWnek
r�ddlZnXyddlmZWnek
r�eZnXer�dnd	ZddlZddlZddlZddlZed
�Zd�Zdefd
��YZdefd��YZdefd��YZdefd��YZdefd��YZdefd��YZdefd��YZ defd��YZ!de fd��YZ"de fd��YZ#d e!fd!��YZ$d"e!fd#��YZ%d$efd%��YZ&d&efd'��YZ'dS((s�Represents cryptographic keys in Keyczar.

Identifies a key by its hash_id and type. Includes several subclasses
of base class Key.

@author: arkajit.dey@gmail.com (Arkajit Dey)
i����N(tsha1(tAES(tDSA(tRSA(tEVPtm2cryptotpycryptocCs�|dkr|j}n|j|�s=tjd|��nyFitjtj6t	jtj
6tjtj6t
jtj6||�SWnQtk
r�|tjks�|tjkr�d}nd}tj||��nXdS(s�
  Generates a key of the given key_type and length.

  @param key_type: the key_type of key to generate
  @key_type key_type: L{keyinfo.KeyType}

  @param size: the length in bits of the key to be generated
  @key_type size: integer

  @return: the generated key of the given key_type and size

  @raise KeyczarError: if key_type is a public key or unsupported or if key size
                       is unsupported.
  sUnsupported key size %d bits.s>Public keys of key_type %s must be exported from private keys.sUnsupported key key_type: %sN(tNonetdefault_sizetIsValidSizeterrorstKeyczarErrortAesKeytGeneratetkeyinfoRtHmacKeyt	HMAC_SHA1t
DsaPrivateKeytDSA_PRIVt
RsaPrivateKeytRSA_PRIVtKeyErrortDSA_PUBtRSA_PUB(tkey_typetsizetmsg((s0/usr/lib/python2.7/site-packages/keyczar/keys.pytGenKey<s


	cCs�y`itjtj6tjtj6tjtj6tjtj	6t
jtj6tjtj
6||�SWn$tk
r�tjd|��nXdS(s\
  Reads a key of the given key_type from a JSON string representation.

  @param key_type: the key_type of key to read
  @key_type key_type: L{keyinfo.KeyType}

  @param key: the JSON string representation of the key
  @key_type key: string

  @return: the key object read from the JSON string

  @raise KeyczarError: if key_type is unsupported
  sUnsupported key key_type: %sN(RtReadRRRRRRRRtDsaPublicKeyRtRsaPublicKeyRRR
R(Rtkey((s0/usr/lib/python2.7/site-packages/keyczar/keys.pytReadKey]s




tKeycBs�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	e
e	dd	�Ze
d
�edd�Ze
edd�Z
e
d
�dd�Zd�ZRS(sParent class for Keyczar Keys.cCs||_|jj|_dS(N(ttypeRt
_Key__size(tselfR((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyt__init__ys	cCs4|j|jko3|j|jko3|j|jkS(N(R"Rt
key_string(R$tother((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyt__eq__}scCs"|jj|�r||_ndS(N(R"R	R#(R$tnew_size((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyt	__SetSize�scCsdS(s,Return the key as a string. Abstract method.N((R$((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyt
_GetKeyString�scCs
|j�S(s#Indirect getter for the key string.(R+(R$((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyt__GetKeyString�scCs;tjtjt|j��|j�}tj|tj �S(sLCompute and return the hash_id id of this key. Can override default hash_id.(tutiltHasht
IntToBytestlent	key_bytestBase64WSEncodetkeyczart
KEY_HASH_SIZE(R$tfullhash((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyt_Hash�s'cCs
|j�S(sIndirect getter for hash_id.(R6(R$((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyt__Hash�stdocsThe hash_id id of the key.cCs|jS(N(R#(R$((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyt<lambda>�ssThe size of the key in bits.sThe key as a Base64 string.cCstj|j�S(N(R-tBase64WSDecodeR&(R$((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR9�ssThe key as bytes.cCsttj�tj|j�S(sGReturn the 5-byte header string including version byte, 4-byte hash_id.(tchrR3tVERSIONR-R:thash_id(R$((s0/usr/lib/python2.7/site-packages/keyczar/keys.pytHeader�s(t__name__t
__module__t__doc__R%R(t
_Key__SetSizeR+t_Key__GetKeyStringR6t
_Key__HashtpropertyR=RR&R1R>(((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR!us									tSymmetricKeycBs eZdZd�Zd�ZRS(s6Parent class for symmetric keys such as AES, HMAC-SHA1cCstj||�||_dS(N(R!R%t_SymmetricKey__key_string(R$RR&((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR%�scCs|jS(sReturn the key as a string.(RG(R$((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR+�s(R?R@RAR%R+(((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyRF�s	t
AsymmetricKeycBseZdZd�ZRS(s!Parent class for asymmetric keys.cCstj||�||_dS(N(R!R%t_params(R$Rtparams((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR%�s(R?R@RAR%(((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyRH�sRcBs�eZdZdefd��YZdefd��YZejjej	d�Z
d�Zd�Ze
ejjd��Ze
d	��Zd
�Zd�Zd�Zd
�Zd�Zejd�ZRS(s&Represents AES symmetric private keys.t
AESAdaptorcBs)eZdZd�Zd�Zd�ZRS(sd
    Adaptor class to make PyCrypto's Cipher behave the same as M2Crypto's
    EVP.Cipher class
    cCstj|||�|_dS(s%
      Constructor

      @param key_bytes: the key for this cipher
      @type key: string

      @param iv_bytes: the initialization vector for this cipher
      @type iv_bytes: string

      @param mode: the cipher mode
      @type mode: integer (using AES values, e.g. AES.MODE_CBC)
      N(Rtnewtcipher(R$R1tiv_bytestmode((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR%�s
cCst|j|�S(N(tgetattrRM(R$tname((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyt__getattr__�scCsdS(s�
      Collect any remaining encrypted data i.e. non-block size conforming

      @return: remaining encrypted data, if any
      t((R$((s0/usr/lib/python2.7/site-packages/keyczar/keys.pytfinal�s(R?R@RAR%RRRT(((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyRK�s		t
EVPAdaptorcBs_eZdZdZdZdZeeefZd�Zd�Zd�Z	d�Z
ed�ZRS(	sd
    Adaptor class to make M2Crypto's EVP.Cipher behave the same as PyCrypto's
    Cipher class
    i����iicCsCi|_||_||_||_tj|_t|�|_dS(s%
      Constructor

      @param key_bytes: the key for this cipher
      @type key: string

      @param iv_bytes: the initialization vector for this cipher
      @type iv_bytes: string

      @param mode: the cipher mode
      @type mode: integer (using AES values, e.g. AES.MODE_CBC)
      N(tciphersR1tIVRORt
block_sizeR0tkey_size(R$R1RNRO((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR%�s				c
Cs||jkstd|��||jkrtt|jj��dks_t|jj��rtdsttd��nd}||jkr�|jj�d}ni|jj|�}|sd|j	d}t
jd|d|jd	|j
d
|dd�}||j|<n|S(
s�
      Helper to get the cipher for this adaptor, creates if required

      @param selector: type of cipher required (active/encrypt/decrypt)
      @type selector: integer one of OP_TYPES

      @return: EVP.Cipher
      sInvalid selector :%siisIf both encryption and decryption used then selector must             be OP_ENCRYPT or OP_DECRYPT and at least 1 must be actives
aes_%s_cbcitalgRtivtoptpaddingN(tOP_TYPEStAssertionErrort	OP_ACTIVER0RVtkeysRtvaluestgetRYRtCipherR1RW(R$tselectorRMRO((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyt__Cipher�s$	*				cCs|j|j�j|�S(s�
      Return decrypted byte string

      @param string: bytes to be decrypted.
      @type string: string

      @return: plaintext string
      @rtype: string
      (t_EVPAdaptor__Ciphert
OP_DECRYPTtupdate(R$tstring((s0/usr/lib/python2.7/site-packages/keyczar/keys.pytdecrypt"s
cCs|j|j�j|�S(s�
      Return encrypted byte string

      @param string: plaintext to be encrypted.
      @type string: string

      @return: raw byte encrypted string  
      @rtype: string
      (Rgt
OP_ENCRYPTRi(R$Rj((s0/usr/lib/python2.7/site-packages/keyczar/keys.pytencrypt.s
cCs|j|�j�S(s�
      Collect any remaining encrypted data i.e. non-block size conforming

      @return: remaining encrypted data, if any
      (RgRT(R$Re((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyRT:s(R?R@RAR`RhRlR^R%RgRkRmRT(((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyRU�s		&		cCsbtj|tj|�||_tjdks4t�tj|_||_|tjks^t�dS(Ni(	RFR%RRthmac_keyRXR_RtCBC(R$R&RnRRO((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR%Bs		cCsJtjittj�d6|jd6|jd6tjt|j��d6�S(NRORtaesKeyStringthmacKey(	tjsontdumpststrRRoRR&tloadsRn(R$((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyt__str__Ns

cCsDtjtjt|j��|j|jj�}tj|tj �S(N(	R-R.R/R0R1RnR2R3R4(R$R5((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR6TscCs>tj|d�}tj|�}tj�}t|||�S(s�
    Return a newly generated AES key.

    @param size: length of key in bits to generate
    @type size: integer

    @return: an AES key
    @rtype: L{AesKey}
    i(R-t	RandBytesR2RR
R(RR1R&Rn((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR
ZscCsRtj|�}|d}t|dt|d|d�|dtj|d��S(s�
    Reads an AES key from a JSON string representation of it.

    @param key: a JSON representation of an AES key
    @type key: string

    @return: an AES key
    @rtype: L{AesKey}
    RqRpt
hmacKeyStringRRO(RrRuRRRtGetMode(Rtaesthmac_val((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyRjs


cCs,|jt|�|j}||t|�S(s
    Returns the data padded using PKCS5.

    For a block size B and data with N bytes in the last block, PKCS5
    pads the data with B-N bytes of the value B-N.

    @param data: data to be padded
    @type data: string

    @return: PKCS5 padded string
    @rtype: string
    (RXR0R;(R$tdatatpad((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyt_Pad{s
cCst|d�}|| S(s�
    Returns the unpadded version of a data padded using PKCS5.

    @param padded: string padded with PKCS5
    @type padded: string

    @return: original, unpadded string
    @rtype: string
    i����(tord(R$tpaddedR}((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyt_UnPad�s
cCs$|j||j}t||j�S(sj
    Return a buffer size that does not require padding that is closest to the
    requested buffer size. Minimum size is 1 block.

    Returns a multiple of the cipher block size so there is NO PADDING required 
    on any blocks of this size

    @param buffer_size: requested buffer size
    @type data: int

    @return: best buffer size
    @rtype: int
    (RXtmax(R$tbuffer_sizetno_pad_size((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyt_NoPadBufferSize�scCs�|j|�}tj|j�}|j|j|�}|j|�}||j�7}|j�||}|j	j
|�}||S(s�
    Return ciphertext byte string containing Header|IV|Ciph|Sig.

    @param data: plaintext to be encrypted.
    @type data: string

    @return: raw byte string ciphertext formatted to have Header|IV|Ciph|Sig.
    @rtype: string
    (R~R-RwRXt_AesKey__CreateCipherR1RmRTR>RntSign(R$R|RNRMt
ciph_bytest	msg_bytest	sig_bytes((s0/usr/lib/python2.7/site-packages/keyczar/keys.pytEncrypt�s
cCs�|tj}t|�|jtjkrAtjt|���n||j }||jtj!}|tj}|jj	|tj |�s�tj
��ntj|j
tj|�j|�}|j|�S(s�
    Decrypts the given ciphertext.

    @param input_bytes: raw byte string formatted as Header|IV|Ciph|Sig where
      Sig is the signature over the entire payload (Header|IV|Ciph).
    @type input_bytes: string

    @return: plaintext message
    @rtype: string

    @raise ShortCiphertextError: if the ciphertext is too short to have IV & Sig
    @raise InvalidSignatureError: if the signature doesn't correspond to payload
    (R3tHEADER_SIZER0RXR-tHLENR
tShortCiphertextErrorRntVerifytInvalidSignatureErrorRRLR1tMODE_CBCRkR�(R$tinput_bytest
data_bytesRNR�R�tplain((s0/usr/lib/python2.7/site-packages/keyczar/keys.pytDecrypt�s

$cCsBtj�dkr+tr+|j|||�S|j|||�SdS(s�
    Factory function for creating cipher of specified type using the active
    crypto library

    @param key_bytes: the key for this cipher
    @type key: string

    @param iv_bytes: the initialization vector for this cipher
    @type iv_bytes: string

    @param mode: the cipher mode
    @type mode: integer (using AES values, e.g. AES.MODE_CBC)

    @return: the cipher object
    RN(tACTIVE_CRYPT_LIBtlowerRRURK(R$R1RNRO((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyt__CreateCipher�s(R?R@RAtobjectRKRURRRRoR%RvR6tstaticmethodR
RR~R�R�R�R�R�R�(((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR�s #i					
			RcBs}eZdZejjd�Zd�Zd�Zd�Z	e
ejjd��Ze
d��Zd�Z
d�Zd	�ZRS(
s,Represents HMAC-SHA1 symmetric private keys.cCs#tj|tj|�||_dS(N(RFR%RRR(R$R&R((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR%�scCs!tji|jd6|jd6�S(NRRx(RrRsRR&(R$((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyRv�scCs&tj|j�}tj|tj �S(N(R-R.R1R2R3R4(R$R5((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR6�scCs
t|�S(s&Return a streaming version of this key(t
HmacKeyStream(R$((s0/usr/lib/python2.7/site-packages/keyczar/keys.pytCreateStreamable�scCs/tj|d�}tj|�}t||�S(s�
    Return a newly generated HMAC-SHA1 key.

    @param size: length of key in bits to generate
    @type size: integer

    @return: an HMAC-SHA1 key
    @rtype: L{HmacKey}
    i(R-RwR2R(RR1R&((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR
scCs$tj|�}t|d|d�S(s�
    Reads an HMAC-SHA1 key from a JSON string representation of it.

    @param key: a JSON representation of an HMAC-SHA1 key
    @type key: string

    @return: an HMAC-SHA1 key
    @rtype: L{HmacKey}
    RxR(RrRuR(Rtmac((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyRscCstj|j|t�j�S(s�
    Return raw byte string of signature on the message.

    @param msg: message to be signed
    @type msg: string

    @return: raw byte string signature
    @rtype: string
    (thmacRLR1Rtdigest(R$R((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR�s
cCs|j|j|�|�S(s-
    Return True if the signature corresponds to the message.

    @param msg: message to be signed
    @type msg: string

    @param sig_bytes: raw byte string of the signature
    @type sig_bytes: string

    @return: True if signature is valid for message. False otherwise.
    @rtype: boolean
    (tVerifySignedDataR�(R$RR�((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR�*s
cCsft|�t|�krtSd}x7t||�D]&\}}|t|�t|�AO}q2W|dkS(s;
    Return True if the signature corresponds to the signed message

    @param msg: message that has been signed
    @type msg: string

    @param sig_bytes: raw byte string of the signature
    @type sig_bytes: string

    @return: True if signature is valid for message. False otherwise.
    @rtype: boolean
    i(R0tFalsetzipR(R$t	mac_bytesR�tresulttxty((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR�9s
(R?R@RARRRR%RvR6R�R�R
RR�R�R�(((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR�s					R�cBs)eZdZd�Zd�Zd�ZRS(s7Represents streamable HMAC-SHA1 symmetric private keys.cCs+||_tj|jjdt�|_dS(NRS(RnR�RLR1R(R$Rn((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR%Ps	cCs|jj|�dS(N(R�Ri(R$R|((s0/usr/lib/python2.7/site-packages/keyczar/keys.pytUpdateTscCs
|jj�S(s�
    Return raw byte string of signature on the streamed message.

    @return: raw byte string signature
    @rtype: string
    (R�R�(R$((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR�Ws(R?R@RAR%R�R�(((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR�Ms		t
PrivateKeycBs eZdZd�Zd�ZRS(s<Represents private keys in Keyczar for asymmetric key pairs.cCs tj|||�||_dS(N(RHR%t
public_key(R$RRJtpub((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR%dscCs
|jjS(N(R�R=(R$((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR6hs(R?R@RAR%R6(((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR�as	t	PublicKeycBseZdZd�ZRS(s;Represents public keys in Keyczar for asymmetric key pairs.cCstj|||�dS(N(RHR%(R$RRJ((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR%ns(R?R@RAR%(((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR�ksRcBsbeZdZejjd�Zd�Zeejjd��Z	ed��Z
d�Zd�ZRS(s:Represents DSA private keys in an asymmetric DSA key pair.cCsAtj|tj||�||_||_||_||_dS(N(R�R%RRRR�RJR(R$RJR�RR((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR%ts
			cCsGtjitjt|j��d6tj|jd�d6|jd6�S(Nt	publicKeyR�R(	RrRsRuRtR�R-R2RJR(R$((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyRv|s"cCs�tj|tj�}itjtj|j�d�d6}|j�}itjtj|j�d�d6tjtj|j	�d�d6tjtj|j
�d�d6tjtj|j�d�d6}t|||�}t
||||�S(s�
    Return a newly generated DSA private key.

    @param size: length of key in bits to generate
    @type size: integer

    @return: a DSA private key
    @rtype: L{DsaPrivateKey}
    iR�tgtptqR�(RtgenerateR-RwtPadBytest
BigIntToBytesR�t	publickeyR�R�R�R�RR(RRRJtpubkeyt
pub_paramsR�((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR
�s%""cCs�tj|�}tjtj|d��}itj|d�d6}tjtj	|j
d�tj	|j
d�tj	|j
d�tj	|j
d�tj	|d�f�}t||||d�S(s�
    Reads a DSA private key from a JSON string representation of it.

    @param key: a JSON representation of a DSA private key
    @type key: string

    @return: an DSA private key
    @rtype: L{DsaPrivateKey}
    R�R�R�R�R�R�R(RrRuRRRsR-R:Rt	constructtBytesToLongRIR(RtdsaR�RJ((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR�scCsVtj�jd|jjd�}|jjtj|�|�\}}tj||�S(s�
    Return raw byte string of signature on the message.

    @param msg: message to be signed
    @type msg: string

    @return: byte string formatted as an ASN.1 sequnce of r and s
    @rtype: string
    ii(	trandomtSystemRandomtrandintRR�tsignR-R.t
MakeDsaSig(R$Rtktrts((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR��s"$cCs|jj||�S(s@see: L{DsaPublicKey.Verify}(R�R�(R$Rtsig((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR��s(
R?R@RARRRR%RvR�R
RR�R�(((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyRqs		RcBs�eZdZejjd�Zdd�Zd�Ze	ejjd��Z
e	d��Zd�Zd�Z
d	�Zd
�ZRS(s:Represents RSA private keys in an asymmetric RSA key pair.cCsAtj|tj||�||_||_||_||_dS(N(R�R%RRRR�RJR(R$RJR�RR((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR%�s
			RScCs�t|�dkr.tjdt|���nt|�dtjdkrgtjdt|���nttjtj|j	j
d��d�}|t|�}|dkr�d|d|}n|tj }|tj}tj|tj�}tj||�}tj|t|��}	tj||	�}
|
tj }tj
|�}||krhtjd��n|
tjjd�}
|
d	d
kr�tjd��n|
dS(
Nii=s+OAEP Decoding Error - label is too large %ds6OAEP Decoding Error - encoded_message is too small: %diits(OAEP Decoding Error - hash_id is invalidiss(OAEP Decoding Error - expected a 1 valueI (R0R
RR-R�tinttmathtfloortlogRtntMGFtXorR.tlstrip(R$tencoded_messagetlabelR�tdiff_lentmasked_seedtmasked_datablockt	seed_masktseedtdatablock_maskt	datablockt
label_hashtexpected_label_hashtdelimited_message((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyt__Decode�s.+


cCs�tjitjt|j��d6tj|jd�d6tj|jd�d6tj|jd�d6tj|jd�d6tj|jd�d6tj|jd�d6|jd6�S(	NR�tprivateExponenttprimePtprimeQtprimeExponentPtprimeExponentQtcrtCoefficientR(	RrRsRuRtR�R-R2RJR(R$((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyRv�s	cCs`tj|tj�}itjtj|j�d�d6tjtj|j�d�d6tjtj|j�d�d6tjtj|j|jd�d�d6tjtj|j|jd�d�d6tjtj|j	�d�d6}|j
�}itjtj|j�d�d6tjtj|j�d�d	6}t
|||�}t||||�S(
s�
    Return a newly generated RSA private key.

    @param size: length of key in bits to generate
    @type size: integer

    @return: a RSA private key
    @rtype: L{RsaPrivateKey}
    iR�R�R�R�R�R�tmodulustpublicExponent(RR�R-RwR�R�tdR�R�tuR�R�teRR(RRRJR�R�R�((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR
�s"**"""c	Cs5tj|�}tjtj|d��}itj|d�d6tj|d�d6tj|d�d6tj|d�d6tj|d�d6tj|d�d6}tjtj	|j
d�tj	|j
d	�tj	|d�tj	|d�tj	|d�tj	|d�f�}t||||d
�S(s�
    Reads a RSA private key from a JSON string representation of it.

    @param key: a JSON representation of a RSA private key
    @type key: string

    @return: a RSA private key
    @rtype: L{RsaPrivateKey}
    R�R�R�R�R�R�R�R�R�R(RrRuRRRsR-R:RR�R�RJR(RtrsaR�RJ((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyRscCs|jj|�S(s@see: L{RsaPublicKey.Encrypt}(R�R�(R$R|((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR�7scCs,|tj}|jj|�}|j|�S(s�
    Decrypts the given ciphertext.

    @param input_bytes: raw byte string formatted as Header|Ciphertext.
    @type input_bytes: string

    @return: plaintext message
    @rtype: string
    (R3R�RRkt_RsaPrivateKey__Decode(R$R�R�t	decrypted((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR�;s

cCs5tj||j�}tj|jj|d�d�S(s�
    Return raw byte string of signature on the SHA-1 hash_id of the message.

    @param msg: message to be signed
    @type msg: string

    @return: string representation of long int signature over message
    @rtype: string
    iN(R-tMakeEmsaMessageRR�RR�R(R$Rtemsa_encoded((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR�Is
cCs|jj||�S(s@see: L{RsaPublicKey.Verify}(R�R�(R$RR�((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR�Vs(R?R@RARRRR%R�RvR�R
RR�R�R�R�(((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR�s)				
RcBsJeZdZejjd�Zd�Zd�Ze	d��Z
d�ZRS(s9Represents DSA public keys in an asymmetric DSA key pair.cCs5tj|tj|�||_||_||_dS(N(R�R%RRRRJR(R$RJRR((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR%^s		cCsstjitj|jd�d6tj|jd�d6tj|jd�d6tj|jd�d6|jd6�S(NR�R�R�R�R(RrRsR-R2RJR(R$((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyRvds
 cCsltjtj|jd�tj|jd�tj|jd�tj|jd��}tj|tj �S(NR�R�R�R�(R-t
PrefixHasht	TrimBytesRIR2R3R4(R$R5((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR6ks
cCs�tj|�}itj|d�d6tj|d�d6tj|d�d6tj|d�d6}tjtj|d�tj|d�tj|d�tj|d�f�}t|||d�S(s�
    Reads a DSA public key from a JSON string representation of it.

    @param key: a JSON representation of a DSA public key
    @type key: string

    @return: a DSA public key
    @rtype: L{DsaPublicKey}
    R�R�R�R�R(RrRuR-R:RR�R�R(RR�RJR�((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyRrscCsWy;tj|�\}}|jjtj|�||f�SWntjk
rRtSXdS(sY
    Return True if the signature corresponds to the message.

    @param msg: message that has been signed
    @type msg: string

    @param sig: raw byte string of the signature formatted as an ASN.1 sequence
      of r and s
    @type sig: string

    @return: True if signature is valid for message. False otherwise.
    @rtype: boolean
    N(R-tParseDsaSigRtverifyR.R
RR�(R$RR�R�R�((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR��s
&(R?R@RARRRR%RvR6R�RR�(((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyRZs		RcBs_eZdZejjd�Zdd�Zd�Zd�Z	e
d��Zd�Zd�Z
RS(	s9Represents RSA public keys in an asymmetric RSA key pair.cCs5tj|tj|�||_||_||_dS(N(R�R%RRRRJR(R$RJRR((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR%�s		RScCsbt|�dkr$tjd��nttjtj|jjd��d�}t|�|dt	j
dkr�tjd��nt	j|�}|t|�dt	j
d}|dkr�tjdt|���n|d	|d
|}t	jt	j
�}t	j
||t	j
d�}t	j||�}	t	j
|	t	j
�}
t	j||
�}d	||	S(Nii=sOAEP parameter string too long.iis Message too long to OAEP encode.isMessage is too long: %dR�sI (R0R
RR�R�R�R�RR�R-R�R.RwR�R�(R$RR�R�R�t
pad_octetsR�R�R�R�R�R�((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyt__Encode�s +!cCsEtjitj|jd�d6tj|jd�d6|jd6�S(NR�R�R(RrRsR-R2RJR(R$((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyRv�scCsFtjtj|jd�tj|jd��}tj|tj �S(NR�R�(R-R�R�RIR2R3R4(R$R5((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR6�scCs�tj|�}itj|d�d6tj|d�d6}tjtj|d�tj|d�f�}t|||d�S(s�
    Reads a RSA public key from a JSON string representation of it.

    @param key: a JSON representation of a RSA public key
    @type key: string

    @return: a RSA public key
    @rtype: L{RsaPublicKey}
    R�R�R(RrRuR-R:RR�R�R(RR�RJR�((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR�scCs6|j|�}|jj|d�d}|j�|S(s�
    Return a raw byte string of the ciphertext in the form Header|Ciph.

    @param data: message to be encrypted
    @type data: string

    @return: ciphertext formatted as Header|Ciph
    @rtype: string
    iN(t_RsaPublicKey__EncodeRRmRR>(R$R|R�((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR��s
cCsKy2|jjtj||j�tj|�f�SWntk
rFtSXdS(s@
    Return True if the signature corresponds to the message.

    @param msg: message that has been signed
    @type msg: string

    @param sig: string representation of long int signature
    @type sig: string

    @return: True if signature is valid for the message hash_id. False otherwise.
    @rtype: boolean
    N(RR�R-R�RR�t
ValueErrorR�(R$RR�((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR��s
2
(R?R@RARRRR%R�RvR6R�RR�R�(((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR�s			tEncryptingStreamWritercBsGeZdZd�Zd�Zd�Zd�Zed�Zd�Z	RS(sh
  An encrypting stream capable of creating a ciphertext byte stream
  containing Header|IV|Ciph|Sig.
  cCs�||_||_d|_t|_|jj�|_tj	|j
�}tj|j
tj|�|_|j�}|jj||�|jj||�dS(s�
    Constructor

    @param key: Keyczar Key to perform the padding, verification, cipher
    creation needed by this stream
    @type key: Key

    @param output_stream: stream for encrypted output
    @type output_stream: 'file-like' object
    RSN(t_EncryptingStreamWriter__keyt&_EncryptingStreamWriter__output_streamt_EncryptingStreamWriter__dataR�t_EncryptingStreamWriter__closedRnR�t$_EncryptingStreamWriter__hmac_streamR-RwRXRRLR1R�t_EncryptingStreamWriter__cipherR>R�twrite(R$Rt
output_streamRNthdr((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR%s				cCs}|jd�|j|7_|jjt|j��}t|j�|krc|j|j| �nd}|j||_dS(s~
    Write the data in encrypted form to the output stream

    @param data: data to be encrypted.
    @type data: string
    R�iN(t"_EncryptingStreamWriter__CheckOpenR�R�R�R0t'_EncryptingStreamWriter__WriteEncrypted(R$R|tencrypt_buffer_size((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR�s
cCsM|jd�|j|jdt�|jj|jj��|jj�dS(s�
    Flush this stream. 
    Writes all remaining encrypted data to the output stream.
    Will also flush the associated output stream.
    tflushR}N(	R�R�R�tTrueR�R�R�R�R�(R$((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR�.s
cCs|jd�t|_dS(sw
    Close this stream. 
    Discards any and all buffered data
    Does *not* close the associated output stream.
    tcloseN(R�R�R�(R$((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR�9s
cCsQ|r|jj|�}n|jj|�}|jj|�|jj|�dS(s�
    Helper to write encrypted bytes to output stream.
    Must *only* pad the last block as PKCS5 *always* pads, even when the data
    length is a multiple of the block size - it adds block_size chars.
    We cannot pad intermediate blocks as there is no guarantee that a streaming
    read will receive the data in the same blocks as the writes were made.

    @param data: data to be written.
    @type data: string

    @param pad: add padding to data
    @type pad: boolean
    N(R�R~R�RmR�R�R�R�(R$R|R}tencrypted_bytes((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyt__WriteEncryptedBs
cCs |jrtd|��ndS(s$Helper to ensure this stream is opens(%s() on a closed stream is not permittedN(R�R�(R$t	operation((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyt__CheckOpenWs	(
R?R@RAR%R�R�R�R�R�R�(((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR��s					tDecryptingStreamReadercBsYeZdZejd�Zdd�Zd�Zd�Ze	d�Z
d�Zd�ZRS(	su
  A stream capable of decrypting a source ciphertext byte stream
  containing Header|IV|Ciph|Sig into plain text.
  cCsL||_||_||_d|_d|_d|_d|_t|_	dS(s�
    Constructor

    @param key_set: Keyczar key set to source key specified in message header
    @type key: Keyczar

    @param input_stream: source of encrypted input
    @type input_stream: 'file-like' object

    @param buffer_size: Suggested buffer size for reading data (will be 
    adjusted to suit the underlying cipher). 
    Use -1 to read as much data as possible from the source stream
    @type buffer_size: integer
    RSN(
t _DecryptingStreamReader__key_sett%_DecryptingStreamReader__input_streamt$_DecryptingStreamReader__buffer_sizeRt_DecryptingStreamReader__keyt_DecryptingStreamReader__ciphert)_DecryptingStreamReader__encrypted_buffert)_DecryptingStreamReader__decrypted_bufferR�t_DecryptingStreamReader__closed(R$tkey_settinput_streamR�((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR%bs							i����c
Cs�|jd�t}|js+|j�}n|rS|jrS|jrS|j�}n|r+|jr+|jr+d}t}x�|r8|j|jjdt�\}}|r�|j	|7_	nt
j}|r�||jj7}n|j	| }|rt|�|jj}nd}|r"|| }n|}|o2|}qzW|r+|j
j|�|j	t|�|_	|jj|�}	|s�|jj|	�}	n|j|	7_|s(t|j	�t
jkr�tjt|j	���n|j
j�}
|j	}d|_	|jjj|
|�s%tj��q%q(q+n|dkrL|j}d|_n|j| }|j||_|r|rd}n|S(s 
    Decrypts data from the source stream and returns the resulting plaintext.
    NOTE: the signature validation is performed on the final read if sufficient
    data is available. Streaming => it isn't possible to validate up front as
    done by Decrypt().

    @param chars: indicates the number of characters to read from the stream.
    read() will never return more than chars characters, but it might return
    less, if there are not enough characters available.
    @type chars: integer

    @raise ShortCiphertextError: if the ciphertext is too short to have IV & Sig
    @raise InvalidSignatureError: if the signature doesn't correspond to payload
    @raise KeyNotFoundError: if key specified in header doesn't exist
    @raise ValueError: if stream closed
    treadRStblockiN(t"_DecryptingStreamReader__CheckOpenR�Rt"_DecryptingStreamReader__CreateKeyR	t%_DecryptingStreamReader__CreateCiphert"_DecryptingStreamReader__ReadBytesRXR�R
R-R�R0t$_DecryptingStreamReader__hmac_streamR�RkR�RR
R�R�RnR�R�R(
R$tcharst
is_data_availtdata_to_decrypttneed_more_datat
read_bytestreserved_data_lentavailable_datatno_decrypt_lentdecrypted_datatcurrent_sig_bytest
msg_sig_bytesR�((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR{sb
							

	cCs
t|_dS(s�
    Close this stream. 
    Assumes all data has been read or is thrown away as no signature validation
    is done until all the data is read.
    N(R�R(R$((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR��scCs |jrtd|��ndS(s$Helper to ensure this stream is opens(%s() on a closed stream is not permittedN(RR�(R$R((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR�s	cCs�t}d}xg|ru|jj|�}|r:||7}n&|dk	rP|tfS|s`|tfSt|�|k}qW|tfS(s�
    Helper to read bytes from the input stream. If requested will block until
    required number of bytes is read or input data is exhausted.  Returns a
    tuple of (the data bytes read, is more data available).
    RSN(R�RRRR�R0(R$RRRR�R((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyt__ReadBytes�s	


cCs�t}|js�|jtjt|j��\}}|rL|j|7_nt|j�tjkr�|jtj }|jtj|_|jj|�|_|jj	j
�|_|jj|�|j
dkr�|jj|j
�|_
q�q�n|S(s5
    Helper to create the actual key from the Header
    NOTE: The key determines what the optimal read buffer size will be. It is a
    size that does not require any padding to allow allow encrypting without
    using a stream anddecrypting with a stream 
    i.e. Encrypt() => DecryptingStreamReader()
    i(R�RRR3R�R0R
Rt_ParseHeaderRnR�RR�RR�(R$RRt	hdr_bytes((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyt__CreateKey�s	!cCs�t}|js�|jj}|t|j�}|j|�\}}|r[|j|7_nt|j�|kr�|j| }|j||_|jj|�t	j
|jjt	j|�|_q�n|S(sC
    Helper to create the cipher using the IV from the message
    (
R�R	RRXR0R
RRR�RRLR1R�(R$Rtreqd_block_sizetnew_bytes_reqdRRN((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR�	s	

'(
R?R@RAR-tDEFAULT_STREAM_BUFF_SIZER%RR�RR�RRR(((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyR\sS			((RAR�R�R�thashlibRtImportErrortshat
Crypto.CipherRtCrypto.PublicKeyRRt
simplejsonRrtM2CryptoRRR�R
R3RR-RR R�R!RFRHRRR�R�R�RRRRR�R(((s0/usr/lib/python2.7/site-packages/keyczar/keys.pyt<module>sP



!	,�=^
O�D`^

Anon7 - 2022
AnonSec Team