Safeguard
Security Guides•

How do you review AI-written cryptography code before it ships?

A checklist for reviewing cryptography an AI assistant wrote: algorithms, keys, randomness, password hashing and IV reuse, based on OWASP guidance.

Safeguard Security Team
3 min read

Review AI-written cryptography against a fixed checklist: no deprecated algorithms, no hard-coded keys, a secure random source, adaptive password hashing, and no reused initialization vectors. Better still, ask whether the code should exist at all, since a maintained library call usually beats custom crypto from any author.

Why this code deserves extra care

Cryptographic code can run without errors and still be broken. A test that encrypts and decrypts proves little about whether the choice of mode, key handling or randomness is safe. OWASP lists Cryptographic Failures as its own category in the 2021 Top 10, and the page maps weaknesses such as use of a hard-coded key (CWE-321) and a hard-coded password (CWE-259) to it.

An assistant will often produce a plausible snippet in the style of older examples. You need a reviewer who knows what to look for.

The checklist

CheckWhat OWASP guidance says
AlgorithmsAvoid deprecated functions and padding schemes such as MD5, SHA1 and PKCS number 1 v1.5
KeysGenerate keys cryptographically at random, manage and rotate them, and do not check them into source repositories
PasswordsUse strong, adaptive, salted hashing with a work factor, such as Argon2, scrypt, bcrypt or PBKDF2
RandomnessUse a cryptographically secure random number generator for cryptographic purposes
IVs and noncesNever reuse an initialization vector with the same fixed key
ModePrefer authenticated encryption over encryption alone
TransportTLS with forward secrecy; do not send sensitive data over legacy protocols

Review steps

  1. Search the diff for the names of hash, cipher and random functions. List each one with its purpose.
  2. Compare each against the table. Anything on the deprecated list needs a written reason.
  3. Trace where each key comes from and where it is stored. A literal string in code fails the review.
  4. Check password handling separately. A fast hash, even salted, is the wrong tool.
  5. Confirm that a standard library or maintained package does the work. Hand-rolled primitives are a red flag.
  6. Add a test that would fail if the algorithm were downgraded.

What a scanner can and cannot do

A static analysis rule can flag a weak hash call or a literal key. It will not tell you that a nonce is derived from a counter that resets after restart. That judgment is the reviewer's, which is why the checklist exists. For the matching key problem see hardcoded secrets in AI-generated code.

Where Safeguard fits

Safeguard runs SAST and secret detection on pull requests, and a policy can block a merge on those findings. A free scan will show what is already in your repository.

Try it yourself

Click through it at your own pace, or open it full screen.

Click through the code scan and look at how a finding points to the exact line and rule.

Quick check

Is SHA1 ever acceptable?

OWASP advises avoiding it among deprecated functions. If an old protocol forces it, document the reason and plan to move.

Should I let an assistant write encryption code at all?

Use it to wire up a vetted library, not to invent primitives, and review the result against this list.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.