Skip to content

Accept negative ENUMERATED values, make PKCS12 write iterations configurable, and wipe transient key material - #216

Merged
Xor-el merged 1 commit into
masterfrom
feature/asn1-dump-pkcs12-key-hygiene
Oct 28, 2026
Merged

Xor-el merged 1 commit into
masterfrom
feature/asn1-dump-pkcs12-key-hygiene

Conversation

@Xor-el

@Xor-el Xor-el commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Summary

Several independent hardening and correctness changes to ASN.1 handling, PKCS#12 writing, and key hygiene.

ASN.1 ENUMERATED

  • DerEnumerated now accepts negative values. X.690 encodes an ENUMERATED as a signed integer, so a negative value is well formed; the previous non-negative check rejected valid encodings. The malformed-encoding check is retained.
  • Adds TryGetIntValueExact to IDerEnumerated, with GetIntValueExact delegating to it.

ASN.1 dumping

  • Asn1Dumper gains AppendAsString overloads so callers can build into an existing buffer; DumpAsString delegates to them. X509Certificate.ToString uses the new path.

Key hygiene

  • The HMAC k-calculator wipes the private scalar bytes after seeding the HMAC, so the secret does not linger in the working buffers.

PKCS#12 write iterations

  • Write-side iteration counts are driven by a configurable TCryptoLibConfig.Pkcs12.StoreIterationCount (default 300000, MAC uses twice the key/cert count, clamped to a sane range). On load, a verified file's MAC configuration is latched and reproduced on save.

Tests

  • ML-DSA and SLH-DSA component encoding-length checks (private, public, and seed lengths where applicable, with bad-length rejection).
  • A negative-value ENUMERATED round-trip test.

…gurable, and wipe transient key material

DerEnumerated now accepts negative values per X.690 signed-integer encoding and gains TryGetIntValueExact. Asn1Dumper gains AppendAsString overloads so callers can build into an existing buffer. The HMAC k-calculator wipes the private scalar bytes after seeding. PKCS12 write-side iteration counts are driven by a configurable StoreIterationCount. Adds ML-DSA and SLH-DSA component encoding-length tests and a negative-ENUMERATED round-trip test.
@Xor-el
Xor-el merged commit 3933ecd into master Oct 28, 2026
28 checks passed
@Xor-el
Xor-el deleted the feature/asn1-dump-pkcs12-key-hygiene branch October 28, 2026 22:56
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