Esempio n. 1
0
WIN32DLL_DEFINE int _mcrypt_self_test()
{
	char *keyword;
	char plaintext[20];
	char ciphertext[20];
	int blocksize = 20, j;
	void *key;
	unsigned char cipher_tmp[200];

	keyword = calloc(1, _mcrypt_get_key_size());
	if (keyword == NULL)
		return -1;

	strcpy(keyword, "enadyotr");

	for (j = 0; j < blocksize; j++) {
		plaintext[j] = j % 256;
	}
	key = malloc(_mcrypt_get_size());
	if (key == NULL) {
		free(keyword);
		return -1;
	}
	memmove(ciphertext, plaintext, blocksize);

	_mcrypt_set_key(key, (void *) keyword, _mcrypt_get_key_size(),
			NULL, 0);
	_mcrypt_encrypt(key, (void *) ciphertext, blocksize);

	for (j = 0; j < blocksize; j++) {
		sprintf(&((char *) cipher_tmp)[2 * j], "%.2x",
			ciphertext[j]);
	}

	if (strcmp((char *) cipher_tmp, CIPHER) != 0) {
		printf("failed compatibility\n");
		printf("Expected: %s\nGot: %s\n", CIPHER,
		       (char *) cipher_tmp);
		free(keyword);
		free(key);
		return -1;
	}

	_mcrypt_set_key(key, (void *) keyword, _mcrypt_get_key_size(),
			NULL, 0);
	free(keyword);
	
	_mcrypt_decrypt(key, (void *) ciphertext, blocksize);
	free(key);

	if (strcmp(ciphertext, plaintext) != 0) {
		printf("failed internally\n");
		return -1;
	}

	return 0;
}
Esempio n. 2
0
WIN32DLL_DEFINE int _mcrypt_self_test()
{
	unsigned char *keyword;
	unsigned char plaintext[43];
	unsigned char ciphertext[43];
	int blocksize = 43, j;
	void *key, *key2;
	unsigned char cipher_tmp[200];

	keyword = calloc(1, _mcrypt_get_key_size());
	for (j = 0; j < _mcrypt_get_key_size(); j++) {
		keyword[j] = (j * 5 + 10) & 0xff;
	}

	for (j = 0; j < blocksize; j++) {
		plaintext[j] = (j + 5) % 0xff;
	}
	key = malloc(_mcrypt_get_size());
	key2 = malloc(_mcrypt_get_size());

	memcpy(ciphertext, plaintext, blocksize);

	_mcrypt_set_key(key, (void *)keyword, _mcrypt_get_key_size(),
		NULL, 0);
	_mcrypt_encrypt(key, (void *)ciphertext, blocksize);
	free(key);

	for (j = 0; j < blocksize; j++) {
		sprintf(&((char *)cipher_tmp)[2 * j], "%.2x",
			ciphertext[j]);
	}

	if (strcmp((char *)cipher_tmp, CIPHER) != 0) {
		printf("failed compatibility\n");
		printf("Expected: %s\nGot: %s\n", CIPHER,
			(char *)cipher_tmp);
		free(key);
		free(key2);
		return -1;
	}
	_mcrypt_set_key(key2, (void *)keyword, _mcrypt_get_key_size(),
		NULL, 0);
	free(keyword);

	_mcrypt_decrypt(key2, (void *)ciphertext, blocksize);
	free(key2);

	if (memcmp(ciphertext, plaintext, blocksize) != 0) {
		printf("failed internally\n");
		return -1;
	}

	return 0;
}
Esempio n. 3
0
WIN32DLL_DEFINE int _mcrypt_self_test()
{
	char *keyword;
	unsigned char plaintext[16];
	unsigned char ciphertext[16];
	int blocksize = _mcrypt_get_block_size(), j;
	void *key;
	unsigned char cipher_tmp[200];

	keyword = calloc(1, _mcrypt_get_key_size());
	if (keyword == NULL)
		return -1;

	for (j = 0; j < _mcrypt_get_key_size(); j++) {
		keyword[j] = ((j * 2 + 10) % 256);
	}

	for (j = 0; j < blocksize; j++) {
		plaintext[j] = j % 256;
	}
	key = malloc(_mcrypt_get_size());
	if (key == NULL)
		return -1;

	memcpy(ciphertext, plaintext, blocksize);

	_mcrypt_set_key(key, (void *) keyword, _mcrypt_get_key_size());
	free(keyword);

	_mcrypt_encrypt(key, (void *) ciphertext);

	for (j = 0; j < blocksize; j++) {
		sprintf(&((char *) cipher_tmp)[2 * j], "%.2x",
			ciphertext[j]);
	}

	if (strcmp((char *) cipher_tmp, CIPHER) != 0) {
		printf("failed compatibility\n");
		printf("Expected: %s\nGot: %s\n", CIPHER,
		       (char *) cipher_tmp);
		free(key);
		return -1;
	}
	_mcrypt_decrypt(key, (void *) ciphertext);
	free(key);

	if (strcmp((const char *)ciphertext, (const char *)plaintext) != 0) {
		printf("failed internally\n");
		return -1;
	}

	return 0;
}