Coder Social home page Coder Social logo

Use SHA instead of Blake2 for MACs? about quinn HOT 14 CLOSED

djc avatar djc commented on July 2, 2024
Use SHA instead of Blake2 for MACs?

from quinn.

Comments (14)

Ralith avatar Ralith commented on July 2, 2024

Blake2b was selected as a convenient high-performance modern cryptographic hash function. It's fine to swap it out with another HMAC scheme (it's not even a breaking change) if you think increasing our use of ring is worth it.

from quinn.

djc avatar djc commented on July 2, 2024

I'd actually also have picked Blake2b if all other things were equal. But having one less dependency means less maintenance (and less compile time), and I don't think this particular area of the code is in a particularly hot loop that the difference between Blake2b and HMAC-SHA256 will be noticeable?

from quinn.

Ralith avatar Ralith commented on July 2, 2024

Yeah, should be fine. It's ran on small amounts of data for every packet that was successfully parsed but not associated with a connection, and (formerly) for every handshake when using stateless retries. No real hot loop.

from quinn.

kylegalloway avatar kylegalloway commented on July 2, 2024

I would like to take a look at this issue. What crate does the HMAC-SHA256 algorithm come from?

Edit: found it in the ring crate.

Should it be used like this:

 let mut mac = SigningKey::new(&digest::SHA256, key.as_ref());

or this:

 let mut mac = hmac::SigningContext::with_key(key.as_ref()).sign();

from quinn.

djc avatar djc commented on July 2, 2024

@kylegalloway great, thanks for working on this! The function that needs changing is here:

https://github.com/djc/quinn/blob/master/quinn-proto/src/crypto.rs#L110

Since (on quick skimming) it seems we're reusing the same key over time, it would probably good to store the SigningKey in the ListenKeys and work from that, but @Ralith knows more about this code.

from quinn.

Ralith avatar Ralith commented on July 2, 2024

@djc is correct; in particular, the reset member of ListenKeys should be replaced with a SigningKey. Let's use SHA-512/256 rather than SHA-256 for the hash algorithm to take better advantage of current hardware, too.

from quinn.

djc avatar djc commented on July 2, 2024

@kylegalloway are you still interested in working on this? If not, someone else might want to take a swing.

from quinn.

kylegalloway avatar kylegalloway commented on July 2, 2024

@djc I have gotten really busy recently. Thanks for the opportunity, but if someone else wants to take a swing, please let them.

from quinn.

djc avatar djc commented on July 2, 2024

@kylegalloway no problem, thanks for the quick response.

from quinn.

stammw avatar stammw commented on July 2, 2024

I'd like to work on this one.

from quinn.

djc avatar djc commented on July 2, 2024

Great! Let me know if you have any questions.

from quinn.

stammw avatar stammw commented on July 2, 2024

SHA512/256 hash seem to have a size of 32 bytes, but the RESET_TOKEN_SIZE is 16, the same as stateless_reset_token field of tls's TransportParameters. Should the digest be truncated?

from quinn.

stammw avatar stammw commented on July 2, 2024

OK, so I found in the ietf draft that it is the expected behavior:

The output of this function is truncated to 16 bytes to produce the Stateless Reset Token for that connection.

from quinn.

djc avatar djc commented on July 2, 2024

This is done, thanks again to @stammw.

from quinn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.