Generic de-/encoding of raw public keys via FFI (in particular for KEMs)? #4366
-
While trying to use FrodoKEM via FFI, I noticed that there is no Adding such a function for FrodoKEM would definitely be helpful, as using it via FFI is currently quite awkward (basically requires unwrapping a DER-encoded public key). But then I wondered why there isn't a generic Similarly, either a specific |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
I believe we could just implement exactly |
Beta Was this translation helpful? Give feedback.
-
For the record: With #4373 and the (open) pull requests for SLH-DSA (#4291), ML-DSA (#4270), ML-KEM (#3893) and Classic McEliece (#3883) we introduced the algorithm-specific loading functions into the FFI (and Python-bindings): Here's an example for ML-KEM using the FFI, the other algorithms provide equivalent functions: botan_privkey_t sk;
botan_pubkey_t pk;
// reading of raw byte array containing an ML-KEM key pair
botan_privkey_load_ml_kem(&sk, sk_bytes, 64 /* length of sk_bytes */, "ML-KEM-768" /* ML-KEM mode */);
botan_pubkey_load_ml_kem(&pk, pk_bytes, pk_bytes_len, "ML-KEM-768" /* ML-KEM mode */);
// encoding of ML-KEM key pair into raw byte array
// (these functions aren't algorithm specific)
botan_privkey_view_raw(sk, nullptr, sk_view_callback);
botan_pubkey_view_raw(pk, nullptr, pk_view_callback); And another example using the Python bindings: sk = botan.PrivateKey.load_ml_kem("ML-KEM-768", sk_bytes)
pk = botan.PublicKey.load_ml_kem("ML-KEM-768", pk_bytes)
sk_bytes2 = sk.to_raw()
pk_bytes2 = pk.to_raw() |
Beta Was this translation helpful? Give feedback.
For the record: With #4373 and the (open) pull requests for SLH-DSA (#4291), ML-DSA (#4270), ML-KEM (#3893) and Classic McEliece (#3883) we introduced the algorithm-specific loading functions into the FFI (and Python-bindings):
Here's an example for ML-KEM using the FFI, the other algorithms provide equivalent functions: