コード例 #1
0
int Keccak_DuplexingFeedPartialInput(Keccak_DuplexInstance *instance, const unsigned char *in, unsigned int inByteLen)
{
    const unsigned int rho_max = instance->rate - 2;

    if ((instance->byteInputIndex+inByteLen)*8 > rho_max)
        return 1;

    if ((instance->byteInputIndex == 0) && (inByteLen >= KeccakF_laneInBytes)) {
        KeccakF_StateXORLanes(instance->state, in, inByteLen/KeccakF_laneInBytes);
        in += (inByteLen/KeccakF_laneInBytes)*KeccakF_laneInBytes;
        instance->byteInputIndex += (inByteLen/KeccakF_laneInBytes)*KeccakF_laneInBytes;
        inByteLen -= (inByteLen/KeccakF_laneInBytes)*KeccakF_laneInBytes;
    }
    while(inByteLen > 0) {
        unsigned int offsetInLane = instance->byteInputIndex % KeccakF_laneInBytes;
        unsigned int bytesInLane = KeccakF_laneInBytes - offsetInLane;
        if (bytesInLane > inByteLen)
            bytesInLane = inByteLen;
        KeccakF_StateXORBytesInLane(instance->state, instance->byteInputIndex/KeccakF_laneInBytes, in, offsetInLane, bytesInLane);
        in += bytesInLane;
        instance->byteInputIndex += bytesInLane;
        inByteLen -= bytesInLane;
    }
    return 0;
}
コード例 #2
0
ファイル: Ket.c プロジェクト: 0x64616E69656C/supercop
void Ket_WrapBlocks( void *state, const unsigned char *plaintext, unsigned char *ciphertext, unsigned int nBlocks )
{
	unsigned char keystream[Ketje_BlockSize];
	unsigned char plaintemp[Ketje_BlockSize];
    unsigned char frameAndPaddingBits[1];
    frameAndPaddingBits[0] = 0x08 | FRAMEBITS11;

	while ( nBlocks-- != 0 ) 
	{
		KeccakF_StateExtractLanes(state, keystream, Ketje_BlockSize / KeccakF_laneInBytes);
		plaintemp[0] = plaintext[0];
		plaintemp[1] = plaintext[1];
		#if (KeccakF_width == 400 )
		plaintemp[2] = plaintext[2];
		plaintemp[3] = plaintext[3];
		#endif
		*(ciphertext++) = *(plaintext++) ^ keystream[0];
		*(ciphertext++) = *(plaintext++) ^ keystream[1];
		#if (KeccakF_width == 400 )
		*(ciphertext++) = *(plaintext++) ^ keystream[2];
		*(ciphertext++) = *(plaintext++) ^ keystream[3];
		#endif
		KeccakF_StateXORLanes(state, plaintemp, Ketje_BlockSize / KeccakF_laneInBytes);
		KeccakF_StateXORBytesInLane(state, Ketje_BlockSize / KeccakF_laneInBytes, frameAndPaddingBits, 0, 1);
		KeccakP_StatePermute(state, Ket_StepRounds);
	}
}
コード例 #3
0
ファイル: Ket.c プロジェクト: 0x64616E69656C/supercop
void Ket_UnwrapBlocks( void *state, const unsigned char *ciphertext, unsigned char *plaintext, unsigned int nBlocks )
{
	unsigned char tempBlock[Ketje_BlockSize];
    unsigned char frameAndPaddingBits[1];
    frameAndPaddingBits[0] = 0x08 | FRAMEBITS11;
	
	while ( nBlocks-- != 0 ) 
	{
		KeccakF_StateExtractLanes(state, tempBlock, Ketje_BlockSize / KeccakF_laneInBytes);
		tempBlock[0] = *(plaintext++) = *(ciphertext++) ^ tempBlock[0];
		tempBlock[1] = *(plaintext++) = *(ciphertext++) ^ tempBlock[1];
		#if (KeccakF_width == 400 )
		tempBlock[2] = *(plaintext++) = *(ciphertext++) ^ tempBlock[2];
		tempBlock[3] = *(plaintext++) = *(ciphertext++) ^ tempBlock[3];
		#endif
		KeccakF_StateXORLanes(state, tempBlock, Ketje_BlockSize / KeccakF_laneInBytes);
		KeccakF_StateXORBytesInLane(state, Ketje_BlockSize / KeccakF_laneInBytes, frameAndPaddingBits, 0, 1);
		KeccakP_StatePermute(state, Ket_StepRounds);
	}
}