a a:&@s4UddlZddlZddlZddlmZddlmZddlmZm Z ddl m Z m Z mZ GdddeZGdd d ejd ZGd d d ejd ZGd ddejd ZeZGdddejd ZeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdd d eZGd!d"d"eZGd#d$d$eZ Gd%d&d&eZ!Gd'd(d(eZ"Gd)d*d*eZ#Gd+d,d,eZ$Gd-d.d.eZ%Gd/d0d0eZ&Gd1d2d2eZ'Gd3d4d4eZ(Gd5d6d6eZ)e&e#e&e%e#e"e!e$e eeeeeeeeee'e(e)d7Z*ej+e,ej-efe.d8<Gd9d:d:eZ/dJeej0ed;dd?d@Z3GdAdBdBeZ4GdCdDdDeZ5GdEdFdFeZ6ej&e&ej%e%ej$e$ej#e#ej"e"ej!e!ej7e'ej8e(ej9e)ej e ejeejeejeejeejeejeejeejeejeiZ:eej-edGdHdIZ;dS)LN)utils)ObjectIdentifier)_serializationhashes)AsymmetricSignatureContextAsymmetricVerificationContextrc@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 SECT571R1rrR/usr/lib64/python3.9/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyrs&rc@s4eZdZejedddZejedddZdS) EllipticCurvereturncCsdS)z8 The name of the curve. e.g. secp256r1. Nrselfrrr name+szEllipticCurve.namecCsdSz< Bit size of a secret scalar for the curve. Nrr$rrr key_size1szEllipticCurve.key_sizeN) r r r abcabstractpropertystrr&intr(rrrr r!*sr!) metaclassc@s.eZdZejejeje j fdddZ dS)EllipticCurveSignatureAlgorithmr"cCsdS)z@ The digest algorithm used with this signature. Nrr$rrr algorithm9sz)EllipticCurveSignatureAlgorithm.algorithmN) r r r r)r*typingUnion asym_utils Prehashedr HashAlgorithmr/rrrr r.8sr.c@seZdZejeedddZejddedddZ ejdd d d Z ej e d d d Z ej ed ddZejeeedddZejdd ddZejejejejedddZdS)EllipticCurvePrivateKey)signature_algorithmr#cCsdS)zN Returns an AsymmetricSignatureContext used for signing data. Nr)r%r6rrr signerCszEllipticCurvePrivateKey.signerECDHEllipticCurvePublicKey)r/peer_public_keyr#cCsdS)z} Performs a key exchange operation using the provided algorithm with the provided peer's public key. Nr)r%r/r:rrr exchangeLsz EllipticCurvePrivateKey.exchanger"cCsdS)zB The EllipticCurvePublicKey for this private key. Nrr$rrr public_keyUsz"EllipticCurvePrivateKey.public_keycCsdSz8 The EllipticCurve that this key is on. Nrr$rrr curve[szEllipticCurvePrivateKey.curvecCsdSr'rr$rrr r(asz EllipticCurvePrivateKey.key_size)datar6r#cCsdS)z Signs the data Nr)r%r?r6rrr signgszEllipticCurvePrivateKey.signEllipticCurvePrivateNumberscCsdS)z9 Returns an EllipticCurvePrivateNumbers. Nrr$rrr private_numbersqsz'EllipticCurvePrivateKey.private_numbers)encodingformatencryption_algorithmr#cCsdSz6 Returns the key serialized as bytes. Nr)r%rCrDrErrr private_byteswsz%EllipticCurvePrivateKey.private_bytesN)r r r r)abstractmethodr.rr7bytesr;r<r*r!r>r,r(r@rBrEncodingZ PrivateFormatZKeySerializationEncryptionrGrrrr r5Bs6 r5c@seZdZejeeedddZej e dddZ ej e dddZ ejd dd d Zejejejed d dZejeeeddddZee eddddZdS)r9) signaturer6r#cCsdS)zQ Returns an AsymmetricVerificationContext used for signing data. Nr)r%rKr6rrr verifierszEllipticCurvePublicKey.verifierr"cCsdSr=rr$rrr r>szEllipticCurvePublicKey.curvecCsdSr'rr$rrr r(szEllipticCurvePublicKey.key_sizeEllipticCurvePublicNumberscCsdS)z8 Returns an EllipticCurvePublicNumbers. Nrr$rrr public_numberssz%EllipticCurvePublicKey.public_numbers)rCrDr#cCsdSrFr)r%rCrDrrr public_bytessz#EllipticCurvePublicKey.public_bytesN)rKr?r6r#cCsdS)z5 Verifies the signature of the data. Nr)r%rKr?r6rrr verifyszEllipticCurvePublicKey.verifyr>r?r#cCs^td|t|tstdt|dkr2td|ddvrFtdddlm}| ||S)Nr?'curve must be an EllipticCurve instancerz%data must not be an empty byte string)%Unsupported elliptic curve point typebackend) r _check_bytes isinstancer! TypeErrorlen ValueError,cryptography.hazmat.backends.openssl.backendrXZ load_elliptic_curve_public_bytes)clsr>r?rXrrr from_encoded_points     z)EllipticCurvePublicKey.from_encoded_point)r r r r)rHrIr.rrLr*r!r>r,r(rNrrJZ PublicFormatrOrP classmethodr`rrrr r9s4   r9c@seZdZdZdZdS)r sect571r1i:Nr r r r&r(rrrr rsrc@seZdZdZdZdS)r sect409r1Nrcrrrr rsrc@seZdZdZdZdS)r sect283r1Nrcrrrr rsrc@seZdZdZdZdS)r sect233r1Nrcrrrr rsrc@seZdZdZdZdS)r sect163r2Nrcrrrr rsrc@seZdZdZdZdS)r sect571k1i;Nrcrrrr rsrc@seZdZdZdZdS)r sect409k1reNrcrrrr rsrc@seZdZdZdZdS)r sect283k1rgNrcrrrr rsrc@seZdZdZdZdS)r sect233k1riNrcrrrr rsrc@seZdZdZdZdS)r sect163k1rkNrcrrrr rsrc@seZdZdZdZdS)r secp521r1i Nrcrrrr rsrc@seZdZdZdZdS)r secp384r1Nrcrrrr rsrc@seZdZdZdZdS)r secp256r1Nrcrrrr r src@seZdZdZdZdS)r secp256k1ruNrcrrrr rsrc@seZdZdZdZdS)r secp224r1Nrcrrrr r sr c@seZdZdZdZdS)r secp192r1Nrcrrrr r sr c@seZdZdZdZdS)BrainpoolP256R1brainpoolP256r1ruNrcrrrr r{sr{c@seZdZdZdZdS)BrainpoolP384R1brainpoolP384r1rsNrcrrrr r}$sr}c@seZdZdZdZdS)BrainpoolP512R1brainpoolP512r1iNrcrrrr r)sr)Z prime192v1Z prime256v1ryrwrtrrrqrvrprornrmrlrjrhrfrdrbr|r~r _CURVE_TYPESc@sHeZdZejejejfdddZ e ejejejfdddZ dS)ECDSA)r/cCs ||_dSNZ _algorithm)r%r/rrr __init__HszECDSA.__init__r"cCs|jSrrr$rrr r/NszECDSA.algorithmN) r r r r0r1r2r3rr4rpropertyr/rrrr rGs  r)r>rXr#cCsddlm}||SNrrW)r^rXZ#generate_elliptic_curve_private_key)r>rXosslrrr generate_private_keyUs r) private_valuer>rXr#cCsLddlm}t|tstd|dkr.tdt|ts@td|||S)NrrWz&private_value must be an integer type.z)private_value must be a positive integer./curve must provide the EllipticCurve interface.)r^rXrZr,r[r]r!Z!derive_elliptic_curve_private_key)rr>rXrrrr derive_private_key]s   rc@seZdZeeedddZdejedddZ e dd d Z e ee dd d d Z eddZeddZeddZddZddZddZddZdS)rM)xyr>cCsDt|trt|tstdt|ts.td||_||_||_dS)Nzx and y must be integers.r)rZr,r[r!_y_x_curve)r%rrr>rrr rqs z#EllipticCurvePublicNumbers.__init__NrXr#cCsddlm}||Sr)r^rXZ"load_elliptic_curve_public_numbersr%rXrrrr r<|s z%EllipticCurvePublicNumbers.public_keyr"cCsBtjdtjdd|jjdd}dt|j|t|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.rS stacklevel) warningswarnrPersistentlyDeprecated2019r>r(Z int_to_bytesrr)r% byte_lengthrrr encode_points   z'EllipticCurvePublicNumbers.encode_pointrQcCst|tstdtjdtjdd|dr|jdd}t |d|dkrt |d|dd }t ||ddd }||||St d nt d dS) NrRzSupport for unsafe construction of public numbers from encoded data will be removed in a future version. Please use EllipticCurvePublicKey.from_encoded_pointrSrrrrbigz(Invalid elliptic curve point data lengthrV) rZr!r[rrrr startswithr(r\r, from_bytesr])r_r>r?rrrrrr r`s    z-EllipticCurvePublicNumbers.from_encoded_pointcCs|jSr)rr$rrr z#EllipticCurvePublicNumbers.cCs|jSr)rr$rrr rrcCs|jSr)rr$rrr rrcCsFt|tstS|j|jkoD|j|jkoD|jj|jjkoD|jj|jjkSr)rZrMNotImplementedrrr>r&r(r%otherrrr __eq__s   z!EllipticCurvePublicNumbers.__eq__cCs ||k Srrrrrr __ne__sz!EllipticCurvePublicNumbers.__ne__cCst|j|j|jj|jjfSr)hashrrr>r&r(r$rrr __hash__sz#EllipticCurvePublicNumbers.__hash__cCs d|S)NzC)rDr$rrr __repr__sz#EllipticCurvePublicNumbers.__repr__)N)r r r r,r!rr0Anyr9r<rIrrar`rr>rrrrrrrrrr rMps     rMc@s`eZdZeedddZdejedddZ e dd Z e d d Z d d Z d dZddZdS)rA)rrNcCs4t|tstdt|ts$td||_||_dS)Nz!private_value must be an integer.z>public_numbers must be an EllipticCurvePublicNumbers instance.)rZr,r[rM_private_value_public_numbers)r%rrNrrr rs  z$EllipticCurvePrivateNumbers.__init__NrcCsddlm}||Sr)r^rXZ#load_elliptic_curve_private_numbersrrrr private_keys z'EllipticCurvePrivateNumbers.private_keycCs|jSr)rr$rrr rrz$EllipticCurvePrivateNumbers.cCs|jSr)rr$rrr rrcCs&t|tstS|j|jko$|j|jkSr)rZrArrrNrrrr rs    z"EllipticCurvePrivateNumbers.__eq__cCs ||k Srrrrrr rsz"EllipticCurvePrivateNumbers.__ne__cCst|j|jfSr)rrrNr$rrr rsz$EllipticCurvePrivateNumbers.__hash__)N)r r r r,rMrr0rr5rrrrNrrrrrrr rAs    rAc@s eZdZdS)r8N)r r r rrrr r8sr8)oidr#cCs*z t|WSty$tdYn0dS)NzCThe provided object identifier has no matching elliptic curve class) _OID_TO_CURVEKeyError LookupError)rrrr get_curve_for_oids   r)N)N)s    AF  [,