signalapp / libsignal

Home to the Signal Protocol as well as other cryptographic primitives which make Signal possible.
GNU Affero General Public License v3.0
3.06k stars 362 forks source link

demonstrate using subtle-ng-derive with ConstantTimeCmp #478

Closed cosmicexplorer closed 1 year ago

cosmicexplorer commented 2 years ago

Problem

In #469 we decided to take a look at whether we could upstream some extensions to the subtle crate to support Ordering comparisons. After creating zkcrypto/subtle-ng#5, I created this PR to demonstrate how adopting subtle::ConstantTimeCmp from that change could improve the code.

Solution

Result

It is now possible to #[derive(ConstEq, ConstOrd, ConstantTimeEq, ConstantTimeCmp)] to get constant-time Eq and Ord implementations for several structs, which allows us to remove utils.rs.

jrose-signal commented 1 year ago

I'm going to close this because it's an extra dependency for something quite subtle (🥁), but it's certainly clever!

cosmicexplorer commented 1 year ago

Note: subtle-ng is unmaintained, and the original subtle crate should be used. I have raised this use case with upstream subtle project at https://github.com/dalek-cryptography/subtle/issues/100 and hope to integrate the derive macros into the upstream subtle crate itself.