UNPKG

@li0ard/kuznyechik

Version:

Kuznyechik cipher implementation in pure TypeScript

92 lines (91 loc) 3.05 kB
import { type TArg, type TRet } from "@li0ard/gost3413"; /** Kuznyechik core class */ export declare class Kuznyechik { private roundKeys; /** * Kuznyechik core class * @param key Encryption key */ constructor(key: TArg<Uint8Array>); /** * Returns round keys */ getRoundKeys(): Uint8Array[]; /** * `S`-transformation. * * The `S` function is a regular substitution function. * Each byte of the input sequence is replaced by the corresponding byte from * the `PI` substitution table. */ private transformS; /** * `Srev`-transformation * * The `Srev` function is a regular substitution function. * Each byte of the input sequence is replaced by the corresponding byte from * the `PI_REV` substitution table. */ private transformS_rev; /** * Performs Galois Field (GF(2)) multiplication. * * This method multiplies two bytes in the Galois Field using bitwise operations, * applying the irreducible polynomial x^8 + x^7 + x^6 + x + 1 for modular reduction. */ private gfMultiply; /** * `R`-transformation * * Performs a linear transformation on the input block by cyclically shifting bytes * and applying Galois Field multiplication with a predefined linear transformation matrix (`L`). */ private transformR; /** * `Rrev`-transformation * * Performs a linear transformation on the input block by applying Galois Field multiplication * with a predefined linear transformation matrix (`L`) and cyclically shifting bytes. */ private transformR_rev; /** * `L`-transformation * * Performs a linear transformation on the input block by repeatedly applying the `R`-transformation * a fixed number of times (equal to the block size). */ private transformL; /** * `Lrev`-transformation * * Performs a linear transformation on the input block by repeatedly applying the `Rrev`-transformation * a fixed number of times (equal to the block size). */ private transformL_rev; /** * `F`-transformation aka `XSLX`-algorithm * * Performs a key transformation using a series of linear and substitution transformations. */ private transformF; /** * Encrypts single block of data using Kuznyechik encryption algorithm. * @param block Block to be encrypted */ encryptBlock(block: TArg<Uint8Array>): TRet<Uint8Array>; /** * Decrypts single block of data using Kuznyechik encryption algorithm. * @param block Block to be decrypted */ decryptBlock(block: TArg<Uint8Array>): TRet<Uint8Array>; } export * from "./const.js"; export * from "./modes/acpkm.js"; export * from "./modes/cbc.js"; export * from "./modes/cfb.js"; export * from "./modes/ctr.js"; export * from "./modes/ecb.js"; export * from "./modes/mac.js"; export * from "./modes/mgm.js"; export * from "./modes/ofb.js"; export * from "./modes/kexp.js";