daniel-p-carvalho opened a new pull request, #20979:
URL: https://github.com/apache/nuttx/pull/20979

   ## Summary
   
   The Wi-Fi library of the PIC32MZ-W1 needs modular arithmetic and P-256 point 
operations for the SAE exchange of WPA3-Personal. The driver only had them on 
the BA414E engine, whose microcode is under Microchip's license and is not part 
of NuttX, so without it `wifibridge start -3` failed with `ENOTSUP`.
   
   `crypto/ecc.c` already has that arithmetic, but only ECDH and ECDSA were 
public. This PR:
   
   1. Fixes `arc4random_buf()` being called with `NUM_ECC_DIGITS` (4) instead 
of `ECC_BYTES` (32) in `ecc_make_key()`, `ecc_make_key_uncomp()`, 
`ecdh_shared_secret()` and `ecdsa_sign()`: only 4 bytes of the private key, the 
blinding value and the ECDSA nonce were random.
   2. Exports `ecc_point_add()`, `ecc_point_mul()`, `ecc_point_is_on_curve()`, 
`ecc_mod_add()`, `ecc_mod_sub()`, `ecc_mod_mul()` and `ecc_mod_exp()` (big 
endian, `ECC_BYTES` per value). The co-Z ladder of `eccpoint_mult()` cannot 
return +/-P (it divides by `X1 - X0`), so `k = 1` and `k = n - 1` are handled 
before it.
   3. Documents them in `Documentation/os/crypto.rst`.
   4. Implements the library interface of the PIC32MZ-W1 with them when 
`CONFIG_PIC32MZ_W1_BA414E` is not set, and accepts WPA3 whatever the engine. 
With the engine nothing changes.
   
   It is one PR because the driver is the user of the new functions.
   
   ## Impact
   
   - New feature: YES, WPA3-Personal on the PIC32MZ-W1 without the BA414E; the 
`ecc_point_*()` and `ecc_mod_*()` functions.
   - Existing feature changed: YES, the key, blinding value and nonce of 
`crypto/ecc.c` now have 256 random bits instead of 32.
   - User impact: YES, WPA3 works with no microcode download. A point 
multiplication takes about 49 ms on the PIC32MZ-W1 (200 MHz).
   - Build: NO new option or dependency. The seven functions are 4812 bytes of 
text (xc32, `ev49n51a:nsh`) and only reach an image that references them.
   - Hardware: NO.
   - Documentation: YES, `crypto.rst` and the EV49N51A page.
   - Security: YES, the `arc4random_buf()` length above.
   - Compatibility: NO. Signatures and keys made before the fix stay valid.
   
   ## Testing
   
   Host: Linux x86-64, gcc 15 (`crypto/ecc.c` with the same test as below, all 
checks pass); target: EV49N51A (PIC32MZ-W1, xc32 v6.00), `ev49n51a:nsh` with 
`CONFIG_CRYPTO` and a test application that is not part of the PR.
   
   ```
   nsh> ecctest
   1*G == G                                     PASS
   2*G == NIST 2G                               PASS
   3*G == NIST 3G                               PASS
   G + G == NIST 2G                             PASS
   2G + G == NIST 3G                            PASS
   G on curve                                   PASS
   2G on curve                                  PASS
   (Gx, Gy^1) not on curve                      PASS
   0*G == O                                     PASS
   n*G == O                                     PASS
   G + (-G) == O                                PASS
   G + O == G                                   PASS
   O + G == G                                   PASS
   (n-d)*G == -(d*G), d=1..5                    PASS
   5+7 mod p                                    PASS
   5-7 mod p == p-2                             PASS
   5*7 mod p                                    PASS
   p*p mod n == (p mod n)^2 sanity (no crash)   PASS
   5^(p-1) mod p == 1 (Fermat)                  PASS
   5^0 mod p == 1                               PASS
   5^(n-1) mod n == 1 (generic mod)             PASS
   in-place mod_mul                             PASS
   in-place point_add (G+G)                     PASS
   in-place point_mul (3*G)                     PASS
   ecc_point_mul : 49000 us
   ecc_point_add : 700 us
   on_curve      : 0 us
   ecc_make_key  : 49000 us
   ecctest: ALL PASS (0 failed)
   ```
   
   WPA3 without the BA414E, `ev49n51a:wifibridge` (out of tree, from #20971) 
with the AP started by `wifibridge start -3 -s NuttX-BR -p nuttxbridge` and a 
Linux client (NetworkManager, `key-mgmt sae`, `pmf 3`):
   
   - 5 of 5 disconnect/connect cycles succeed, and `ping -c 5 10.0.0.2` has 0% 
loss (rtt 0.6 to 1.1 ms).
   - The same client with a wrong passphrase is refused.
   - With `CONFIG_PIC32MZ_W1_BA414E=y` (microcode built in) 3 of 3 cycles 
succeed as before.
   
   Not tested: the board as a station against a WPA3 access point, and the 
stack use of the WLAN thread.
   
   `checkpatch.sh -c -u -m -g` passes on the four commits.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to