3 lá˜_ã@sòddlmZmZmZddlZddlZddlmZddlm Z ddd„Z Gdd„de ƒZ Gd d „d e ƒZ Gd d „d e ƒZejejƒGd d„de ƒƒZeZejejƒGdd„de ƒƒZejejƒGdd„deƒƒZejejƒGdd„de ƒƒZeZdS)é)Úabsolute_importÚdivisionÚprint_functionN)Úutils)Ú _get_backendcCst|ƒ}|j||ƒS)N)rZgenerate_dh_parameters)Ú generatorÚkey_sizeÚbackend©r ú/usr/lib64/python3.6/dh.pyÚgenerate_parameterssr c@sBeZdZdd„Zdd„Zdd„Zd dd „Zejd ƒZ ejd ƒZ dS) ÚDHPrivateNumberscCs6t|tjƒstdƒ‚t|tƒs&tdƒ‚||_||_dS)Nzx must be an integer.z6public_numbers must be an instance of DHPublicNumbers.)Ú isinstanceÚsixÚ integer_typesÚ TypeErrorÚDHPublicNumbersÚ_xÚ_public_numbers)ÚselfÚxÚpublic_numbersr r r Ú__init__s  zDHPrivateNumbers.__init__cCs&t|tƒstS|j|jko$|j|jkS)N)rr ÚNotImplementedrr)rÚotherr r r Ú__eq__!s  zDHPrivateNumbers.__eq__cCs ||k S)Nr )rrr r r Ú__ne__*szDHPrivateNumbers.__ne__NcCst|ƒ}|j|ƒS)N)rZload_dh_private_numbers)rr r r r Ú private_key-szDHPrivateNumbers.private_keyrr)N) Ú__name__Ú __module__Ú __qualname__rrrrrÚread_only_propertyrrr r r r r s     r c@sBeZdZdd„Zdd„Zdd„Zd dd „Zejd ƒZ ejd ƒZ dS) rcCs6t|tjƒstdƒ‚t|tƒs&tdƒ‚||_||_dS)Nzy must be an integer.z5parameters must be an instance of DHParameterNumbers.)rrrrÚDHParameterNumbersÚ_yÚ_parameter_numbers)rÚyÚparameter_numbersr r r r6s  zDHPublicNumbers.__init__cCs&t|tƒstS|j|jko$|j|jkS)N)rrrr#r$)rrr r r rBs  zDHPublicNumbers.__eq__cCs ||k S)Nr )rrr r r rKszDHPublicNumbers.__ne__NcCst|ƒ}|j|ƒS)N)rZload_dh_public_numbers)rr r r r Ú public_keyNszDHPublicNumbers.public_keyr#r$)N) rrr rrrr'rr!r%r&r r r r r5s     rc@sNeZdZd dd„Zdd„Zdd„Zddd „Zejd ƒZ ejd ƒZ ejd ƒZ dS)r"NcCsht|tjƒ st|tjƒ r$tdƒ‚|dk rBt|tjƒ rBtdƒ‚|dkrRtdƒ‚||_||_||_dS)Nzp and g must be integerszq must be integer or Noneéz!DH generator must be 2 or greater)rrrrÚ ValueErrorÚ_pÚ_gÚ_q)rÚpÚgÚqr r r rWs zDHParameterNumbers.__init__cCs2t|tƒstS|j|jko0|j|jko0|j|jkS)N)rr"rr*r+r,)rrr r r rfs zDHParameterNumbers.__eq__cCs ||k S)Nr )rrr r r rnszDHParameterNumbers.__ne__cCst|ƒ}|j|ƒS)N)rZload_dh_parameter_numbers)rr r r r Ú parametersqszDHParameterNumbers.parametersr*r+r,)N)N) rrr rrrr0rr!r-r.r/r r r r r"Vs    r"c@s6eZdZejdd„ƒZejdd„ƒZejdd„ƒZdS)Ú DHParameterscCsdS)z7 Generates and returns a DHPrivateKey. Nr )rr r r Úgenerate_private_key|sz!DHParameters.generate_private_keycCsdS)z= Returns the parameters serialized as bytes. Nr )rÚencodingÚformatr r r Úparameter_bytes‚szDHParameters.parameter_bytescCsdS)z/ Returns a DHParameterNumbers. Nr )rr r r r&ˆszDHParameters.parameter_numbersN)rrr ÚabcÚabstractmethodr2r5r&r r r r r1zsr1c@sDeZdZejdd„ƒZejdd„ƒZejdd„ƒZejdd„ƒZ d S) Ú DHPrivateKeycCsdS)z6 The bit length of the prime modulus. Nr )rr r r r”szDHPrivateKey.key_sizecCsdS)zC The DHPublicKey associated with this private key. Nr )rr r r r'šszDHPrivateKey.public_keycCsdS)zK The DHParameters object associated with this private key. Nr )rr r r r0 szDHPrivateKey.parameterscCsdS)zn Given peer's DHPublicKey, carry out the key exchange and return shared key as bytes. Nr )rZpeer_public_keyr r r Úexchange¦szDHPrivateKey.exchangeN) rrr r6Úabstractpropertyrr7r'r0r9r r r r r8’sr8c@s(eZdZejdd„ƒZejdd„ƒZdS)ÚDHPrivateKeyWithSerializationcCsdS)z- Returns a DHPrivateNumbers. Nr )rr r r Úprivate_numbers°sz-DHPrivateKeyWithSerialization.private_numberscCsdS)z6 Returns the key serialized as bytes. Nr )rr3r4Zencryption_algorithmr r r Ú private_bytes¶sz+DHPrivateKeyWithSerialization.private_bytesN)rrr r6r7r<r=r r r r r;®sr;c@sDeZdZejdd„ƒZejdd„ƒZejdd„ƒZejdd„ƒZ d S) Ú DHPublicKeycCsdS)z6 The bit length of the prime modulus. Nr )rr r r r¿szDHPublicKey.key_sizecCsdS)zJ The DHParameters object associated with this public key. Nr )rr r r r0ÅszDHPublicKey.parameterscCsdS)z, Returns a DHPublicNumbers. Nr )rr r r rËszDHPublicKey.public_numberscCsdS)z6 Returns the key serialized as bytes. Nr )rr3r4r r r Ú public_bytesÑszDHPublicKey.public_bytesN) rrr r6r:rr7r0rr?r r r r r>½sr>)N)Z __future__rrrr6rZ cryptographyrZcryptography.hazmat.backendsrr Úobjectr rr"Z add_metaclassÚABCMetar1ZDHParametersWithSerializationr8r;r>ZDHPublicKeyWithSerializationr r r r Ús$   !!$