3 yá˜_&ã@s€ddlmZmZmZddlmZmZddlmZddl m Z m Z m Z m Z eje ƒGdd„deƒƒZeje ƒGdd„deƒƒZd S) é)Úabsolute_importÚdivisionÚprint_function)Ú exceptionsÚutils)Ú serialization)ÚEd25519PrivateKeyÚEd25519PublicKeyÚ_ED25519_KEY_SIZEÚ_ED25519_SIG_SIZEc@s,eZdZdd„Zdd„Zdd„Zdd„Zd S) Ú_Ed25519PublicKeycCs||_||_dS)N)Ú_backendÚ _evp_pkey)ÚselfÚbackendÚevp_pkey©rú/usr/lib64/python3.6/ed25519.pyÚ__init__sz_Ed25519PublicKey.__init__cCsV|tjjks|tjjkr@|tjjk s0|tjjk r8tdƒ‚|jƒS|jj||||jdƒS)Nz3When using Raw both encoding and format must be Raw) rÚEncodingÚRawÚ PublicFormatÚ ValueErrorÚ_raw_public_bytesr Z_public_key_bytesr)rÚencodingÚformatrrrÚ public_bytess    z_Ed25519PublicKey.public_bytescCsp|jjjdtƒ}|jjjdtƒ}|jjj|j||ƒ}|jj|dkƒ|jj|dtkƒ|jjj|tƒdd…S)Nzunsigned char []zsize_t *ér) r Ú_ffiÚnewr Ú_libÚEVP_PKEY_get_raw_public_keyrÚopenssl_assertÚbuffer)rÚbufÚbuflenÚresrrrr*s z#_Ed25519PublicKey._raw_public_bytescCs¬|jjjƒ}|jj||jjjkƒ|jjj||jjjƒ}|jjj||jjj|jjj|jjj|j ƒ}|jj|dkƒ|jjj ||t |ƒ|t |ƒƒ}|dkr¨|jj ƒt j‚dS)Nr)r r ÚCryptography_EVP_MD_CTX_newr"rÚNULLÚgcÚCryptography_EVP_MD_CTX_freeZEVP_DigestVerifyInitrZEVP_DigestVerifyÚlenZ_consume_errorsrZInvalidSignature)rZ signatureÚdataÚ evp_md_ctxr&rrrÚverify4s   z_Ed25519PublicKey.verifyN)Ú__name__Ú __module__Ú __qualname__rrrr.rrrrr s r c@s4eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd S) Ú_Ed25519PrivateKeycCs||_||_dS)N)r r)rrrrrrrLsz_Ed25519PrivateKey.__init__cCsz|jjjdtƒ}|jjjdtƒ}|jjj|j||ƒ}|jj|dkƒ|jj|dtkƒ|jjj|ƒdd…}|jj |ƒS)Nzunsigned char []zsize_t *rr) r rrr r r!rr"r#Zed25519_load_public_bytes)rr$r%r&rrrrÚ public_keyPs z_Ed25519PrivateKey.public_keycCsð|jjjƒ}|jj||jjjkƒ|jjj||jjjƒ}|jjj||jjj|jjj|jjj|j ƒ}|jj|dkƒ|jjj dt ƒ}|jjj dt |ƒƒ}|jjj ||||t |ƒƒ}|jj|dkƒ|jj|dt kƒ|jjj||dƒdd…S)Nrzunsigned char[]zsize_t *r)r r r'r"rr(r)r*ZEVP_DigestSignInitrrr r+ZEVP_DigestSignr#)rr,r-r&r$r%rrrÚsign[s$ z_Ed25519PrivateKey.signcCsf|tjjks|tjjkrN|tjjk s>|tjjk s>t|tjƒ rFtdƒ‚|jƒS|j j |||||j dƒS)NzcWhen using Raw both encoding and format must be Raw and encryption_algorithm must be NoEncryption()) rrrrZ PrivateFormatÚ isinstanceZ NoEncryptionrÚ_raw_private_bytesr Z_private_key_bytesr)rrrZencryption_algorithmrrrÚ private_bytesrs     z _Ed25519PrivateKey.private_bytescCsp|jjjdtƒ}|jjjdtƒ}|jjj|j||ƒ}|jj|dkƒ|jj|dtkƒ|jjj|tƒdd…S)Nzunsigned char []zsize_t *rr) r rrr r ZEVP_PKEY_get_raw_private_keyrr"r#)rr$r%r&rrrr6‰s z%_Ed25519PrivateKey._raw_private_bytesN)r/r0r1rr3r4r7r6rrrrr2Js  r2N)Z __future__rrrZ cryptographyrrZcryptography.hazmat.primitivesrZ1cryptography.hazmat.primitives.asymmetric.ed25519rr r r Zregister_interfaceÚobjectr r2rrrrÚs 8