UNPKG

@li0ard/kuznyechik

Version:

Kuznyechik cipher implementation in pure TypeScript

31 lines (30 loc) 1.22 kB
import { BLOCK_SIZE, Kuznyechik } from "../"; import { kexp15 as kexp15_, kimp15 as kimp15_ } from "@li0ard/gost3413"; /** * KExp15 key exporting * @param key Key to export * @param keyEnc Key for key encryption * @param keyMac Key for key authentication * @param iv Initialization vector (Half of block size) */ export const kexp15 = (key, keyEnc, keyMac, iv) => { const keyCipher = new Kuznyechik(keyEnc); const keyEncrypter = (block) => keyCipher.encryptBlock(block); const macCipher = new Kuznyechik(keyMac); const macEncrypter = (block) => macCipher.encryptBlock(block); return kexp15_(keyEncrypter, macEncrypter, BLOCK_SIZE, key, iv); }; /** * KImp15 key importing * @param kexp Key to import * @param keyEnc Key for key decryption * @param keyMac Key for key authentication * @param iv Initialization vector (Half of block size) */ export const kimp15 = (kexp, keyEnc, keyMac, iv) => { const keyCipher = new Kuznyechik(keyEnc); const keyEncrypter = (block) => keyCipher.encryptBlock(block); const macCipher = new Kuznyechik(keyMac); const macEncrypter = (block) => macCipher.encryptBlock(block); return kimp15_(keyEncrypter, macEncrypter, BLOCK_SIZE, kexp, iv); };