Repository navigation
SHA and BigInteger intrinsics - #20
Conversation
…turn KeyPairGenerator/Failover to the passing list.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 8 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
There was a problem hiding this comment.
This PR adds native JavaScript intrinsics for SHA-1/256/512 compression and BigInteger arithmetic (Montgomery multiply/square, multiply, square, mulAdd) to replace bytecode that allocated a JS BigInt per 64-bit operation. Performance improvements are significant. However, the SHA and SHA-512 implementations use module-level shared mutable arrays (w32, wh, wl, sh, sl) which will cause data corruption when multiple threads execute these intrinsics concurrently. The JVM supports threading, so this is a correctness bug.
review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict request_changes
There was a problem hiding this comment.
This PR adds high-performance intrinsics for SHA-1/256/512 compression and BigInteger arithmetic (Montgomery multiply/square, multiply, square, mulAdd). The algorithms are correct and deliver large speedups. However, the SHA implementations use module-level shared arrays (w32 for SHA-1/256; wh, wl, sh, sl for SHA-512) for the message schedule and working variables. Concurrent calls from different threads will overwrite each other's state, producing wrong digests. This is a correctness bug that must be fixed before merge.
review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict request_changes
There was a problem hiding this comment.
This PR adds native JavaScript intrinsics for SHA-1, SHA-256, SHA-512 block compression and BigInteger arithmetic (Montgomery multiply/square, multiplyToLen, squareToLen, mulAdd), replacing bytecode that allocated a JS BigInt per 64-bit operation. Performance improves by 10-50x on benchmarks. The CryptoMath test verifies correctness against HotSpot across SHA variants, HMAC, and BigInteger operations up to 4100 bits.
Not approved: 3 earlier points are still open in the threads.
review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict comment
Superseded by the review of 43ef332, which has no blocking findings, and its threads are settled.
Part of #15.
HotSpot replaces these methods with intrinsics; java-web ran them as bytecode, where every Java
longoperation allocates a JS BigInt.src/natives/crypto.tsimplements them in JS through the existing intrinsics table:SHA.implCompress0,SHA2.implCompress0,SHA5.implCompress0: SHA-1, SHA-224/256 and SHA-384/512 block compression on the digest'sstate(SHA-512 on 32-bit halves, so no BigInt).BigInteger.implMontgomeryMultiply,implMontgomerySquare(one BigInt REDC; the result fully reduced inproduct[0..len), the rest of a 2 len product zeroed, as the Java version leaves it),implMultiplyToLen,implSquareToLenandimplMulAdd.Measured on a small ARM board, two cores (HotSpot in brackets):
modPow, 2048 bit x 20java/security/KeyPairGenerator/Failover.javatakes 13 s there now and returns topassing.txt.java/security/SecureRandom/NoSync.javawent from about 235 s to 114 s, still too close to CI's timeout, so it stays out: what remains is general cost (long arithmetic inMutableBigInteger, many small calls around each HMAC and AES block), not the intrinsified methods. #15 stays open for it.test/java/CryptoMath.javacompares with HotSpot: every SHA variant at lengths around the block boundaries and from an offset, HMAC-SHA512, BigInteger multiply, square,powandmodPow(odd and even moduli) from 31 to 4,100 bits, deterministic RSA-2048 key generation andprobablePrime.Verified:
CryptoMath,NoSyncandFailoverthrough the jtreg runner,pnpm typecheck. CI runs every OpenJDK test, since the natives changed.