UNPKG

@hackbg/miscreant-esm

Version:

(ESM port) Misuse resistant symmetric encryption library providing AES-SIV (RFC 5297), AES-PMAC-SIV, and STREAM constructions

36 lines (35 loc) 795 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const constant_time_1 = require("./constant-time.dist.cjs"); const wipe_1 = require("./wipe.dist.cjs"); class Block { constructor() { this.data = new Uint8Array(Block.SIZE); } clear() { (0, wipe_1.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] ^= (0, constant_time_1.select)(carry, Block.R, 0); carry = 0; } } Block.SIZE = 16; Block.R = 0x87; exports.default = Block;