3 L]5&@sddlmZmZmZddlZddlZddlZddlmZddl m Z Gddde Z ej ejGddde Zej ejGd d d e Zej ejGd d d e Zej ejGd ddeZej ejGddde ZeZejeGddde ZejeGddde ZejeGddde ZejeGddde ZejeGddde ZejeGddde ZejeGddde ZejeGdd d e ZejeGd!d"d"e ZejeGd#d$d$e ZejeGd%d&d&e Z ejeGd'd(d(e Z!ejeGd)d*d*e Z"ejeGd+d,d,e Z#ejeGd-d.d.e Z$ejeGd/d0d0e Z%ejeGd1d2d2e Z&ejeGd3d4d4e Z'ejeGd5d6d6e Z(e%e"e%e$e"e!e e#eeeeeeeeeee&e'e(d7Z)ejeGd8d9d9e Z*d:d;Z+dd?d?e Z-Gd@dAdAe Z.GdBdCdCe Z/e j%e%e j$e$e j#e#e j"e"e j!e!e j e e j0e&e j1e'e j2e(e jee jee jee jee jee jee jee jee jee jeiZ3dDdEZ4dS)F)absolute_importdivisionprint_functionN)utils)ObjectIdentifierc@seZdZedZedZedZedZedZedZ edZ edZ ed Z ed Z ed Zed Zed ZedZedZedZedZedZedZdS)EllipticCurveOIDz1.2.840.10045.3.1.1z 1.3.132.0.33z 1.3.132.0.10z1.2.840.10045.3.1.7z 1.3.132.0.34z 1.3.132.0.35z1.3.36.3.3.2.8.1.1.7z1.3.36.3.3.2.8.1.1.11z1.3.36.3.3.2.8.1.1.13z 1.3.132.0.1z 1.3.132.0.15z 1.3.132.0.26z 1.3.132.0.27z 1.3.132.0.16z 1.3.132.0.17z 1.3.132.0.36z 1.3.132.0.37z 1.3.132.0.38z 1.3.132.0.39N)__name__ __module__ __qualname__r SECP192R1 SECP224R1 SECP256K1 SECP256R1 SECP384R1 SECP521R1BRAINPOOLP256R1BRAINPOOLP384R1BRAINPOOLP512R1 SECT163K1 SECT163R2 SECT233K1 SECT233R1 SECT283K1 SECT283R1 SECT409K1 SECT409R1 SECT571K1 SECT571R1rrV/tmp/pip-install-wfra5znf/cryptography/cryptography/hazmat/primitives/asymmetric/ec.pyrs&rc@s(eZdZejddZejddZdS) EllipticCurvecCsdS)z8 The name of the curve. e.g. secp256r1. Nr)selfrrrname(szEllipticCurve.namecCsdS)z< Bit size of a secret scalar for the curve. Nr)r!rrrkey_size.szEllipticCurve.key_sizeN)rr r abcabstractpropertyr"r#rrrrr &sr c@seZdZejddZdS)EllipticCurveSignatureAlgorithmcCsdS)z@ The digest algorithm used with this signature. Nr)r!rrr algorithm7sz)EllipticCurveSignatureAlgorithm.algorithmN)rr r r$r%r'rrrrr&5sr&c@s`eZdZejddZejddZejddZejddZ ejd d Z ejd d Z d S)EllipticCurvePrivateKeycCsdS)zN Returns an AsymmetricSignatureContext used for signing data. Nr)r!signature_algorithmrrrsigner@szEllipticCurvePrivateKey.signercCsdS)z} Performs a key exchange operation using the provided algorithm with the provided peer's public key. Nr)r!r'Zpeer_public_keyrrrexchangeFsz EllipticCurvePrivateKey.exchangecCsdS)zB The EllipticCurvePublicKey for this private key. Nr)r!rrr public_keyMsz"EllipticCurvePrivateKey.public_keycCsdS)z8 The EllipticCurve that this key is on. Nr)r!rrrcurveSszEllipticCurvePrivateKey.curvecCsdS)z< Bit size of a secret scalar for the curve. Nr)r!rrrr#Ysz EllipticCurvePrivateKey.key_sizecCsdS)z Signs the data Nr)r!datar)rrrsign_szEllipticCurvePrivateKey.signN) rr r r$abstractmethodr*r+r,r%r-r#r/rrrrr(>s r(c@s(eZdZejddZejddZdS)(EllipticCurvePrivateKeyWithSerializationcCsdS)z9 Returns an EllipticCurvePrivateNumbers. Nr)r!rrrprivate_numbershsz8EllipticCurvePrivateKeyWithSerialization.private_numberscCsdS)z6 Returns the key serialized as bytes. Nr)r!encodingformatZencryption_algorithmrrr private_bytesnsz6EllipticCurvePrivateKeyWithSerialization.private_bytesN)rr r r$r0r2r5rrrrr1fsr1c@sleZdZejddZejddZejddZejddZ ejd d Z ejd d Z e d dZ dS)EllipticCurvePublicKeycCsdS)zQ Returns an AsymmetricVerificationContext used for signing data. Nr)r! signaturer)rrrverifierwszEllipticCurvePublicKey.verifiercCsdS)z8 The EllipticCurve that this key is on. Nr)r!rrrr-}szEllipticCurvePublicKey.curvecCsdS)z< Bit size of a secret scalar for the curve. Nr)r!rrrr#szEllipticCurvePublicKey.key_sizecCsdS)z8 Returns an EllipticCurvePublicNumbers. Nr)r!rrrpublic_numberssz%EllipticCurvePublicKey.public_numberscCsdS)z6 Returns the key serialized as bytes. Nr)r!r3r4rrr public_bytessz#EllipticCurvePublicKey.public_bytescCsdS)z5 Verifies the signature of the data. Nr)r!r7r.r)rrrverifyszEllipticCurvePublicKey.verifycCsbtjd|t|tstdt|dkr2tdtj|dd krJtddd l m }|j ||S) Nr.z'curve must be an EllipticCurve instancerz%data must not be an empty byte stringz%Unsupported elliptic curve point type)backend)r<r=r>) r _check_bytes isinstancer TypeErrorlen ValueErrorsix indexbytesZ,cryptography.hazmat.backends.openssl.backendr?Z load_elliptic_curve_public_bytes)clsr-r.r?rrrfrom_encoded_points    z)EllipticCurvePublicKey.from_encoded_pointN)rr r r$r0r8r%r-r#r9r:r; classmethodrHrrrrr6usr6c@seZdZdZdZdS)r sect571r1i:N)rr r r"r#rrrrrsrc@seZdZdZdZdS)r sect409r1iN)rr r r"r#rrrrrsrc@seZdZdZdZdS)r sect283r1iN)rr r r"r#rrrrrsrc@seZdZdZdZdS)r sect233r1N)rr r r"r#rrrrrsrc@seZdZdZdZdS)r sect163r2N)rr r r"r#rrrrrsrc@seZdZdZdZdS)r sect571k1i;N)rr r r"r#rrrrrsrc@seZdZdZdZdS)r sect409k1iN)rr r r"r#rrrrrsrc@seZdZdZdZdS)r sect283k1iN)rr r r"r#rrrrrsrc@seZdZdZdZdS)r sect233k1rNN)rr r r"r#rrrrrsrc@seZdZdZdZdS)r sect163k1rPN)rr r r"r#rrrrrsrc@seZdZdZdZdS)r secp521r1i N)rr r r"r#rrrrrsrc@seZdZdZdZdS)r secp384r1iN)rr r r"r#rrrrrsrc@seZdZdZdZdS)r secp256r1N)rr r r"r#rrrrrsrc@seZdZdZdZdS)r secp256k1rYN)rr r r"r#rrrrr sr c@seZdZdZdZdS)r secp224r1N)rr r r"r#rrrrr sr c@seZdZdZdZdS)r secp192r1N)rr r r"r#rrrrr sr c@seZdZdZdZdS)BrainpoolP256R1brainpoolP256r1rYN)rr r r"r#rrrrr_sr_c@seZdZdZdZdS)BrainpoolP384R1brainpoolP384r1iN)rr r r"r#rrrrrasrac@seZdZdZdZdS)BrainpoolP512R1brainpoolP512r1iN)rr r r"r#rrrrrcsrc)Z prime192v1Z prime256v1r]r[rXrWrVrZrUrTrSrRrQrOrMrLrKrJr`rbrdc@seZdZddZejdZdS)ECDSAcCs ||_dS)N) _algorithm)r!r'rrr__init__@szECDSA.__init__rfN)rr r rgrread_only_propertyr'rrrrre>srecCs |j|S)N)Z#generate_elliptic_curve_private_key)r-r?rrrgenerate_private_keyFsricCsBt|tjstd|dkr$tdt|ts6td|j||S)Nz&private_value must be an integer type.rz)private_value must be a positive integer.z/curve must provide the EllipticCurve interface.)rArE integer_typesrBrDr Z!derive_elliptic_curve_private_key) private_valuer-r?rrrderive_private_keyJs  rlc@sneZdZddZddZddZeddZej d Z ej d Z ej d Z d d Z ddZddZddZdS)EllipticCurvePublicNumberscCsLt|tj st|tj r$tdt|ts6td||_||_||_dS)Nzx and y must be integers.z/curve must provide the EllipticCurve interface.)rArErjrBr _y_x_curve)r!xyr-rrrrgXs z#EllipticCurvePublicNumbers.__init__cCs |j|S)N)Z"load_elliptic_curve_public_numbers)r!r?rrrr,fsz%EllipticCurvePublicNumbers.public_keycCsBtjdtjdd|jjdd}dtj|j|tj|j|S)Nzencode_point has been deprecated on EllipticCurvePublicNumbers and will be removed in a future version. Please use EllipticCurvePublicKey.public_bytes to obtain both compressed and uncompressed point encoding.r<) stacklevel) warningswarnrDeprecatedIn25r-r#Z int_to_bytesrqrr)r! byte_lengthrrr encode_pointisz'EllipticCurvePublicNumbers.encode_pointcCst|tstdtjdtjdd|jdr|jdd}t |d|dkrtj |d|dd }tj ||ddd }||||St d nt d dS) Nz'curve must be an EllipticCurve instancezSupport for unsafe construction of public numbers from encoded data will be removed in a future version. Please use EllipticCurvePublicKey.from_encoded_pointr<)rsrvrtrubigz(Invalid elliptic curve point data lengthz%Unsupported elliptic curve point type) rAr rBrwrxrry startswithr#rCZint_from_bytesrD)rGr-r.rzrqrrrrrrHys    z-EllipticCurvePublicNumbers.from_encoded_pointrprorncCsFt|tstS|j|jkoD|j|jkoD|jj|jjkoD|jj|jjkS)N)rArmNotImplementedrqrrr-r"r#)r!otherrrr__eq__s    z!EllipticCurvePublicNumbers.__eq__cCs ||k S)Nr)r!rrrr__ne__sz!EllipticCurvePublicNumbers.__ne__cCst|j|j|jj|jjfS)N)hashrqrrr-r"r#)r!rrr__hash__sz#EllipticCurvePublicNumbers.__hash__cCs dj|S)NzC)r4)r!rrr__repr__sz#EllipticCurvePublicNumbers.__repr__N)rr r rgr,r{rIrHrrhr-rqrrrrrrrrrrrmWs     rmc@sHeZdZddZddZejdZejdZddZ d d Z d d Z d S)EllipticCurvePrivateNumberscCs6t|tjstdt|ts&td||_||_dS)Nz!private_value must be an integer.z>public_numbers must be an EllipticCurvePublicNumbers instance.)rArErjrBrm_private_value_public_numbers)r!rkr9rrrrgs  z$EllipticCurvePrivateNumbers.__init__cCs |j|S)N)Z#load_elliptic_curve_private_numbers)r!r?rrr private_keysz'EllipticCurvePrivateNumbers.private_keyrrcCs&t|tstS|j|jko$|j|jkS)N)rArrrkr9)r!rrrrrs  z"EllipticCurvePrivateNumbers.__eq__cCs ||k S)Nr)r!rrrrrsz"EllipticCurvePrivateNumbers.__ne__cCst|j|jfS)N)rrkr9)r!rrrrsz$EllipticCurvePrivateNumbers.__hash__N) rr r rgrrrhrkr9rrrrrrrrs    rc@s eZdZdS)ECDHN)rr r rrrrrsrc Cs*yt|Stk r$tdYnXdS)NzCThe provided object identifier has no matching elliptic curve class) _OID_TO_CURVEKeyError LookupError)oidrrrget_curve_for_oids r)5 __future__rrrr$rwrEZ cryptographyrZcryptography.hazmat._oidrobjectr add_metaclassABCMetar r&r(r1r6Z'EllipticCurvePublicKeyWithSerializationZregister_interfacerrrrrrrrrrrrrr r r r_rarcZ _CURVE_TYPESrerirlrmrrrrrrrrrrrs  '6 W$