void KeccakP800_OverwriteBytes(void *argState, const unsigned char *data, unsigned int offset, unsigned int length)
{
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
#ifdef KeccakP800_useLaneComplementing
    unsigned int sizeLeft = length;
    unsigned int lanePosition = offset/4;
    unsigned int offsetInLane = offset%4;
    const unsigned char *curData = data;
    UINT32 *state = (UINT32*)argState;

    if ((sizeLeft > 0) && (offsetInLane != 0)) {
        unsigned int bytesInLane = 4 - offsetInLane;
        unsigned char laneComplement = (unsigned char)KeccakP800LaneComplement[lanePosition];
        if (bytesInLane > sizeLeft)
            bytesInLane = sizeLeft;
        sizeLeft -= bytesInLane;
        do {
            *(((unsigned char *)&state[lanePosition] + offsetInLane)) = *curData++ ^ laneComplement;
            ++offsetInLane;
        }
        while ( --bytesInLane != 0);
        lanePosition++;
    }

    while(sizeLeft >= 4) {
        state[lanePosition] = READ32_UNALIGNED( curData ) ^ KeccakP800LaneComplement[lanePosition];
        sizeLeft -= 4;
        lanePosition++;
        curData += 4;
    }

    if (sizeLeft > 0) {
        unsigned char laneComplement = (unsigned char)KeccakP800LaneComplement[lanePosition];
        unsigned int i;
        for ( i = 0; i < sizeLeft; ++i ) {
            *((unsigned char *)&state[lanePosition] + i) = *curData++ ^ laneComplement;
        }
    }
#else
    memcpy((unsigned char*)argState+offset, data, length);
#endif
#else
#error "Not yet implemented"
#endif
}
void KeccakF800_StateXORBytes(void *argState, const unsigned char *data, unsigned int offset, unsigned int length)
{
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
    unsigned int sizeLeft = length;
    unsigned int lanePosition = offset/KeccakF_laneInBytes;
    unsigned int offsetInLane = offset%KeccakF_laneInBytes;
    const unsigned char *curData = data;
    UINT32 *state = argState;

    if ((sizeLeft > 0) && (offsetInLane != 0)) {
        unsigned int bytesInLane = KeccakF_laneInBytes - offsetInLane;
        UINT32 lane = 0;
        if (bytesInLane > sizeLeft)
            bytesInLane = sizeLeft;
        memcpy((unsigned char*)&lane + offsetInLane, curData, bytesInLane);
        state[lanePosition] ^= lane;
        sizeLeft -= bytesInLane;
        lanePosition++;
        curData += bytesInLane;
    }

    while(sizeLeft >= KeccakF_laneInBytes) {
        state[lanePosition] ^= READ32_UNALIGNED( curData );
        sizeLeft -= KeccakF_laneInBytes;
        lanePosition++;
        curData += KeccakF_laneInBytes;
    }

    if (sizeLeft > 0) {
        UINT32 lane = 0;
        memcpy(&lane, curData, sizeLeft);
        state[lanePosition] ^= lane;
    }
#else
#error "Not yet implemented"
#endif
}
void Xoodoo_AddBytes(void *argState, const unsigned char *data, unsigned int offset, unsigned int length)
{
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
    unsigned int sizeLeft = length;
    unsigned int lanePosition = offset/4;
    unsigned int offsetInLane = offset%4;
    const unsigned char *curData = data;
    uint32_t *state = (uint32_t*)argState;

    state += lanePosition;
    if ((sizeLeft > 0) && (offsetInLane != 0)) {
        unsigned int bytesInLane = 4 - offsetInLane;
        uint32_t lane = 0;
        if (bytesInLane > sizeLeft)
            bytesInLane = sizeLeft;
        memcpy((unsigned char*)&lane + offsetInLane, curData, bytesInLane);
        *state++ ^= lane;
        sizeLeft -= bytesInLane;
        curData += bytesInLane;
    }

    while(sizeLeft >= 4) {
        *state++ ^= READ32_UNALIGNED( curData );
        sizeLeft -= 4;
        curData += 4;
    }

    if (sizeLeft > 0) {
        uint32_t lane = 0;
        memcpy(&lane, curData, sizeLeft);
        *state ^= lane;
    }
#else
    #error "Not yet implemented"
#endif
}
void KeccakF800_StateExtractAndXORBytes(const void *argState, unsigned char *data, unsigned int offset, unsigned int length)
{
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
#ifdef UseLaneComplementing
    unsigned int sizeLeft = length;
    unsigned int lanePosition = offset/KeccakF_laneInBytes;
    unsigned int offsetInLane = offset%KeccakF_laneInBytes;
    unsigned char *curData = data;
    const UINT32 *state = (UINT32*)argState;

    if ((sizeLeft > 0) && (offsetInLane != 0)) {
        unsigned int bytesInLane = KeccakF_laneInBytes - offsetInLane;
	    unsigned char laneComplement = (unsigned char)KeccakF800LaneComplement[lanePosition];
        if (bytesInLane > sizeLeft)
            bytesInLane = sizeLeft;
        sizeLeft -= bytesInLane;
		do {
	        *curData++ ^= *(((unsigned char *)&state[lanePosition]) + offsetInLane)  ^ laneComplement;
			++offsetInLane;
		}
		while ( --bytesInLane != 0);
        lanePosition++;
    }

    while(sizeLeft >= KeccakF_laneInBytes) {
        WRITE32_UNALIGNED( curData, READ32_UNALIGNED( curData ) ^ state[lanePosition] ^ KeccakF800LaneComplement[lanePosition] );
        sizeLeft -= KeccakF_laneInBytes;
        lanePosition++;
        curData += KeccakF_laneInBytes;
    }

    if (sizeLeft > 0) {
	    unsigned char laneComplement = (unsigned char)KeccakF800LaneComplement[lanePosition];
		unsigned int i;
		for ( i = 0; i < sizeLeft; ++i ) {
	        *curData++ ^= *(((unsigned char *)&state[lanePosition]) + i) ^ laneComplement;
		}
    }
#else
    unsigned int sizeLeft = length;
    unsigned int lanePosition = offset/KeccakF_laneInBytes;
    unsigned int offsetInLane = offset%KeccakF_laneInBytes;
    unsigned char *curData = data;
    const UINT32 *state = (UINT32*)argState;

    if ((sizeLeft > 0) && (offsetInLane != 0)) {
        unsigned int bytesInLane = KeccakF_laneInBytes - offsetInLane;
        if (bytesInLane > sizeLeft)
            bytesInLane = sizeLeft;
        sizeLeft -= bytesInLane;
		do {
	        *curData++ ^= *(((unsigned char *)&state[lanePosition]) + offsetInLane);
			++offsetInLane;
		}
		while ( --bytesInLane != 0);
        lanePosition++;
    }

    while(sizeLeft >= KeccakF_laneInBytes) {
        WRITE32_UNALIGNED( curData, READ32_UNALIGNED( curData ) ^ state[lanePosition] );
        sizeLeft -= KeccakF_laneInBytes;
        lanePosition++;
        curData += KeccakF_laneInBytes;
    }

    if (sizeLeft > 0) {
		unsigned int i;
		for ( i = 0; i < sizeLeft; ++i ) {
	        *curData++ ^= *(((unsigned char *)&state[lanePosition]) + i);
		}
    }
#endif
#else
#error "Not yet implemented"
#endif
}