summaryrefslogtreecommitdiff
path: root/lib/crypto
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-03-12 00:02:02 -0700
committerOri Bernstein <ori@eigenstate.org>2018-03-12 00:02:43 -0700
commitbd5cf6784d403e5540291a2674336b07010bc54c (patch)
tree57705505efb1b34985c6e41c18522f354712f5d2 /lib/crypto
parentdda657081b032dc653f669ca85f2c09984f0cb35 (diff)
downloadmc-bd5cf6784d403e5540291a2674336b07010bc54c.tar.gz
Add constant time 'min()' and 'max()'
Diffstat (limited to 'lib/crypto')
-rw-r--r--lib/crypto/ct.myr16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/crypto/ct.myr b/lib/crypto/ct.myr
index 2b976f4..28be694 100644
--- a/lib/crypto/ct.myr
+++ b/lib/crypto/ct.myr
@@ -10,6 +10,8 @@ pkg crypto =
generic ge : (a : @t, b : @t -> @t) :: integral,numeric @t
generic le : (a : @t, b : @t -> @t) :: integral,numeric @t
generic mux : (x : @t, a : @t, b : @t ->@t) :: integral,numeric @t
+ generic min : (a : @t, b : @t -> @t) :: integral,numeric @t
+ generic max : (a : @t, b : @t -> @t) :: integral,numeric @t
;;
generic not = {a : @t :: integral,numeric @t
@@ -57,3 +59,17 @@ generic ne = {a, b
generic mux = {c, a, b
-> b ^ (-c & (a ^ b))
}
+
+generic min = {a, b
+ var x
+
+ x = lt(a, b)
+ -> mux(x, a, b)
+}
+
+generic max = {a, b
+ var x
+
+ x = lt(a, b)
+ -> mux(x, b, a)
+}