void performTestBitLevel(unsigned int rate, unsigned int capacity, unsigned char *checksum) { #define inputByteSize 512 #define outputByteSize 512 unsigned char input[inputByteSize]; unsigned char output[outputByteSize]; unsigned char acc[outputByteSize]; unsigned int inputBitLength; /* Acumulated test vector */ memset(acc, 0x00, sizeof(acc)); for(inputBitLength = 0; inputBitLength <= (inputByteSize*8); inputBitLength += (inputBitLength < 1600) ? 1 : 8) { unsigned int i; unsigned int inputByteLengthCeiling = (inputBitLength + 7) / 8; /* Preparing some input value */ for(i=0; i<inputByteLengthCeiling; i++) input[i] = inputBitLength - i; if ((inputBitLength % 8) != 0) input[inputByteLengthCeiling-1] &= (1 << (inputBitLength % 8)) - 1; if ((inputBitLength % 8) == 0) { Keccak(rate, capacity, input, inputBitLength/8, 0x01, output, outputByteSize); } else { unsigned char delimitedSuffix = input[inputByteLengthCeiling-1] | (1 << (inputBitLength % 8)); Keccak(rate, capacity, input, inputBitLength/8, delimitedSuffix, output, outputByteSize); } #ifdef VERBOSE printf("Keccak[r=%d, c=%d]\n", rate, capacity); printf("Input of %d bits:", inputBitLength); for(i=0; i<inputByteLengthCeiling; i++) printf(" %02x", (int)input[i]); printf("\n"); printf("Output of %d bits:", outputByteSize*8); for(i=0; i<outputByteSize; i++) printf(" %02x", (int)output[i]); printf("\n\n"); #endif for (i = 0; i < outputByteSize; i++) acc[i] ^= output[i]; Keccak(1344, 256, acc, outputByteSize, 0x1F, acc, outputByteSize); } memcpy(checksum, acc, outputByteSize); #ifdef VERBOSE { unsigned int i; printf("Keccak[r=%d, c=%d]\n", rate, capacity); printf("Checksum: ", outputByteSize); for(i=0; i<outputByteSize; i++) printf("\\x%02x", (int)checksum[i]); printf("\n\n"); } #endif }
void performTestByteLevel(unsigned int rate, unsigned int capacity, unsigned char delimitedSuffix, unsigned int outputByteLength, unsigned char *checksum) { #define inputByteSize 1024 #define outputByteSize 512 unsigned char input[inputByteSize]; unsigned char output[outputByteSize]; unsigned char acc[outputByteSize]; unsigned int inputByteLength; assert(outputByteLength <= outputByteSize); /* Acumulated test vector */ memset(acc, 0x00, sizeof(acc)); for(inputByteLength = 0; inputByteLength <= inputByteSize; inputByteLength++) { unsigned int i; /* Preparing some input value */ for(i=0; i<inputByteLength; i++) input[i] = inputByteLength - i; Keccak(rate, capacity, input, inputByteLength, delimitedSuffix, output, outputByteLength); #ifdef VERBOSE printf("Keccak[r=%d, c=%d] with suffix=%02x\n", rate, capacity, delimitedSuffix); printf("Input of %d bytes:", inputByteLength); for(i=0; i<inputByteLength; i++) printf(" %02x", (int)input[i]); printf("\n"); printf("Output of %d bytes:", outputByteLength); for(i=0; i<outputByteLength; i++) printf(" %02x", (int)output[i]); printf("\n\n"); #endif for (i = 0; i < outputByteLength; i++) acc[i] ^= output[i]; Keccak(1344, 256, acc, outputByteLength, 0x1F, acc, outputByteLength); } memcpy(checksum, acc, outputByteLength); #ifdef VERBOSE { unsigned int i; printf("Keccak[r=%d, c=%d] with suffix=%02x and %d bytes of output\n", rate, capacity, delimitedSuffix, outputByteLength); printf("Checksum: ", outputByteLength); for(i=0; i<outputByteLength; i++) printf("\\x%02x", (int)checksum[i]); printf("\n\n"); } #endif }
/* Function to compute SHA3-512 on the input message. The output length is fixed to 64 bytes. */ static void FIPS202_SHA3_512( const unsigned char * input, HB_SIZE inputByteLen, unsigned char * output ) { Keccak( 576, 1024, input, inputByteLen, 0x06, output, 64 ); }
/* Function to compute SHA3-384 on the input message. The output length is fixed to 48 bytes. */ static void FIPS202_SHA3_384( const unsigned char * input, HB_SIZE inputByteLen, unsigned char * output ) { Keccak( 832, 768, input, inputByteLen, 0x06, output, 48 ); }
/* Function to compute SHA3-256 on the input message. The output length is fixed to 32 bytes. */ static void FIPS202_SHA3_256( const unsigned char * input, HB_SIZE inputByteLen, unsigned char * output ) { Keccak( 1088, 512, input, inputByteLen, 0x06, output, 32 ); }
/* Function to compute SHA3-224 on the input message. The output length is fixed to 28 bytes. */ static void FIPS202_SHA3_224( const unsigned char * input, HB_SIZE inputByteLen, unsigned char * output ) { Keccak( 1152, 448, input, inputByteLen, 0x06, output, 28 ); }
/* Function to compute SHAKE256 on the input message with any output length. */ static void FIPS202_SHAKE256( const unsigned char * input, HB_SIZE inputByteLen, unsigned char * output, HB_SIZE outputByteLen ) { Keccak( 1088, 512, input, inputByteLen, 0x1F, output, outputByteLen ); }
/* Function to compute SHAKE128 on the input message with any output length. */ static void FIPS202_SHAKE128( const unsigned char * input, HB_SIZE inputByteLen, unsigned char * output, HB_SIZE outputByteLen ) { Keccak( 1344, 256, input, inputByteLen, 0x1F, output, outputByteLen ); }
/** * Function to compute SHAKE256 on the input message with any output length. */ void FIPS202_SHAKE256(const unsigned char *input, unsigned int inputByteLen, unsigned char *output, int outputByteLen) { Keccak(1088, 512, input, inputByteLen, 0x1F, output, outputByteLen); }
/** * Function to compute SHAKE128 on the input message with any output length. */ void FIPS202_SHAKE128(const unsigned char *input, unsigned int inputByteLen, unsigned char *output, int outputByteLen) { Keccak(1344, 256, input, inputByteLen, 0x1F, output, outputByteLen); }