| |
|
| assert(ctx && key); |
assert(ctx && key); |
| |
|
| ctx->nlfsr_offset = 0; |
|
| ctx->key_size = keysize; |
ctx->key_size = keysize; |
| ctx->full_rekeying = 1; |
|
| ctx->buffer_index = 0; |
|
| |
|
| /** |
/** |
| * Dragon supports the following combinations of key and IV sizes only: |
* Dragon supports the following combinations of key and IV sizes only: |
| assert(ctx && iv); |
assert(ctx && iv); |
| |
|
| /** |
/** |
| * This is either a continuation of key initialization, |
* Restore the state to the post-keysetup state. |
| * or a fresh IV rekeying. In the latter case, restore the |
|
| * state to the post-keysetup state. |
|
| */ |
*/ |
| if (ctx->full_rekeying == 0) { |
|
| for (idx = 0; idx < DRAGON_NLFSR_SIZE; idx++) { |
for (idx = 0; idx < DRAGON_NLFSR_SIZE; idx++) { |
| ctx->nlfsr_word[idx] = ctx->init_state[idx]; |
ctx->nlfsr_word[idx] = ctx->init_state[idx]; |
| } |
} |
| } |
|
| |
|
| /* For a keysize of 128 bits, the Dragon NLFSR is initialized |
/* For a keysize of 128 bits, the Dragon NLFSR is initialized |
| using K and IV as follows (where k' and iv' represent |
using K and IV as follows (where k' and iv' represent |
| } |
} |
| } |
} |
| |
|
| |
ctx->nlfsr_offset = 0; |
| |
|
| /** Iterate mixing process */ |
/** Iterate mixing process */ |
| for (idx = 0; idx < DRAGON_MIXING_STAGES; idx++) { |
for (idx = 0; idx < DRAGON_MIXING_STAGES; idx++) { |
| a = DRAGON_NLFSR_WORD(ctx, 0) ^ |
a = DRAGON_NLFSR_WORD(ctx, 0) ^ |
| } |
} |
| ctx->state_counter = ((u64)e << 32) | (u64)f; |
ctx->state_counter = ((u64)e << 32) | (u64)f; |
| |
|
| /* Assume that the next keying operation will be IV only */ |
/* reset buffer index */ |
| ctx->full_rekeying = 0 ; |
ctx->buffer_index = 0; |
| } |
} |
| |
|
| /** |
/** |
| DRAGON_BUFFER_SIZE); |
DRAGON_BUFFER_SIZE); |
| } |
} |
| *(keystream++) = ctx->keystream_buffer[ctx->buffer_index]; |
*(keystream++) = ctx->keystream_buffer[ctx->buffer_index]; |
| ctx->buffer_index = (ctx->buffer_index % DRAGON_BUFFER_SIZE); |
ctx->buffer_index = ((ctx->buffer_index + 1) % DRAGON_BUFFER_BYTES); |
| } |
} |
| } |
} |
| |
|