From cae9f743d3bbcfd02e03120465df8fb538cd941b Mon Sep 17 00:00:00 2001 From: mratsim Date: Sat, 1 Dec 2018 18:03:52 +0100 Subject: [PATCH] Add more tests for multiplexer --- hardy/ct_primitives.nim | 2 +- tests/all_tests.nim | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/hardy/ct_primitives.nim b/hardy/ct_primitives.nim index 793b878..e8ded4d 100644 --- a/hardy/ct_primitives.nim +++ b/hardy/ct_primitives.nim @@ -80,7 +80,7 @@ func `not`*(ctl: HardBool): HardBool {.inline.}= ## Negate a constant-time boolean (type result)(ctl.undistinct xor (type ctl.undistinct)(1)) -template select*[T: HardBase](ctl: HardBool[T], x, y: T): T = +template mux*[T: HardBase](ctl: HardBool[T], x, y: T): T = ## Multiplexer / selector ## Returns x if ctl == 1 ## else returns y diff --git a/tests/all_tests.nim b/tests/all_tests.nim index 7cacd56..c297070 100644 --- a/tests/all_tests.nim +++ b/tests/all_tests.nim @@ -167,7 +167,7 @@ suite "Hardened booleans": bool(hard(10'u32) >= hard(5'u32)) == true bool(hard(10'u32) >= hard(0xFFFFFFFF'u32)) == false - test "Multiplexer/selector - select(ctl, x, y) <=> ctl? x: y": + test "Multiplexer/selector - mux(ctl, x, y) <=> ctl? x: y": let u = 10'u32.hard let v = 20'u32.hard let w = 5'u32.hard @@ -176,5 +176,11 @@ suite "Hardened booleans": let n = hfalse(uint32) check: - bool(select(y, u, v) == u) + bool(mux(y, u, v) == u) + bool(mux(n, u, v) == v) + bool(mux(y, u, w) == u) + bool(mux(n, u, w) == w) + + bool(mux(y, v, w) == v) + bool(mux(n, v, w) == w)