~/bend-docscommunity

xtea.bend checks

raw source on the hub · import bend-osdev-legacy-ciphers@0.1.0.0/xtea.bend as Xtea

XTEA (R. Needham, D. Wheeler, "Tea extensions", 1997, the routine "tean"): TEA with a different key schedule, a 64-bit block cipher with a 128-bit key. Each cycle is y += (((z << 4) xor (z >> 5)) + z) xor (sum + k[sum & 3]) sum += delta z += (((y << 4) xor (y >> 5)) + y) xor (sum + k[(sum >> 11) & 3]) The key schedule computes each step's sum + k[..] once, as a step of tea.bend's (LcXteaY, LcXteaZ); decryption undoes the steps last to first, the paper's decoding, so decrypt(encrypt(b)) == b is provable for every key and block, as for TEA.

The byte order of the words is a parameter, as for TEA: little-endian (the Linux kernel's "xtea") is LcXtea.key, big-endian LcXtea.key_be, and LcXtea.key_with takes the order and the number of cycles (32 recommended).

4 imports
import Base
import bend-osdev-bytes@0.1.0.0/bytes.bend as B
import ./legacy_ciphers.bend as L
import ./tea.bend as T

Types

type LcXteaKey source · line 34 · raw

Data

An XTEA key: the steps of the cipher (opaque; built by LcXtea.key)

Definitions

def xtea.kw source · line 21 · raw

@+i:U32 -> @+k0:U32 -> @+k1:U32 -> @+k2:U32 -> @+k3:U32 -> U32

key word i & 3 of k0 .. k3

def xtea.cycles source · line 25 · raw

@n:Nat -> @+s:U32 -> @+k0:U32 -> @+k1:U32 -> @+k2:U32 -> @+k3:U32 -> List<&2, 0x7d16ec09f99b830428c8e2852af315f6/tea.LcTeaOp>

XTEA's steps for n more cycles from sum s

def xtea.key.pick source · line 37 · raw

@ok:Bool -> @+le:Bool -> @n:Nat -> @+xs:List<&2, U32> -> Result<&2, &2, 0x7d16ec09f99b830428c8e2852af315f6/legacy_ciphers.LcError, LcXteaKey>

def LcXtea.key_with source · line 48 · raw

@le:Bool -> @n:Nat -> @o:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> Result<&2, &2, 0x7d16ec09f99b830428c8e2852af315f6/legacy_ciphers.LcError, LcXteaKey>

a 16-byte key, words in the order le picks (True: little-endian), and n cycles (32 recommended)

def LcXtea.key source · line 54 · raw

@o:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> Result<&2, &2, 0x7d16ec09f99b830428c8e2852af315f6/legacy_ciphers.LcError, LcXteaKey>

the named default: little-endian words (the Linux kernel's "xtea"), 32 cycles

def LcXtea.key_be source · line 58 · raw

@o:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> Result<&2, &2, 0x7d16ec09f99b830428c8e2852af315f6/legacy_ciphers.LcError, LcXteaKey>

big-endian words, 32 cycles

def LcXtea.encrypt source · line 61 · raw

@k:LcXteaKey -> @b:0x7d16ec09f99b830428c8e2852af315f6/legacy_ciphers.LcBlock64 -> 0x7d16ec09f99b830428c8e2852af315f6/legacy_ciphers.LcBlock64

def LcXtea.decrypt source · line 66 · raw

@k:LcXteaKey -> @b:0x7d16ec09f99b830428c8e2852af315f6/legacy_ciphers.LcBlock64 -> 0x7d16ec09f99b830428c8e2852af315f6/legacy_ciphers.LcBlock64