Skip to content

[Cherry-pick FIPS 2025] Make N1 cpucap a subset of that of V1 and V2 (#2815) - #2838

Merged
nebeid merged 1 commit into
aws:fips-2025-09-12from
nebeid:armcap-N1-fips-2025-09-12
Nov 18, 2025
Merged

nebeid merged 1 commit into
aws:fips-2025-09-12from
nebeid:armcap-N1-fips-2025-09-12

Conversation

@nebeid

@nebeid nebeid commented Nov 17, 2025

Copy link
Copy Markdown
Contributor

- Change: On a V1/V2 machine, when we detect we're on it, we set the bit
N1 to 1 as well
  - On an N1 machine, we will only set the bit N1 as we do now
- Change: When we check if we're on N1, we check that N1 is set but both
V1 and V2 are 0
- When we check if we're on V1/V2, we check their respective bit as we
do now
- Benefit: On a V2 machine, we can set to 0 the bit V1, leaving the bit
N1 on and now the code path will think it's on an N1 machine and N1
Keccka-4x code path can be tested on V1 or V2.
- Without this change, we cannot set bit N1 on a V2 machine; we will get
a fatal error like the one below. That's because we can unset an
existing capability but we cannot set a non-existing one.
- Rationale: we can think of the N1 capabilities as a subset of those of
V1 and V2, so enabling its bit is semantically valid

Testing:
4 different benchmarking results for Keccak-4x are showing on Graviton 4
(V2) with various capability settings
```
# To find the default capabilities
$ OPENSSL_armcap=0xFFFF   ./tool/bssl speed -filter SHAKE256-x4
Fatal Error: HW capability found: 0x3C8FD, but HW capability requested: 0xFFFF.

# Bit assignment
# 7: N1, 11: SHA3, 12: V1, 14: V2
# default benchmark of SHAKE256-4x
$ ./tool/bssl speed -filter SHAKE256-x4
Did 1464000 SHAKE256-x4 (Absorb) (16 bytes) operations in 1000040us (1463941.4 ops/sec): 23.4 MB/s
Did 823000 SHAKE256-x4 (Absorb) (256 bytes) operations in 1000725us (822403.8 ops/sec): 210.5 MB/s
Did 183000 SHAKE256-x4 (Absorb) (1350 bytes) operations in 1003286us (182400.6 ops/sec): 246.2 MB/s
Did 31000 SHAKE256-x4 (Absorb) (8192 bytes) operations in 1010747us (30670.4 ops/sec): 251.3 MB/s
Did 16000 SHAKE256-x4 (Absorb) (16384 bytes) operations in 1033110us (15487.2 ops/sec): 253.7 MB/s
Did 1473000 SHAKE256-x4 (Squeeze) (16 bytes) operations in 1000369us (1472456.7 ops/sec): 23.6 MB/s
Did 778000 SHAKE256-x4 (Squeeze) (256 bytes) operations in 1000773us (777399.1 ops/sec): 199.0 MB/s
Did 164000 SHAKE256-x4 (Squeeze) (1350 bytes) operations in 1004048us (163338.8 ops/sec): 220.5 MB/s
Did 28000 SHAKE256-x4 (Squeeze) (8192 bytes) operations in 1033405us (27094.9 ops/sec): 222.0 MB/s
Did 14000 SHAKE256-x4 (Squeeze) (16384 bytes) operations in 1024232us (13668.8 ops/sec): 223.9 MB/s

# V2 code path (same as default). This can work on V1 as well using `OPENSSL_armcap=0x107D`
$ OPENSSL_armcap=0x407D   ./tool/bssl speed -filter SHAKE256-x4
Did 1455000 SHAKE256-x4 (Absorb) (16 bytes) operations in 1000628us (1454086.8 ops/sec): 23.3 MB/s
Did 824000 SHAKE256-x4 (Absorb) (256 bytes) operations in 1000359us (823704.3 ops/sec): 210.9 MB/s
Did 183000 SHAKE256-x4 (Absorb) (1350 bytes) operations in 1002131us (182610.9 ops/sec): 246.5 MB/s
Did 31000 SHAKE256-x4 (Absorb) (8192 bytes) operations in 1009942us (30694.8 ops/sec): 251.5 MB/s
Did 16000 SHAKE256-x4 (Absorb) (16384 bytes) operations in 1032534us (15495.9 ops/sec): 253.9 MB/s
Did 1465000 SHAKE256-x4 (Squeeze) (16 bytes) operations in 1000080us (1464882.8 ops/sec): 23.4 MB/s
Did 777000 SHAKE256-x4 (Squeeze) (256 bytes) operations in 1000265us (776794.1 ops/sec): 198.9 MB/s
Did 164000 SHAKE256-x4 (Squeeze) (1350 bytes) operations in 1005024us (163180.2 ops/sec): 220.3 MB/s
Did 28000 SHAKE256-x4 (Squeeze) (8192 bytes) operations in 1031505us (27144.8 ops/sec): 222.4 MB/s
Did 14000 SHAKE256-x4 (Squeeze) (16384 bytes) operations in 1022396us (13693.3 ops/sec): 224.4 MB/s

# N1 code path
$ OPENSSL_armcap=0xFD   ./tool/bssl speed -filter SHAKE256-x4
Did 1297000 SHAKE256-x4 (Absorb) (16 bytes) operations in 1000558us (1296276.7 ops/sec): 20.7 MB/s
Did 714000 SHAKE256-x4 (Absorb) (256 bytes) operations in 1001360us (713030.3 ops/sec): 182.5 MB/s
Did 156000 SHAKE256-x4 (Absorb) (1350 bytes) operations in 1000112us (155982.5 ops/sec): 210.6 MB/s
Did 27000 SHAKE256-x4 (Absorb) (8192 bytes) operations in 1032464us (26151.0 ops/sec): 214.2 MB/s
Did 14000 SHAKE256-x4 (Absorb) (16384 bytes) operations in 1060417us (13202.4 ops/sec): 216.3 MB/s
Did 1303000 SHAKE256-x4 (Squeeze) (16 bytes) operations in 1000588us (1302234.3 ops/sec): 20.8 MB/s
Did 681000 SHAKE256-x4 (Squeeze) (256 bytes) operations in 1000333us (680773.3 ops/sec): 174.3 MB/s
Did 143000 SHAKE256-x4 (Squeeze) (1350 bytes) operations in 1003421us (142512.5 ops/sec): 192.4 MB/s
Did 24000 SHAKE256-x4 (Squeeze) (8192 bytes) operations in 1014605us (23654.5 ops/sec): 193.8 MB/s
Did 12000 SHAKE256-x4 (Squeeze) (16384 bytes) operations in 1005765us (11931.2 ops/sec): 195.5 MB/s

# SHA-3 extension code path (used on M processors)
$ OPENSSL_armcap=0x87D   ./tool/bssl speed -filter SHAKE256-x4
Did 762000 SHAKE256-x4 (Absorb) (16 bytes) operations in 1000347us (761735.7 ops/sec): 12.2 MB/s
Did 410000 SHAKE256-x4 (Absorb) (256 bytes) operations in 1001014us (409584.7 ops/sec): 104.9 MB/s
Did 87000 SHAKE256-x4 (Absorb) (1350 bytes) operations in 1007343us (86365.8 ops/sec): 116.6 MB/s
Did 15000 SHAKE256-x4 (Absorb) (8192 bytes) operations in 1046478us (14333.8 ops/sec): 117.4 MB/s
Did 7290 SHAKE256-x4 (Absorb) (16384 bytes) operations in 1008399us (7229.3 ops/sec): 118.4 MB/s
Did 762000 SHAKE256-x4 (Squeeze) (16 bytes) operations in 1000376us (761713.6 ops/sec): 12.2 MB/s
Did 396000 SHAKE256-x4 (Squeeze) (256 bytes) operations in 1000504us (395800.5 ops/sec): 101.3 MB/s
Did 82000 SHAKE256-x4 (Squeeze) (1350 bytes) operations in 1004520us (81631.0 ops/sec): 110.2 MB/s
Did 14000 SHAKE256-x4 (Squeeze) (8192 bytes) operations in 1038071us (13486.6 ops/sec): 110.5 MB/s
Did 6840 SHAKE256-x4 (Squeeze) (16384 bytes) operations in 1005651us (6801.6 ops/sec): 111.4 MB/s

# fallback to Perl assembly
$ OPENSSL_armcap=0x7D   ./tool/bssl speed -filter SHAKE256-x4
Did 793000 SHAKE256-x4 (Absorb) (16 bytes) operations in 1000394us (792687.7 ops/sec): 12.7 MB/s
Did 426000 SHAKE256-x4 (Absorb) (256 bytes) operations in 1000583us (425751.8 ops/sec): 109.0 MB/s
Did 91000 SHAKE256-x4 (Absorb) (1350 bytes) operations in 1009347us (90157.3 ops/sec): 121.7 MB/s
Did 15000 SHAKE256-x4 (Absorb) (8192 bytes) operations in 1001652us (14975.3 ops/sec): 122.7 MB/s
Did 7570 SHAKE256-x4 (Absorb) (16384 bytes) operations in 1001905us (7555.6 ops/sec): 123.8 MB/s
Did 795000 SHAKE256-x4 (Squeeze) (16 bytes) operations in 1001123us (794108.2 ops/sec): 12.7 MB/s
Did 412000 SHAKE256-x4 (Squeeze) (256 bytes) operations in 1001381us (411431.8 ops/sec): 105.3 MB/s
Did 86000 SHAKE256-x4 (Squeeze) (1350 bytes) operations in 1011160us (85050.8 ops/sec): 114.8 MB/s
Did 15000 SHAKE256-x4 (Squeeze) (8192 bytes) operations in 1067129us (14056.4 ops/sec): 115.2 MB/s
Did 7634 SHAKE256-x4 (Squeeze) (16384 bytes) operations in 1077150us (7087.2 ops/sec): 116.1 MB/s

# Note: N1 is picked up even if the bit of SHA3 is set
$ OPENSSL_armcap=0x8FD   ./tool/bssl speed -filter SHAKE256-x4
Did 1298000 SHAKE256-x4 (Absorb) (16 bytes) operations in 1000455us (1297409.7 ops/sec): 20.8 MB/s
Did 714000 SHAKE256-x4 (Absorb) (256 bytes) operations in 1001327us (713053.8 ops/sec): 182.5 MB/s
Did 157000 SHAKE256-x4 (Absorb) (1350 bytes) operations in 1006211us (156030.9 ops/sec): 210.6 MB/s
Did 27000 SHAKE256-x4 (Absorb) (8192 bytes) operations in 1032000us (26162.8 ops/sec): 214.3 MB/s
Did 14000 SHAKE256-x4 (Absorb) (16384 bytes) operations in 1059878us (13209.1 ops/sec): 216.4 MB/s
Did 1303000 SHAKE256-x4 (Squeeze) (16 bytes) operations in 1000746us (1302028.7 ops/sec): 20.8 MB/s
Did 681000 SHAKE256-x4 (Squeeze) (256 bytes) operations in 1000193us (680868.6 ops/sec): 174.3 MB/s
Did 143000 SHAKE256-x4 (Squeeze) (1350 bytes) operations in 1003264us (142534.8 ops/sec): 192.4 MB/s
Did 24000 SHAKE256-x4 (Squeeze) (8192 bytes) operations in 1014346us (23660.6 ops/sec): 193.8 MB/s
Did 12000 SHAKE256-x4 (Squeeze) (16384 bytes) operations in 1005506us (11934.3 ops/sec): 195.5 MB/s
```
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and the ISC license.

(cherry picked from commit b01d54a)
@nebeid
nebeid requested a review from a team as a code owner November 17, 2025 19:25
@nebeid
nebeid requested a review from skmcgrail November 17, 2025 19:26
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 78.71%. Comparing base (e5059ea) to head (02e1b6d).

Additional details and impacted files
@@                 Coverage Diff                 @@
##           fips-2025-09-12    #2838      +/-   ##
===================================================
- Coverage            78.83%   78.71%   -0.13%     
===================================================
  Files                  667      667              
  Lines               114077   113002    -1075     
  Branches             16046    16062      +16     
===================================================
- Hits                 89932    88944     -988     
+ Misses               23370    23284      -86     
+ Partials               775      774       -1     

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nebeid
nebeid enabled auto-merge (squash) November 17, 2025 23:08
@nebeid
nebeid disabled auto-merge November 18, 2025 17:00
@nebeid
nebeid merged commit 948fdac into aws:fips-2025-09-12 Nov 18, 2025
134 of 144 checks passed
@nebeid
nebeid deleted the armcap-N1-fips-2025-09-12 branch November 18, 2025 18:59
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.

4 participants