commit e1dada5bf98002610dc5857cec7c3510c8d1f006 parent b98348c2d847b9c482aa6cb8429b0c1c109e54d8 Author: Armin Preiml <apreiml@strohwolke.at> Date: Wed, 12 Jan 2022 18:12:49 +0100 crypto: implement compare Signed-off-by: Armin Preiml <apreiml@strohwolke.at> Diffstat:
M | crypto/authenc.ha | | | 11 | +++++++++++ |
1 file changed, 11 insertions(+), 0 deletions(-)
diff --git a/crypto/authenc.ha b/crypto/authenc.ha @@ -90,5 +90,16 @@ export fn decrypt( additional: []u8... ) ([]u8 | errors::invalid); +// Compares two slices and returns true if they are equal. Comparison is done +// in constant time, meaning that the time it takes depends only on the size of +// the slices and not the content. +export fn compare(a: []u8, b: []u8) bool = { + if (len(a) != len(b)) { + return false; + }; + + return math::cmpslice(a, b) == 1; +}; + // TODO: Add additional entry-points which provide a finer degree of control // over buffer usage.