@li0ard/kuznyechik
Version:
Kuznyechik cipher implementation in pure TypeScript
29 lines (28 loc) • 933 B
JavaScript
import { BLOCK_SIZE, Kuznyechik } from "../";
import { cfb_encrypt, cfb_decrypt } from "@li0ard/gost3413";
/**
* Encrypts data using Cipher Feedback (CFB) mode with Kuznyechik cipher
*
* @param key Encryption key
* @param data Data to be encrypted
* @param iv Initialization vector
* @returns {Uint8Array}
*/
export const encryptCFB = (key, data, iv) => {
const cipher = new Kuznyechik(key);
const encrypter = (buf) => cipher.encryptBlock(buf);
return cfb_encrypt(encrypter, BLOCK_SIZE, data, iv);
};
/**
* Decrypts data using Cipher Feedback (CFB) mode with Kuznyechik cipher
*
* @param key Encryption key
* @param data Data to be decrypted
* @param iv Initialization vector
* @returns {Uint8Array}
*/
export const decryptCFB = (key, data, iv) => {
const cipher = new Kuznyechik(key);
const decrypter = (buf) => cipher.encryptBlock(buf);
return cfb_decrypt(decrypter, BLOCK_SIZE, data, iv);
};