§
    öÛg<h  ã                   ó°   — d Z dZdZdZdZdgZddlZddlZdZd	Z	d
Z
dZdZdZd„ Zd„ Z ej        d¦  «        Zd„ Zd„ Zd„ Zd„ Zedk    r e¦   «          dS dS )aÖ  Unix crypt(3) password hash algorithm.

This is a port to Python of the standard Unix password crypt function.
It's a single self-contained source file that works with any version
of Python from version 1.5 or higher.  The code is based on Eric
Young's optimised crypt in C.

Python fcrypt is intended for users whose Python installation has not
had the crypt module enabled, or whose C library doesn't include the
crypt function.  See the documentation for the Python crypt module for
more information:

  http://www.python.org/doc/current/lib/module-crypt.html

An alternative Python crypt module that uses the MD5 algorithm and is
more secure than fcrypt is available from michal j wallace at:

  http://www.sabren.net/code/python/crypt/index.php3

The crypt() function is a one-way hash function, intended to hide a
password such that the only way to find out the original password is
to guess values until you get a match.  If you need to encrypt and
decrypt data, this is not the module for you.

There are at least two packages providing Python cryptography support:
M2Crypto at <http://www.pobox.org.sg/home/ngps/m2/>, and amkCrypto at
<http://www.amk.ca/python/code/crypto.html>.

Functions:

  crypt() -- return hashed password
z Carey Evans <careye@spamcop.net>z1.3.1z21 February 2004zgmichal j wallace for inspiring me to write this.
Eric Young for the C code this module was copied from.Úcrypté    Né   ))@é ‚ é   ì       ì     é  € ì      ì       r   r
   r   é  ‚ ì       ì      r	   r   r   r   ì        é € é  r   r   r   r   r   é   r   ì      r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
   r   r   r   r   r   r   r   r	   r   r   r   r   r	   r   r   r   r   r   r
   )@é r   é   é  é  é   é   r   é    é é   r   é  é  r   r   é   é  r   r   é  é   r   r   r    r!   r   r   r"   r   r   r   r   r   r   r!   r   r   r   r   r"   r   r   r   r   r"   r!   r    r   r   r   r   r   r   r   r   r   r   r   r   r    r   r   r   )@é   Aé@ é@   é@  Aé  @é   r&   é@  é@  é   é  é   @é@ Aé@  @r-   é  Ar   r'   r$   r%   r/   r.   r+   r#   r0   r*   é@ @r,   r)   r   r(   r1   r$   r%   r-   r+   r/   r'   r,   r&   r   r$   r)   r0   r'   r(   r.   r-   r1   r#   r(   r.   r+   r*   r&   r)   r*   r   r0   r/   r#   r1   r%   r,   )@é é  é   ér   é  é é  é é  é   é  r:   r2   é   r;   é é  é   r4   r?   r7   r6   r@   r<   r   r8   r9   r3   r>   r5   r=   r>   r<   r=   r:   r?   r3   r4   r6   r7   r   r@   r8   r   r>   r9   r@   r;   r5   r2   r=   r5   r4   r3   r2   r8   r?   r6   r7   r<   r;   r:   r9   )@é   é @  é   éA é@ é  éA  é @ rB   é   é  é A  é rE   é A r   rK   rA   é@  é  rF   rG   r   rJ   rI   rL   rD   rN   rH   rC   rO   rM   rM   rL   rN   rH   rB   rI   rJ   rF   rA   rK   rD   r   rG   rA   rC   rN   rL   rC   r   rD   rE   rM   rO   rB   rK   rE   rF   rO   rI   rG   rH   rJ   )@é   é  r   é  rQ   é   é  é   é  é é  é    é   rP   é   é rU   rT   é  r   rS   r   rR   r]   rW   r[   rY   rV   r   rX   r\   rZ   rV   rY   rZ   r\   rR   rQ   r   rZ   rY   rS   r]   rU   rQ   rW   rX   r   rW   rX   rU   rT   rP   r[   r\   r   rS   rP   rT   rR   r[   rV   r   r]   )@é   é€   é€ @ é @ é�@ é  é€  r   é  @ é� @ é�   é @ é   é€@ rh   rg   rf   r^   rc   rb   r   r`   ra   rd   é@ é�  rj   ri   rl   rk   r_   re   rl   rh   rk   rg   r^   r_   re   rk   rf   rl   rd   r   r_   ra   ri   r`   r   rf   r`   rd   rg   r^   rb   re   rj   ri   rc   rb   ra   rj   rh   rc   )@é   é € é €  r   é € é    é   é € é    é   é €  ro   é €  é € é   rr   é €  rw   rq   rp   rs   ry   r   rv   ru   é    rx   rm   r{   rz   rn   rt   r{   rz   ry   rs   ro   ru   r   rv   rm   rx   rp   rq   rn   rt   rq   rp   rs   r{   rr   ry   rv   ro   rx   rr   rt   rn   rw   r   ru   rm   rz   rw   ))@r   r   rY   rP   r+   i  é   i  rS   rV   rZ   rT   i  i i  i rt   é0   i    i0   i   i0  i   i0  é   i0  i   i0  i  i0 i  i0 rU   rQ   r[   r]   i  	 i 	 i  	 i 	 rX   r\   rR   rW   i 	 i	 i 	 i	 i   i0  i   i0  i  	 i0 	 i  	 i0 	 i  i0 i  i0 i 	 i0	 i 	 i0	 )@r   rA   r   i   r{   i   i    i   r   i  r   i  i   i  i   i  r@   é  i $  i $ i   i  i $  i $ i  i i$  i$ i  i i$  i$ r"   i   r   i   i   i   i   i   r   i  r    i  i  i  i  i  i  i  i $ i $ i  i  i $ i $ i i i$ i$ i i i$ i$ )@r   ri   r   i  r(   i  i  i r4   é   é  i  i  i  i i r   i  i  i é  i i ii  i  i i i i iiru   é  i  i i   	i  	i  	i 	i  i  i i i  	i  	i 	i 	i  i i ii  	i 	i 	i	i i iii 	i 	i	i	)@r   r=   rC   i  rI   i  rO   i r^   é  i   i  i  i i  i r;   r6   i  i i  i i ii  i i  i i ii ir   i   i  i  é  i  i i i  i  i  i  i i i i i  i  i i i i iii i i i iiii)@r   r"   r+   i  r   r   i  i rY   i   0r|   i  0i   i  0i  i 0r=   i  i   i  i  i i  i i   i  0i   i  0i  i 0i  i 0r^   i  i  i i  i i ii   i  0i  i 0i  i 0i i0r„   i i  i i ii ii  i 0i  i 0i i0i i0)@r   ru   rI   i  r@   i  i  i r   i  r…   i i  i i iri   rƒ   é	   i	  i  i i	  i	 i  i i	  i	 i ii	 i	rA   i   
rJ   i  
r   i  
i i 
i  i  
i i 
i i 
ii
i  i  
i	  i	  
i i 
i	 i	 
i i 
i	 i	 
ii
i	i	
)@r   rC   rU   i  r(   i  i  i r   i  rQ   i i  i i ir{   i   i  ( i ( i   i  i  (i (i   i  i ( i( i  i i (i(r   i   i  i  r‚   i  i i i  i  i i i i iii   i   i ( i ( i  i  i (i (i  i  i( i( i i i(i()@r   r;   r   i  r4   r:   r�   i r   i   r   i  i   i  i  i rt   i   i   i  é"   i"  i"  i" i    i   i   i  i"   i"  i"  i" rS   i  i  i i  i i ii (  i ( i ( i (i(  i( i( i(r~   i  i  i i"  i" i" i"i (  i ( i ( i (i"(  i"( i"( i"()r   r   ri   ri   ri   ri   ri   ri   r   ri   ri   ri   ri   ri   ri   r   )€éÒ   éÓ   éÔ   éÕ   éÖ   é×   éØ   éÙ   éÚ   éÛ   éÜ   éÝ   éÞ   éß   éà   éá   éâ   éã   éä   éå   éæ   éç   éè   éé   éê   éë   éì   éí   éî   éï   éð   éñ   éò   éó   éô   éõ   éö   é÷   éø   éù   éú   éû   éü   éý   éþ   éÿ   r   ri   r4   r€   r   é   é   é   rI   r†   é
   é   r¶   r·   r¸   rI   r†   r¹   rº   é   é   é   é   r   é   é   é   é   é   é   é   é   é   é   é   é   é   é   é   rt   é!   r‡   é#   é$   é%   rt   rÎ   r‡   rÏ   rÐ   rÑ   é&   é'   é(   é)   é*   é+   é,   é-   é.   é/   r}   é1   é2   é3   é4   é5   é6   é7   é8   é9   é:   é;   é<   é=   é>   é?   r%   éA   éB   éC   éD   s@   ./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzc                 ó4   — | dz  | z  dz  }| |z  |dz	  dz  z  S )zClever bit manipulation.rÀ   l     ˜ iÿ?  © )ÚaÚts     úO/granary/edev/quantum/lib/python3.11/site-packages/postgresql/resolved/crypt.pyÚ	_HPERM_OPrô   »  s,   € à
ˆr‰'�Q‰˜*Ñ$€AØˆq‰5�Q˜"‘W Ñ&Ñ'Ð'ó    c                 ó:   — | |z	  |z  |z  }||z  }| ||z  z  } | |fS )zCleverer bit manipulation.rð   )rñ   ÚbÚnÚmrò   s        ró   Ú_PERM_OPrú   À  s3   € à
ˆq‰&�A‰˜Ñ€AØ	ˆA‰€AØ	ˆQ�!‰V‰€AØˆQˆ3€Jrõ   z<iic                 óJ  — t                                | ¦  «        \  }}|dz  dz  }|dz  dz  }t          ||dd¦  «        \  }}t          |¦  «        }t          |¦  «        }t          ||dd¦  «        \  }}t          ||dd¦  «        \  }}t          ||dd¦  «        \  }}|dz  d	z  |d
z  z  |dz  d	z	  z  |dz	  dz  z  }|dz  }t          }t
          \  }}}}}}	}
}dgt          dz  z  }t          t          ¦  «        D �]#}||         r|dz	  |dz  z  }|dz	  |dz  z  }n|dz	  |dz  z  }|dz	  |dz  z  }|dz  }|dz  }||dz           ||dz	  dz  |dz	  dz  z           z  ||dz	  dz  |dz	  dz  z           z  ||dz	  dz  |dz	  dz  z  |dz	  dz  z           z  }||dz           |	|dz	  dz  |dz	  dz  z           z  |
|dz	  dz           z  ||dz	  dz  |dz	  dz  z           z  }|d	z  |dz  z  d z  |d|z  <   |d	z	  |d!z  z  }|dz  |d"z	  dz  z  }|d z  |d|z  dz   <   �Œ%|S )#z.Generate DES key schedule from ASCII password.iri   r   ééUUUUrI   éÿ ÿ rµ   r   é ÿ  é  ÿ i   éÿÿÿr   r4   rÈ   rÉ   rê   r·   r€   r¸   rç   r¼   r¾   r½   r}   rÂ   rÃ   rÄ   rã   éÿÿ  l   ÿÿ l     þ rÊ   )Ú	ii_structÚunpackrú   rô   Ú_shifts2Ú_skbÚ_ITERATIONSÚrange)ÚpasswordÚcÚdÚshifts2Úskbc0Úskbc1Úskbc2Úskbc3Úskbd0Úskbd1Úskbd2Úskbd3ÚkÚiÚsrò   s                   ró   Ú_set_keyr  É  s÷  € õ ×
Ò
˜8Ñ
$Ô
$�C€A€aØ	
ˆZ‰˜AÑ€AØ	
ˆZ‰˜AÑ€Aå
�1�Q�q˜Ñ
$Ô
$�C€A€aÝ�!‰Œ€AÝ�!‰Œ€AÝ
�1�Q�q˜Ñ
$Ô
$�C€A€aÝ
�1�Q�q˜Ñ
$Ô
$�C€A€aÝ
�1�Q�q˜Ñ
$Ô
$�C€A€að ˆz‰>˜bÑ
  Q¨¡^Ñ	4Øˆz‰>˜bÑ
 ñ
"Ø&'¨1¡f°
Ñ%:ñ
<€Aà	ˆJ‰€Aõ €GÝ=AÑ:€Eˆ5�%˜  u¨e°Uà	
ˆ�{˜Q‰Ñ€Aå•;ÑÔð $ñ $ˆà�1Œ:ð 	%Ø�a‘˜A ™GÑ$ˆAØ�a‘˜A ™GÑ$ˆAˆAà�a‘˜A ™GÑ$ˆAØ�a‘˜A ™GÑ$ˆAØ�
‰NˆØ�
‰Nˆà�a˜t‘mÔ8Ø�a˜!‘e˜t‘^¨¨Q©°$©Ñ7Ô8ñ9à�a˜‘e˜t‘^¨¨B©°$©Ñ7Ô8ñ9ð �a˜‘e˜t‘^Ø˜‘e˜t‘^ñ%Ø)*¨B©°$©ñ8ô 9ñ9ˆð �a˜t‘mÔ8Ø�a˜!‘e˜t‘^¨¨Q©°$©Ñ7Ô8ñ9à�a˜‘e˜t‘^Ô8ñ9ð �a˜‘e˜t‘^¨¨B©°$©Ñ7Ô8ñ9ˆð
 ˜‘7˜q :™~Ñ.°*Ñ<ˆˆ!ˆA‰#‰Ø�"‰W˜˜Z™Ñ(ˆð �!‰V˜˜b™ DÑ(Ñ)ˆØ˜‘^ˆˆ!ˆA‰#�‰'‰
‰
à€Hrõ   c                 ó8  — t           \  }}}}}}}	}
t          dt          dz  d¦  «        }dx}}t          d¦  «        D ]Ï}||}}|D ]Æ}||dz	  dz  z  }||z  }||z  }||dz  z  |z  | |         z  }||dz  z  |z  | |dz            z  }|dz	  dz  |d	z  z  }|||d
z           ||dz	  d
z           z  ||dz	  d
z           z  |
|dz	  d
z           z  ||d
z           z  ||dz	  d
z           z  ||dz	  d
z           z  |	|dz	  d
z           z  |z  }}ŒÇŒÐ|dz	  dz  |dz  dz  z  }|dz	  dz  |dz  dz  z  }t          ||dd¦  «        \  }}t          ||dd¦  «        \  }}t          ||dd¦  «        \  }}t          ||dd¦  «        \  }}t          ||dd¦  «        \  }}||fS )zDUse the key schedule ks and salt E0, E1 to create the password hash.r   r4   rÇ   r   r  ri   r   r  rÊ   rê   rI   rÆ   iÿÿÿrÍ   rý   rþ   i3333rü   )Ú_SPtransr  r  rú   )ÚksÚE0ÚE1ÚSP0ÚSP1ÚSP2ÚSP3ÚSP4ÚSP5ÚSP6ÚSP7ÚinnerÚlÚrÚjr  rò   Úus                     ró   Ú_bodyr+    sJ  € õ .6Ñ*€Cˆˆc�3˜˜S # så�!•[ ‘] AÑ&Ô&€EØ€I€AˆÝ�2‰YŒYð Dð DˆØ�ˆ!ˆØð 	Dð 	DˆAØ�a˜2‘g Ñ'Ñ(ˆAØ�B‘ˆAØ�B‘ˆAØ�Q˜"‘W‘ Ñ! B q¤EÑ)ˆAØ�Q˜"‘W‘ Ñ! B q¨¡s¤GÑ+ˆAØ�q‘&˜JÑ&¨1°©7Ñ3ˆAà�S˜! 4™Ô(¨3°°A±¸©~Ô+>Ñ>Ø˜!˜R™% 4™Ô(ñ)Ø+.°°2±¸©~Ô+>ñ?à˜! 4™Ô(ñ)à+.°°A±¸©~Ô+>ñ?ð ˜!˜R™% 4™Ô(ñ)ð ,/°°2±¸©~Ô+>ñ?ð BCñCˆaˆAˆAð	Dð ˆq‰&�JÑ	 A¨¡G°¡?Ñ3€AØ
ˆq‰&�JÑ	 A¨¡G°¡?Ñ3€Aå
�1�a˜!˜ZÑ
(Ô
(�C€A€aÝ
�1�a˜!˜ZÑ
(Ô
(�C€A€aÝ
�1�a˜!˜ZÑ
(Ô
(�C€A€aÝ
�1�a˜˜ZÑ
(Ô
(�C€A€aÝ
�1�a˜!˜ZÑ
(Ô
(�C€A€aàˆQˆ3€Jrõ   c                 óè  — t          |¦  «        dk    rd}nt          |¦  «        dk    r|dz   }t          |d         dz           }t          |d         dz           dz  }t          | dz   dd	…         ¦  «        }t          |||¦  «        \  }}|d
z  dz  |dz  z  |d
z	  dz  z  }|d	z	  dz  |d	z  dz  z  |d	z	  dz  z  }|dz  |d
z	  dz  z  }	|dz	  dz  |dz	  dz  |dz	  dz  |dz  |dz	  dz  |dz	  dz  |dz	  dz  |dz  |	dz	  dz  |	dz	  dz  |	dz	  dz  g}
t	          t          |
¦  «        ¦  «        D ]#}t
          |
|         |
|         dz   …         |
|<   Œ$|dd…         d                     |
¦  «        z   S )a  Generate an encrypted hash from the passed password.  If the password
is longer than eight characters, only the first eight will be used.

The first two characters of the salt are used to modify the encryption
algorithm used to generate in the hash in one of 4096 different ways.
The characters for the salt should be upper- and lower-case letters A
to Z, digits 0 to 9, '.' and '/'.

The returned hash begins with the two characters of the salt, and
should be passed as the salt to verify the password.

Example:

  >>> from fcrypt import crypt
  >>> password = 'AlOtBsOl'
  >>> salt = 'cE'
  >>> hash = crypt(password, salt)
  >>> hash
  'cEpWz5IUCShqM'
  >>> crypt(password, hash) == hash
  1
  >>> crypt('IaLaIoK', hash) == hash
  0

In practice, you would read the password using something like the
getpass module, and generate the salt randomly:

  >>> import random, string
  >>> saltchars = string.letters + string.digits + './'
  >>> salt = random.choice(saltchars) + random.choice(saltchars)

Note that other ASCII characters are accepted in the salt, but the
results may not be the same as other versions of crypt.  In
particular, '_', '$1' and '$2' do not select alternative hash
algorithms such as the extended passwords, MD5 crypt and Blowfish
crypt supported by the OpenBSD C library.
r   s   AAri   ó   Aé   r   s           NrI   r   r   rÿ   rµ   rÀ   rê   r»   r·   r4   rõ   )ÚlenÚ	_con_saltr  r+  r  Ú
_cov_2charÚjoin)r	  ÚsaltÚEswap0ÚEswap1r  Úo1Úo2Út1Út2Út3r(  r  s               ró   r   r   %  s¿  € õP ˆ4�y„y�A‚~€~ØˆˆÝ	ˆT‰Œ�aŠˆØ�d‰{ˆÝ�t˜A”w ‘~Ô&€FÝ�t˜A”w ‘~Ô&¨!Ñ+€Fõ 
�8ÐAÑAÀ2ÀAÀ2ÔFÑ	GÔ	G€BÝ�2�v˜vÑ&Ô&�F€Bˆð �‰(�XÑ
 " v¡+Ñ	.°"¸±(¸T±/Ñ	B€BØ
�‰'�HÑ
  q¡¨6Ñ!1Ñ	2°b¸A±gÀ±nÑ	E€BØ
ˆx‰-˜B "™H vÑ-Ñ	.€Bà
�‰(�T‰/˜2 ™8 d™?¨B°!©G°d©N¸BÀ¹IØ
�‰(�T‰/˜2 ™8 d™?¨B°!©G°d©N¸BÀ¹IØ
�‰(�T‰/˜2 ™8 d™?¨B°!©G°d©Nð	=€Aõ •3�q‘6”6‰]Œ]ð 'ð 'ˆÝ˜!˜Aœ$˜q œt A™v˜+Ô&ˆˆ!‰ˆØ���Œ8�c—h’h˜q‘k”kÑ!Ð!rõ   c                  ó<   — ddl } ddl}|                      |¦  «        S )zRun doctest on fcrypt module.r   N)ÚdoctestÚfcryptÚtestmod)r<  r=  s     ró   Ú_testr?  e  s,   € àÐÐÐÐÐÐÐØ�?Š?˜6Ñ"Ô"Ð"rõ   Ú__main__)Ú__doc__Ú
__author__Ú__version__Ú__date__Ú__credits__Ú__all__ÚstringÚstructr  r  r  r  r0  r1  rô   rú   ÚStructr  r  r+  r   r?  Ú__name__rð   rõ   ró   ú<module>rK     s  ððð ðB 0€
Ø€Ø€ð:€ð ˆ)€ð` Ð Ð Ð Ð Ð Ð Ð ð €ðP€ðdP€ðd -€ð€	ð& Q€
ð(ð (ð (ð
ð ð ð ˆFŒM˜%Ñ Ô €	ð6ð 6ð 6ðr ð  ð  ðF>"ð >"ð >"ð@#ð #ð #ð
 ˆzÒÐØ	€E�G„G€G€G€Gð Ðrõ   