UNPKG

@hackbg/miscreant-esm

Version:

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

42 lines (41 loc) 1.51 kB
import { IBlockCipher } from "../../interfaces.dist"; import Block from "../../internals/block.dist"; /** * WebCrypto-based implementation of the AES block cipher. * * This implementation (ab)uses AES-CBC mode to implement AES-ECB. This is * likely to be rather slow, as it requires an async call per block, and * discards half the buffer. * * In theory it should be constant time due to the use of WebCrypto (provided * the browser's implementation is constant time), but it could probably benefit * from some clever optimization work, or improvements to the WebCrypto API. * * Key size: 16 or 32 bytes, block size: 16 bytes. */ export default class WebCryptoAes implements IBlockCipher { private _crypto; private _key; /** * Create a new WebCryptoAes instance * * @param {Crypto} crypto - the Web Cryptography provider * @param {Uint8Array} keyData - the AES secret key * @returns {Promise<WebCryptoAes} */ static importKey(crypto: Crypto, keyData: Uint8Array): Promise<WebCryptoAes>; private _iv; private _emptyPromise; constructor(_crypto: Crypto, _key: CryptoKey); /** * Cleans expanded keys from memory, setting them to zeros. */ clear(): this; /** * Encrypt a single AES block. While ordinarily this might let us see penguins, we're using it safely * * @param {Block} block - block to be encrypted in-place * @returns {Promise<this>} */ encryptBlock(block: Block): Promise<this>; }