3 yá˜_úã@s€ddlmZmZmZddlmZmZddlmZddl m Z m Z dZ dZ eje ƒGdd„deƒƒZeje ƒGd d „d eƒƒZd S) é)Úabsolute_importÚdivisionÚprint_function)Ú exceptionsÚutils)Ú serialization)ÚEd448PrivateKeyÚEd448PublicKeyé9érc@s,eZdZdd„Zdd„Zdd„Zdd„Zd S) Ú_Ed448PublicKeycCs||_||_dS)N)Ú_backendÚ _evp_pkey)ÚselfÚbackendÚevp_pkey©rú/usr/lib64/python3.6/ed448.pyÚ__init__sz_Ed448PublicKey.__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_Ed448PublicKey.public_bytescCsp|jjjdtƒ}|jjjdtƒ}|jjj|j||ƒ}|jj|dkƒ|jj|dtkƒ|jjj|tƒdd…S)Nzunsigned char []zsize_t *ér) r Ú_ffiÚnewÚ_ED448_KEY_SIZEÚ_libÚEVP_PKEY_get_raw_public_keyrÚopenssl_assertÚbuffer)rÚbufÚbuflenÚresrrrr+s z!_Ed448PublicKey._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Úverify5s   z_Ed448PublicKey.verifyN)Ú__name__Ú __module__Ú __qualname__rrrr/rrrrr s r c@s4eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd S) Ú_Ed448PrivateKeycCs||_||_dS)N)r r)rrrrrrrMsz_Ed448PrivateKey.__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$Zed448_load_public_bytes)rr%r&r'rrrrÚ public_keyQs z_Ed448PrivateKey.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_DigestSignInitrrÚ_ED448_SIG_SIZEr,ZEVP_DigestSignr$)rr-r.r'r%r&rrrÚsign\s$ z_Ed448PrivateKey.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_bytesss     z_Ed448PrivateKey.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'rrrr8Šs z#_Ed448PrivateKey._raw_private_bytesN)r0r1r2rr4r6r9r8rrrrr3Ks  r3N)Z __future__rrrZ cryptographyrrZcryptography.hazmat.primitivesrZ/cryptography.hazmat.primitives.asymmetric.ed448rr r r5Zregister_interfaceÚobjectr r3rrrrÚs 8