Skip to content

Instantly share code, notes, and snippets.

View tricky-labyrinth's full-sized avatar

Tricky Labyrinth tricky-labyrinth

View GitHub Profile
@tricky-labyrinth
tricky-labyrinth / ml_kem.py
Created April 20, 2025 21:26
A simple python implementation of the NIST ML-KEM specification.
# This is a reference implementation for the ML-KEM NIST standard, located @ https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.203.pdf.
# It's definitely not secure to timing attacks, and almost certainly not secure in other ways too. DO NOT USE THIS IN PRODUCTION.
# It's not very performant. Even in Python, it could be written significantly faster.
# My goal with this implementation was just to try to get the math correct, as simply as possible in Python,
# by matching the specification above line by line. Understanding this code is much easier with the above spec open.
import secrets
import hashlib