def aes_add_key.go

qasim-bend-kit@0.1.0.2 · libs/AES256GCMCore.bend:123

import qasim-bend-kit@0.1.0.2/libs/AES256GCMCore.bend as AES256GCMCore
import Base

123def aes_add_key.go(+state: List<&2, U32>, +words: List<&2, U32>,
124                   +round: Nat, +index: Nat, fuel: Nat,
125                   acc: List<&2, U32>) -> List<&2, U32>:
126    match state fuel:
127        case Nil{} _: List.reverse(&2, U32, acc)
128        case byte <> tail 0n: List.reverse(&2, U32, acc)
129        case +byte <> tail 1n+p:
130            word_index = ((round * 4n + (index / 4n : Nat)) : Nat)
131            word = aes_word_at(words, word_index)
132            shift = ((3n - (index % 4n : Nat)) * 8n : Nat)
133            keybyte = U32.and(255, U32.shrn(word, shift))
134            aes_add_key.go(tail, words, round, (index + 1n : Nat), p,
135                U32.xor(byte, keybyte) <> acc)

Uses (13)

Used by (1)