statement
stringlengths
1
746
proof
stringlengths
0
19.5k
type
stringclasses
7 values
symbolic_name
stringlengths
1
36
library
stringclasses
13 values
filename
stringclasses
70 values
imports
listlengths
0
23
deps
listlengths
0
14
docstring
stringclasses
1 value
source_url
stringclasses
1 value
commit
stringclasses
1 value
test8
= GCM_192_96_0_128::encrypt { key = 0x00000000000000000000000000000000 # 0x0000000000000000 , pt = 0x00000000000000000000000000000000 , iv = 0x000000000000000000000000 , aad = [] } == { ct = 0x98e7247c07f0fe411c267e4384b0f600 , tag = 0x2ff58d80033927ab8ef4d4587514f0fb }
property
test8
examples.param_modules
examples/param_modules/GCM_AES_Tests.cry
[ "AES", "AES", "AES", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM" ]
[ "==" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
test9
= GCM_192_96_0_128::encrypt { key = 0xfeffe9928665731c6d6a8f9467308308 # 0xfeffe9928665731c , pt = 0xd9313225f88406e5a55909c5aff5269a # 0x86a7a9531534f7da2e4c303d8a318a72 # 0x1c3c0c95956809532fcf0e2449a6b525 # 0xb16aedf5aa0de657ba637b391aafd255 , iv = 0xca...
property
test9
examples.param_modules
examples/param_modules/GCM_AES_Tests.cry
[ "AES", "AES", "AES", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM" ]
[ "==" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
test10
= GCM_192_96_160_128::encrypt { key = 0xfeffe9928665731c6d6a8f9467308308 # 0xfeffe9928665731c , pt = 0xd9313225f88406e5a55909c5aff5269a # 0x86a7a9531534f7da2e4c303d8a318a72 # 0x1c3c0c95956809532fcf0e2449a6b525 # 0xb16aedf5aa0de657ba637b39 , aad = 0xfeedface...
property
test10
examples.param_modules
examples/param_modules/GCM_AES_Tests.cry
[ "AES", "AES", "AES", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM" ]
[ "==" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
test11
= GCM_192_64_160_128::encrypt { key = 0xfeffe9928665731c6d6a8f9467308308 # 0xfeffe9928665731c , pt = 0xd9313225f88406e5a55909c5aff5269a # 0x86a7a9531534f7da2e4c303d8a318a72 # 0x1c3c0c95956809532fcf0e2449a6b525 # 0xb16aedf5aa0de657ba637b39 , aad = 0xfeedface...
property
test11
examples.param_modules
examples/param_modules/GCM_AES_Tests.cry
[ "AES", "AES", "AES", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM" ]
[ "==" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
test12
= GCM_192_480_160_128::encrypt { key = 0xfeffe9928665731c6d6a8f9467308308 # 0xfeffe9928665731c , pt = 0xd9313225f88406e5a55909c5aff5269a # 0x86a7a9531534f7da2e4c303d8a318a72 # 0x1c3c0c95956809532fcf0e2449a6b525 # 0xb16aedf5aa0de657ba637b39 , aad = 0xfeedfac...
property
test12
examples.param_modules
examples/param_modules/GCM_AES_Tests.cry
[ "AES", "AES", "AES", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM" ]
[ "==" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
test13
= GCM_256_96_0_128::encrypt { key = 0x00000000000000000000000000000000 # 0x00000000000000000000000000000000 , pt = [] , iv = 0x000000000000000000000000 , aad = [] } == { ct = [] , tag = 0x530f8afbc74536b9a963b4f1c4cb738b }
property
test13
examples.param_modules
examples/param_modules/GCM_AES_Tests.cry
[ "AES", "AES", "AES", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM" ]
[ "==" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
test14
= GCM_256_96_0_128::encrypt { key = 0x00000000000000000000000000000000 # 0x00000000000000000000000000000000 , pt = 0x00000000000000000000000000000000 , iv = 0x000000000000000000000000 , aad = [] } == { ct = 0xcea7403d4d606b6e074ec5d3baf39d18 , tag = 0xd0d1c8a799996bf0265b98b5d...
property
test14
examples.param_modules
examples/param_modules/GCM_AES_Tests.cry
[ "AES", "AES", "AES", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM" ]
[ "==" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
test15
= GCM_256_96_0_128::encrypt { key = 0xfeffe9928665731c6d6a8f9467308308 # 0xfeffe9928665731c6d6a8f9467308308 , pt = 0xd9313225f88406e5a55909c5aff5269a # 0x86a7a9531534f7da2e4c303d8a318a72 # 0x1c3c0c95956809532fcf0e2449a6b525 # 0xb16aedf5aa0de657ba637b391aafd255 ...
property
test15
examples.param_modules
examples/param_modules/GCM_AES_Tests.cry
[ "AES", "AES", "AES", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM" ]
[ "==" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
test16
= GCM_256_96_160_128::encrypt { key = 0xfeffe9928665731c6d6a8f9467308308 # 0xfeffe9928665731c6d6a8f9467308308 , pt = 0xd9313225f88406e5a55909c5aff5269a # 0x86a7a9531534f7da2e4c303d8a318a72 # 0x1c3c0c95956809532fcf0e2449a6b525 # 0xb16aedf5aa0de657ba637b39 , ...
property
test16
examples.param_modules
examples/param_modules/GCM_AES_Tests.cry
[ "AES", "AES", "AES", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM" ]
[ "==" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
test17
= GCM_256_64_160_128::encrypt { key = 0xfeffe9928665731c6d6a8f9467308308 # 0xfeffe9928665731c6d6a8f9467308308 , pt = 0xd9313225f88406e5a55909c5aff5269a # 0x86a7a9531534f7da2e4c303d8a318a72 # 0x1c3c0c95956809532fcf0e2449a6b525 # 0xb16aedf5aa0de657ba637b39 , ...
property
test17
examples.param_modules
examples/param_modules/GCM_AES_Tests.cry
[ "AES", "AES", "AES", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM" ]
[ "==" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
test18
= GCM_256_480_160_128::encrypt { key = 0xfeffe9928665731c6d6a8f9467308308 # 0xfeffe9928665731c6d6a8f9467308308 , pt = 0xd9313225f88406e5a55909c5aff5269a # 0x86a7a9531534f7da2e4c303d8a318a72 # 0x1c3c0c95956809532fcf0e2449a6b525 # 0xb16aedf5aa0de657ba637b39 ,...
property
test18
examples.param_modules
examples/param_modules/GCM_AES_Tests.cry
[ "AES", "AES", "AES", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM", "Common::GCM" ]
[ "==" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
katsPass
= ~zero == [test == kat | (test,kat) <- sha256tests ]
property
katsPass
examples.param_modules
examples/param_modules/SHA.cry
[ "SHA256" ]
[ "==", "sha256tests" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
sha256 : {n} (64 >= width n) => [n] -> [256]
sha256 = SHA256::sha
function
sha256
examples.param_modules
examples/param_modules/SHA.cry
[ "SHA256" ]
[ ">=", "width" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
sha256tests
= [ (go "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" , 0x248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1 ) , (go "" , 0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 ) , (go "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoi...
function
sha256tests
examples.param_modules
examples/param_modules/SHA.cry
[ "SHA256" ]
[ ">=", "join", "sha256", "width" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
w
= 32
type
w
examples.param_modules
examples/param_modules/SHA256.cry
[]
[]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
j
= 64
type
j
examples.param_modules
examples/param_modules/SHA256.cry
[]
[]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
H0
= [ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a , 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 ]
function
H0
examples.param_modules
examples/param_modules/SHA256.cry
[]
[]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
K
= [ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5 , 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5 , 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3 , 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174 , 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc , 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da ...
function
K
examples.param_modules
examples/param_modules/SHA256.cry
[]
[]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
SIGMA_0 x
= (x >>> 2) ^ (x >>> 13) ^ (x >>> 22)
function
SIGMA_0
examples.param_modules
examples/param_modules/SHA256.cry
[]
[ ">>>" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
SIGMA_1 x
= (x >>> 6) ^ (x >>> 11) ^ (x >>> 25)
function
SIGMA_1
examples.param_modules
examples/param_modules/SHA256.cry
[]
[ ">>>" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
sigma_0 x
= (x >>> 7) ^ (x >>> 18) ^ (x >> 3)
function
sigma_0
examples.param_modules
examples/param_modules/SHA256.cry
[]
[ ">>", ">>>" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
sigma_1 x
= (x >>> 17) ^ (x >>> 19) ^ (x >> 10)
function
sigma_1
examples.param_modules
examples/param_modules/SHA256.cry
[]
[ ">>", ">>>" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
Nk
= 4 + 2 * Mode /** Number of rounds */
type
Nk
examples.param_modules.AES
examples/param_modules/AES/Algorithm.cry
[ "AES::State", "AES::Round" ]
[ "Mode" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
Nr
= 6 + Nk /** Key size in bits */
type
Nr
examples.param_modules.AES
examples/param_modules/AES/Algorithm.cry
[ "AES::State", "AES::Round" ]
[ "Nk" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
AESKeySize
= 32 * Nk /** The keys for all the rounds */
type
AESKeySize
examples.param_modules.AES
examples/param_modules/AES/Algorithm.cry
[ "AES::State", "AES::Round" ]
[ "Nk" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
KeySchedule
= (RoundKey, [Nr-1]RoundKey, RoundKey) /** AES Encryption with an expanded key. This is useful if many things will be encrypted with the same key. */
type
KeySchedule
examples.param_modules.AES
examples/param_modules/AES/Algorithm.cry
[ "AES::State", "AES::Round" ]
[ "RoundKey" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
encrypt : KeySchedule -> [128] -> [128]
encrypt (kInit,ks,kFinal) pt = stateToMsg (AESFinalRound kFinal (rounds ! 0)) where state0 = kInit ^ msgToState pt rounds = [state0] # [ encRound rk s | rk <- ks | s <- rounds ] /** AES decryption with an expanded key. This is useful if many things will be decrypted with the same key....
function
encrypt
examples.param_modules.AES
examples/param_modules/AES/Algorithm.cry
[ "AES::State", "AES::Round" ]
[ "AESFinalRound", "KeySchedule", "ks", "msgToState", "stateToMsg" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
decrypt : KeySchedule -> [128] -> [128]
decrypt (kInit, ks, kFinal) ct = stateToMsg (AESFinalInvRound kFinal (rounds ! 0)) where state0 = kInit ^ msgToState ct rounds = [state0] # [ decRound rk s | rk <- ks | s <- rounds ]
function
decrypt
examples.param_modules.AES
examples/param_modules/AES/Algorithm.cry
[ "AES::State", "AES::Round" ]
[ "AESFinalInvRound", "KeySchedule", "ks", "msgToState", "stateToMsg" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
Nk : #
type
Nk
examples.param_modules.AES
examples/param_modules/AES/ExpandKey.cry
[ "AES::GF28", "AES::State", "AES::SubByteSBox" ]
[]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
(8 >= width Nk, Nk >= 1) /** Number of rounds */
type constraint
width
examples.param_modules.AES
examples/param_modules/AES/ExpandKey.cry
[ "AES::GF28", "AES::State", "AES::SubByteSBox" ]
[ ">=", "Nk", "width" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
Nr : #
type
Nr
examples.param_modules.AES
examples/param_modules/AES/ExpandKey.cry
[ "AES::GF28", "AES::State", "AES::SubByteSBox" ]
[]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
(8 >= width Nr, Nr >= 2)
type constraint
width
examples.param_modules.AES
examples/param_modules/AES/ExpandKey.cry
[ "AES::GF28", "AES::State", "AES::SubByteSBox" ]
[ ">=", "Nr", "width" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
expandKey : [32 * Nk] -> (RoundKey, [Nr-1]RoundKey, RoundKey)
expandKey key = ( keys @ 0 , keys @@ ([1 .. (Nr - 1)] : [_][8]) , keys @ (`Nr : [8]) ) where seed : [Nk][4][8] seed = split (split key) keys = expandKeyForever seed
function
expandKey
examples.param_modules.AES
examples/param_modules/AES/ExpandKey.cry
[ "AES::GF28", "AES::State", "AES::SubByteSBox" ]
[ "Nr", "RoundKey", "expandKeyForever", "split" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
expandKeyForever : [Nk][4][8] -> [inf]RoundKey
expandKeyForever seed = [ transpose g | g <- split (keyWS seed) ]
function
expandKeyForever
examples.param_modules.AES
examples/param_modules/AES/ExpandKey.cry
[ "AES::GF28", "AES::State", "AES::SubByteSBox" ]
[ "keyWS", "split", "transpose" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
keyWS : [Nk][4][8] -> [inf][4][8]
keyWS seed = xs where xs = seed # [ NextWord i prev old | i <- [ `Nk ... ] | prev <- drop`{Nk-1} xs | old <- xs ] // Key expansion
function
keyWS
examples.param_modules.AES
examples/param_modules/AES/ExpandKey.cry
[ "AES::GF28", "AES::State", "AES::SubByteSBox" ]
[ "NextWord", "xs" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
Rcon : [8] -> [4]GF28
Rcon i = [ gf28Pow <| x |> (i-1), 0, 0, 0]
function
Rcon
examples.param_modules.AES
examples/param_modules/AES/ExpandKey.cry
[ "AES::GF28", "AES::State", "AES::SubByteSBox" ]
[ "gf28Pow" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
SubWord : [4]GF28 -> [4]GF28
SubWord bs = [ SubByte b | b <- bs ]
function
SubWord
examples.param_modules.AES
examples/param_modules/AES/ExpandKey.cry
[ "AES::GF28", "AES::State", "AES::SubByteSBox" ]
[ "SubByte" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
NextWord : [8] ->[4][8] -> [4][8] -> [4][8]
NextWord i prev old = old ^ mask where mask = if i % nk == 0 then SubWord (RotWord(prev)) ^ Rcon (i / `Nk) else if (nk > 6) && (i % nk == 4) then SubWord prev else prev nk = `Nk : [8]
function
NextWord
examples.param_modules.AES
examples/param_modules/AES/ExpandKey.cry
[ "AES::GF28", "AES::State", "AES::SubByteSBox" ]
[ "&&", "==", "Rcon", "RotWord", "SubWord" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
GF28
= [8] /** The irreducable polynomial */
type
GF28
examples.param_modules.AES
examples/param_modules/AES/GF28.cry
[]
[]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
gf28Add : {n} (fin n) => [n]GF28 -> GF28
gf28Add ps = sums ! 0 where sums = [zero] # [ p ^ s | p <- ps | s <- sums ] /** Multiply two GF28 values */
function
gf28Add
examples.param_modules.AES
examples/param_modules/AES/GF28.cry
[]
[ "GF28", "fin", "sums" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
gf28Mult : GF28 -> GF28 -> GF28
gf28Mult x y = pmod (pmult x y) irreducible /** A GF28 value to a scalar power */
function
gf28Mult
examples.param_modules.AES
examples/param_modules/AES/GF28.cry
[]
[ "GF28", "irreducible", "pmod", "pmult" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
gf28Pow : GF28 -> [8] -> GF28
gf28Pow n k = pow k where sq x = gf28Mult x x odd x = x ! 0 pow i = if i == 0 then 1 else if odd i then gf28Mult n (sq (pow (i >> 1))) else sq (pow (i >> 1)) /** Compute the inverse of a value */
function
gf28Pow
examples.param_modules.AES
examples/param_modules/AES/GF28.cry
[]
[ "==", ">>", "GF28", "gf28Mult" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
gf28Inverse : GF28 -> GF28
gf28Inverse x = gf28Pow x 254 /** Dot product of two vectors */
function
gf28Inverse
examples.param_modules.AES
examples/param_modules/AES/GF28.cry
[]
[ "GF28", "gf28Pow" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
gf28DotProduct : {n} (fin n) => [n]GF28 -> [n]GF28 -> GF28
gf28DotProduct xs ys = gf28Add [ gf28Mult x y | x <- xs | y <- ys ] /** Multiply a matrix by a vector */
function
gf28DotProduct
examples.param_modules.AES
examples/param_modules/AES/GF28.cry
[]
[ "GF28", "fin", "gf28Add", "gf28Mult", "xs" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
gf28VectorMult : {n, m} (fin n) => [n]GF28 -> [m][n]GF28 -> [m]GF28
gf28VectorMult v ms = [ gf28DotProduct v m | m <- ms ] /** Multiply two matrices */
function
gf28VectorMult
examples.param_modules.AES
examples/param_modules/AES/GF28.cry
[]
[ "fin", "gf28DotProduct" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
gf28MatrixMult : {n, m, k} (fin m) => [n][m]GF28 -> [m][k]GF28 -> [n][k]GF28
gf28MatrixMult xss yss = [ gf28VectorMult xs yss' | xs <- xss ] where yss' = transpose yss
function
gf28MatrixMult
examples.param_modules.AES
examples/param_modules/AES/GF28.cry
[]
[ "fin", "gf28VectorMult", "transpose", "xs" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
irreducible
= <| x^^8 + x^^4 + x^^3 + x + 1 |> /** Sum up a bunch of GF28 values */
function
irreducible
examples.param_modules.AES
examples/param_modules/AES/GF28.cry
[]
[]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
AESRound : RoundKey -> State -> State
AESRound rk s = rk ^ MixColumns (ShiftRows (SubBytes s))
function
AESRound
examples.param_modules.AES
examples/param_modules/AES/Round.cry
[ "AES::GF28", "AES::State", "AES::SubByteSBox" ]
[ "MixColumns", "RoundKey", "ShiftRows", "State", "SubBytes" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
SubBytes : State -> State
SubBytes state = [ [ SubByte b | b <- row ] | row <- state ]
function
SubBytes
examples.param_modules.AES
examples/param_modules/AES/Round.cry
[ "AES::GF28", "AES::State", "AES::SubByteSBox" ]
[ "State", "SubByte" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
ShiftRows : State -> State
ShiftRows state = [ row <<< i | row <- state | i : [2] <- [0 .. 3] ]
function
ShiftRows
examples.param_modules.AES
examples/param_modules/AES/Round.cry
[ "AES::GF28", "AES::State", "AES::SubByteSBox" ]
[ "<<<", "State" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
MixColumns : State -> State
MixColumns state = gf28MatrixMult m state where m = [ [2,3,1,1] >>> i | i <- [0 .. 3] ] /** The final AES round */
function
MixColumns
examples.param_modules.AES
examples/param_modules/AES/Round.cry
[ "AES::GF28", "AES::State", "AES::SubByteSBox" ]
[ ">>>", "State", "gf28MatrixMult" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
AESFinalRound : RoundKey -> State -> State
AESFinalRound rk s = rk ^ ShiftRows (SubBytes s) /** One inverse round of AES */
function
AESFinalRound
examples.param_modules.AES
examples/param_modules/AES/Round.cry
[ "AES::GF28", "AES::State", "AES::SubByteSBox" ]
[ "RoundKey", "ShiftRows", "State", "SubBytes" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
AESInvRound : RoundKey -> State -> State
AESInvRound rk s = InvMixColumns (rk ^ InvSubBytes (InvShiftRows s))
function
AESInvRound
examples.param_modules.AES
examples/param_modules/AES/Round.cry
[ "AES::GF28", "AES::State", "AES::SubByteSBox" ]
[ "InvMixColumns", "InvShiftRows", "InvSubBytes", "RoundKey", "State" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
InvSubBytes : State -> State
InvSubBytes state = [ [ InvSubByte b | b <- row ] | row <- state ]
function
InvSubBytes
examples.param_modules.AES
examples/param_modules/AES/Round.cry
[ "AES::GF28", "AES::State", "AES::SubByteSBox" ]
[ "InvSubByte", "State" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
InvShiftRows : State -> State
InvShiftRows state = [ row >>> shiftAmount | row <- state | shiftAmount : [2] <- [0 .. 3] ]
function
InvShiftRows
examples.param_modules.AES
examples/param_modules/AES/Round.cry
[ "AES::GF28", "AES::State", "AES::SubByteSBox" ]
[ ">>>", "State" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
InvMixColumns : State -> State
InvMixColumns state = gf28MatrixMult m state where m = [[0x0e, 0x0b, 0x0d, 0x09] >>> i | i <- [0 .. 3] ] /** The final inverted AES round */
function
InvMixColumns
examples.param_modules.AES
examples/param_modules/AES/Round.cry
[ "AES::GF28", "AES::State", "AES::SubByteSBox" ]
[ ">>>", "State", "gf28MatrixMult" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
AESFinalInvRound : RoundKey -> State -> State
AESFinalInvRound rk s = rk ^ InvSubBytes (InvShiftRows s)
function
AESFinalInvRound
examples.param_modules.AES
examples/param_modules/AES/Round.cry
[ "AES::GF28", "AES::State", "AES::SubByteSBox" ]
[ "InvShiftRows", "InvSubBytes", "RoundKey", "State" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
SBox
= [256] GF28
type
SBox
examples.param_modules.AES
examples/param_modules/AES/SBox.cry
[ "AES::GF28", "AES::SubBytePlain" ]
[ "GF28" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
sbox : SBox
sbox = [ SubByte x | x <- [0 .. 255] ]
function
sbox
examples.param_modules.AES
examples/param_modules/AES/SBox.cry
[ "AES::GF28", "AES::SubBytePlain" ]
[ "SBox", "SubByte" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
sboxInv : SBox
sboxInv = [ InvSubByte x | x <- [0 .. 255] ]
function
sboxInv
examples.param_modules.AES
examples/param_modules/AES/SBox.cry
[ "AES::GF28", "AES::SubBytePlain" ]
[ "InvSubByte", "SBox" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
Nb
= 4
type
Nb
examples.param_modules.AES
examples/param_modules/AES/State.cry
[ "AES::GF28" ]
[]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
stateToMsg : State -> [128]
stateToMsg st = join (join (transpose st))
function
stateToMsg
examples.param_modules.AES
examples/param_modules/AES/State.cry
[ "AES::GF28" ]
[ "State", "join", "transpose" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
InvSubByte : GF28 -> GF28
InvSubByte b = gf28Inverse (xformByte' b) // The affine transform and its inverse
function
InvSubByte
examples.param_modules.AES
examples/param_modules/AES/SubBytePlain.cry
[ "AES::GF28" ]
[ "GF28", "gf28Inverse", "xformByte'" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
xformByte' : GF28 -> GF28
xformByte' b = gf28Add [(b >>> 2), (b >>> 5), (b >>> 7), d] where d = 0x05
function
xformByte'
examples.param_modules.AES
examples/param_modules/AES/SubBytePlain.cry
[ "AES::GF28" ]
[ ">>>", "GF28", "gf28Add" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
SubByte : GF28 -> GF28
SubByte b = sbox @ b
function
SubByte
examples.param_modules.AES
examples/param_modules/AES/SubByteSBox.cry
[ "AES::GF28", "AES::SBox" ]
[ "GF28", "sbox" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
InvSubByte : GF28 -> GF28
InvSubByte b = sboxInv @ b
function
InvSubByte
examples.param_modules.AES
examples/param_modules/AES/SubByteSBox.cry
[ "AES::GF28", "AES::SBox" ]
[ "GF28", "sboxInv" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
TBox
= [4][256][4]GF28
type
TBox
examples.param_modules.AES
examples/param_modules/AES/TBox.cry
[ "AES::GF28", "AES::State", "AES::SBox", "AES::Round" ]
[]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
genRound : (State -> State) -> TBox -> RoundKey -> State -> State
genRound shift boxes rk st = rk ^ transpose [ add [ box @ i | box <- boxes | i <- col ] | col <- transpose (shift st) ] where add [ a, b, c, d ] = a ^ b ^ c ^ d // Computing the TBoxes
function
genRound
examples.param_modules.AES
examples/param_modules/AES/TBox.cry
[ "AES::GF28", "AES::State", "AES::SBox", "AES::Round" ]
[ "RoundKey", "State", "TBox", "transpose" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
tbox : TBox
tbox = mkTBox [ 0x02, 0x01, 0x01, 0x03 ] sbox
function
tbox
examples.param_modules.AES
examples/param_modules/AES/TBox.cry
[ "AES::GF28", "AES::State", "AES::SBox", "AES::Round" ]
[ "TBox", "mkTBox", "sbox" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
tboxInv : TBox
tboxInv = mkTBox [ 0x0e, 0x09, 0x0d, 0x0b ] sboxInv
function
tboxInv
examples.param_modules.AES
examples/param_modules/AES/TBox.cry
[ "AES::GF28", "AES::State", "AES::SBox", "AES::Round" ]
[ "TBox", "mkTBox", "sboxInv" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
mkTBox : [4]GF28 -> SBox -> TBox
mkTBox seed box = [ [ a >>> i | a <- t0 ] | i <- [0 .. 3] ] where t0 = [ [ gf28Mult c s | c <- seed ] | s <- box ]
function
mkTBox
examples.param_modules.AES
examples/param_modules/AES/TBox.cry
[ "AES::GF28", "AES::State", "AES::SBox", "AES::Round" ]
[ ">>>", "SBox", "TBox", "gf28Mult" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
AESRound rk st
= genRound ShiftRows tbox rk st // AESInvRound rk st = genRound InvShiftRows tboxInv (InvMixColumns rk) st
function
AESRound
examples.param_modules.AES
examples/param_modules/AES/TBox.cry
[ "AES::GF28", "AES::State", "AES::SBox", "AES::Round" ]
[ "ShiftRows", "genRound", "tbox" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
AESInvRound rk st
= genRound InvShiftRows tboxInv rk st
function
AESInvRound
examples.param_modules.AES
examples/param_modules/AES/TBox.cry
[ "AES::GF28", "AES::State", "AES::SBox", "AES::Round" ]
[ "InvShiftRows", "genRound", "tboxInv" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
makeDecKey (a,xs,b)
= (b, [ InvMixColumns rk | rk <- reverse xs ], a)
function
makeDecKey
examples.param_modules.AES
examples/param_modules/AES/TBox.cry
[ "AES::GF28", "AES::State", "AES::SBox", "AES::Round" ]
[ "InvMixColumns", "reverse", "xs" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
Mode : #
type
Mode
examples.param_modules.Common
examples/param_modules/Common/AES_GCM_SIV.cry
[ "AES" ]
[]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
(1 >= Mode)
type constraint
Mode
examples.param_modules.Common
examples/param_modules/Common/AES_GCM_SIV.cry
[ "AES" ]
[ ">=", "Mode" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
AAD : #
type
AAD
examples.param_modules.Common
examples/param_modules/Common/AES_GCM_SIV.cry
[ "AES" ]
[]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
( (36 + 8) >= width AAD )
type constraint
width
examples.param_modules.Common
examples/param_modules/Common/AES_GCM_SIV.cry
[ "AES" ]
[ ">=", "AAD", "width" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
K
= 128 + 128 * Mode
type
K
examples.param_modules.Common
examples/param_modules/Common/AES_GCM_SIV.cry
[ "AES" ]
[ "Mode" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
KS
= AES::EncKey /** Note the weird byte-swapping business (also in `blockify` and `unblockify`) It is not quite clear in what format we want the inputs/outputs, but we do the swapping so that inputs/ouputs match the test vectors at https://tools.ietf.org/html/draft-irtf-cfrg-gcmsiv-06 */
type
KS
examples.param_modules.Common
examples/param_modules/Common/AES_GCM_SIV.cry
[ "AES" ]
[]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
aes_gcm_siv : {n} ((36 + 8) >= width n) => { key : [K] , nonce : [96] , aad : [AAD] , msg : [n] } -> [n + 128]
aes_gcm_siv input = c # byteSwap t where (c,t) = gcm_siv_plus (derive_key k' n') n' input.aad input.msg k' = byteSwap input.key n' = byteSwap input.nonce
function
aes_gcm_siv
examples.param_modules.Common
examples/param_modules/Common/AES_GCM_SIV.cry
[ "AES" ]
[ ">=", "byteSwap", "derive_key", "gcm_siv_plus", "width" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
aes : KS -> [128] -> [128]
aes ks v = byteSwap (AES::encryptWithSchedule ks (byteSwap v))
function
aes
examples.param_modules.Common
examples/param_modules/Common/AES_GCM_SIV.cry
[ "AES" ]
[ "KS", "byteSwap", "ks" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
expandKey : [K] -> KS
expandKey k = AES::expandKeyEnc (byteSwap k) /** See Figure 2 in Section 4 */
function
expandKey
examples.param_modules.Common
examples/param_modules/Common/AES_GCM_SIV.cry
[ "AES" ]
[ "KS", "byteSwap" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
derive_key : [K] -> [96] -> ([128], KS)
derive_key K N = (mkKey parts1, expandKey (mkKey parts2)) where parts1 # parts2 = [ drop (aes (expandKey K) (N # i)) | i <- take [ 0 ... ] ] mkKey : {n} (fin n) => [n][64] -> [64 * n] mkKey xs = join (reverse xs) /** See Figure 1 in Section 3 */
function
derive_key
examples.param_modules.Common
examples/param_modules/Common/AES_GCM_SIV.cry
[ "AES" ]
[ "KS", "aes", "drop", "expandKey", "fin", "join", "reverse", "take", "xs" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
gcm_siv_plus : {n} (64 >= width n) => ([128], KS) -> [96] -> [AAD] -> [n] -> ([n],[128])
gcm_siv_plus (K1,K2) N AAD MSG = (unblockify Cs,TAG) where TAG = aes K2 (0b0 # drop (T ^ (0 # N))) T = polyvalFrom K1 (A # M # [msg_len # aad_len]) 0 A = blockify AAD M = blockify MSG aad_len = `AAD : [64] msg_len = `n : [64] _ # tUpper # tLower = TAG Cs = counter_mode K2 (0...
function
gcm_siv_plus
examples.param_modules.Common
examples/param_modules/Common/AES_GCM_SIV.cry
[ "AES" ]
[ ">=", "AAD", "KS", "aes", "blockify", "counter_mode", "drop", "polyvalFrom", "unblockify", "width" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
counter_mode : {n} KS -> ([96],[32]) -> [n][128] -> [n][128]
counter_mode K2 (tUpper,tLower) M = [ aes K2 (tUpper # lower32 i) ^ m | m <- M | i <- [ 0 ... ] ] where lower32 i = tLower + i /** See Section 2.2 */
function
counter_mode
examples.param_modules.Common
examples/param_modules/Common/AES_GCM_SIV.cry
[ "AES" ]
[ "KS", "aes" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
polyvalFrom : {n} (fin n) => [128] -> [n][128] -> [128] -> [128]
polyvalFrom H Xs start = psums ! 0 where psums = [start] # [ dot (s ^ x) H | s <- psums | x <- Xs ]
function
polyvalFrom
examples.param_modules.Common
examples/param_modules/Common/AES_GCM_SIV.cry
[ "AES" ]
[ "dot", "fin", "start" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
dot : [128] -> [128] -> [128]
dot x y = mult x (mult y x_neg_128) where x_neg_128 = <| 1 + x^^114 + x^^121 + x^^124 + x^^127 |> // This is x^(-128)
function
dot
examples.param_modules.Common
examples/param_modules/Common/AES_GCM_SIV.cry
[ "AES" ]
[ "mult" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
mult : [128] -> [128] -> [128]
mult x y = pmod (pmult x y) irred where irred = <| 1 + x^^121 + x^^126 + x^^127 + x^^128 |> // -----------------------------------------------------------------------------
function
mult
examples.param_modules.Common
examples/param_modules/Common/AES_GCM_SIV.cry
[ "AES" ]
[ "pmod", "pmult" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
blockify : {n} (fin n) => [n] -> [n /^ 128][128]
blockify x = [ byteSwap b | b <- split (x # zero) ]
function
blockify
examples.param_modules.Common
examples/param_modules/Common/AES_GCM_SIV.cry
[ "AES" ]
[ "byteSwap", "fin", "split", "zero" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
unblockify : {n} (fin n) => [n /^ 128][128] -> [n]
unblockify xs = take (join [ byteSwap b | b <- xs ]) // The spec uses byte-oriented little-endian representations. // This function changes back and forth.
function
unblockify
examples.param_modules.Common
examples/param_modules/Common/AES_GCM_SIV.cry
[ "AES" ]
[ "byteSwap", "fin", "join", "take", "xs" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
byteSwap : {n} (fin n) => [8 * n] -> [8 * n]
byteSwap xs = join (reverse (split`{each=8} xs))
function
byteSwap
examples.param_modules.Common
examples/param_modules/Common/AES_GCM_SIV.cry
[ "AES" ]
[ "fin", "join", "reverse", "xs" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
K : #
type
K
examples.param_modules.Common
examples/param_modules/Common/GCM.cry
[]
[]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
(fin K) /** Size of initialization vector */
type constraint
fin
examples.param_modules.Common
examples/param_modules/Common/GCM.cry
[]
[ "fin" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
IV : #
type
IV
examples.param_modules.Common
examples/param_modules/Common/GCM.cry
[]
[]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
(64 >= width IV, IV >= 1) /** Size of additional authenticated data */
type constraint
width
examples.param_modules.Common
examples/param_modules/Common/GCM.cry
[]
[ ">=", "IV", "width" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
AAD : #
type
AAD
examples.param_modules.Common
examples/param_modules/Common/GCM.cry
[]
[]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
(64 >= width AAD) /** Size of authentication tag */
type constraint
width
examples.param_modules.Common
examples/param_modules/Common/GCM.cry
[]
[ ">=", "AAD", "width" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
T : #
type
T
examples.param_modules.Common
examples/param_modules/Common/GCM.cry
[]
[]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb
(128 >= T, T >= 64) /** Block encryption function */
type constraint
T
examples.param_modules.Common
examples/param_modules/Common/GCM.cry
[]
[ ">=" ]
https://github.com/GaloisInc/cryptol
a50cac6eb2c30a79503814f423f375f9476aaceb