Пример #1
0
int Keccak_DuplexingOverwritePartialInput(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_StateOverwriteLanes(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_StateOverwriteBytesInLane(instance->state, instance->byteInputIndex/KeccakF_laneInBytes, in, offsetInLane, bytesInLane);
        in += bytesInLane;
        instance->byteInputIndex += bytesInLane;
        inByteLen -= bytesInLane;
    }
    return 0;
}
Пример #2
0
void Ket_StateOverwrite( void *state, unsigned int offset, const unsigned char *data, unsigned int length )
{
	unsigned int lanePosition;
	unsigned int laneOffset;
	unsigned int sizeInLane;

	lanePosition = offset / KeccakF_laneInBytes; 
	laneOffset = offset % KeccakF_laneInBytes; 
	while ( length != 0 ) {
		sizeInLane = Ket_Minimum( KeccakF_laneInBytes - laneOffset, length );
		KeccakF_StateOverwriteBytesInLane(state, lanePosition, data, laneOffset, sizeInLane);
		data += sizeInLane;
		length -= sizeInLane;
		++lanePosition; 
		laneOffset = 0; 
	}
}