Datasets:
id stringlengths 6 14 | cwe stringclasses 9
values | category stringclasses 9
values | label stringclasses 2
values | code stringlengths 66 209 |
|---|---|---|---|---|
wh_md5pw | CWE-328 | weak_hash | vuln | import hashlib
def store_password(pw):
return hashlib.md5(pw.encode()).hexdigest()
|
wh_sha1pw | CWE-328 | weak_hash | vuln | import hashlib
def hash_pw(pw):
return hashlib.sha1(pw.encode()).hexdigest()
|
wh_md5tok | CWE-328 | weak_hash | vuln | import hashlib
def api_token(user_id):
return hashlib.md5(str(user_id).encode()).hexdigest()
|
wh_sha1sig | CWE-328 | weak_hash | vuln | import hashlib
def sign(msg, key):
return hashlib.sha1(key + msg).hexdigest()
|
wh_bcrypt | CWE-328 | weak_hash | secure | import bcrypt
def store_password(pw):
return bcrypt.hashpw(pw.encode(), bcrypt.gensalt())
|
wh_argon | CWE-328 | weak_hash | secure | from argon2 import PasswordHasher
ph = PasswordHasher()
def store_password(pw):
return ph.hash(pw)
|
ecb_aes | CWE-327 | ecb_mode | vuln | from Crypto.Cipher import AES
def enc(key, data):
c = AES.new(key, AES.MODE_ECB)
return c.encrypt(data)
|
ecb_aes2 | CWE-327 | ecb_mode | vuln | from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
def enc(key, data):
c = Cipher(algorithms.AES(key), modes.ECB())
e = c.encryptor()
return e.update(data) + e.finalize()
|
ecb_field | CWE-327 | ecb_mode | vuln | from Crypto.Cipher import AES
def encrypt_ssn(key, ssn):
return AES.new(key, AES.MODE_ECB).encrypt(ssn.ljust(16).encode())
|
ecb_loop | CWE-327 | ecb_mode | vuln | from Crypto.Cipher import AES
def enc_blocks(key, blocks):
c = AES.new(key, AES.MODE_ECB)
return [c.encrypt(b) for b in blocks]
|
ecb_gcm | CWE-327 | ecb_mode | secure | import os
from Crypto.Cipher import AES
def enc(key, data):
nonce = os.urandom(12)
c = AES.new(key, AES.MODE_GCM, nonce=nonce)
ct, tag = c.encrypt_and_digest(data)
return nonce, ct, tag
|
ecb_cbc | CWE-327 | ecb_mode | secure | import os
from Crypto.Cipher import AES
def enc(key, data):
iv = os.urandom(16)
return iv, AES.new(key, AES.MODE_CBC, iv).encrypt(data)
|
hk_aes | CWE-321 | hardcoded_key | vuln | from Crypto.Cipher import AES
KEY = b"0123456789abcdef"
def enc(data, iv):
return AES.new(KEY, AES.MODE_CBC, iv).encrypt(data)
|
hk_hmac | CWE-321 | hardcoded_key | vuln | import hmac, hashlib
SECRET = b"s3cr3t_signing_key"
def sign(msg):
return hmac.new(SECRET, msg, hashlib.sha256).hexdigest()
|
hk_jwt | CWE-321 | hardcoded_key | vuln | import jwt
JWT_SECRET = "my-hardcoded-jwt-secret"
def make_token(uid):
return jwt.encode({"uid": uid}, JWT_SECRET, algorithm="HS256")
|
hk_fernet | CWE-321 | hardcoded_key | vuln | from cryptography.fernet import Fernet
KEY = b"dGhpc19pc19hX2hhcmRjb2RlZF9rZXlfMTIzND0="
def enc(data):
return Fernet(KEY).encrypt(data)
|
hk_env | CWE-321 | hardcoded_key | secure | import os
from Crypto.Cipher import AES
def enc(data, iv):
key = os.environ["AES_KEY"].encode()
return AES.new(key, AES.MODE_CBC, iv).encrypt(data)
|
hk_env2 | CWE-321 | hardcoded_key | secure | import os, hmac, hashlib
def sign(msg):
secret = os.environ["SIGNING_KEY"].encode()
return hmac.new(secret, msg, hashlib.sha256).hexdigest()
|
iv_zero | CWE-329 | static_iv | vuln | from Crypto.Cipher import AES
IV = b"\x00" * 16
def enc(key, data):
return AES.new(key, AES.MODE_CBC, IV).encrypt(data)
|
iv_const | CWE-329 | static_iv | vuln | from Crypto.Cipher import AES
IV = b"1234567890abcdef"
def enc(key, data):
return AES.new(key, AES.MODE_CFB, IV).encrypt(data)
|
iv_nonce | CWE-329 | static_iv | vuln | from Crypto.Cipher import AES
NONCE = b"000000000000"
def enc(key, data):
c = AES.new(key, AES.MODE_GCM, nonce=NONCE)
return c.encrypt(data)
|
iv_reuse | CWE-329 | static_iv | vuln | from Crypto.Cipher import AES
def enc(key, data, iv=b"\x11"*16):
return AES.new(key, AES.MODE_CBC, iv).encrypt(data)
|
iv_rand | CWE-329 | static_iv | secure | import os
from Crypto.Cipher import AES
def enc(key, data):
iv = os.urandom(16)
return iv, AES.new(key, AES.MODE_CBC, iv).encrypt(data)
|
iv_rand2 | CWE-329 | static_iv | secure | import os
from Crypto.Cipher import AES
def enc(key, data):
nonce = os.urandom(12)
c = AES.new(key, AES.MODE_GCM, nonce=nonce)
return nonce, c.encrypt(data)
|
pr_token | CWE-338 | weak_prng | vuln | import random
def make_token(n=16):
return "".join(random.choice("0123456789abcdef") for _ in range(n))
|
pr_otp | CWE-338 | weak_prng | vuln | import random
def generate_otp():
return random.randint(100000, 999999)
|
pr_reset | CWE-338 | weak_prng | vuln | import random, string
def reset_token():
return "".join(random.choices(string.ascii_letters, k=32))
|
pr_seed | CWE-338 | weak_prng | vuln | import random, time
def session_key():
random.seed(time.time())
return random.getrandbits(128)
|
pr_secrets | CWE-338 | weak_prng | secure | import secrets
def make_token(n=16):
return secrets.token_hex(n)
|
pr_secrets2 | CWE-338 | weak_prng | secure | import secrets
def reset_token():
return secrets.token_urlsafe(32)
|
sk_rsa512 | CWE-326 | short_key | vuln | from Crypto.PublicKey import RSA
def gen():
return RSA.generate(512)
|
sk_rsa1024 | CWE-326 | short_key | vuln | from Crypto.PublicKey import RSA
def gen():
return RSA.generate(1024)
|
sk_dsa | CWE-326 | short_key | vuln | from Crypto.PublicKey import DSA
def gen():
return DSA.generate(512)
|
sk_rsa768 | CWE-326 | short_key | vuln | from cryptography.hazmat.primitives.asymmetric import rsa
def gen():
return rsa.generate_private_key(public_exponent=65537, key_size=768)
|
sk_rsa3072 | CWE-326 | short_key | secure | from Crypto.PublicKey import RSA
def gen():
return RSA.generate(3072)
|
sk_rsa4096 | CWE-326 | short_key | secure | from cryptography.hazmat.primitives.asymmetric import rsa
def gen():
return rsa.generate_private_key(public_exponent=65537, key_size=4096)
|
bc_des | CWE-327 | broken_cipher | vuln | from Crypto.Cipher import DES
def enc(key, data):
return DES.new(key, DES.MODE_ECB).encrypt(data)
|
bc_3des | CWE-327 | broken_cipher | vuln | from Crypto.Cipher import DES3
def enc(key, data, iv):
return DES3.new(key, DES3.MODE_CBC, iv).encrypt(data)
|
bc_rc4 | CWE-327 | broken_cipher | vuln | from Crypto.Cipher import ARC4
def enc(key, data):
return ARC4.new(key).encrypt(data)
|
bc_blowfish | CWE-327 | broken_cipher | vuln | from Crypto.Cipher import Blowfish
def enc(key, data, iv):
return Blowfish.new(key, Blowfish.MODE_CBC, iv).encrypt(data)
|
bc_aesgcm | CWE-327 | broken_cipher | secure | import os
from Crypto.Cipher import AES
def enc(key, data):
n = os.urandom(12)
return n, AES.new(key, AES.MODE_GCM, nonce=n).encrypt(data)
|
bc_chacha | CWE-327 | broken_cipher | secure | import os
from Crypto.Cipher import ChaCha20
def enc(key, data):
n = os.urandom(12)
return n, ChaCha20.new(key=key, nonce=n).encrypt(data)
|
ns_sha256 | CWE-759 | no_salt | vuln | import hashlib
def derive(pw):
return hashlib.sha256(pw.encode()).hexdigest()
|
ns_md5 | CWE-759 | no_salt | vuln | import hashlib
def derive(pw):
return hashlib.md5(pw.encode()).digest()
|
ns_lowiter | CWE-916 | no_salt | vuln | import hashlib
def derive(pw, salt):
return hashlib.pbkdf2_hmac("sha256", pw.encode(), salt, 100)
|
ns_double | CWE-759 | no_salt | vuln | import hashlib
def derive(pw):
return hashlib.sha256(hashlib.sha256(pw.encode()).digest()).hexdigest()
|
ns_pbkdf2 | CWE-759 | no_salt | secure | import os, hashlib
def derive(pw):
salt = os.urandom(16)
return salt, hashlib.pbkdf2_hmac("sha256", pw.encode(), salt, 200000)
|
ns_scrypt | CWE-759 | no_salt | secure | import os, hashlib
def derive(pw):
salt = os.urandom(16)
return salt, hashlib.scrypt(pw.encode(), salt=salt, n=16384, r=8, p=1)
|
cv_verifyfalse | CWE-295 | cert_verify | vuln | import requests
def fetch(url):
return requests.get(url, verify=False).text
|
cv_sslctx | CWE-295 | cert_verify | vuln | import ssl, urllib.request
def fetch(url):
ctx = ssl._create_unverified_context()
return urllib.request.urlopen(url, context=ctx).read()
|
cv_certnone | CWE-295 | cert_verify | vuln | import ssl
def ctx():
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
|
cv_session | CWE-295 | cert_verify | vuln | import requests
def client():
s = requests.Session()
s.verify = False
return s
|
cv_verifytrue | CWE-295 | cert_verify | secure | import requests
def fetch(url):
return requests.get(url).text
|
cv_pinned | CWE-295 | cert_verify | secure | import requests
def fetch(url):
return requests.get(url, verify="/etc/ssl/ca-bundle.pem").text
|
CryptoBench: Testing LLM Detection of Cryptographic API Misuse
A controlled benchmark for measuring which classes of cryptographic API misuse a code-reviewing language model catches, and which it misses.
- 54 Python snippets across nine misuse classes: 36 vulnerable, 18 matched secure controls that do the same task correctly.
- 1,890 recorded trials: every snippet, 5 repeats, 7 open code models run locally through Ollama at its default sampling settings. The dataset viewer shows 1,944 rows in total because it adds the 54 snippets to the 1,890 results.
- Verdict-only protocol: the model answers
VERDICT: VULNERABLEorVERDICT: SAFEwith a one-sentence reason.
Try it in 2 minutes
from datasets import load_dataset
snippets = load_dataset("sunny-chokshi/cryptobench", "snippets", split="train")
results = load_dataset("sunny-chokshi/cryptobench", "results", split="train")
print(snippets[0]["category"], snippets[0]["label"])
print(snippets[0]["code"])
To test your own model, use the harness in the GitHub repository (python3 crypto_bench.py --model <ollama-model> --repeats 5) and share the result.
Misuse classes
| Class | CWE |
|---|---|
| Weak password hash (MD5 / SHA-1) | 328 |
| ECB mode | 327 |
| Hardcoded key or secret | 321 |
| Static or reused IV / nonce | 329 |
| Weak PRNG for security values | 338 |
| Short asymmetric key | 326 |
| Obsolete / broken cipher (DES, RC4, Blowfish) | 327 |
| Unsalted or fast KDF | 759 / 916 |
| Disabled certificate verification | 295 |
Configs
snippets (snippets.jsonl): id, cwe, category, label (vuln or secure), code.
results (crypto_results.jsonl): ts, model, sample_id, cwe, category, label, verdict, detected, correct, repeat, note. One row is one trial. detected is 1 when the verdict was VULNERABLE, and correct is 1 when the verdict matches label. The repeat column is not a unique index: it takes the values 0, 1 and 2, and the values 0 and 1 appear twice for each model and snippet, so each model-snippet pair has five rows. Use ts to order them.
Models in the results
qwen2.5-coder 0.5B / 1.5B / 3B / 7B / 14B, deepseek-coder 6.7B, codellama 7B.
Key finding
Four of seven models barely discriminate. codellama 7B and qwen2.5-coder 0.5B flag 90% and 93% of the secure snippets, and qwen2.5-coder 1.5B and 3B flag 70% and 68% of them, against 71% and 78% of the vulnerable ones. Among the three that discriminate (qwen2.5-coder 7B and 14B, deepseek-coder 6.7B), detection ranges from 96.7% for disabled certificate verification down to 38.3% for weak PRNG used for security tokens. Those class rates pool the three models: 60 reviews per class, from only 4 vulnerable snippets. Misuse that carries a known-bad name (DES, MD5, verify=False) is caught; misuse that is an ordinary API in the wrong place is not, and larger models do not close the gap.
Limitations
- Each class has 4 vulnerable and 2 secure snippets. Five repeats of one snippet are not five independent examples, so a per-class rate rests on 4 distinct vulnerable snippets, and a false-alarm rate on 18 distinct secure ones.
- The snippets are short, synthetic Python functions, reviewed one at a time. The results say nothing about other languages, longer files or whole repositories.
- Seven local models, from 0.5B to 14B parameters, at Ollama's default sampling settings. No larger or hosted models were tested.
- The protocol records the verdict only. A VULNERABLE verdict counts as a detection even if the model's reason names a different flaw.
- The dataset files give counts, not confidence intervals.
scripts/analyze.pyin the GitHub repository computes Wilson 95% intervals.
Harness and reproduction
The harness and analysis script live in the companion GitHub repository: https://github.com/sunny-chokshi/cryptobench python3 scripts/analyze.py regenerates every number above with Wilson 95% intervals.
Safety
All snippets are synthetic. No real credentials, no exploit code, nothing that touches a live system.
Citation
Paper: S. Chokshi, "Known-Bad Names, Unknown-Bad Uses: What Local Code Models Detect When They Review Cryptographic API Misuse," preprint, Zenodo, 2026. doi:10.5281/zenodo.23113861
Dataset: S. Chokshi, CryptoBench, Zenodo, 2026. All versions: doi:10.5281/zenodo.23067051 (v1.0.0: doi:10.5281/zenodo.23067052; v1.1.0: doi:10.5281/zenodo.23680776)
Author: Sunny Chokshi, University of the Cumberlands. ORCID 0009-0003-4738-7759.
Write-up: https://sunny-chokshi.github.io/blog/ | Zenodo (all versions): https://doi.org/10.5281/zenodo.23067051
- Downloads last month
- 51