4 ms·
Eh, my experience with crypto libraries is that they're poorly written from a user perspective (regardless of if they do it right under the hood). The hardest
by SilasX 8y ago
Eh, my experience with crypto libraries is that they're poorly written from a user perspective (regardless of if they do it right under the hood). The hardest parts of the Matasano security challenge are those that require me to get some off-the-shelf crypto library to perform as expected.
For example, Rust's main AES implementation requires you to delve into details you shouldn't care about in order to get it to work. It doesn't let you just pass in Vec<u8> bytes and get Vec<u8> back out. It doesn't even let you put it through a converter functions to match the library's internal representation.
No, you have to learn low level details of how to instantiate a special fixed-size mutable buffer type and then figure out how to manage that and maintain proper ownership when extracting.
- tptacek 8y agoI can't speak to Rust's library, but Go's NewGCM/AEAD.Seal is about as good an interface as I think you could reasonably ask for.
- SilasX 8y agoOh, nice, that's what I wish Rust had, which makes you navigate through this: https://docs.rs/rust-crypto/0.2.36/x86_64-apple-darwin/crypto/aes/index.html https://docs.rs/rust-crypto/0.2.36/x86_64-apple-darwin/crypt...
- steveklabnik 8y agoIsn’t rust-crypto abandoned? I didn’t think it was the best practice here. EDIT: yep, not touched since 2016. I'm not a crypto expert, but I asked someone who is and he pointed me to https://docs.rs/miscreant/0.4.2/miscreant/aead/trait.Aead.html https://docs.rs/miscreant/0.4.2/miscreant/aead/trait.Aead.ht...
- SilasX 8y agoHm, rust-crypto was what came up with when I searched -- don't remember why I chose that vs the others. (And it's not 2016 that was the wild-west days of poor Rust design and unnecessary mutable params.) Miscreant looks like its has just as bad an interface as the one I used. You have to do a lot of work -- and deal with unnecessary low-level details of mutable fixed-length buffers -- to implement the thing you really want, which is a function that takes a byte stream of any length, a key and returns you another byte stream.
- steveklabnik 8y agorust-crypto probably has a lot of google juice because it used to be the premier project. Then its team disbanded. While you're right that 2016 isn't super long ago, it was originally created before Rust 1.0. Const generics will also help these sorts of interfaces significantly.
- SilasX 8y agoBut that's the thing: it's the premier project, and doesn't expose the simple interface that the Go library did. Looking throw my code for cryptopals, I had to do these extra steps that aren't relevant to my problem (encrypting the plaintext with a key and cipher): 1) Create a mutable Vec<u8> vector from the plaintext. 2) Use that vector to create a mutable buffer of a type in the crypto library. 3) Create a second mutable Vec<u8> vector for the output. 4) Do step 2) for it also. 5) Call the encryption function with those two buffers as arguments. (This step's fine because calling an encryption function is unavoidable.) 6) Convert one of them back to Vec<u8> via `take_read_buffer().take_remaining().to_vec()` (I'm ignoring the steps where you declare the key and cipher parameters since those are necessary) And getting those to work required looking up the types of their library buffers. But I don't care about the buffers where the library writes to when encrypting. I just want to be able to pass in a Vec<u8> and get a new one back out. At most, I should have to convert to and from the library's internal representation. Instead, I have to learn about and manage mutable variables and their ownership.
- bascule 8y agoThere's an entire section in my 2019 blog post about this: https://tonyarcieri.com/rust-in-2019-security-maturity-stability#rustcrypto-is-dead-long-live-rustcrypto_2 https://tonyarcieri.com/rust-in-2019-security-maturity-stabi... rust-crypto has the most upstream dependencies, but is an unmaintained, abandoned project. There are a number of other awesome cryptography projects in Rust (in fact some of the most advanced cryptography in the world is being developed in Rust), but they suffer from an awareness problem. The Go standard library's cryptography, while full-featured and very mature, does suffer from a particular problem: it's a mixture of high-level and low-level APIs all within a single namespace / module. This makes it difficult to compare to Rust projects, because it's an enormous omnibus library, whereas in Rust there is no equivalent to that because the projects are more compartmentalized, and in my opinion that arrangement is preferable to what the Go standard library is doing. See also: https://cryptocoding.net/index.php/Coding_rules#Avoid_mixing_security_and_abstraction_levels_of_cryptographic_primitives_in_the_same_API_layer https://cryptocoding.net/index.php/Coding_rules#Avoid_mixing... The closest thing to an all-in-one crypto library is ring. There's a notable difference between ring and the Go standard library though: ring presents a very high-level, hard-to-misuse API. This makes ring unsuitable for usages where you want "shoot yourself in the foot" cryptographic primitives which are difficult to use correctly and fail catastrophically unless used as such. For the Rust equivalent of these "shoot yourself in the foot" cryptographic interfaces like Go "crypto/cipher" types such as Block, BlockMode, and Stream, take a look at the Rust Cryptography project: https://github.com/RustCrypto https://github.com/RustCrypto Miscreant is built on top of these, and presents an AEAD interface, which could eventually be upstreamed into RustCrypto so Miscreant just implements it.
- tptacek 8y agoNot being a Rust person, my understanding was that Ring was where it was at now.
- steveklabnik 8y agoring is great, I have no idea what its interface looks like, though. I've only used it transitively.