gf128.bend checks
raw source on the hub · import bend-osdev-gf@0.1.1.0/gf128.bend as Gf128
bend-osdev-gf, GF(2^128): the field of GCM's GHASH (NIST SP 800-38D) and of the tweak arithmetic in XTS (IEEE Std 1619), LRW and CMAC (NIST SP 800-38B), all modulo x^128 + x^7 + x^2 + x + 1, in the three bit orders they use.
A Gf128 is a 16-byte block as four big-endian 32-bit words: byte 0 is the top byte of w0, byte 15 the bottom byte of w3. The bit orders:
* GCM (SP 800-38D, 6.3): bit 0 of the block, the most significant bit of byte 0, is the coefficient of x^0; bit 127, the least significant bit of byte 15, that of x^127. Multiplying by x shifts the block right one bit, and a bit falling off the end adds R = 0xE1 || 0^120. * big-endian (CMAC's doubling, SP 800-38B 6.1; LRW): the block is a 128-bit big-endian number whose bit i is the coefficient of x^i. Multiplying by x shifts it left one bit, and a carry adds 0x87. * little-endian (XTS, IEEE 1619 5.2): the block is a 128-bit little-endian number (byte 0 least significant); multiplying by x shifts it left one bit, and a carry adds 0x87 to byte 0.
2 imports
import Base import bend-osdev-bytes@0.1.1.0/bytes.bend as B
Types
type Gf128 source · line 22 · raw
Data
Gf128@w0:U32 -> @w1:U32 -> @w2:U32 -> @w3:U32 -> Gf128
type Gf128Error source · line 25 · raw
Data
Gf128BadLength@got:Nat -> Gf128Error
Definitions
def Gf128.zero source · line 28 · raw
Gf128
def Gf128.of_words source · line 31 · raw
@w0:U32 -> @w1:U32 -> @w2:U32 -> @w3:U32 -> Gf128
def Gf128.words source · line 34 · raw
@x:Gf128 -> List<&2, U32>
def Gf128.xor source · line 39 · raw
@a:Gf128 -> @b:Gf128 -> Gf128
def Gf128.is_eq source · line 44 · raw
@a:Gf128 -> @b:Gf128 -> Bool
def gf128.word source · line 51 · raw
@a:U32 -> @b:U32 -> @c:U32 -> @d:U32 -> U32
def gf128.of_list.go source · line 54 · raw
@xs:List<&2, U32> -> Gf128
def gf128.of_list.pick source · line 61 · raw
@ok:Bool -> @+n:Nat -> @+xs:List<&2, U32> -> Result<&2, &2, Gf128Error, Gf128>
def Gf128.of_octets source · line 69 · raw
@+o:0xe0217e1ab38629fddf738452c1f2a82e/bytes.Octets -> Result<&2, &2, Gf128Error, Gf128>
the block of 16 bytes (any other length is refused)
def Gf128.to_octets source · line 73 · raw
@x:Gf128 -> 0xe0217e1ab38629fddf738452c1f2a82e/bytes.Octets
def Gf128.hex source · line 78 · raw
@x:Gf128 -> String
def gf128.mask source · line 82 · raw
@b:U32 -> U32
all ones if the low bit of b is set, else 0
def Gf128.and_mask source · line 85 · raw
@a:Gf128 -> @+m:U32 -> Gf128
def Gf128.mul_x_gcm source · line 93 · raw
@v:Gf128 -> Gf128
GCM's order: shift right one bit; bit 127 falling off adds 0xE1 to byte 0
def Gf128.double_be source · line 100 · raw
@v:Gf128 -> Gf128
big-endian (CMAC's doubling, LRW): shift left one bit; a carry adds 0x87 to byte 15
def gf128.le.shift source · line 109 · raw
@+w:U32 -> U32
each byte of w shifted left, with the carries between w's own bytes
def gf128.le.carry source · line 113 · raw
@w:U32 -> U32
the carry out of w's last byte, into the first byte of the next word
def Gf128.double_le source · line 116 · raw
@v:Gf128 -> Gf128
def gf128.gcm.bit source · line 124 · raw
@+x:U32 -> @zv:Pair(Gf128, Gf128) -> Pair(Gf128, Gf128)
def gf128.gcm.word source · line 129 · raw
@n:Nat -> @+x:U32 -> @zv:Pair(Gf128, Gf128) -> Pair(Gf128, Gf128)
the 32 bits of the word x, from its top bit
def gf128.fst source · line 136 · raw
@p:Pair(Gf128, Gf128) -> Gf128
def Gf128.mul_gcm source · line 140 · raw
@x:Gf128 -> @y:Gf128 -> Gf128
def Gf128.ghash_update source · line 146 · raw
@+h:Gf128 -> @y:Gf128 -> @x:Gf128 -> Gf128
GHASH (SP 800-38D, 6.4): Y = (Y + X_i) * H for each block X_i
def Gf128.ghash.go source · line 149 · raw
@xs:List<&2, Gf128> -> @+h:Gf128 -> @y:Gf128 -> Gf128
def Gf128.ghash source · line 156 · raw
@+h:Gf128 -> @xs:List<&2, Gf128> -> Gf128
def gf128.be.word source · line 162 · raw
@n:Nat -> @+x:U32 -> @+a:Gf128 -> @z:Gf128 -> Gf128
def Gf128.mul_be source · line 169 · raw
@+a:Gf128 -> @b:Gf128 -> Gf128