Page MenuHomeFreeBSD

/dev/crypto: Minimize cipher-specific logic.
ClosedPublic

Authored by jhb on Dec 22 2021, 1:01 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 14 2024, 4:47 PM
Unknown Object (File)
Mar 14 2024, 4:47 PM
Unknown Object (File)
Mar 14 2024, 4:47 PM
Unknown Object (File)
Mar 11 2024, 4:38 AM
Unknown Object (File)
Mar 7 2024, 8:01 PM
Unknown Object (File)
Feb 7 2024, 11:40 PM
Unknown Object (File)
Feb 6 2024, 12:09 AM
Unknown Object (File)
Feb 2 2024, 6:43 AM
Subscribers

Details

Summary

Rather than duplicating the switches in crypto_auth_hash() and
crypto_cipher(), copy the algorithm constants from the new session
ioctl into a csp directly which permits using the functions in
crypto.c.

Sponsored by: Chelsio Communications

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

jhb requested review of this revision.Dec 22 2021, 1:01 AM
sys/opencrypto/cryptodev.c
397–398

Almost worth exporting alg_is_aead from crypto.c for this check.

418

I don't really like this check, or at least, I think I'd like to move it into check_csp in crypto.c so that all calls to crypto_newsession validate the key lengths rather than the logic living here. The whole minkey/maxkey thing is kind of bonkers though as ciphers that accept more than one key size that we support all support discrete values (like AES) rather than an inclusive range.

438

Similarly, this check really belongs in check_csp I think.

457

Possibly worth adding an 'ivsize' member to 'struct auth_hash' to remove this special knowledge.

sys/opencrypto/cryptodev.c
397–398

I guess I could actually check 'txform->macsize' to determine if this is an AEAD cipher. Would just need to setup most of the rest of the csp before the mode.

markj added inline comments.
sys/opencrypto/cryptodev.c
397–398

Seems reasonable: we don't use the mode for most of the setup.

418

Should we add an array of valid key sizes to each txform?

uint16_t keysizes[CRYPTO_MAX_KEYSIZES] = { 16, 24, 32 };

and treat a keysize of zero as invalid.

I definitely agree that check_csp() is a better place to validate the key size.

This revision is now accepted and ready to land.Dec 29 2021, 2:43 PM
sys/opencrypto/cryptodev.c
438

Actually, this check is kind of bogus. You can pass larger keys in to a HMAC. The key is hashed and the result of that hash is used as the key. hmac_init_pad already handles this, so could probably just remove this particular check entirely.

This revision was automatically updated to reflect the committed changes.