@hackbg/miscreant-esm
Version:
(ESM port) Misuse resistant symmetric encryption library providing AES-SIV (RFC 5297), AES-PMAC-SIV, and STREAM constructions
32 lines (31 loc) • 670 B
JavaScript
import {select} from "./constant-time.dist.mjs";
import {wipe} from "./wipe.dist.mjs";
export default class Block {
static SIZE = 16;
static R = 0x87;
data;
constructor() {
this.data = new Uint8Array(Block.SIZE);
}
clear() {
wipe(this.data);
}
clone() {
const ret = new Block();
ret.copy(this);
return ret;
}
copy(other) {
this.data.set(other.data);
}
dbl() {
let carry = 0;
for (let i = Block.SIZE - 1; i >= 0; i--) {
const b = this.data[i] >>> 7 & 0xff;
this.data[i] = this.data[i] << 1 | carry;
carry = b;
}
this.data[Block.SIZE - 1] ^= select(carry, Block.R, 0);
carry = 0;
}
}