@li0ard/magma
Version:
Magma cipher implementation in pure TypeScript
27 lines (26 loc) • 950 B
JavaScript
import { BLOCK_SIZE, Magma, sboxes } from "../";
import { ofb } from "@li0ard/gost3413";
/**
* Encrypts data using the Output Feedback (OFB) mode with Magma cipher.
*
* @param key Encryption key
* @param data Data to be encrypted
* @param iv Initialization vector
* @param sbox Optional substitution box, defaults to `ID_TC26_GOST_28147_PARAM_Z`
* @returns {Uint8Array}
*/
export const encryptOFB = (key, data, iv, sbox = sboxes.ID_TC26_GOST_28147_PARAM_Z) => {
const cipher = new Magma(key, sbox);
const encrypter = (buf) => cipher.encryptBlock(buf);
return ofb(encrypter, BLOCK_SIZE, data, iv);
};
/**
* Decrypts data using the Output Feedback (OFB) mode with Magma cipher.
*
* @param key Encryption key
* @param data Data to be decrypted
* @param iv Initialization vector
* @param sbox Optional substitution box, defaults to `ID_TC26_GOST_28147_PARAM_Z`
* @returns {Uint8Array}
*/
export const decryptOFB = encryptOFB;