summaryrefslogtreecommitdiff
path: root/lib/crypto
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-03-24 22:35:40 -0700
committerOri Bernstein <ori@eigenstate.org>2018-03-24 23:13:51 -0700
commitb39e8ca0f806bd6a76f378373cb4d27fcf028190 (patch)
tree5a9c057b27a55d45424b844e697b277088c62fdb /lib/crypto
parent17cb502c1578b8e1a94f02b84cf47acfef6b20b1 (diff)
downloadmc-b39e8ca0f806bd6a76f378373cb4d27fcf028190.tar.gz
Improve test runner test filtering.
Filter on what the user sees. Before, we would use the internal target names, which bore a resemblance to the target names used by the user, but they didn't match perfectly. This led to unintuitive behavior. Now, we filter on a substring of the test name matching. So, you can do something like: mbld test crypto/sha3 instead of mbld test lib/bio/test:delim In addition, not all tests had an explicit target, and these would be impossible to match on. Still left to do is adding subtest patterns.
Diffstat (limited to 'lib/crypto')
-rw-r--r--lib/crypto/bld.sub1
-rw-r--r--lib/crypto/ctbig.myr52
2 files changed, 38 insertions, 15 deletions
diff --git a/lib/crypto/bld.sub b/lib/crypto/bld.sub
index 1c58997..309ef7d 100644
--- a/lib/crypto/bld.sub
+++ b/lib/crypto/bld.sub
@@ -22,6 +22,7 @@ lib crypto =
# utilities for subtle bits
ct.myr
+ ctbig.myr
clear.myr
lib ../std:std
diff --git a/lib/crypto/ctbig.myr b/lib/crypto/ctbig.myr
index 59ff5f7..cf3f92d 100644
--- a/lib/crypto/ctbig.myr
+++ b/lib/crypto/ctbig.myr
@@ -9,6 +9,8 @@ pkg crypto =
;;
generic mkctbign : (v : @a, nbit : std.size -> ctbig#) :: numeric,integral @a
+
+ const ctzero : (nbit : std.size -> ctbig#)
const mkctbigle : (v : byte[:], nbit : std.size -> ctbig#)
//const mkctbigbe : (v : byte[:], nbit : std.size -> ctbig#)
@@ -16,13 +18,13 @@ pkg crypto =
const ctbigdup : (v : ctbig# -> ctbig#)
const ctlike : (v : ctbig# -> ctbig#)
const ct2big : (v : ctbig# -> std.bigint#)
- const big2ct : (v : std.bigint#, ndig : std.size -> ctbig#)
+ const big2ct : (v : std.bigint#, nbit : std.size -> ctbig#)
const ctadd : (r : ctbig#, a : ctbig#, b : ctbig# -> void)
const ctsub : (r : ctbig#, a : ctbig#, b : ctbig# -> void)
const ctmul : (r : ctbig#, a : ctbig#, b : ctbig# -> void)
//const ctdivmod : (r : ctbig#, m : ctbig#, a : ctbig#, b : ctbig# -> void)
- //const ctmodpow : (r : ctbig#, a : ctbig#, b : ctbig# -> void)
+ const ctmodpow : (r : ctbig#, a : ctbig#, b : ctbig# -> void)
const ctiszero : (v : ctbig# -> bool)
const cteq : (a : ctbig#, b : ctbig# -> bool)
@@ -33,6 +35,7 @@ pkg crypto =
const ctle : (a : ctbig#, b : ctbig# -> bool)
;;
+const Bits = 32
const Base = 0x100000000ul
generic mkctbign = {v : @a, nbit : std.size :: integral,numeric @a
@@ -50,7 +53,14 @@ generic mkctbign = {v : @a, nbit : std.size :: integral,numeric @a
if nbit > 32
a.dig[1] = (val >> 32 : uint32)
;;
- -> a
+ -> clip(a)
+}
+
+const ctzero = {nbit
+ -> std.mk([
+ .nbit=nbit,
+ .dig=std.slalloc(ndig(nbit)),
+ ])
}
const ct2big = {ct
@@ -67,10 +77,10 @@ const big2ct = {ct, nbit
l = std.min(n, ct.dig.len)
v = std.slzalloc(n)
std.slcp(v, ct.dig[:l])
- -> std.mk([
+ -> clip(std.mk([
.nbit=nbit,
.dig=v,
- ])
+ ]))
}
const mkctbigle = {v, nbit
@@ -96,7 +106,7 @@ const mkctbigle = {v, nbit
last |= (v[off] : uint32) << (8 *off)
;;
a[o++] = last
- -> std.mk([.nbit=nbit, .dig=a])
+ -> clip(std.mk([.nbit=nbit, .dig=a]))
}
const ctlike = {v
@@ -146,6 +156,7 @@ const ctsub = {r, a, b
v = mux(borrow, v + Base, v)
r.dig[i] = (v : uint32)
;;
+ clip(r)
}
const ctmul = {r, a, b
@@ -176,17 +187,18 @@ const ctmul = {r, a, b
std.slfree(a.dig)
;;
r.dig = w[:a.dig.len]
+ clip(r)
}
-//const ctmodpow = {res, a, b
-// /* find rinv, mprime */
-//
-// /* convert to monty space */
-//
-// /* do the modpow */
-//
-// /* and come back */
-//}
+const ctmodpow = {res, a, b
+ /* find rinv, mprime */
+
+ /* convert to monty space */
+
+ /* do the modpow */
+
+ /* and come back */
+}
const ctiszero = {a
var z, zz
@@ -270,3 +282,13 @@ const checksz = {a, b
std.assert(a.nbit == b.nbit, "mismatched bit sizes")
std.assert(a.dig.len == b.dig.len, "mismatched backing sizes")
}
+
+const clip = {v
+ var mask, edge
+
+
+ edge = v.nbit & (Bits - 1)
+ mask = (1 << edge) - 1
+ v.dig[v.dig.len - 1] &= (mask : uint32)
+ -> v
+}