# Crypto : Hashing
- https://en.wikipedia.org/wiki/Secure_Hash_Algorithms
> "The terms “secure hash” and “message digest” are interchangeable. The modern term is secure hash."
> - https://docs.python.org/3/library/hashlib.html
- [MD5](https://en.wikipedia.org/wiki/MD5) — Output 128 bit hashes = 16 bytes = 32 hex digits. Published in 1992. It remains suitable for other non-cryptographic purposes.
- [SHA-1](https://en.wikipedia.org/wiki/SHA-1) — Outputs 160 bit hashes = 20 bytes = 40 hex digits. Published in 1993. "Since 2005, SHA-1 has not been considered secure against well-funded opponents; as of 2010 many organizations have recommended its replacement. NIST formally deprecated use of SHA-1 in 2011 and disallowed its use for digital signatures in 2013, and declared that it should be phased out by 2030. As of 2020, chosen-prefix-attacks against SHA-1 are practical." *(wikipedia)*
- [SHA-2](https://en.wikipedia.org/wiki/SHA-2) — Family of six functions (SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, SHA-512/256). Outputs 224 (28B), 256 (32B), 384 (48B), or 512 (64B) bit hashes. Published in 2001.
- [SHA-3](https://en.wikipedia.org/wiki/SHA-3) aka Keccak — Published in 2015.
Cryptographic weaknesses were discovered in SHA-1, and the standard was no longer approved for most cryptographic uses after 2010.
## Python
```python
import hashlib
hashlib.algorithms_available
{'shake_128', 'blake2s', 'blake2b', 'md5-sha1', 'sha3_224', 'sha1', 'shake_256', 'sha3_512', 'sha384', 'sha512_256', 'sha512_224', 'sha512', 'sha3_256', 'sha3_384', 'sha256', 'sm3', 'sha224', 'md5'}
# same with any algorithm in hashlib.algorithms_available
h = hashlib.sha1( data: bytes ) -> haslib.HASH
h.name -> str # ex: "sha1"
h.update( data: bytes ) # append more data
h.digest_size -> int # ex: 20
h.digest -> bytes # ex: b"\x0b\xee\xc7\xb5\xea?\x0f\xdb\xc9]\r\xd4\x7f<[\xc2u\xda\x8a3"
h.hexdigest() -> str # ex: "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"
hashlib.file_digest( fileobj, "ALGORITHM" ) -> hashlib.HASH obj # fileobj must be in "rb" mode
```