Closed cosmicexplorer closed 1 year ago
I'm going to close this because it's an extra dependency for something quite subtle (🥁), but it's certainly clever!
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.
Problem
In #469 we decided to take a look at whether we could upstream some extensions to the
subtle
crate to supportOrdering
comparisons. After creating zkcrypto/subtle-ng#5, I created this PR to demonstrate how adoptingsubtle::ConstantTimeCmp
from that change could improve the code.Solution
subtle-ng-derive
crate in order to derive constant-time comparisons for aggregate structs using the technique developed in zkcrypto/subtle-ng#6.subtle-ng
which contained the changes from zkcrypto/subtle-ng#5.Result
It is now possible to
#[derive(ConstEq, ConstOrd, ConstantTimeEq, ConstantTimeCmp)]
to get constant-timeEq
andOrd
implementations for several structs, which allows us to removeutils.rs
.