3 lį˜_bć@s¤ddlmZmZmZddlZddlmZddlmZddl m Z ddl m Z ddl mZdd „Zdd d „Zd d „Zddd„Zddd„Zddd„ZGdd„deƒZdS)é)Śabsolute_importŚdivisionŚprint_functionN)Ś _get_backend)ŚCipher)ŚAES)ŚECB)Śbytes_eqc Cs¢tt|ƒtƒ|ƒjƒ}t|ƒ}xttdƒD]h}xbt|ƒD]V}|j|||ƒ}tjdtj d|dd…ƒd|||dAƒ}|dd…||<q6Wq(W|dj |ƒS)Néz>Qéréóių’’’) rrrŚ encryptorŚlenŚrangeŚupdateŚstructŚpackŚunpackŚjoin) Ś wrapping_keyŚaŚrŚbackendrŚnŚjŚiŚb©rś/usr/lib64/python3.6/keywrap.pyŚ _wrap_cores,r csxt|ƒ}t|ƒd krtdƒ‚tˆƒdkr0tdƒ‚tˆƒddkrHtdƒ‚d }‡fd d „tdtˆƒdƒDƒ}t||||ƒS) Nééé z/The wrapping key must be a valid AES key lengthz)The key to wrap must be at least 16 bytesr rz-The key to wrap must be a multiple of 8 bytess¦¦¦¦¦¦¦¦csg|]}ˆ||d…‘qS)r r)Ś.0r)Ś key_to_wraprrś 1sz aes_key_wrap..)r!r"r#)rrŚ ValueErrorrr )rr%rrrr)r%rŚ aes_key_wrap%s  r(c CsØtt|ƒtƒ|ƒjƒ}t|ƒ}x€ttdƒƒD]p}xjtt|ƒƒD]Z}tjdtj d|ƒd|||dAƒ||}|j |ƒ} | dd…}| dd…||<q>Wq,W||fS)Nr z>Qrr r ių’’’) rrrŚ decryptorrŚreversedrrrrr) rrrrr)rrrZatrrrrrŚ _unwrap_core5s"   r+cs“t|ƒ}t|ƒd krtdƒ‚dtjdtˆƒƒ}dtˆƒdd}ˆd|‰tˆƒdkr„tt|ƒtƒ|ƒjƒ}|j |ˆƒ}|S‡fd d „t d tˆƒdƒDƒ}t ||||ƒSdS) Nr!r"r#z/The wrapping key must be a valid AES key lengths¦YY¦z>ir ócsg|]}ˆ||d…‘qS)r r)r$r)r%rrr&\sz-aes_key_wrap_with_padding..r)r!r"r#) rrr'rrrrrrrrr )rr%rŚaivZpadrrrr)r%rŚaes_key_wrap_with_paddingLs   r.c stt|ƒ}tˆƒdkrtdƒ‚t|ƒdkr0tdƒ‚tˆƒdkrztt|ƒtƒ|ƒjƒ}|jˆƒ}|dd…}|dd…}d}nL‡fdd „t d tˆƒdƒDƒ}|j d ƒ} t|ƒ}t || ||ƒ\}}d j |ƒ}t jd |d d…ƒ\} d|| }t|dd …dƒ sNd|d| kod|kn sN|d krTt|| d…d|ƒ rTtƒ‚|d krb|S|d| …SdS)Nr!zMust be at least 16 bytesr"r#z/The wrapping key must be a valid AES key lengthr r csg|]}ˆ||d…‘qS)r r)r$r)Ś wrapped_keyrrr&qsz/aes_key_unwrap_with_padding..rr z>Iés¦YY¦r,)r!r"r#)rrŚ InvalidUnwrapr'rrrr)rrŚpopr+rrrr ) rr/rr)rrŚdatarrZ encrypted_aivZmlir)r/rŚaes_key_unwrap_with_padding`s2         *& r4cs t|ƒ}tˆƒdkrtdƒ‚tˆƒddkr4tdƒ‚t|ƒd krHtdƒ‚d }‡fd d „tdtˆƒdƒDƒ}|jdƒ}t||||ƒ\}}t||ƒs–tƒ‚d j|ƒS)Nr"zMust be at least 24 bytesr rz-The wrapped key must be a multiple of 8 bytesr!r#z/The wrapping key must be a valid AES key lengths¦¦¦¦¦¦¦¦csg|]}ˆ||d…‘qS)r r)r$r)r/rrr&—sz"aes_key_unwrap..r )r!r"r#) rrr1r'rr2r+r r)rr/rr-rrr)r/rŚaes_key_unwrap‹s    r5c@s eZdZdS)r1N)Ś__name__Ś __module__Ś __qualname__rrrrr1 sr1)N)N)N)N)Z __future__rrrrZcryptography.hazmat.backendsrZ&cryptography.hazmat.primitives.ciphersrZ1cryptography.hazmat.primitives.ciphers.algorithmsrZ,cryptography.hazmat.primitives.ciphers.modesrZ,cryptography.hazmat.primitives.constant_timer r r(r+r.r4r5Ś Exceptionr1rrrrŚs        +