@li0ard/kuznyechik
Version:
Kuznyechik cipher implementation in pure TypeScript
29 lines (28 loc) • 955 B
JavaScript
import { BLOCK_SIZE, Kuznyechik } from "../";
import { cbc_encrypt, cbc_decrypt } from "@li0ard/gost3413";
/**
* Encrypts data using Cipher Block Chaining (CBC) mode with the Kuznyechik cipher.
*
* @param key Encryption key
* @param data Data to be encrypted
* @param iv Initialization vector
* @returns {Uint8Array}
*/
export const encryptCBC = (key, data, iv) => {
const cipher = new Kuznyechik(key);
const encrypter = (buf) => cipher.encryptBlock(buf);
return cbc_encrypt(encrypter, BLOCK_SIZE, data, iv);
};
/**
* Decrypts data using Cipher Block Chaining (CBC) mode with the Kuznyechik cipher.
*
* @param key Encryption key
* @param data Data to be decrypted
* @param iv Initialization vector
* @returns {Uint8Array}
*/
export const decryptCBC = (key, data, iv) => {
const cipher = new Kuznyechik(key);
const decrypter = (buf) => cipher.decryptBlock(buf);
return cbc_decrypt(decrypter, BLOCK_SIZE, data, iv);
};