Skip to content

Speed up crypto reference implementations#2526

Merged
jviotti merged 3 commits into
mainfrom
optimise-reference-crypto
Jun 17, 2026
Merged

Speed up crypto reference implementations#2526
jviotti merged 3 commits into
mainfrom
optimise-reference-crypto

Conversation

@jviotti

@jviotti jviotti commented Jun 17, 2026

Copy link
Copy Markdown
Member

Signed-off-by: Juan Cruz Viotti jv@jviotti.com

Review in cubic

Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@augmentcode

augmentcode Bot commented Jun 17, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: This PR speeds up the reference crypto verification backend by replacing expensive generic big-integer operations with curve-specific optimizations.

Changes:

  • Replaced modular inverse via Fermat exponentiation with a binary extended Euclidean modular inverse in crypto_bignum.h.
  • Added fast field reduction paths for NIST P-256/P-384 (generalized Mersenne primes) and P-521 (2^521−1) in crypto_ecc.h.
  • Introduced NISTPrime and a per-curve reduction selector to route reductions to the correct specialized routine.
  • Switched ECC point arithmetic to use the new field multiply/square helpers to avoid long-division based modular reductions.
  • Added mixed Jacobian+affine point addition and affine normalization to reduce the cost of repeated additions.
  • Implemented Shamir’s trick (point_double_scalar_multiply) to compute u1*G + u2*Q with a single ladder.
  • Updated ECDSA verification to use the combined double-scalar multiplication path.

Technical Notes: These changes intentionally prioritize speed over constant-time behavior, consistent with verification using only public inputs.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Bignum second_coefficient;

while (bignum_compare(first, one) != 0 && bignum_compare(second, one) != 0) {
while ((first.words[0] & 1u) == 0) {

@augmentcode augmentcode Bot Jun 17, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bignum_mod_inverse can enter an infinite loop when value is 0 or not coprime with modulus (e.g., first can become 0, and then while ((first.words[0] & 1u) == 0) keeps shifting 0 forever). Even if callers usually ensure invertibility, this is a potential DoS/hang if a malformed public input reaches this function.

Severity: high

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (linux/gcc)

Details
Benchmark suite Current: 717aa30 Previous: 278db4b Ratio
JOSE_VerifySignature_RS256 37797.95794089257 ns/iter 37995.81681046153 ns/iter 0.99
JOSE_VerifySignature_ES512 660607.220546659 ns/iter 667907.8322211525 ns/iter 0.99
JOSE_Verify_RS256 39923.79268849248 ns/iter 39736.793725531854 ns/iter 1.00
JOSE_Verify_ES512 662176.3260869602 ns/iter 670314.506231996 ns/iter 0.99
GZIP_Compress_ISO_Language_Set_3_Locations 39308123.111115694 ns/iter 39214448.88888775 ns/iter 1.00
GZIP_Decompress_ISO_Language_Set_3_Locations 4160043.913295229 ns/iter 4039952.710982264 ns/iter 1.03
GZIP_Compress_ISO_Language_Set_3_Schema 2277846.1172636505 ns/iter 2275265.5584416995 ns/iter 1.00
GZIP_Decompress_ISO_Language_Set_3_Schema 275667.09897474595 ns/iter 276975.3880538183 ns/iter 1.00
HTML_Build_Table_100000 72362852.70000735 ns/iter 70064024.3999942 ns/iter 1.03
HTML_Render_Table_100000 1909627.6880224568 ns/iter 1880264.3091395989 ns/iter 1.02
JSONL_Parse_Large 11975467.672414199 ns/iter 11996595.413793014 ns/iter 1.00
JSONL_Parse_Large_GZIP 13485669.923078638 ns/iter 13479820.211537905 ns/iter 1.00
URITemplateRouter_Create 30581.326584930164 ns/iter 29523.564509976975 ns/iter 1.04
URITemplateRouter_Match 150.7022281866047 ns/iter 154.1542922033451 ns/iter 0.98
URITemplateRouter_Match_BasePath 181.51060530378675 ns/iter 185.72657038407846 ns/iter 0.98
URITemplateRouterView_Restore 8688.495334927396 ns/iter 8783.203766628967 ns/iter 0.99
URITemplateRouterView_Match 130.06684120056556 ns/iter 126.18213342604462 ns/iter 1.03
URITemplateRouterView_Match_BasePath 141.473175194716 ns/iter 140.93928786783658 ns/iter 1.00
URITemplateRouterView_Arguments 464.81604831346834 ns/iter 455.0661972232561 ns/iter 1.02
Pointer_Object_Traverse 29.612753276537973 ns/iter 29.534945006578567 ns/iter 1.00
Pointer_Object_Try_Traverse 24.98303536232663 ns/iter 24.98526309982822 ns/iter 1.00
Pointer_Push_Back_Pointer_To_Weak_Pointer 147.57808673788898 ns/iter 170.5789770919292 ns/iter 0.87
Pointer_Walker_Schema_ISO_Language 1971026.0111111212 ns/iter 1905314.7893331093 ns/iter 1.03
Pointer_Maybe_Tracked_Deeply_Nested/0 1507677.2419007083 ns/iter 1507709.5247311606 ns/iter 1.00
Pointer_Maybe_Tracked_Deeply_Nested/1 1664126.7387173215 ns/iter 1665337.6880951566 ns/iter 1.00
Pointer_Position_Tracker_Get_Deeply_Nested 413.230187722808 ns/iter 446.4024944449966 ns/iter 0.93
JSON_Array_Of_Objects_Unique 418.95250608553886 ns/iter 444.6900134084387 ns/iter 0.94
JSON_Parse_1 7214.431013343006 ns/iter 7386.540942876077 ns/iter 0.98
JSON_Parse_Real 6415.426295844522 ns/iter 6541.790090746819 ns/iter 0.98
JSON_Parse_Decimal 9663.127098091105 ns/iter 9645.239050365013 ns/iter 1.00
JSON_Parse_Schema_ISO_Language 5088834.138686531 ns/iter 5040384.848920727 ns/iter 1.01
JSON_Parse_Integer 4816.261402675381 ns/iter 4869.415509122193 ns/iter 0.99
JSON_Parse_String_NonSSO_Plain 8491.270201002975 ns/iter 8422.64744019974 ns/iter 1.01
JSON_Parse_String_SSO_Plain 3566.3403251285977 ns/iter 3534.2909131334404 ns/iter 1.01
JSON_Parse_String_Escape_Heavy 19687.31789647966 ns/iter 19756.26931523814 ns/iter 1.00
JSON_Parse_Object_Short_Keys 11276.218394863445 ns/iter 11125.123204033838 ns/iter 1.01
JSON_Parse_Object_Scalar_Properties 5729.945825809517 ns/iter 5673.3281004327155 ns/iter 1.01
JSON_Parse_Object_Array_Properties 8981.30539615449 ns/iter 8866.040908804569 ns/iter 1.01
JSON_Parse_Object_Object_Properties 9106.634861718472 ns/iter 8950.319490047159 ns/iter 1.02
JSON_Parse_Nested_Containers 71438.90326220475 ns/iter 71296.27548013534 ns/iter 1.00
JSON_From_String_Copy 19.421875850525087 ns/iter 19.034031935057797 ns/iter 1.02
JSON_From_String_Temporary 16.012550346705765 ns/iter 15.335311407891783 ns/iter 1.04
JSON_Number_To_Double 19.37400950722765 ns/iter 19.392186774449762 ns/iter 1.00
JSON_Object_At_Last_Key/8 6.683673540445948 ns/iter 6.6940122825381625 ns/iter 1.00
JSON_Object_At_Last_Key/32 23.5731831563856 ns/iter 23.575036602134126 ns/iter 1.00
JSON_Object_At_Last_Key/128 91.10626182327438 ns/iter 91.37888935926027 ns/iter 1.00
JSON_Object_At_Last_Key/512 378.5853793194181 ns/iter 378.50808034824536 ns/iter 1.00
JSON_Fast_Hash_Helm_Chart_Lock 61.37877924468784 ns/iter 67.18068868820393 ns/iter 0.91
JSON_Equality_Helm_Chart_Lock 156.33964360845818 ns/iter 164.78881754870474 ns/iter 0.95
JSON_Divisible_By_Decimal 232.0137129583128 ns/iter 231.43480238540982 ns/iter 1.00
JSON_String_Equal/10 5.674279717392006 ns/iter 5.678221156289154 ns/iter 1.00
JSON_String_Equal/100 6.376893661515981 ns/iter 6.382308318674387 ns/iter 1.00
JSON_String_Equal_Small_By_Perfect_Hash/10 0.7132498883530273 ns/iter 0.7145982255432428 ns/iter 1.00
JSON_String_Equal_Small_By_Runtime_Perfect_Hash/10 22.016670384173825 ns/iter 21.9482076522974 ns/iter 1.00
JSON_String_Fast_Hash/10 1.0555953155802458 ns/iter 1.056079354299442 ns/iter 1.00
JSON_String_Fast_Hash/100 1.0556058182787433 ns/iter 1.057286991002516 ns/iter 1.00
JSON_String_Key_Hash/10 1.086273763473549 ns/iter 1.0906411272078735 ns/iter 1.00
JSON_String_Key_Hash/100 14.758095970064726 ns/iter 14.766876633596814 ns/iter 1.00
JSON_Object_Defines_Miss_Same_Length 3.870713168162991 ns/iter 3.872394244146865 ns/iter 1.00
JSON_Object_Defines_Miss_Too_Small 3.86788178622594 ns/iter 3.8724781728725164 ns/iter 1.00
JSON_Object_Defines_Miss_Too_Large 3.517923971459361 ns/iter 3.520211809323315 ns/iter 1.00
Regex_Lower_S_Or_Upper_S_Asterisk 0.703407864742645 ns/iter 0.7049849320868212 ns/iter 1.00
Regex_Caret_Lower_S_Or_Upper_S_Asterisk_Dollar 1.0555179692193597 ns/iter 1.0564596790967582 ns/iter 1.00
Regex_Period_Asterisk 1.0564333945011617 ns/iter 1.056544487067072 ns/iter 1.00
Regex_Group_Period_Asterisk_Group 0.7037149711320734 ns/iter 0.7045066898078433 ns/iter 1.00
Regex_Period_Plus 0.7040191727336674 ns/iter 0.7042498085690584 ns/iter 1.00
Regex_Period 1.0551707846770713 ns/iter 1.0561912250275756 ns/iter 1.00
Regex_Caret_Period_Plus_Dollar 1.0555652656769652 ns/iter 1.0586423861075718 ns/iter 1.00
Regex_Caret_Group_Period_Plus_Group_Dollar 0.7034122064372881 ns/iter 0.7038876899464706 ns/iter 1.00
Regex_Caret_Period_Asterisk_Dollar 0.7033212054728414 ns/iter 0.7041281565763903 ns/iter 1.00
Regex_Caret_Group_Period_Asterisk_Group_Dollar 1.0558709462611828 ns/iter 1.0563429034370284 ns/iter 1.00
Regex_Caret_X_Hyphen 3.868803709540719 ns/iter 3.8683282912778383 ns/iter 1.00
Regex_Period_Md_Dollar 33.03110585219739 ns/iter 48.2679459760739 ns/iter 0.68
Regex_Caret_Slash_Period_Asterisk 4.218224660714868 ns/iter 4.221954848353462 ns/iter 1.00
Regex_Caret_Period_Range_Dollar 1.4063616366154645 ns/iter 1.4079678727938745 ns/iter 1.00
Regex_Nested_Backtrack 39.404805956755844 ns/iter 47.6478827918594 ns/iter 0.83

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (macos/llvm)

Details
Benchmark suite Current: 717aa30 Previous: 278db4b Ratio
Regex_Lower_S_Or_Upper_S_Asterisk 1.731805917151507 ns/iter 1.650575356756053 ns/iter 1.05
Regex_Caret_Lower_S_Or_Upper_S_Asterisk_Dollar 1.8063720542438046 ns/iter 1.707244594937989 ns/iter 1.06
Regex_Period_Asterisk 1.798272723222243 ns/iter 1.6557272495861262 ns/iter 1.09
Regex_Group_Period_Asterisk_Group 1.7699752556448478 ns/iter 1.692436112017759 ns/iter 1.05
Regex_Period_Plus 2.2415208584502206 ns/iter 2.002351203973237 ns/iter 1.12
Regex_Period 2.521578363738323 ns/iter 2.0083904128127097 ns/iter 1.26
Regex_Caret_Period_Plus_Dollar 2.4650253973145917 ns/iter 2.0287482251327424 ns/iter 1.22
Regex_Caret_Group_Period_Plus_Group_Dollar 2.586615201259777 ns/iter 1.9810818805957644 ns/iter 1.31
Regex_Caret_Period_Asterisk_Dollar 2.312943092170984 ns/iter 1.701899445201897 ns/iter 1.36
Regex_Caret_Group_Period_Asterisk_Group_Dollar 2.359021424491717 ns/iter 1.6952367284742629 ns/iter 1.39
Regex_Caret_X_Hyphen 8.127896213595784 ns/iter 6.236938879577507 ns/iter 1.30
Regex_Period_Md_Dollar 20.022472524206005 ns/iter 16.484461026320254 ns/iter 1.21
Regex_Caret_Slash_Period_Asterisk 6.862464947906629 ns/iter 4.447593365571679 ns/iter 1.54
Regex_Caret_Period_Range_Dollar 2.464692641271676 ns/iter 2.009987173855784 ns/iter 1.23
Regex_Nested_Backtrack 32.99829153903727 ns/iter 24.454271035311624 ns/iter 1.35
JSON_Array_Of_Objects_Unique 379.381245592377 ns/iter 363.80030156016795 ns/iter 1.04
JSON_Parse_1 4453.95525105079 ns/iter 3555.215727537501 ns/iter 1.25
JSON_Parse_Real 6268.334944932334 ns/iter 5440.240296163301 ns/iter 1.15
JSON_Parse_Decimal 6471.537009118498 ns/iter 5467.504233959808 ns/iter 1.18
JSON_Parse_Schema_ISO_Language 5096530.783581879 ns/iter 3985454.5638302215 ns/iter 1.28
JSON_Parse_Integer 3528.25032171243 ns/iter 3045.338172622405 ns/iter 1.16
JSON_Parse_String_NonSSO_Plain 4107.7863866256475 ns/iter 3621.534757513603 ns/iter 1.13
JSON_Parse_String_SSO_Plain 2065.6203330867766 ns/iter 1780.1538151502184 ns/iter 1.16
JSON_Parse_String_Escape_Heavy 21010.0702275258 ns/iter 15925.742485556142 ns/iter 1.32
JSON_Parse_Object_Short_Keys 6300.946915208409 ns/iter 5215.07458124135 ns/iter 1.21
JSON_Parse_Object_Scalar_Properties 3786.2479410870815 ns/iter 2631.1901256487404 ns/iter 1.44
JSON_Parse_Object_Array_Properties 4755.818981379256 ns/iter 3577.0204555439423 ns/iter 1.33
JSON_Parse_Object_Object_Properties 3914.685945762129 ns/iter 3682.753353439126 ns/iter 1.06
JSON_Parse_Nested_Containers 29579.228635648527 ns/iter 29397.353076487572 ns/iter 1.01
JSON_From_String_Copy 28.13110261585585 ns/iter 24.671802179170363 ns/iter 1.14
JSON_From_String_Temporary 21.38645939974165 ns/iter 19.118385662619072 ns/iter 1.12
JSON_Number_To_Double 39.55246783194355 ns/iter 33.44449028891262 ns/iter 1.18
JSON_Object_At_Last_Key/8 4.378924282223022 ns/iter 3.818636731396208 ns/iter 1.15
JSON_Object_At_Last_Key/32 12.218452910340728 ns/iter 11.876835810724826 ns/iter 1.03
JSON_Object_At_Last_Key/128 54.83891045328814 ns/iter 53.64038404485772 ns/iter 1.02
JSON_Object_At_Last_Key/512 199.88307501792062 ns/iter 187.49231666471582 ns/iter 1.07
JSON_Fast_Hash_Helm_Chart_Lock 56.86956027247055 ns/iter 57.100593407421336 ns/iter 1.00
JSON_Equality_Helm_Chart_Lock 157.93250452007194 ns/iter 134.14606256927738 ns/iter 1.18
JSON_Divisible_By_Decimal 196.63426950300283 ns/iter 169.9686772114425 ns/iter 1.16
JSON_String_Equal/10 7.174837854674136 ns/iter 6.792107581404792 ns/iter 1.06
JSON_String_Equal/100 6.790770746312097 ns/iter 6.389377792056105 ns/iter 1.06
JSON_String_Equal_Small_By_Perfect_Hash/10 0.7614277509346166 ns/iter 0.7746025874189049 ns/iter 0.98
JSON_String_Equal_Small_By_Runtime_Perfect_Hash/10 3.7600082780449893 ns/iter 3.197713199488296 ns/iter 1.18
JSON_String_Fast_Hash/10 2.4576168967354683 ns/iter 2.3796350891549523 ns/iter 1.03
JSON_String_Fast_Hash/100 2.0793385540874714 ns/iter 2.0294040079744557 ns/iter 1.02
JSON_String_Key_Hash/10 1.3972150282045563 ns/iter 1.388925541441618 ns/iter 1.01
JSON_String_Key_Hash/100 2.1699218008434213 ns/iter 2.0982998997150974 ns/iter 1.03
JSON_Object_Defines_Miss_Same_Length 2.4199095249491833 ns/iter 2.351346561617762 ns/iter 1.03
JSON_Object_Defines_Miss_Too_Small 2.4983716631136494 ns/iter 2.3728863742840516 ns/iter 1.05
JSON_Object_Defines_Miss_Too_Large 2.639286247524996 ns/iter 2.304283706349052 ns/iter 1.15
Pointer_Object_Traverse 14.624292056724547 ns/iter 13.877551637635838 ns/iter 1.05
Pointer_Object_Try_Traverse 22.121539006205758 ns/iter 22.527947515702746 ns/iter 0.98
Pointer_Push_Back_Pointer_To_Weak_Pointer 146.73944744407592 ns/iter 155.62859198030378 ns/iter 0.94
Pointer_Walker_Schema_ISO_Language 2077157.3777092246 ns/iter 2208879.3355703806 ns/iter 0.94
Pointer_Maybe_Tracked_Deeply_Nested/0 807186.8225057966 ns/iter 932583.019999811 ns/iter 0.87
Pointer_Maybe_Tracked_Deeply_Nested/1 1182160.1012862027 ns/iter 1153524.0083751916 ns/iter 1.02
Pointer_Position_Tracker_Get_Deeply_Nested 330.5659193834387 ns/iter 374.55341364064185 ns/iter 0.88
URITemplateRouter_Create 24555.67969395805 ns/iter 23474.404956697494 ns/iter 1.05
URITemplateRouter_Match 159.2652528147012 ns/iter 159.36661459857905 ns/iter 1.00
URITemplateRouter_Match_BasePath 183.9399568369282 ns/iter 192.47813459207237 ns/iter 0.96
URITemplateRouterView_Restore 9968.387609726271 ns/iter 9052.268802381193 ns/iter 1.10
URITemplateRouterView_Match 143.14737186604668 ns/iter 130.63374130820185 ns/iter 1.10
URITemplateRouterView_Match_BasePath 149.36324222997942 ns/iter 151.62812222690746 ns/iter 0.99
URITemplateRouterView_Arguments 406.000391023755 ns/iter 405.58696656581424 ns/iter 1.00
JSONL_Parse_Large 12376639.89285766 ns/iter 12303125.699994175 ns/iter 1.01
JSONL_Parse_Large_GZIP 12602010.226414505 ns/iter 13278695.51922644 ns/iter 0.95
HTML_Build_Table_100000 60960321.999997094 ns/iter 65778496.181833774 ns/iter 0.93
HTML_Render_Table_100000 2439705.2845528363 ns/iter 2703436.602870174 ns/iter 0.90
GZIP_Compress_ISO_Language_Set_3_Locations 25254459.82142774 ns/iter 27801878.35998731 ns/iter 0.91
GZIP_Decompress_ISO_Language_Set_3_Locations 4680852.189780836 ns/iter 5163326.388890075 ns/iter 0.91
GZIP_Compress_ISO_Language_Set_3_Schema 1435367.0318724378 ns/iter 1528796.2662342654 ns/iter 0.94
GZIP_Decompress_ISO_Language_Set_3_Schema 261105.88065230695 ns/iter 273830.0507302956 ns/iter 0.95
JOSE_VerifySignature_RS256 26897.521499532882 ns/iter 28041.99139504118 ns/iter 0.96
JOSE_VerifySignature_ES512 953724.2404226096 ns/iter 980070.0748658231 ns/iter 0.97
JOSE_Verify_RS256 28414.181982462786 ns/iter 29305.142684558225 ns/iter 0.97
JOSE_Verify_ES512 1008904.5788005351 ns/iter 992671.6417906821 ns/iter 1.02

This comment was automatically generated by workflow using github-action-benchmark.

Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (linux/llvm)

Details
Benchmark suite Current: 717aa30 Previous: 278db4b Ratio
Regex_Lower_S_Or_Upper_S_Asterisk 2.467292450095526 ns/iter 1.996371444319947 ns/iter 1.24
Regex_Caret_Lower_S_Or_Upper_S_Asterisk_Dollar 2.468956692575758 ns/iter 1.9595132340326862 ns/iter 1.26
Regex_Period_Asterisk 2.8146915610302132 ns/iter 2.0509534802779665 ns/iter 1.37
Regex_Group_Period_Asterisk_Group 2.819050024236861 ns/iter 2.0324687140362254 ns/iter 1.39
Regex_Period_Plus 3.877881038480768 ns/iter 2.0283082367619256 ns/iter 1.91
Regex_Period 3.8755656851885143 ns/iter 2.0311387522388555 ns/iter 1.91
Regex_Caret_Period_Plus_Dollar 3.035444985844066 ns/iter 2.304225243246482 ns/iter 1.32
Regex_Caret_Group_Period_Plus_Group_Dollar 2.813834545905428 ns/iter 2.3039157003213373 ns/iter 1.22
Regex_Caret_Period_Asterisk_Dollar 3.8749047356353654 ns/iter 1.9417037358020275 ns/iter 2.00
Regex_Caret_Group_Period_Asterisk_Group_Dollar 3.8798074155952302 ns/iter 2.034273189778452 ns/iter 1.91
Regex_Caret_X_Hyphen 7.041449718788309 ns/iter 4.031407220446888 ns/iter 1.75
Regex_Period_Md_Dollar 26.59912698889446 ns/iter 24.76259406712663 ns/iter 1.07
Regex_Caret_Slash_Period_Asterisk 7.166854991037438 ns/iter 3.7461378081618966 ns/iter 1.91
Regex_Caret_Period_Range_Dollar 3.8809203060352506 ns/iter 2.0341013750136314 ns/iter 1.91
Regex_Nested_Backtrack 37.90846932215111 ns/iter 34.25532093394834 ns/iter 1.11
JSON_Array_Of_Objects_Unique 440.58394931555586 ns/iter 356.4976858831933 ns/iter 1.24
JSON_Parse_1 4631.928871036491 ns/iter 4563.674257483814 ns/iter 1.01
JSON_Parse_Real 5171.366661982166 ns/iter 4615.126980368271 ns/iter 1.12
JSON_Parse_Decimal 7812.884495572739 ns/iter 7127.171657357081 ns/iter 1.10
JSON_Parse_Schema_ISO_Language 3486302.791045195 ns/iter 3263676.051162906 ns/iter 1.07
JSON_Parse_Integer 3995.770636616372 ns/iter 3560.8601722890185 ns/iter 1.12
JSON_Parse_String_NonSSO_Plain 5221.078915174603 ns/iter 4561.875584176944 ns/iter 1.14
JSON_Parse_String_SSO_Plain 2848.303186176964 ns/iter 2328.832190731534 ns/iter 1.22
JSON_Parse_String_Escape_Heavy 14639.899987652978 ns/iter 16499.331054478746 ns/iter 0.89
JSON_Parse_Object_Short_Keys 7887.288334498064 ns/iter 6921.801163227375 ns/iter 1.14
JSON_Parse_Object_Scalar_Properties 4008.284631012414 ns/iter 3648.9859467570577 ns/iter 1.10
JSON_Parse_Object_Array_Properties 5517.426512990169 ns/iter 5052.804838255849 ns/iter 1.09
JSON_Parse_Object_Object_Properties 5469.219119176499 ns/iter 5026.493641527171 ns/iter 1.09
JSON_Parse_Nested_Containers 44181.663139891745 ns/iter 40932.39852182489 ns/iter 1.08
JSON_From_String_Copy 23.21587250757889 ns/iter 16.00088071068857 ns/iter 1.45
JSON_From_String_Temporary 20.409541107237178 ns/iter 14.944613276056316 ns/iter 1.37
JSON_Number_To_Double 22.821043103272622 ns/iter 21.675764834020963 ns/iter 1.05
JSON_Object_At_Last_Key/8 4.697550515346322 ns/iter 4.9287611618418055 ns/iter 0.95
JSON_Object_At_Last_Key/32 13.57287732266004 ns/iter 17.95719838534851 ns/iter 0.76
JSON_Object_At_Last_Key/128 47.28220677685605 ns/iter 73.82109670520843 ns/iter 0.64
JSON_Object_At_Last_Key/512 366.0551048612022 ns/iter 304.44080137088264 ns/iter 1.20
JSON_Fast_Hash_Helm_Chart_Lock 72.77664041362152 ns/iter 57.8749696090739 ns/iter 1.26
JSON_Equality_Helm_Chart_Lock 160.16842990771818 ns/iter 130.7874278905931 ns/iter 1.22
JSON_Divisible_By_Decimal 251.81235878119222 ns/iter 252.968963044155 ns/iter 1.00
JSON_String_Equal/10 6.334136079274038 ns/iter 4.8954000331772445 ns/iter 1.29
JSON_String_Equal/100 7.038568146385656 ns/iter 6.167732237694323 ns/iter 1.14
JSON_String_Equal_Small_By_Perfect_Hash/10 1.0552067097498425 ns/iter 0.6910828452779059 ns/iter 1.53
JSON_String_Equal_Small_By_Runtime_Perfect_Hash/10 12.335390696342275 ns/iter 9.81053670982996 ns/iter 1.26
JSON_String_Fast_Hash/10 2.461236637736529 ns/iter 2.0173578575640954 ns/iter 1.22
JSON_String_Fast_Hash/100 2.468259405650708 ns/iter 2.015776291465466 ns/iter 1.22
JSON_String_Key_Hash/10 2.461586814751788 ns/iter 1.7288674371633608 ns/iter 1.42
JSON_String_Key_Hash/100 7.7354777439551645 ns/iter 6.647727385947661 ns/iter 1.16
JSON_Object_Defines_Miss_Same_Length 2.9079837016935133 ns/iter 3.1682856278451688 ns/iter 0.92
JSON_Object_Defines_Miss_Too_Small 2.9356549120845905 ns/iter 3.169321090070228 ns/iter 0.93
JSON_Object_Defines_Miss_Too_Large 2.9131227409699627 ns/iter 3.455480687620015 ns/iter 0.84
Pointer_Object_Traverse 25.551291505849843 ns/iter 23.007215875064475 ns/iter 1.11
Pointer_Object_Try_Traverse 30.611603127573638 ns/iter 36.70898831049191 ns/iter 0.83
Pointer_Push_Back_Pointer_To_Weak_Pointer 165.21884326227465 ns/iter 171.17230706942226 ns/iter 0.97
Pointer_Walker_Schema_ISO_Language 1757166.1381907687 ns/iter 1773807.9467003585 ns/iter 0.99
Pointer_Maybe_Tracked_Deeply_Nested/0 1227561.3824561317 ns/iter 1130961.5185783913 ns/iter 1.09
Pointer_Maybe_Tracked_Deeply_Nested/1 1581452.970588171 ns/iter 1908930.514986428 ns/iter 0.83
Pointer_Position_Tracker_Get_Deeply_Nested 735.416845558522 ns/iter 703.7919486445062 ns/iter 1.04
URITemplateRouter_Create 31448.490930054024 ns/iter 28890.34998348756 ns/iter 1.09
URITemplateRouter_Match 181.8123762236516 ns/iter 156.46866579551218 ns/iter 1.16
URITemplateRouter_Match_BasePath 210.67779044223113 ns/iter 176.066982589758 ns/iter 1.20
URITemplateRouterView_Restore 8797.671396780173 ns/iter 3339.2241325701616 ns/iter 2.63
URITemplateRouterView_Match 170.97261484680922 ns/iter 143.87268237511708 ns/iter 1.19
URITemplateRouterView_Match_BasePath 194.9837171738868 ns/iter 161.2721590015858 ns/iter 1.21
URITemplateRouterView_Arguments 449.7461867337563 ns/iter 422.6258616032701 ns/iter 1.06
JSONL_Parse_Large 8823031.587499486 ns/iter 8860624.43037967 ns/iter 1.00
JSONL_Parse_Large_GZIP 10499683.686565623 ns/iter 10296912.264705911 ns/iter 1.02
HTML_Build_Table_100000 75850279.77778383 ns/iter 69918274.89999877 ns/iter 1.08
HTML_Render_Table_100000 5215508.923076693 ns/iter 9787464.014285823 ns/iter 0.53
GZIP_Compress_ISO_Language_Set_3_Locations 35242773.20000237 ns/iter 29812940.666663695 ns/iter 1.18
GZIP_Decompress_ISO_Language_Set_3_Locations 4280956.153374248 ns/iter 4039241.5629622955 ns/iter 1.06
GZIP_Compress_ISO_Language_Set_3_Schema 2089831.2925374508 ns/iter 1856215.9389920277 ns/iter 1.13
GZIP_Decompress_ISO_Language_Set_3_Schema 278838.474522271 ns/iter 335635.6639501899 ns/iter 0.83
JOSE_VerifySignature_RS256 64468.89559528829 ns/iter 50141.21534936999 ns/iter 1.29
JOSE_VerifySignature_ES512 2731716.3463032614 ns/iter 8578373.853658943 ns/iter 0.32
JOSE_Verify_RS256 66187.3591755704 ns/iter 51816.14760667984 ns/iter 1.28
JOSE_Verify_ES512 2650799.234848822 ns/iter 8611251.20987697 ns/iter 0.31

This comment was automatically generated by workflow using github-action-benchmark.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found and verified against the latest diff

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/core/crypto/crypto_ecc.h">

<violation number="1" location="src/core/crypto/crypto_ecc.h:485">
P1: Double-scalar multiply reads bits past the shorter scalar’s length. This can use stale high words and produce incorrect verification results.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment on lines +485 to +486
const auto bit_one{bignum_get_bit(scalar_one, index - 1)};
const auto bit_two{bignum_get_bit(scalar_two, index - 1)};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Double-scalar multiply reads bits past the shorter scalar’s length. This can use stale high words and produce incorrect verification results.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/core/crypto/crypto_ecc.h, line 485:

<comment>Double-scalar multiply reads bits past the shorter scalar’s length. This can use stale high words and produce incorrect verification results.</comment>

<file context>
@@ -127,51 +356,140 @@ inline auto point_add(const JacobianPoint &left, const JacobianPoint &right,
     result = point_double(result, curve);
-    if (bignum_get_bit(scalar, index - 1)) {
-      result = point_add(result, point, curve);
+    const auto bit_one{bignum_get_bit(scalar_one, index - 1)};
+    const auto bit_two{bignum_get_bit(scalar_two, index - 1)};
+    if (bit_one && bit_two) {
</file context>
Suggested change
const auto bit_one{bignum_get_bit(scalar_one, index - 1)};
const auto bit_two{bignum_get_bit(scalar_two, index - 1)};
const auto bit_one{index <= bits_one && bignum_get_bit(scalar_one, index - 1)};
const auto bit_two{index <= bits_two && bignum_get_bit(scalar_two, index - 1)};

Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (windows/msvc)

Details
Benchmark suite Current: 717aa30 Previous: 278db4b Ratio
Regex_Lower_S_Or_Upper_S_Asterisk 5.069795535715928 ns/iter 5.070227678572792 ns/iter 1.00
Regex_Caret_Lower_S_Or_Upper_S_Asterisk_Dollar 5.023145000000113 ns/iter 4.964106999998421 ns/iter 1.01
Regex_Period_Asterisk 5.118860000000041 ns/iter 5.01273035714332 ns/iter 1.02
Regex_Group_Period_Asterisk_Group 5.171389999998155 ns/iter 4.965220999999929 ns/iter 1.04
Regex_Period_Plus 4.773504554635878 ns/iter 4.644726572867506 ns/iter 1.03
Regex_Period 4.780373684102369 ns/iter 4.7090601223651 ns/iter 1.02
Regex_Caret_Period_Plus_Dollar 4.775038639458418 ns/iter 4.6712404122123035 ns/iter 1.02
Regex_Caret_Group_Period_Plus_Group_Dollar 4.860476853763355 ns/iter 4.606254251353964 ns/iter 1.06
Regex_Caret_Period_Asterisk_Dollar 5.0900630000001 ns/iter 4.9618919999988975 ns/iter 1.03
Regex_Caret_Group_Period_Asterisk_Group_Dollar 5.065520535714946 ns/iter 5.030589000000418 ns/iter 1.01
Regex_Caret_X_Hyphen 8.172176749230315 ns/iter 8.062839285715638 ns/iter 1.01
Regex_Period_Md_Dollar 47.16873261455585 ns/iter 54.615130000001955 ns/iter 0.86
Regex_Caret_Slash_Period_Asterisk 8.235697731091074 ns/iter 7.451368303570406 ns/iter 1.11
Regex_Caret_Period_Range_Dollar 5.734788392857127 ns/iter 5.321093000000019 ns/iter 1.08
Regex_Nested_Backtrack 53.91185999999379 ns/iter 69.17875892859067 ns/iter 0.78
JSON_Array_Of_Objects_Unique 490.54320000004736 ns/iter 523.5469642857181 ns/iter 0.94
JSON_Parse_1 9367.010861558318 ns/iter 9354.50332810895 ns/iter 1.00
JSON_Parse_Real 16262.558008199501 ns/iter 16429.81314606684 ns/iter 0.99
JSON_Parse_Decimal 11834.357812499973 ns/iter 11229.93750000134 ns/iter 1.05
JSON_Parse_Schema_ISO_Language 8080576.66666476 ns/iter 7864248.888889354 ns/iter 1.03
JSON_Parse_Integer 6226.767857143045 ns/iter 5972.09196428748 ns/iter 1.04
JSON_Parse_String_NonSSO_Plain 7886.207589287153 ns/iter 7857.877232143754 ns/iter 1.00
JSON_Parse_String_SSO_Plain 3622.5045306829115 ns/iter 3727.537272255414 ns/iter 0.97
JSON_Parse_String_Escape_Heavy 22851.987499997504 ns/iter 20978.529975048797 ns/iter 1.09
JSON_Parse_Object_Short_Keys 13554.96604925664 ns/iter 13104.18571428532 ns/iter 1.03
JSON_Parse_Object_Scalar_Properties 6969.838392858411 ns/iter 6682.247321427732 ns/iter 1.04
JSON_Parse_Object_Array_Properties 11617.908928570841 ns/iter 11436.81093750004 ns/iter 1.02
JSON_Parse_Object_Object_Properties 11743.987499999419 ns/iter 11811.60624999933 ns/iter 0.99
JSON_Parse_Nested_Containers 85721.88295165525 ns/iter 85249.05584572564 ns/iter 1.01
JSON_From_String_Copy 64.29579241071792 ns/iter 62.45503571428961 ns/iter 1.03
JSON_From_String_Temporary 58.984330357146426 ns/iter 88.44993355135223 ns/iter 0.67
JSON_Number_To_Double 123.34749999999823 ns/iter 122.76650000001968 ns/iter 1.00
JSON_Object_At_Last_Key/8 7.21385937500025 ns/iter 7.5117276785700176 ns/iter 0.96
JSON_Object_At_Last_Key/32 23.777855761406904 ns/iter 25.252853571422357 ns/iter 0.94
JSON_Object_At_Last_Key/128 90.97650933139668 ns/iter 93.5505156250116 ns/iter 0.97
JSON_Object_At_Last_Key/512 427.96875000007617 ns/iter 430.13005222640317 ns/iter 0.99
JSON_Fast_Hash_Helm_Chart_Lock 62.91768749999196 ns/iter 65.78895089285805 ns/iter 0.96
JSON_Equality_Helm_Chart_Lock 305.35808422344206 ns/iter 292.6946119333045 ns/iter 1.04
JSON_Divisible_By_Decimal 306.6889322892106 ns/iter 380.71244419641505 ns/iter 0.81
JSON_String_Equal/10 15.88572767856939 ns/iter 16.85855483545119 ns/iter 0.94
JSON_String_Equal/100 17.03066640380818 ns/iter 17.315167410712565 ns/iter 0.98
JSON_String_Equal_Small_By_Perfect_Hash/10 2.5469657142853714 ns/iter 2.1602690625002197 ns/iter 1.18
JSON_String_Equal_Small_By_Runtime_Perfect_Hash/10 15.150310267857087 ns/iter 14.182033195613547 ns/iter 1.07
JSON_String_Fast_Hash/10 5.0470389999986764 ns/iter 4.747308862667455 ns/iter 1.06
JSON_String_Fast_Hash/100 5.150103000000854 ns/iter 4.741557947486622 ns/iter 1.09
JSON_String_Key_Hash/10 5.523122321428835 ns/iter 4.989009000000806 ns/iter 1.11
JSON_String_Key_Hash/100 11.901875000002553 ns/iter 10.981756249996977 ns/iter 1.08
JSON_Object_Defines_Miss_Same_Length 5.0612070000011045 ns/iter 5.072202000001198 ns/iter 1.00
JSON_Object_Defines_Miss_Too_Small 4.191490624999972 ns/iter 4.065158623329932 ns/iter 1.03
JSON_Object_Defines_Miss_Too_Large 4.166528502603221 ns/iter 3.8949631696435665 ns/iter 1.07
Pointer_Object_Traverse 69.64510714285309 ns/iter 70.39785714285175 ns/iter 0.99
Pointer_Object_Try_Traverse 69.5918571428576 ns/iter 68.55534598214165 ns/iter 1.02
Pointer_Push_Back_Pointer_To_Weak_Pointer 174.8559263263769 ns/iter 175.4620067377148 ns/iter 1.00
Pointer_Walker_Schema_ISO_Language 7894423.999999466 ns/iter 8584225.555556359 ns/iter 0.92
Pointer_Maybe_Tracked_Deeply_Nested/0 2634067.068273575 ns/iter 2401125.357143233 ns/iter 1.10
Pointer_Maybe_Tracked_Deeply_Nested/1 4690185.5421680575 ns/iter 3727742.2459891066 ns/iter 1.26
Pointer_Position_Tracker_Get_Deeply_Nested 682.1258395565613 ns/iter 562.0858258928203 ns/iter 1.21
URITemplateRouter_Create 40899.50892858241 ns/iter 41458.29609423962 ns/iter 0.99
URITemplateRouter_Match 192.4519457546452 ns/iter 220.91733025478192 ns/iter 0.87
URITemplateRouter_Match_BasePath 218.23324999999727 ns/iter 229.62174892612776 ns/iter 0.95
URITemplateRouterView_Restore 33497.16165783044 ns/iter 25394.869654311908 ns/iter 1.32
URITemplateRouterView_Match 155.7414955357217 ns/iter 153.89044642856018 ns/iter 1.01
URITemplateRouterView_Match_BasePath 172.97928390487175 ns/iter 176.09086000611475 ns/iter 0.98
URITemplateRouterView_Arguments 531.2217000000601 ns/iter 578.3455000000686 ns/iter 0.92
JSONL_Parse_Large 33061442.105259914 ns/iter 33588638.0952334 ns/iter 0.98
JSONL_Parse_Large_GZIP 33875335.00000472 ns/iter 33855361.90475726 ns/iter 1.00
HTML_Build_Table_100000 89331042.85711125 ns/iter 92046042.85712646 ns/iter 0.97
HTML_Render_Table_100000 7773009.999997763 ns/iter 7968003.333333703 ns/iter 0.98
GZIP_Compress_ISO_Language_Set_3_Locations 36312357.89473402 ns/iter 37923705.55555004 ns/iter 0.96
GZIP_Decompress_ISO_Language_Set_3_Locations 9893621.333333917 ns/iter 10613120.000001194 ns/iter 0.93
GZIP_Compress_ISO_Language_Set_3_Schema 2109644.347825926 ns/iter 2338228.093645149 ns/iter 0.90
GZIP_Decompress_ISO_Language_Set_3_Schema 641095.2678572405 ns/iter 603295.53571421 ns/iter 1.06
JOSE_VerifySignature_RS256 37086.00985726845 ns/iter 41334.55674079723 ns/iter 0.90
JOSE_VerifySignature_ES512 1708960.6879607697 ns/iter 1701597.0515970096 ns/iter 1.00
JOSE_Verify_RS256 40631.84376995395 ns/iter 45352.49870533958 ns/iter 0.90
JOSE_Verify_ES512 1708616.9533169812 ns/iter 1697445.3124995697 ns/iter 1.01

This comment was automatically generated by workflow using github-action-benchmark.

@jviotti jviotti merged commit 3fd528c into main Jun 17, 2026
12 checks passed
@jviotti jviotti deleted the optimise-reference-crypto branch June 17, 2026 16:04
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