@li0ard/kuznyechik
Version:
Kuznyechik cipher implementation in pure TypeScript
101 lines (100 loc) • 3.63 kB
TypeScript
/** Kuznyechik core class */
export declare class Kuznyechik {
private roundKeys;
/**
* Kuznyechik core class
* @param key Encryption key
*/
constructor(key: Uint8Array);
/**
* Returns round keys
*/
getRoundKeys(): Uint8Array[];
/**
* `X`-transformation.
*
* The input of the `X` function is two sequences, and the output of the function is the XOR of these two sequences.
*/
transformX(a: Uint8Array, b: Uint8Array): 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.
*/
transformS(input: Uint8Array): Uint8Array;
/**
* `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.
*/
transformS_rev(input: Uint8Array): Uint8Array;
/**
* 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.
*/
gfMultiply(a: number, b: number): number;
/**
* `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`).
*/
transformR(input: Uint8Array): Uint8Array;
/**
* `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.
*/
transformR_rev(input: Uint8Array): Uint8Array;
/**
* `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).
*/
transformL(input: Uint8Array): Uint8Array;
/**
* `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).
*/
transformL_rev(input: Uint8Array): Uint8Array;
/**
* `F`-transformation aka `XSLX`-algorithm
*
* Performs a key transformation using a series of linear and substitution transformations.
*/
transformF(in_key1: Uint8Array, in_key2: Uint8Array, iter_constant: Uint8Array): Uint8Array[];
/**
* Encrypts single block of data using Kuznyechik encryption algorithm.
* @param block Block to be encrypted
* @returns {Uint8Array} Encrypted block
* @throws {CipherError} Block size is invalid or data is too short
*/
encryptBlock(block: Uint8Array): Uint8Array;
/**
* Decrypts single block of data using Kuznyechik encryption algorithm.
* @param block Block to be decrypted
* @returns {Uint8Array} Decrypted block
* @throws {CipherError} Block size is invalid or data is too short
*/
decryptBlock(block: Uint8Array): Uint8Array;
}
export * from "./const";
export * from "./modes/acpkm";
export * from "./modes/cbc";
export * from "./modes/cfb";
export * from "./modes/ctr";
export * from "./modes/ecb";
export * from "./modes/mac";
export * from "./modes/mgm";
export * from "./modes/ofb";
export * from "./modes/kexp";