Exemplo n.º 1
0
void KeccakPermutationAfterXor(unsigned char *state, const unsigned char *data, unsigned int dataLengthInBytes)
{
    unsigned int i;

    for(i=0; i<dataLengthInBytes; i++)
        state[i] ^= data[i];
    KeccakPermutation(state);
}
Exemplo n.º 2
0
static void KeccakAbsorb(u64 st[25], unsigned char * p, int rsiz)
{
  int i;
  rsiz = rsiz / 8;
  for (i = 0; i < rsiz; i += 1, p += 8) {
    // fixme: use direct access for little-endian platforms without
    // alignment constraints?
      unsigned int l = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
      unsigned int h = p[4] | (p[5] << 8) | (p[6] << 16) | (p[7] << 24);
      st[i] ^= l | ((unsigned long long) h << 32);
  }
  KeccakPermutation(st);
}
Exemplo n.º 3
0
static int Squeeze(spongeState *state, unsigned char *output, unsigned long long outputLength)
{
    unsigned long long i;
    unsigned int partialBlock;

    if (!state->squeezing)
        PadAndSwitchToSqueezingPhase(state);
    if ((outputLength % 8) != 0)
        return 1; // Only multiple of 8 bits are allowed, truncation can be done at user level

    i = 0;
    while(i < outputLength) {
        if (state->bitsAvailableForSqueezing == 0) {
            KeccakPermutation(state->state);
#ifdef ProvideFast1024
            if (state->rate == 1024) {
                KeccakExtract1024bits(state->state, state->dataQueue);
                state->bitsAvailableForSqueezing = 1024;
            }
            else
#endif
            {
                KeccakExtract(state->state, state->dataQueue, state->rate/64);
                state->bitsAvailableForSqueezing = state->rate;
            }
            #ifdef KeccakReference
            displayBytes(1, "Block available for squeezing", state->dataQueue, state->bitsAvailableForSqueezing/8);
            #endif
        }
        partialBlock = state->bitsAvailableForSqueezing;
        if ((unsigned long long)partialBlock > outputLength - i)
            partialBlock = (unsigned int)(outputLength - i);
        memcpy(output+i/8, state->dataQueue+(state->rate-state->bitsAvailableForSqueezing)/8, partialBlock/8);
        state->bitsAvailableForSqueezing -= partialBlock;
        i += partialBlock;
    }
    return 0;
}
Exemplo n.º 4
0
int main()
{
    UINT32 x = 0;
    int i;
	{
	    UINT32 state[50];
	    const UINT32 imageOfAllZero[50] = {
	        0xD33D89FB, 0xC4B60CAD, 0x2FAD58B0, 0x88AE581B, 0xF4262C1A, 
	        0x8A53D3EF, 0x77B4B09B, 0xE0147822, 0x10A38DCF, 0xB6305181, 
	        0xF723F2BE, 0xF9C67B78, 0x4EB02ABA, 0x8FCCC118, 0x2DC2E52E, 
	        0xA3B29275, 0x342F5536, 0xE4DD320A, 0x45C7C3EA, 0x493D8BE4, 
	        0x9C1717E7, 0xF3E75194, 0x12A23D11, 0xEDD52441, 0x13E6DBFF, 
	        0x8C61BB03, 0x945B1B82, 0x1E4A11A5, 0x1C3453E7, 0x0D730C1B, 
	        0x3B9C1D29, 0x0C534AF4, 0xA6EC29CC, 0x4FFDAA4D, 0x96C7DAA5, 
	        0x45487850, 0x4ECFBC29, 0xE630383B, 0x26806B48, 0xA7EB2B5A,
	        0x62D02426, 0x8265F750, 0x49D20B1A, 0x20E4D82C, 0x6F72B2B8, 
	        0x1C45D049, 0xFEA9F415, 0x4D0E74C7, 0x8DFDEA09, 0xFCF72ED2 };

		// Test 1 (all-zero state through Keccak-f[1600])
	    memset(state, 0, 50*sizeof(UINT32));
		KeccakPermutation((unsigned char*)state);
	    for(i=0; i<50; i++)
	        if (state[i] != imageOfAllZero[i])
	            for( ; ; ) {
					//	Kaccek (aka other algo)
	                x++;
	            }
		// For benchmarking
		{
			#ifdef ProvideFast1024
			KeccakAbsorb1024bits((unsigned char*)state, (unsigned char*)imageOfAllZero);
			#else
			KeccakAbsorb((unsigned char*)state, (unsigned char*)imageOfAllZero, 16);
			#endif
		}
	}
	{
		hashState state;
		const UINT8 Msg29[4] = { 0x53, 0x58, 0x7B, 0xC8 };
		const UINT8 Msg29_out[160] = {
			0xDE, 0xEB, 0xFB, 0x5F, 0xBC, 0x67, 0x14, 0x3A, 0x70, 0xF5, 0xEE, 0x51, 0x8F, 0x3C, 0xE2, 0x0A, 
			0x70, 0x2A, 0x3C, 0x25, 0x0C, 0x22, 0xD9, 0x39, 0xD7, 0xEE, 0xF5, 0x98, 0xA3, 0x9C, 0xA5, 0xC5, 
			0x37, 0x41, 0xB6, 0xF5, 0x7B, 0x58, 0x40, 0xAD, 0xD2, 0x8E, 0xF6, 0x14, 0x0A, 0xAD, 0x9D, 0x4C, 
			0x2B, 0x8E, 0xCC, 0x6A, 0x89, 0xFC, 0x5E, 0xFE, 0x73, 0x1F, 0x5E, 0x69, 0x7B, 0x83, 0xB8, 0x1C, 
			0x27, 0xED, 0xE0, 0xD2, 0x26, 0xBB, 0x30, 0xDE, 0x0A, 0x93, 0xF5, 0xCE, 0xDB, 0xC1, 0x6E, 0x32, 
			0xBA, 0x9D, 0x6B, 0x10, 0x48, 0x8A, 0x5A, 0x0E, 0x55, 0x5C, 0xB2, 0x96, 0x9F, 0x51, 0xE5, 0x8D, 
			0x46, 0xF0, 0x03, 0xF5, 0x0F, 0x9D, 0x84, 0x5A, 0xAF, 0x43, 0x07, 0x66, 0x76, 0x23, 0x82, 0xAD, 
			0xFD, 0x9B, 0x4C, 0xF0, 0x59, 0x16, 0xDF, 0xD6, 0x5C, 0x8A, 0x8C, 0xFC, 0xDE, 0xC5, 0xD0, 0x45, 
			0x34, 0x07, 0x38, 0x7D, 0xBC, 0xF3, 0xA7, 0x44, 0x26, 0x8E, 0x85, 0xB3, 0x5B, 0x50, 0x0E, 0xDD, 
			0x1E, 0xD5, 0x09, 0x01, 0x55, 0xA6, 0x35, 0xBF, 0xA4, 0x6A, 0xC2, 0x4D, 0xA7, 0x98, 0xE8, 0x24 };
		UINT8 output[160];

		// Test 2 (message of length 29 from ShortMsgKAT_0.txt)
		Init(&state, 0);
		Update(&state, Msg29, 29);
		Final(&state, 0);
		Squeeze(&state, output, 160*8);
	    for(i=0; i<160; i++)
	        if (output[i] != Msg29_out[i])
	            for( ; ; ) {
					//	Kaccek (aka other algo)
	                x++;
	            }
	}

	for ( ; ; ) ;
}