latchset / kryoptic

a pkcs#11 software token written in Rust
GNU General Public License v3.0
10 stars 4 forks source link

Support for wrapping EC keys + RSA wrapping fixes/comments/questions #5

Closed Jakuje closed 7 months ago

Jakuje commented 7 months ago

Fixes also unwrapping for RSA keys, but we might need better solution.

I think the DerEncBigUint ensures the BN is unsigned and starts with zero byte, which is something we do not want when we import the BN as a modulus as you are using the modulus size to enforce the buffer size. Without stripping the null byte from the modulus, the operation requires 257 B buffer for signature and verification of this signature does not work.

The RSA wrapping is also using the RSAPrivateKey ASN1 directly, but from my reading of the PKCS#11 specification, we should use PrivateKeyInfo. This not obvious for RSA keys as everything needed is in the inner object, but EC keys needs the privateKeyAlgorithm field to learn what curve is used, if I read it right.

Keeping it as a draft as there is more quesitons to resolve before merging.