Exemple #1
0
unsigned char *SHA3_512(const unsigned char *dataIn, size_t nBytesIn, unsigned char *md)
{
    Keccak_HashInstance h;
    static BitSequence  m[SHA3_512_DL];

    if (md == NULL) {
        md = m;
    }
    Keccak_HashInitialize_SHA3_512(&h);
    Keccak_HashUpdate(&h, dataIn, (DataLength)nBytesIn * 8);
    Keccak_HashFinal(&h, md);

    return(md);
}
static int crypt_all(int *pcount, struct db_salt *salt)
{
	const int count = *pcount;
	int index = 0;
#ifdef _OPENMP
#pragma omp parallel for
#endif
	for (index = 0; index < count; index++)
	{
		Keccak_HashInstance hash;
		Keccak_HashInitialize(&hash, 1088, 512, 256, 0x01);
		Keccak_HashUpdate(&hash, (unsigned char*)saved_key[index], saved_len[index] * 8);
		Keccak_HashFinal(&hash, (unsigned char*)crypt_out[index]);
	}
	return count;
}
Exemple #3
0
int SHAKE80(const unsigned char *dataIn, size_t nBitsIn, unsigned char *md, int nOutBytes)
{
    Keccak_HashInstance h;

    if (md == NULL || nOutBytes == 0) {
        return 0;
    }
    if (nOutBytes > SHAKE_MAX_BITS / 8) {
        nOutBytes = SHAKE_MAX_BITS / 8;
    }
    Keccak_HashInitialize(&h, SHAKE80_R, SHAKE80_C, 0, SHAKE80_P);
    Keccak_HashUpdate(&h, dataIn, (DataLength)nBitsIn);
    Keccak_HashFinal(&h, NULL);
    Keccak_HashSqueeze(&h, md, nOutBytes * 8);

    return nOutBytes;
}
Exemple #4
0
static PyObject *
SHA3_digest(SHAobject *self, PyObject *unused)
{
    unsigned char *digest = malloc(self->outputlen / 8 + 1); //[MAX_DIGEST_SIZE];
    SHAobject temp;

    SHAcopy(self, &temp);

    Keccak_HashFinal(&temp.state, digest);

    if (self->hashbitlen > 512) { // SHAKE
        Keccak_HashSqueeze(&temp.state, digest, self->outputlen);
    }

    PyObject *ret = PyBytes_FromStringAndSize((const char *)digest, self->outputlen / 8);
    free(digest);
    return ret;
}
Exemple #5
0
int main(int argc, char* argv[]) {

  if (argc < 3) {
    print_usage();
  }

  int hash_size = atoi(argv[1]);
  Keccak_HashInstance hash;

  HashReturn initResult = FAIL;
  if (hash_size == 224) {

    initResult = Keccak_HashInitialize_SHA3_224(&hash);

  } else if (hash_size == 256) {

    initResult = Keccak_HashInitialize_SHA3_256(&hash);

  } else if (hash_size == 384) {

    initResult = Keccak_HashInitialize_SHA3_384(&hash);

  } else if (hash_size == 512) {

    initResult = Keccak_HashInitialize_SHA3_512(&hash);

  } else {

    printf("Error : wrong size argument\nAvailable sizes : 224, 256, 384, 512\n");
    exit(0);

  }

  if (initResult != SUCCESS) {
    printf("error when itializing SHA-3\n");
    return -1;
  }

  if (Keccak_HashUpdate(&hash, (unsigned char*)argv[STRING_POSITION], strlen(argv[STRING_POSITION]) * 8) != SUCCESS) {
    printf("error when updating SHA-3\n");
    return -1;
  }

  int bytes_hash_size = hash_size / 8;
  unsigned char* output = malloc(bytes_hash_size);
  if (output == NULL) {
    printf("memory allocation error\n");
    return -1;
  }

  if (Keccak_HashFinal(&hash, output) != SUCCESS) {
    printf("error when extracting the result hash\n");
    return -1;
  }

  int i;
  for (i = 0; i < bytes_hash_size; i++) {
    printf("%02x", (unsigned int)output[i]);
  }

  putchar('\n');

  return 0;
}