feat: add BinPoly arithmetic layer, expand ASN.1/X.509/Ed25519 test coverage, and miscellaneous cleanups#108
Merged
Merged
Conversation
- Fix handling of hex-escaped UTF8 in X509Name - Support S as a parsing alias for ST in X509Name
- High-tag support in ASN.1 streaming generators - Add more ASN.1 time format tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a new binary-polynomial (GF(2^n)) arithmetic subsystem,
expands test coverage across ASN.1, X.509, Ed25519, and utility layers,
adds an ONVIF raw-keyBag PKCS#12 fixture, and applies several small
correctness and structural cleanups throughout the library.
New: Binary Polynomial (BinPoly) Arithmetic
A self-contained GF(2^n) arithmetic layer has been added under
CryptoLib/src/Math/BinPoly/andCryptoLib/src/Interfaces/Math/BinPoly/.Interfaces
ClpIBinPolyMul—IBinPolyMul: multiply, square, squareN, sizeClpIBinPolyInv—IBinPolyInv: field inversionScalar (portable) backend
ClpBinPolyScalarKernels— core carryless-multiply kernelsClpBinPolyScalarMedium/ClpBinPolyScalarLarge— size-dispatch wrappersClpBinPolyScalarBackend— backend wiringx86 SSE2/PCLMULQDQ backend
ClpBinPolyX86V128Kernels/ClpBinPolyX86V128SizesClpBinPolyX86V128Medium/ClpBinPolyX86V128LargeClpBinPolyX86V128BackendReduction strategies
ClpBinPolyMulBaseBinomialReduce— x^r + 1 reduction (BIKE-style)ClpBinPolyMulBaseTrinomialReduce— x^n + x^k + 1ClpBinPolyMulBasePentanomialReduce— x^n + x^k3 + x^k2 + x^k1 + 1Supporting units
ClpBinPolyMulBase— abstract base for all mul implementationsClpItohTsujiiInv— Itoh–Tsujii inversion algorithmClpBinPolys— public facade:Create,Add,AddTo,Zero,EqualTo,TBinPolysMul.Binomial/Trinomial/PentanomialClpIF2mFieldData/ClpF2mFieldData— F(2^m) field parameter data,replacing the previous
ClpLongArrayreference in all.dpr/.lprproject files
New Tests
BinPolyTests.pas— comprehensive property-based tests for the newarithmetic layer covering:
AddandAddToagainst XOR reference for BIKE-R1Multiply,Square,SquareNagainst reference implementations forbinomial, trinomial, and pentanomial reductions across many sizes
(including small edge cases, even-degree binomials, and BIKE-R1)
RunAllOpsAtOffsets) verifying no out-of-boundswrites to input or surrounding buffer regions
Invert(0)=0,Invert(1)=1,a*inv(a)=1,inv(inv(a))=a, and in-place inversionAsn1GeneratorTests.pas— new test suite for streaming ASN.1 generators:of tag numbers
Asn1TimeFormatTests.pas— accept/reject format tests forTAsn1UtcTimeandTAsn1GeneralizedTime:IdpRelativeNameTests.pas— tests forTIssuingDistributionPointrelative distinguished name encoding and round-trip parsing.
BinaryPrimitivesTests.pas— tests forTBinaryPrimitives:ReadUInt16/32/64LE/BE array vs pointer overloadsCopyUInt32/64LE/BE bulk copy correctnessByteUtilitiesTests.pas— tests forTByteUtilitiesnumber-utilityhelpers.
New Test Data
CryptoLib.Tests/Data/Pkcs/Pkcs12Store/Stores/RawKeyBagStore.der—binary PKCS#12 store containing an ONVIF raw
keyBag(noshroudedKeyBag), for testing stores where the private key is carriedunencrypted.
CryptoLib.Tests/Data/Pkcs/Pkcs12Store/Manifest.csv— entry added forthe new store (
RawKeyBagStore, no password).Ed25519 Additions
ImplTestEd25519ConsistencyExpandedKey— consistency tests betweenseed-path signing and
TExpandedKey-path signing for both the standardSHA-512 digest and the Blake2b variant, including sign/verify
round-trips and single-bit corruption rejection.
TestEd25519ExpandedKeyBlake2bPinnedVector— pinned known-answer testfor the Blake2b
ExpandedKeypath against a fixed sk/xk/pk/sig tuple.TestEd25519ConsistencyExpandedKey/TestEd25519ConsistencyExpandedKeyBlake2b— published test methods wiring the above.
Ed448 Fix
TEd448.Precompute()call fromTTestEd448.SetUp; precomputation is handled internally and theexplicit call was unnecessary.
Structural Cleanups
Bootmethod elimination — the two-stepclass constructor → Boot()indirection has been collapsed into a direct
class constructorbodyacross multiple classes:
TX509AttrCertParser,TX509CertificateParser,TX509CrlParser,TX509Utilities,TOSRandomProviderIn each case the
Bootmethod is removed and its body is inlined directlyinto the
class constructor. ForTX509UtilitiesandTOSRandomProviderthe
class destructordeclaration order is also corrected to follow theclass constructorin the implementation section.Asn1SequenceParserTeststidy-up — allTDerInteger.Create(TBigInteger.Zero/One/ValueOf(n))call sites replacedwith
TDerInteger.ValueOf(n), which is the preferred allocation-friendlyfactory.
Project file updates — all Delphi
.dprfiles(
CryptoLib.Tests.dpr,CryptoLib.Tests.Mobile.dpr,CryptoLib.BenchmarkConsole.dpr,CryptoLib.Examples.dpr) and theLazarus
.lpi/.lprfiles updated to:ClpLongArraywith the new BinPoly unit setsrc\Math\BinPolyto the FPCOtherUnitFilessearch path