gcm.bend checks
raw source on the hub · import element-crypto@0.1.0.0/gcm.bend as Gcm
4 imports
import Base import ./aes.bend as Aes import ./chacha20.bend as ChaCha import ./poly1305.bend as Poly
Types
type W4 source · line 12 · raw
Data
A 128-bit block as four big-endian words; a is the most significant.
W4@a:U32 -> @b:U32 -> @c:U32 -> @d:U32 -> W4
type ZV source · line 56 · raw
Data
ZV@z:W4 -> @v:W4 -> ZV
Definitions
def nth source · line 15 · raw
@xs:List<&2, U32> -> @n:Nat -> U32
def be32_at source · line 18 · raw
@+bs:List<&2, U32> -> @+i:Nat -> U32
def w4_of source · line 26 · raw
@+bs:List<&2, U32> -> W4
up to 16 bytes; a short final block is padded with zeros (nth answers 0)
def be_bytes source · line 29 · raw
@+x:U32 -> List<&2, U32>
def w4_bytes source · line 32 · raw
@w:W4 -> List<&2, U32>
def wxor source · line 37 · raw
@x:W4 -> @y:W4 -> W4
def wand source · line 42 · raw
@x:W4 -> @+m:U32 -> W4
def shr1 source · line 48 · raw
@v:W4 -> W4
V >> 1, and R = 11100001 || 0^120 folded in when a bit fell off (6.3)
def bits source · line 61 · raw
@n:Nat -> @+x:U32 -> @zv:ZV -> ZV
Algorithm 1 of 6.3 over the 32 bits of one word of X, most significant first. Z ^= V when the bit is set, as a mask (0 or all ones), no branch.
def z_of source · line 71 · raw
@zv:ZV -> W4
def gmul source · line 77 · raw
@x:W4 -> @+h:W4 -> W4
X . H in GF(2^128)
def blocks source · line 82 · raw
@+bs:List<&2, U32> -> Nat
def ghash_go source · line 86 · raw
@n:Nat -> @+h:W4 -> @+y:W4 -> @+data:List<&2, U32> -> W4
Y_i = (Y_{i-1} ^ X_i) . H over the data, zero-padded to whole blocks
def len_block source · line 93 · raw
@+aad:List<&2, U32> -> @+ct:List<&2, U32> -> W4
def ghash source · line 97 · raw
@+h:W4 -> @+aad:List<&2, U32> -> @+ct:List<&2, U32> -> W4
GHASH_H(A || 0* || C || 0* || [len A]64 || [len C]64)
def block_at source · line 102 · raw
@+ks:List<&2, 0x29d6f1ff259add9ea6c8f213fda12377/aes.B16> -> @+nonce:List<&2, U32> -> @+ctr:U32 -> List<&2, U32>
def ctr_go source · line 106 · raw
@n:Nat -> @+ks:List<&2, 0x29d6f1ff259add9ea6c8f213fda12377/aes.B16> -> @+nonce:List<&2, U32> -> @+ctr:U32 -> @+data:List<&2, U32> -> List<&2, U32>
GCTR from counter ctr: one AES block of keystream per 16 bytes
def tag_with source · line 116 · raw
@+ks:List<&2, 0x29d6f1ff259add9ea6c8f213fda12377/aes.B16> -> @+nonce:List<&2, U32> -> @+aad:List<&2, U32> -> @+ct:List<&2, U32> -> List<&2, U32>
H = E(K, 0^128); the tag is E(K, J0) ^ GHASH, J0 = nonce || 1; data from 2
def tag_of source · line 120 · raw
@+key:List<&2, U32> -> @+nonce:List<&2, U32> -> @+aad:List<&2, U32> -> @+ct:List<&2, U32> -> List<&2, U32>
def crypt_with source · line 123 · raw
@+ks:List<&2, 0x29d6f1ff259add9ea6c8f213fda12377/aes.B16> -> @+nonce:List<&2, U32> -> @+data:List<&2, U32> -> List<&2, U32>
def seal source · line 127 · raw
@+key:List<&2, U32> -> @+nonce:List<&2, U32> -> @+aad:List<&2, U32> -> @+pt:List<&2, U32> -> List<&2, U32>
ciphertext | tag
def opened source · line 133 · raw
@ok:Bool -> @+ks:List<&2, 0x29d6f1ff259add9ea6c8f213fda12377/aes.B16> -> @+nonce:List<&2, U32> -> @+ct:List<&2, U32> -> Maybe<&2, List<&2, U32>>
the plaintext is computed only when the tag verifies (a match, not a pick)
def open source · line 140 · raw
@+key:List<&2, U32> -> @+nonce:List<&2, U32> -> @+aad:List<&2, U32> -> @+sealed:List<&2, U32> -> Maybe<&2, List<&2, U32>>