1 # Generated by tools/generators/blake2b_gen.py; do not edit by hand. 2 import Base 3 import ./types.bend as T 4 5 # 64-bit addition modulo 2^64: the low halves add, their carry-out enters the high half. 6 def add(a: T.Lane, b: T.Lane) -> T.Lane: 7 match a b: 8 case T.W{+al,ah} T.W{bl,bh}: 9 +lo = U32.add(al,bl) 10 T.W{lo,U32.add(U32.add(ah,bh),Bool.to_u32(U32.is_lt(lo,al)))} 11 12 def xor(a: T.Lane, b: T.Lane) -> T.Lane: 13 match a b: 14 case T.W{al,ah} T.W{bl,bh}: T.W{U32.xor(al,bl),U32.xor(ah,bh)} 15 16 # The four fixed right rotations of BLAKE2b. 17 def rot32(a: T.Lane) -> T.Lane: 18 match a: 19 case T.W{lo,hi}: T.W{hi,lo} 20 21 def rot24(a: T.Lane) -> T.Lane: 22 match a: 23 case T.W{+lo,+hi}: 24 T.W{U32.or(U32.shrn(lo,24n),U32.shln(hi,8n)),U32.or(U32.shrn(hi,24n),U32.shln(lo,8n))} 25 26 def rot16(a: T.Lane) -> T.Lane: 27 match a: 28 case T.W{+lo,+hi}: 29 T.W{U32.or(U32.shrn(lo,16n),U32.shln(hi,16n)),U32.or(U32.shrn(hi,16n),U32.shln(lo,16n))} 30 31 def rot63(a: T.Lane) -> T.Lane: 32 match a: 33 case T.W{+lo,+hi}: 34 T.W{U32.or(U32.shrn(hi,31n),U32.shln(lo,1n)),U32.or(U32.shrn(lo,31n),U32.shln(hi,1n))}