cederom commented on PR #4092:
URL: https://github.com/apache/nuttx-apps/pull/4092#issuecomment-7116263045
**Fixed: cleanup when a case fails**
Every case now jumps to a single `err:` label that deletes every key id the
case holds. I checked this against the kernel code in #22061
(`crypto/cryptosoft.c`), and it's correct:
- **Unused ids are safe to delete.** The key store hands out ids starting at
1, and every key operation rejects id 0. The test starts its ids at 0, so the
cleanup's delete call on an id that was never allocated (for example `dkeyid`
when importing `n` failed) fails harmlessly.
- **Allocation alone writes to flash.** `swkey_is_valid()` reserves a new id
by writing a marker string to `/dev/nvs` straight away. So even a failure right
after allocation, before anything was imported, used to leave something behind.
That path is now cleaned up too.
- **Deleting twice is harmless.** In the ECDSA and RSA cases, if one delete
fails after another succeeded, the error path deletes the successful one again.
That call just returns an error; nothing else can take the freed id in between
because the test is single-threaded.
- The commit message and the file's header comment now describe this cleanup.
**Also improved**
- The Case 6 comments now match the code: encrypt with the public key,
decrypt with the private one. The private-key operation is now described as a
"raw private-key operation with type-2 padding" instead of a PKCS#1 v1.5
signature.
- The comment about one driver's key cache is gone. A note now says the test
needs the device set by `CONFIG_CRYPTO_CRYPTODEV_SOFTWARE_KEYMGMT_DEVICE`.
- A comment on `ecdsa_genkey_keyid` explains why that call doesn't set
`SOP_F_KEYID`: the operation always takes key ids. The kernel code confirms
this.
- The Kconfig menu text is now "key management crypto test".
**Still open (all minor)**
1. **The Kconfig option has no dependency.** `TESTING_CRYPTO_KEY_MANAGEMENT`
still lacks `depends on CRYPTO_CRYPTODEV_SOFTWARE_KEYMGMT`. I'd still ask for
this one: without it, the test shows up in menuconfig on builds where it can't
work.
2. **The flag name moved the wrong way.** The header comment now says the
test works "with CRD_F_KEYID" too, not only the commit message, but the code
sets `SOP_F_KEYID` throughout. `CRD_F_KEYID` is the kernel's internal
descriptor flag; the user-space flag is `SOP_F_KEYID`. The comment on
`ecdsa_genkey_keyid` uses the correct name, so the file is now inconsistent
with itself.
3. **Sessions still leak on failure.** `aescbc_crypt`, `hmac_keyid` and
`aescmac_keyid` still return without `CIOCFSESSION` when `CIOCCRYPT` fails.
These are RAM-only sessions that go away when the program closes its file
descriptors, so this is purely cosmetic.
4. **Leftovers from last time:**
- `<errno.h>` is still not included for `-EINVAL`.
- Casts still drop `const`.
- The RSA messages still say "rsa sign failed" and "rsa verify failed",
though the comments no longer call it signing.
The change you requested is done, and done correctly. I'd approve after the
`depends on` line, and would mention the `CRD_F_KEYID`/`SOP_F_KEYID` wording as
a nit. The rest is optional.
--
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]