News

Python Integrates Verified Cryptography with HACL*

Python Integrates Verified Cryptography with HACL*

April 18, 2025
Python HACL* Cryptography Hashlib Verified Code Security OpenSSL Streaming APIs Error Management
Python has fully integrated HACL*, a verified cryptographic library, into its core hashlib module, enhancing security and reliability for default hash and HMAC algorithms.

Python's Integration with HACL* for Verified Cryptography

Python has fully integrated HACL*, a verified cryptographic library, into its core hashlib module. This integration ensures that all default hash and HMAC algorithms in Python are now provided by HACL*, offering enhanced security and reliability.

Key Highlights of the Integration

  • Verified Code: HACL* provides mathematically verified implementations of cryptographic primitives, ensuring memory safety, functional correctness, and resistance to timing side-channels.
  • Transparency: The transition to HACL* was seamless for Python users, with no loss of functionality.
  • Automated Updates: Python now vendors 15,000 lines of verified C code from HACL*, with automated scripts to pull newer versions from the upstream repository.
  • Performance: HACL* implementations are competitive with, and sometimes exceed, the performance of OpenSSL and other cryptographic libraries.

Technical Details

The integration involved several technical advancements:

  • Streaming APIs: HACL*'s generic streaming API was adapted to handle various block algorithms, ensuring efficient and secure processing of data blocks.
  • Build System: The build process was refined to handle complex dependencies, including the use of abstract structs to manage AVX2 optimizations without compromising compatibility.
  • Error Management: The implementation was updated to propagate memory allocation failures, ensuring robust error handling.

Conclusion

This integration marks a significant milestone in the adoption of verified cryptographic code in real-world software. Python's use of HACL* demonstrates that formally verified cryptography is not only academically sound but also practical for large-scale, production environments.

For more details, you can refer to the detailed blog post by Jonathan Protzenko, one of the key contributors to this effort.

Sources

15000 lines of verified cryptography now in Python HACL* was able to successfully implement new features to meet all of the requirements of Python, such as: additional modes for the Blake2 family ...
Replace built-in hashlib with verified implementations from HACL We propose to replace the non-OpenSSL cryptographic primitives in hashlib with high-assurance, verified versions from the HACL* project.
HACL*: A Verified Modern Cryptographic Library HACL is a verified portable C cryptographic library that implements modern cryptographic primitives such as the ChaCha20 and Salsa20 encryption algorithms.