Skip to content

Import the first private key from a PEM file, and tighten random-source and ML-KEM input checks - #222

Merged
Xor-el merged 2 commits into
deep-audit-fixesfrom
audit-cry-crypto
Oct 6, 2026
Merged

Xor-el merged 2 commits into
deep-audit-fixesfrom
audit-cry-crypto

Conversation

@Xor-el

@Xor-el Xor-el commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

The portable key import read only the first PEM object, so openssl ecparam -genkey output (EC PARAMETERS, then the key) and cert+key bundles failed with a misleading malformed-key error while the Windows overlay imported them. The blocks are now framed without being parsed, the first private key is picked, and only that block (with its RFC 1421 headers, so legacy encrypted keys still decrypt) is parsed. Objects ahead of the key, including types the reader has no parser for, are never judged.

Also: the random-source bridge range-checks the span it fills and refuses a short read from an injected source instead of copying past it; ML-KEM-768 encapsulation keys are checked for coefficients below q in the named group (FIPS 203 7.2), so a backend that only checks the length no longer lets one through (the native facet left it to the OS import); and the native PKCS#12 key is adopted only when it has the same public key as the portable parse.

Test data comes from openssl and lives in ImportKeys.txt (an EC key file with its parameters, and one with an unrecognised block ahead of the key). The ML-KEM test runs against the default provider and a test provider whose KEM checks only the length, and fails if the group's own check is removed. Each change has a test that fails without it. FPC x64 and i386 1439/0, Delphi Win32 OK, BoGo hard gate in portable and native-crypto modes and the fuzzer smoke clean.

Xor-el added 2 commits October 6, 2026 20:42
…KEM input checks

- A key file is no longer read as its first PEM object. `openssl ecparam
  -genkey` writes EC PARAMETERS ahead of the key and cert+key bundles lead with
  the chain, so the portable import failed where the Windows overlay did not.
  The blocks are now framed without being parsed, the first private key is
  chosen, and only that block (headers included, so legacy encrypted keys still
  decrypt) goes through the PEM reader.
- The portable RSASSA-PKCS1-v1_5 handshake verifier sets StrictDigestInfo, so a
  DigestInfo without the NULL parameters is not accepted (RFC 8017 9.2).
- The bridge that serves an injected random source to the crypto backend checks
  the span it fills and refuses a source that returns fewer bytes than asked.
- ML-KEM-768 encapsulation keys are checked for coefficients below q (FIPS 203
  7.2) in the named group, so the check holds for every backend; the native
  facet previously left it to the OS import.
- The native PKCS#12 key replaces the portable one only when both parsers chose
  the same public key.
Take the handshake verifier's StrictDigestInfo call, its test and the vector out of this change; the strict check will come back as part of a wider one.
@Xor-el Xor-el changed the title Import the first private key from a PEM file, and tighten RSA and ML-KEM input checks Import the first private key from a PEM file, and tighten random-source and ML-KEM input checks Oct 6, 2026
@Xor-el
Xor-el merged commit 69035d2 into deep-audit-fixes Oct 6, 2026
15 checks passed
@Xor-el
Xor-el deleted the audit-cry-crypto branch October 7, 2026 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant