Пример #1
0
void cbc512Encrypt(ThreefishKey_t* key,
                   const uint64_t* iv,
                   uint64_t* plain_text,
                   const uint64_t num_blocks)
{
    //xor the initialization vector with the first block of input
    plain_text[0] ^= iv[0]; plain_text[1] ^= iv[1];
    plain_text[2] ^= iv[2]; plain_text[3] ^= iv[3];
    plain_text[4] ^= iv[4]; plain_text[5] ^= iv[5];
    plain_text[6] ^= iv[6]; plain_text[7] ^= iv[7];

    //run each block through the cipher chaining on the previous block
    for(uint64_t block=0; block<(num_blocks*SECURE_SLICE); block+=SECURE_SLICE)
    {
        //feedback the previous block into the next block by xoring them together
        if(block > 0)
        {
            const uint64_t offset = block-SECURE_SLICE;
            plain_text[block] ^= plain_text[offset];
            plain_text[block+1] ^= plain_text[offset+1];
            plain_text[block+2] ^= plain_text[offset+2];
            plain_text[block+3] ^= plain_text[offset+3];
            plain_text[block+4] ^= plain_text[offset+4];
            plain_text[block+5] ^= plain_text[offset+5];
            plain_text[block+6] ^= plain_text[offset+6];
            plain_text[block+7] ^= plain_text[offset+7];
        }
        //run the current block through the cipher
        threefishEncryptBlockWords(key, &plain_text[block], &plain_text[block]);
    }
}
Пример #2
0
void threefishEncryptBlockBytes(ThreefishKey_t* keyCtx, uint8_t* in,
                                uint8_t* out)
{
    u64b_t plain[SKEIN_MAX_STATE_WORDS];        /* max number of words*/
    u64b_t cipher[SKEIN_MAX_STATE_WORDS];
    
    Skein_Get64_LSB_First(plain, in, keyCtx->stateSize / 64);   /* bytes to words */
    threefishEncryptBlockWords(keyCtx, plain, cipher);
    Skein_Put64_LSB_First(out, cipher, keyCtx->stateSize / 8);  /* words to bytes */
}