ff0zddlmZddlmZmZddlmZmZddlm Z m Z m Z m Z dZ dZGddeZd d Zd S) )Integer)SHA512SHAKE256)bchris_bytes)EccKey construct_import_ed25519_public_key_import_ed448_public_keyct|dkrt|\}}d}nGt|dkrt|\}}d}ntdt|zt |||S)aCreate a new Ed25519 or Ed448 public key object, starting from the key encoded as raw ``bytes``, in the format described in RFC8032. Args: encoded (bytes): The EdDSA public key to import. It must be 32 bytes for Ed25519, and 57 bytes for Ed448. Returns: :class:`Crypto.PublicKey.EccKey` : a new ECC key object. Raises: ValueError: when the given key cannot be parsed. Ed255199Ed448zNot an EdDSA key (%d bytes))curvepoint_xpoint_y)lenr r ValueErrorr )encodedxy curve_names x/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/Signature/eddsa.pyimport_public_keyr)s" 7||r)'221 W  '001 6WEFFF :q! < < <<ct|dkrd}n%t|dkrd}ntdt||S)aCreate a new Ed25519 or Ed448 private key object, starting from the key encoded as raw ``bytes``, in the format described in RFC8032. Args: encoded (bytes): The EdDSA private key to import. It must be 32 bytes for Ed25519, and 57 bytes for Ed448. Returns: :class:`Crypto.PublicKey.EccKey` : a new ECC key object. Raises: ValueError: when the given key cannot be parsed. r ed25519red448z8Incorrect length. Only EdDSA private keys are supported.)seedr)rrr )rrs rimport_private_keyr!EsX" 7||r W   STTT ' 4 4 44rcBeZdZdZdZdZdZdZdZdZ dZ d Z d S) EdDSASigSchemezlAn EdDSA signature object. Do not instantiate directly. Use :func:`Crypto.Signature.eddsa.new`. cv||_||_||_|jj|_dS)zCreate a new EdDSA object. Do not instantiate this object directly, use `Crypto.Signature.DSS.new` instead. N)_key_context _export_eddsa_A_curveorder_order)selfkeycontexts r__init__zEdDSASigScheme.__init__is5  ##%%j& rc4|jS)zRReturn ``True`` if this signature object can be used for signing messages.)r% has_private)r,s rcan_signzEdDSASigScheme.can_signusy$$&&&rc|jstd|jjjdkrBt |t j}|st|std|j }nf|jjjdkrBt |tj }|st|std|j }ntd|||S)aJCompute the EdDSA signature of a message. Args: msg_or_hash (bytes or a hash object): The message to sign (``bytes``, in case of *PureEdDSA*) or the hash that was carried out over the message (hash object, for *HashEdDSA*). The hash object must be :class:`Crypto.Hash.SHA512` for Ed25519, and :class:`Crypto.Hash.SHAKE256` object for Ed448. :return: The signature as ``bytes``. It is always 64 bytes for Ed25519, and 114 bytes for Ed448. :raise TypeError: if the EdDSA key has no private half zPrivate key is needed to signr-'msg_or_hash' must be bytes of a SHA-512 hashr.'msg_or_hash' must be bytes of a SHAKE256 hashIncorrect curve for EdDSA)r%r1 TypeErrorr)name isinstancer SHA512Hashr _sign_ed25519r SHAKE256_XOF _sign_ed448r)r, msg_or_hashpheddsa_sign_methods rsignzEdDSASigScheme.sign{sy$$&& =;<< < 9  I - -K):;;B Q(;// Q OPPP $ 2   Y  "g - -K)>??B R(;// R PQQQ $ 0  899 9  b111rc|js|rLt|}dt|ztt|jz|jz}nd}|r|n|}t j||jjz|z}tj |d|j z}t||jj jz}t j||z|jz|z} tj | d|j z} || |jjzz|j z} || ddzS)N SigEd25519 no Ed25519 collisionsrlittlepointr )r&intrrdigestrnewr%_prefixr from_bytesr+rr)Gr'r(dto_bytes) r,r>r?flagdom2PHMr_hashrR_pkk_hashkss rr;zEdDSASigScheme._sign_ed25519sZ = B r77D6dCDM**++,.2mA 0 22333AACCD4K$'1C788??AA  vx 0 04; > TY[ DK /ajjX....rct|}dt|ztt|jz|jz}|r|dn|}t j||jjz|zd}tj |d|j z}t||jj jz}t j||z|jz|zd} tj | d|j z} || |jjzz|j z} || ddzS)NSigEd448@rrDrEr)rGrrr&readrrIr%rJrrKr+rr)rLr'r(rMrN) r,r>r?rOdom4rQrRrSrTrUrVrWs rr=zEdDSASigScheme._sign_ed448sH2wwT$ZZ'C &&''(*.-8')9kr"""k dTY%66<==BB3GG  vx 0 04; >A 0 22333AACCdTkDG3c9::??DD  vx 0 04; > TY[ DK /ajjX....rc|jjjdkrBt|tj}|st |std|j}nf|jjjdkrBt|tj }|st |std|j }ntd||||S)aCheck if an EdDSA signature is authentic. Args: msg_or_hash (bytes or a hash object): The message to verify (``bytes``, in case of *PureEdDSA*) or the hash that was carried out over the message (hash object, for *HashEdDSA*). The hash object must be :class:`Crypto.Hash.SHA512` object for Ed25519, and :class:`Crypto.Hash.SHAKE256` for Ed448. signature (``bytes``): The signature that needs to be validated. It must be 64 bytes for Ed25519, and 114 bytes for Ed448. :raise ValueError: if the signature is not authentic rr4rr5r6) r%r)r8r9rr:rr7_verify_ed25519rr< _verify_ed448r)r,r> signaturer?eddsa_verify_methods rverifyzEdDSASigScheme.verifys$ 9  I - -K):;;B Q(;// Q OPPP"&"6   Y  "g - -K)>??B R(;// R PQQQ"&"4  899 9""; 2>>>rcFt|dkrtd|js|rLt|}dt |zt t|jz|jz}nd}|r|n|} t |ddj}n#t$rtdwxYwtj |ddd}||j krtdtj ||ddz|j z|z} tj | d|j z} |d z|jjjz} d |z| d z|jjzz} | | krtd dS) NrZ'The signature is not authentic (length)rCrr "The signature is not authentic (R)rD"The signature is not authentic (S)The signature is not authentic)rrr&rGrrHrpointQrrKr+rrIr(r%r)rL) r,r>rar?rOrPrQRrWrUrVpoint1point2s rr_zEdDSASigScheme._verify_ed25519s y>>R  FGG G = B r77D6dCDM**++,.2m1DG;cABBIIKK  vx 0 04; >Q)++QQ!111 V  =>> >  s B00C c2t|dkrtdt|}dt|ztt|jz|jz}|r|dn|} t |ddj}n#t$rtdwxYwtj |ddd}||j krtdtj ||ddz|j z|zd} tj | d|j z} |d z|jjjz} d |z| d z|jjzz} | | krtd dS) Nr[rerYrZrrfrDrgrhri)rrrGrr&r\rrjrrKr+rrIr(r%r)rL) r,r>rar?rOr]rQrkrWrUrVrlrms rr`zEdDSASigScheme._verify_ed448s y>>S FGG G2wwT$ZZ'C &&''(*.-8')9kr"""k  C!)CRC.118AA C C CABB B C  y~x 8 8 t{??ABB BdYss^3dg=CDDII#NN  vx 0 04; >Q)++QQ!111 V  =>> >  s B%%B?N) __name__ __module__ __qualname____doc__r/r2rAr;r=rcr_r`rrr#r#cs ' ' '''' !2!2!2F///6///0!?!?!?F!?!?!?F?????rr#Nc t|tr|std|dkrtd|d}n"t |dkrtdt ||S)aCreate a signature object :class:`EdDSASigScheme` that can perform or verify an EdDSA signature. Args: key (:class:`Crypto.PublicKey.ECC` object): The key to use for computing the signature (*private* keys only) or for verifying one. The key must be on the curve ``Ed25519`` or ``Ed448``. mode (string): This parameter must be ``'rfc8032'``. context (bytes): Up to 255 bytes of `context `_, which is a constant byte string to segregate different protocols or different applications of the same key. z&EdDSA can only be used with EdDSA keysrfc8032zMode must be 'rfc8032'Nrz3Context for EdDSA must not be longer than 255 bytes)r9r _is_eddsarrr#)r-moder.s rrIrI9s& c6 " "C#--//CABBB y1222 W  NOOO #w ' ''r)N)Crypto.Math.Numbersr Crypto.HashrrCrypto.Util.py3compatrrCrypto.PublicKey.ECCrr r r rr!objectr#rIrsrrr~s>('''''((((((((00000000<<<<<<<<<<<< ===8555