summaryrefslogtreecommitdiff
path: root/lib/crypto
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2019-01-27 22:30:08 -0800
committerOri Bernstein <ori@eigenstate.org>2019-01-27 22:30:08 -0800
commitd975956a1a2a1b05e328247fc0f5ca841edc8e18 (patch)
treed32f9af0ba33dfeb07021794d9a45fec91297759 /lib/crypto
parent1ed7430691158c6a2a0c5a7bae36e9e49a43a0e2 (diff)
downloadmc-d975956a1a2a1b05e328247fc0f5ca841edc8e18.tar.gz
Add commonly used constants.
Diffstat (limited to 'lib/crypto')
-rw-r--r--lib/crypto/curve25519.myr14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/crypto/curve25519.myr b/lib/crypto/curve25519.myr
index c23c0f9..07f57fe 100644
--- a/lib/crypto/curve25519.myr
+++ b/lib/crypto/curve25519.myr
@@ -50,9 +50,16 @@
use std
pkg crypto =
- const curve25519 : (pub : byte[:/*32*/], secret : byte[:/*32*/], basepoint : byte[:/*32*/] -> void)
+ const Nine : byte[:]
+ const curve25519 : (pub : byte[:/*32*/], secret : byte[:/*32*/], basepoint : byte[:/*32*/] -> void)
;;
+const Nine = \
+ "\x09\x00\x00\x00\x00\x00\x00\x00" \
+ "\x00\x00\x00\x00\x00\x00\x00\x00" \
+ "\x00\x00\x00\x00\x00\x00\x00\x00" \
+ "\x00\x00\x00\x00\x00\x00\x00\x00"
+
/* Sum two numbers: out += in */
const fsum = {out, in
for var i = 0; i < 10; i += 2
@@ -692,11 +699,14 @@ const curve25519 = {pub : byte[:/*32*/], secret : byte[:/*32*/], basepoint : byt
var z : int64[11] /* one extra for reduced coefficients */
var zmone : int64[10]
+ std.assert(pub.len == 32 , "wrong pubkey size\n")
+ std.assert(secret.len == 32 , "wrong secret size\n")
+ std.assert(basepoint.len == 32 , "wrong basepoint size\n")
+
secret[0] &= 248
secret[31] &= 127
secret[31] |= 64
- std.assert(pub.len == 32 && secret.len == 32 && basepoint.len == 32, "wrong key sizes")
fexpand(bp[:], basepoint[:])
cmult(x[:], z[:], secret[:], bp[:])
crecip(zmone[:], z[:])