3 Header file for the reference implementation of the Kalyna block cipher (DSTU 7624:2014), all block and key length variants
5 Authors: Ruslan Kiianchuk, Ruslan Mordvinov, Roman Oliynykov
17 typedef unsigned char uint8_t;
18 typedef unsigned long long uint64_t;
21 * Context to store Kalyna cipher parameters.
24 size_t nb; /**< Number of 64-bit words in enciphering block. */
25 size_t nk; /**< Number of 64-bit words in key. */
26 size_t nr; /**< Number of enciphering rounds. */
27 uint64_t* state; /**< Current cipher state. */
28 uint64_t** round_keys; /**< Round key computed from enciphering key. */
33 * Initialize Kalyna parameters and create cipher context.
35 * @param block_size Enciphering block bit size (128, 256 or 512 bit sizes are
37 * @param block_size Enciphering key bit size. Must be equal or double the
39 * @return Pointer to Kalyna context containing cipher instance
40 * parameters and allocated memory for state and round keys. NULL in case of
43 kalyna_t* KalynaInit(size_t block_size, size_t key_size);
46 * Delete Kalyna cipher context and free used memory.
48 * @param ctx Kalyna cipher context.
49 * @return Zero in case of success.
51 int KalynaDelete(kalyna_t* ctx);
54 * Compute round keys given the enciphering key and store them in cipher
57 * @param key Kalyna enciphering key.
58 * @param ctx Initialized cipher context.
60 void KalynaKeyExpand(uint64_t* key, kalyna_t* ctx);
63 * Encipher plaintext using Kalyna symmetric block cipher.
64 * KalynaInit() function with appropriate block and enciphering key sizes must
65 * be called beforehand to get the cipher context `ctx`. After all enciphering
66 * is completed KalynaDelete() must be called to free up allocated memory.
68 * @param plaintext Plaintext of length Nb words for enciphering.
69 * @param ctx Initialized cipher context with precomputed round keys.
70 * @param ciphertext The result of enciphering.
72 void KalynaEncipher(uint64_t* plaintext, kalyna_t* ctx, uint64_t* ciphertext);
75 * Decipher ciphertext using Kalyna symmetric block cipher.
76 * KalynaInit() function with appropriate block and enciphering key sizes must
77 * be called beforehand to get the cipher context `ctx`. After all enciphering
78 * is completed KalynaDelete() must be called to free up allocated memory.
80 * @param ciphertext Enciphered data of length Nb words.
81 * @param ctx Initialized cipher context with precomputed round keys.
82 * @param plaintext The result of deciphering.
84 void KalynaDecipher(uint64_t* ciphertext, kalyna_t* ctx, uint64_t* plaintext);