mirror of
https://github.com/GaloisInc/cryptol.git
synced 2024-09-22 03:19:57 +03:00
Merge branch 'devel'
This was the branch I originally set up for git flow, but we're moving to production=release and develop=master, so this branch is obsolete.
This commit is contained in:
commit
d409116160
10
.travis.yml
Normal file
10
.travis.yml
Normal file
@ -0,0 +1,10 @@
|
||||
language: haskell
|
||||
ghc: 7.6
|
||||
install:
|
||||
- cabal sandbox init
|
||||
- cabal install Cabal
|
||||
- make
|
||||
script:
|
||||
- make test
|
||||
notifications:
|
||||
email: false
|
5
Makefile
5
Makefile
@ -75,6 +75,9 @@ src/GitRev.hs:
|
||||
${CS_BIN}/cryptol: ${CS_BIN}/alex ${CS_BIN}/happy | ${CS}
|
||||
$(CABAL) install .
|
||||
|
||||
${CS_BIN}/cryptolnb: ${CS_BIN}/alex ${CS_BIN}/happy | ${CS}
|
||||
$(CABAL) install . -fnotebook
|
||||
|
||||
${PKG}: ${CS_BIN}/cryptol
|
||||
mkdir -p ${PKG}/bin
|
||||
mkdir -p ${PKG}/lib
|
||||
@ -128,7 +131,7 @@ test: ${CS_BIN}/cryptol-test-runner
|
||||
)
|
||||
|
||||
.PHONY: notebook
|
||||
notebook: ${CS_BIN}/cryptol
|
||||
notebook: ${CS_BIN}/cryptolnb
|
||||
cd notebook && ./notebook.sh
|
||||
|
||||
|
||||
|
@ -15,6 +15,10 @@ flag static
|
||||
default: False
|
||||
description: Create a statically-linked binary
|
||||
|
||||
flag notebook
|
||||
default: False
|
||||
description: Build the IPython-style Cryptol notebook interface
|
||||
|
||||
library
|
||||
Build-depends: base >= 4.6,
|
||||
array >= 0.4,
|
||||
@ -182,7 +186,10 @@ executable cryptol
|
||||
ld-options: -static -pthread
|
||||
|
||||
executable cryptolnb
|
||||
buildable: False
|
||||
if flag(notebook)
|
||||
buildable: True
|
||||
else
|
||||
buildable: False
|
||||
Main-is: Main_notebook.hs
|
||||
hs-source-dirs: cryptol, notebook
|
||||
build-depends: base,
|
||||
|
131
examples/contrib/keccak.cry
Normal file
131
examples/contrib/keccak.cry
Normal file
@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (c) 2013 David Lazar <lazard@galois.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
* /
|
||||
|
||||
// Specification of the Keccak (SHA-3) hash function
|
||||
// Author: David Lazar
|
||||
|
||||
SHA_3_224 M = take(224, Keccak `{r = 1152, c = 448} M);
|
||||
SHA_3_256 M = take(256, Keccak `{r = 1088, c = 512} M);
|
||||
SHA_3_384 M = take(384, Keccak `{r = 832, c = 768} M);
|
||||
SHA_3_512 M = take(512, Keccak `{r = 576, c = 1024} M);
|
||||
|
||||
Keccak : {r c m}
|
||||
( fin r, fin c, fin m
|
||||
, r >= 0, c >= 0, m >= 0
|
||||
, fin ((r + m + 1) / r)
|
||||
, (r + m + 1) / r >= 0
|
||||
, (r + m + 1) / r * r - m >= 2
|
||||
, 64 >= (r + c) / 25
|
||||
, 25 * ((r + c) / 25) >= r
|
||||
) => [m] -> [inf];
|
||||
Keccak M = squeeze `{r = r} (absorb `{w = (r + c) / 25} Ps)
|
||||
where Ps = pad `{r = r} M;
|
||||
|
||||
squeeze : {r w} (fin r, fin w, 64 >= w, r >= 0, 25 * w >= r) => [5][5][w] -> [inf];
|
||||
squeeze A = take(`r, flatten A) # squeeze `{r = r} (Keccak_f A);
|
||||
|
||||
absorb : {r w n} (fin r, fin w, fin n, 64 >= w, 25 * w >= r) => [n][r] -> [5][5][w];
|
||||
absorb Ps = as ! 0
|
||||
where {
|
||||
as = [zero] # [| Keccak_f `{w = w} (s ^ (unflatten p)) || s <- as || p <- Ps |];
|
||||
};
|
||||
|
||||
pad : {r m n}
|
||||
( fin r, fin m, fin n
|
||||
, n == (r + m + 1) / r
|
||||
, r * n - m >= 2
|
||||
) => [m] -> [n][r];
|
||||
pad M = split (M # [True] # zero # [True]);
|
||||
|
||||
Keccak_f : {b w} (fin w, b == 25 * w, 64 >= w) => [5][5][w] -> [5][5][w];
|
||||
Keccak_f A = rounds ! 0
|
||||
where {
|
||||
rounds = [A] # [| Round RC A || RC <- RCs `{w = w} || A <- rounds |];
|
||||
};
|
||||
|
||||
Round : {w} (fin w) => [5][5][w] -> [5][5][w] -> [5][5][w];
|
||||
Round RC A = ι RC (χ (π (ρ (θ A))));
|
||||
|
||||
θ : {w} (fin w) => [5][5][w] -> [5][5][w];
|
||||
θ A = A'
|
||||
where {
|
||||
C = [| xor a || a <- A |];
|
||||
D = [| C @ x ^ (C @ y <<< 1)
|
||||
|| x <- [0 .. 4] >>> 1
|
||||
|| y <- [0 .. 4] <<< 1
|
||||
|];
|
||||
A' = [| [| a ^ (D @ x) || a <- A @ x |] || x <- [0 .. 4] |];
|
||||
};
|
||||
|
||||
ρ : {w} (fin w) => [5][5][w] -> [5][5][w];
|
||||
ρ A = groupBy(5, [| a <<< r || a <- join(A) || r <- R |])
|
||||
where R = [00 36 03 41 18
|
||||
01 44 10 45 02
|
||||
62 06 43 15 61
|
||||
28 55 25 21 56
|
||||
27 20 39 08 14];
|
||||
|
||||
π : {w} (fin w) => [5][5][w] -> [5][5][w];
|
||||
π A = groupBy(5, [| A @ ((x + (3:[8]) * y) % 5) @ x
|
||||
|| x <- [0..4], y <- [0..4]
|
||||
|]);
|
||||
|
||||
χ : {w} (fin w) => [5][5][w] -> [5][5][w];
|
||||
χ A = groupBy(5, [| (A @ x @ y) ^ (~ A @ ((x + 1) % 5) @ y
|
||||
& A @ ((x + 2) % 5) @ y)
|
||||
|| x <- [0..4], y <- [0..4]
|
||||
|]);
|
||||
|
||||
ι : {w} (fin w) => [5][5][w] -> [5][5][w] -> [5][5][w];
|
||||
ι RC A = A ^ RC;
|
||||
|
||||
RCs : {w n} (fin w, fin n, 24 >= n, n == 12 + 2 * (lg2 w)) => [n][5][5][w];
|
||||
RCs = [| [([(RC @@ [0 .. `(w - 1)])] # zero)] # zero
|
||||
|| RC <- RCs64
|
||||
|| _ <- [1 .. `n]
|
||||
|];
|
||||
|
||||
RCs64 : [24][64];
|
||||
RCs64 = join (transpose [
|
||||
[0x0000000000000001 0x000000008000808B]
|
||||
[0x0000000000008082 0x800000000000008B]
|
||||
[0x800000000000808A 0x8000000000008089]
|
||||
[0x8000000080008000 0x8000000000008003]
|
||||
[0x000000000000808B 0x8000000000008002]
|
||||
[0x0000000080000001 0x8000000000000080]
|
||||
[0x8000000080008081 0x000000000000800A]
|
||||
[0x8000000000008009 0x800000008000000A]
|
||||
[0x000000000000008A 0x8000000080008081]
|
||||
[0x0000000000000088 0x8000000000008080]
|
||||
[0x0000000080008009 0x0000000080000001]
|
||||
[0x000000008000000A 0x8000000080008008]
|
||||
]);
|
||||
|
||||
unflatten : {r w} (fin r, 25*w >= r) => [r] -> [5][5][w];
|
||||
unflatten p = transpose(groupBy(5, groupBy(`w, p # zero)));
|
||||
|
||||
flatten : {r w} [5][5][w] -> [5 * 5 * w];
|
||||
flatten A = join (join (transpose A));
|
||||
|
||||
xor : {a b} (fin a) => [a][b] -> [b];
|
||||
xor xs = xors ! 0
|
||||
where xors = [0] # [| x ^ z || x <- xs || z <- xors |];
|
@ -71,7 +71,7 @@ def setup_cryptol_process():
|
||||
"""
|
||||
Static method that setups up an interactive cryptol process.
|
||||
"""
|
||||
cryptol = pexpect.spawn("../cabal-dev/bin/cryptol2nb")
|
||||
cryptol = pexpect.spawn("../.cabal-sandbox/bin/cryptolnb")
|
||||
cryptol.setecho(False)
|
||||
return cryptol
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
Loading module Cryptol
|
||||
Loading module Cryptol
|
||||
Loading module Cryptol
|
||||
Loading module import01_dep
|
||||
Loading module import01
|
||||
|
Loading…
Reference in New Issue
Block a user