+
      xi  c                  s    R t ^ RIHt ^ RIt^ RIt^ RIt^ RIHt ^ RIH	t	H
t
Ht ^ RIHtHt R R lt]P                   ! R4      tRR	 R
 lltR R ltR# )z;Implement Triple DES key wrapping as described in RFC 3217.)annotationsN)default_backend)Cipher
algorithmsmodes)DecryptionErrorEncryptionErrorc               s     V ^8  d   QhRRRR/# )   valuebytesreturn Zformat   "</usr/lib/python3.14/site-packages/pskc/crypto/tripledeskw.py__annotate__r   #   s     , ,U ,u ,    c                sX    \         P                  ! V 4      P                  4       R,          # )z>Return the key hash algorithm described in RFC 3217 section 2.N   N)hashlibZsha1Zdigest)r   s   &r   	_cms_hashr   #   s    <<%%'++r   Z4adda22c79e82105c               s(    V ^8  d   QhRRRRRRRR/# )r   	plaintextr	   keyivzbytes | Noner
   r   r   r   r   r   r   +   s(     > >E > >< >5 >r   c                s   ^\        V 4      ,          \        P                  P                  ,          ^ 8w  d   \	        R4      hVf   \
        P                  ! ^4      p\        4       p\        \        P                  ! V4      \        P                  ! V4      V4      pVP                  4       pW%P                  V \        V 4      ,           4      ,           VP                  4       ,           p\        \        P                  ! V4      \        P                  ! \        4      V4      pVP                  4       pVP                  VRRR1,          4      VP                  4       ,           # )zWrap one key (typically a Triple DES key) with another Triple DES key.

This uses the algorithm from RFC 3217 to encrypt the plaintext (the key
to wrap) using the provided key. If the iv is None, it is randomly
generated.
zPlaintext length wrongN)lenr   	TripleDES
block_sizer   osZurandomr   r   r   CBC	encryptorupdater   finalize
RFC3217_IV)r   r   r   backendcipherr   tmps   &&&    r   wrapr%   +   s    	3y>J00;;;q@677	zZZ]GJ((-uyy}gFF  "I
i)I*>>??	  J((-uyy/DgNF  "IC"I&););)===r   c               s$    V ^8  d   QhRRRRRR/# )r   
ciphertextr	   r   r
   r   r   r   r   r   r   A   s!     4 4u 45 4U 4r   c                s   ^\        V 4      ,          \        P                  P                  ,          ^ 8w  d   \	        R4      h\        4       p\        \        P                  ! V4      \        P                  ! \        4      V4      pVP                  4       pVP                  V 4      VP                  4       ,           RRR1,          p\        \        P                  ! V4      \        P                  ! VR,          4      V4      pVP                  4       pVP                  VR,          4      VP                  4       ,           pVRR \        VRR 4      8X  d   VRR # \	        R4      h)zUnwrap a key (typically Triple DES key ) with another Triple DES key.

This uses the algorithm from RFC 3217 to decrypt the ciphertext (the
previously wrapped key) using the provided key.
zCiphertext length wrongNr   :r   NNzCMS key checksum errorr   i)r   r   r   r   r   r   r   r   r   r!   	decryptorr   r    r   )r&   r   r"   r#   r'   r$   s   &&    r   unwrapr(   A   s    	3z?Z11<<<A788GJ((-uyy/DgNF  "IJ')*<*<*>>"
ECJ((-uyyR/A7KF  "I


3r7
#i&8&8&:
:C
23x9S"X&&3Bx
2
33r   )N)Z__doc__Z
__future__r    Zbinasciir   r   Zcryptography.hazmat.backendsr   Z&cryptography.hazmat.primitives.ciphersr   r   r   Zpskc.exceptionsr   r   r   Za2b_hexr!   r%   r(   r   r   r   <module>r)      sE   * B "   	 8 L L <,
 01
>,4r   