~/bend-docscommunity

cipher_core.bend checks

raw source on the hub · import bend-osdev-cipher-core@0.1.0.0/cipher_core.bend as Cipher_core

bend-osdev-cipher-core: what the block and stream ciphers of the cipher packages (des, sm4, camellia, serpent, twofish, aria, cast6, blowfish, cast5, tea, xtea, fcrypt, rc4) share: their error type, the 64-bit block, word helpers, tables, and Feistel rounds over any round function. The 64-bit modes are in modes64.bend.

The 128-bit block ciphers work on mode-core's CmBlock, so they plug into every mode there as the template arguments ~K, ~enc, ~dec. The 64-bit ones (des, blowfish, cast5, tea, xtea, fcrypt) work on LcBlock64 below, and the 64-bit modes in modes64.bend.

3 imports
import Base
import bend-osdev-bytes@0.1.1.0/bytes.bend as B
import bend-osdev-word64@0.1.1.0/word64.bend as W

Types

type LcError source · line 16 · raw

Data

Every failure the package reports

type LcBlock64 source · line 25 · raw

Data

A 64-bit block: two 32-bit words, big-endian (hi holds bytes 0 to 3, byte 0 in its top 8 bits). Every value of the type is a block, so "decryption inverts encryption" can be stated for every block. The type is open: a cipher may build and match blocks directly.

type LcTab source · line 241 · raw

Data

Definitions

def LcBlock64.zero source · line 28 · raw

LcBlock64

def LcBlock64.xor source · line 31 · raw

@a:LcBlock64 -> @b:LcBlock64 -> LcBlock64

def lc.rotl source · line 39 · raw

@+x:U32 -> @+n:Nat -> U32

def lc.byte source · line 43 · raw

@x:U32 -> @n:Nat -> U32

byte n of x, counting from the least significant (n = 0 to 3)

def lc.be source · line 47 · raw

@a:U32 -> @b:U32 -> @c:U32 -> @d:U32 -> U32

the word with bytes a (most significant), b, c, d

def lc.le source · line 51 · raw

@a:U32 -> @b:U32 -> @c:U32 -> @d:U32 -> U32

the word with bytes a (least significant), b, c, d

def lc.bit source · line 55 · raw

@x:U32 -> @i:Nat -> U32

bit i of x (0 the least significant), as 0 or 1

def lc.at source · line 59 · raw

@xs:List<&2, U32> -> @n:Nat -> U32

element n of a list of words (0 past the end)

def lc.wrotl source · line 76 · raw

@+m:Nat -> @+n:Nat -> @+w:Word(Nat.add(m, n)) -> Word(Nat.add(n, m))

the (m + n)-bit word w rotated left by n

def lc.rotl1.bits source · line 79 · raw

@x:U32 -> U32

def lc.rotl3.bits source · line 84 · raw

@x:U32 -> U32

def lc.rotl5.bits source · line 89 · raw

@x:U32 -> U32

def lc.rotl7.bits source · line 94 · raw

@x:U32 -> U32

def lc.rotl10.bits source · line 99 · raw

@x:U32 -> U32

def lc.rotl13.bits source · line 104 · raw

@x:U32 -> U32

def lc.rotl19.bits source · line 109 · raw

@x:U32 -> U32

def lc.rotl22.bits source · line 114 · raw

@x:U32 -> U32

def lc.rotl25.bits source · line 119 · raw

@x:U32 -> U32

def lc.rotl27.bits source · line 124 · raw

@x:U32 -> U32

def lc.rotl29.bits source · line 129 · raw

@x:U32 -> U32

def lc.rotl31.bits source · line 134 · raw

@x:U32 -> U32

def lc.bits8 source · line 140 · raw

@b:U32 -> Word(8n)

the low 8 bits of a word, as bits, and the byte with these bits

def lc.of8 source · line 145 · raw

@s:Word(8n) -> U32

def lc.be.bits source · line 149 · raw

@a:U32 -> @b:U32 -> @c:U32 -> @d:U32 -> U32

the word with bytes a (most significant), b, c, d, by bits

def lc.b0.bits source · line 153 · raw

@w:U32 -> U32

the bytes of w, by bits: b0 the most significant

def lc.b1.bits source · line 158 · raw

@w:U32 -> U32

def lc.b2.bits source · line 163 · raw

@w:U32 -> U32

def lc.b3.bits source · line 168 · raw

@w:U32 -> U32

def lc.bswap.bits source · line 174 · raw

@+w:U32 -> U32

the word with its bytes in reverse order (big-endian to little-endian)

def lc.msb.go source · line 178 · raw

@n:Nat -> @w:Word(n) -> @acc:List<&2, Bool> -> List<&2, Bool>

the bits of a word, most significant first, in front of acc

def lc.msb source · line 187 · raw

@x:U32 -> @acc:List<&2, Bool> -> List<&2, Bool>

def lc.rev_bits source · line 193 · raw

@bs:List<&2, Bool> -> @acc:List<&2, Bool> -> List<&2, Bool>

bs reversed, in front of acc

def lc.drop_bits source · line 201 · raw

@n:Nat -> @bs:List<&2, Bool> -> List<&2, Bool>

all but the first n of bs

def lc.word_lsb source · line 214 · raw

@n:Nat -> @bs:List<&2, Bool> -> Word(n)

the n-bit word whose bits, least significant first, are the first n of bs (False past the end)

def lc.nth source · line 226 · raw

@bs:List<&2, Bool> -> @i:Nat -> Bool

the element i of bs (False past the end)

def lc.tab.leaves source · line 245 · raw

@xs:List<&2, U32> -> List<&2, LcTab>

def lc.tab.pairs source · line 252 · raw

@ts:List<&2, LcTab> -> List<&2, LcTab>

def lc.tab.up source · line 259 · raw

@n:Nat -> @ts:List<&2, LcTab> -> List<&2, LcTab>

def lc.tab.root source · line 266 · raw

@ts:List<&2, LcTab> -> LcTab

def lc.tab source · line 274 · raw

@d:Nat -> @xs:List<&2, U32> -> LcTab

the table of the 2^d words xs (entry i is element i)

def lc.tab.pick source · line 277 · raw

@one:Bool -> @l:LcTab -> @r:LcTab -> LcTab

def lc.tab.get source · line 285 · raw

@d:Nat -> @t:LcTab -> @+i:U32 -> U32

entry i of a table of depth d (i below 2^d)

def lc.tab.path source · line 301 · raw

@d:Nat -> @+i:U32 -> List<&2, Bool>

the bits of i (below 2^d) that pick its entry, most significant first

def lc.tab.set.go source · line 308 · raw

@t:LcTab -> @path:List<&2, Bool> -> @v:U32 -> LcTab

def lc.tab.set source · line 324 · raw

@d:Nat -> @t:LcTab -> @+i:U32 -> @v:U32 -> LcTab

entry i of a table of depth d set to v (i below 2^d)

def lc.swap source · line 357 · raw

@b:LcBlock64 -> LcBlock64

the two halves exchanged

def lc.block_bytes source · line 365 · raw

@b:LcBlock64 -> @rest:List<&2, U32> -> List<&2, U32>

the 8 bytes of a block in front of rest

def lc.block8 source · line 370 · raw

@a0:U32 -> @a1:U32 -> @a2:U32 -> @a3:U32 -> @a4:U32 -> @a5:U32 -> @a6:U32 -> @a7:U32 -> LcBlock64

def LcBlock64.to_octets source · line 373 · raw

@b:LcBlock64 -> 0xe0217e1ab38629fddf738452c1f2a82e/bytes.Octets

def lc.block_of source · line 376 · raw

@xs:List<&2, U32> -> Maybe<&2, LcBlock64>

def LcBlock64.of_octets source · line 384 · raw

@o:0xe0217e1ab38629fddf738452c1f2a82e/bytes.Octets -> Maybe<&2, LcBlock64>

an 8-byte string as a block (big-endian words); None for any other length

def LcBlock64.hex source · line 387 · raw

@b:LcBlock64 -> String

Templates

template lc.fe.step source · line 332 · raw

@-RK:Data -> @-f:(@_:RK -> @_:U32 -> U32) -> @k:RK -> @b:LcBlock64 -> LcBlock64

template lc.fe.unstep source · line 337 · raw

@-RK:Data -> @-f:(@_:RK -> @_:U32 -> U32) -> @k:RK -> @b:LcBlock64 -> LcBlock64

template lc.fe.run source · line 342 · raw

@-RK:Data -> @-f:(@_:RK -> @_:U32 -> U32) -> @ks:List<&2, RK> -> @b:LcBlock64 -> LcBlock64

template lc.fe.unrun source · line 349 · raw

@-RK:Data -> @-f:(@_:RK -> @_:U32 -> U32) -> @ks:List<&2, RK> -> @b:LcBlock64 -> LcBlock64