How to use Chacha as key scheduling algorithm for any other algorithm #364
-
|
Hi, I want to use Chacha as key scheduling algorithm for any other algorithm, It will be very helpful if you provide and example for integrating Chacha as key scheduling algorithm for any of the existing CLAASP's implemented algorithms. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Hi @Moh-Gebril, With CLAASP you cannot directly create a cipher object that mixes the key schedule of one cipher with the round function of another. To do this, you’d need to either:
Using Chacha as a round-key generatorIf you want to use the Chacha permutation to derive round keys, here’s how:
Step 1. Run Chacha to generate round outputsExample with a toy Chacha using 8-bit words (instead of the usual 32-bit): from claasp.ciphers.permutations.chacha_permutation import ChachaPermutation
N_ROUNDS = 4
secret_key = 0x01_02_03_04_05_06_07_08_0a_0b_0c_0d_0e_0f # 16-byte key
chacha = ChachaPermutation(
number_of_rounds=N_ROUNDS,
rotations=[2, 1, 4, 3],
word_size=8
)
# Evaluate and collect intermediate outputs
chacha_outputs = chacha.evaluate([secret_key], intermediate_output=True)
From (2), you can extract all round outputs: round_keys = chacha_outputs[1]['round_output'] + chacha_outputs[1]['cipher_output']Step 2. Create Speck without a key schedulefrom claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher
speck = SpeckBlockCipher(
block_bit_size=32,
key_bit_size=64,
number_of_rounds=N_ROUNDS
).remove_key_schedule()Check inputs: speck.inputs_size_to_dict()
# {'plaintext': 32, 'key_0_2': 16, 'key_1_2': 16, 'key_2_2': 16, 'key_3_2': 16}Notice: instead of a single master key, Speck now expects 4 round keys of 16 bits each. Step 3. Truncate Chacha outputs to 16 bitsSince Chacha produces 32-bit values, reduce them to 16 bits: shortened_round_keys = [x & 0xFFFF for x in round_keys]Step 4. Evaluate Speck with custom round keysplaintext = 0x74614620
speck.evaluate([plaintext] + shortened_round_keys)This way, you effectively use Chacha to generate round keys and Speck to process them, without having to implement a new cipher class manually. |
Beta Was this translation helpful? Give feedback.
-
|
Thank you @p-huynh, I am really appreciated. |
Beta Was this translation helpful? Give feedback.
Hi @Moh-Gebril,
With CLAASP you cannot directly create a cipher object that mixes the key schedule of one cipher with the round function of another. To do this, you’d need to either:
Using Chacha as a round-key generator
If you want to use the Chacha permutation to derive round keys, here’s how: