예제 #1
0
END_TEST

START_TEST(test_memxor_aligned)
{
	uint64_t a = 0, b = 0;
	chunk_t ca, cb;
	int i;

	ca = chunk_from_thing(a);
	cb = chunk_from_thing(b);

	for (i = 0; i < 8; i++)
	{
		cb.ptr[i] = i + 1;
	}

	/* 64-bit aligned */
	memxor(ca.ptr, cb.ptr, 8);
	ck_assert(a == b);
	/* 32-bit aligned source */
	a = 0;
	memxor(ca.ptr, cb.ptr + 4, 4);
	ck_assert(chunk_equals(ca, chunk_from_chars(0x05, 0x06, 0x07, 0x08,
												0x00, 0x00, 0x00, 0x00)));
	/* 16-bit aligned source */
	a = 0;
	memxor(ca.ptr, cb.ptr + 2, 6);
	ck_assert(chunk_equals(ca, chunk_from_chars(0x03, 0x04, 0x05, 0x06,
												0x07, 0x08, 0x00, 0x00)));
	/* 8-bit aligned source */
	a = 0;
	memxor(ca.ptr, cb.ptr + 1, 7);
	ck_assert(chunk_equals(ca, chunk_from_chars(0x02, 0x03, 0x04, 0x05,
												0x06, 0x07, 0x08, 0x00)));
}
예제 #2
0
END_TEST

/*******************************************************************************
 * htoun/untoh
 */

START_TEST(test_htoun)
{
	chunk_t net64, expected;
	uint16_t host16 = 513;
	uint32_t net16 = 0, host32 = 67305985;
	uint64_t net32 = 0, host64 = 578437695752307201ULL;

	net64 = chunk_alloca(16);
	memset(net64.ptr, 0, net64.len);

	expected = chunk_from_chars(0x00, 0x02, 0x01, 0x00);
	htoun16((char*)&net16 + 1, host16);
	ck_assert(chunk_equals(expected, chunk_from_thing(net16)));

	expected = chunk_from_chars(0x00, 0x00, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00);
	htoun32((uint16_t*)&net32 + 1, host32);
	ck_assert(chunk_equals(expected, chunk_from_thing(net32)));

	expected = chunk_from_chars(0x00, 0x00, 0x00, 0x00,
								0x08, 0x07, 0x06, 0x05,
								0x04, 0x03, 0x02, 0x01,
								0x00, 0x00, 0x00, 0x00);
	htoun64((uint32_t*)net64.ptr + 1, host64);
	ck_assert(chunk_equals(expected, net64));
}
예제 #3
0
int main(int argc, char *argv[])
{
	hash_algorithm_t alg;
	hasher_t *hasher;
	char buffer[1024];
	int limit = 0, i = 0;

	library_init(NULL, "hash_burn");
	lib->plugins->load(lib->plugins, PLUGINS);
	atexit(library_deinit);

	printf("loaded: %s\n", PLUGINS);

	memset(buffer, 0x12, sizeof(buffer));

	if (argc < 2)
	{
		fprintf(stderr, "usage: %s <algorithm>!\n", argv[0]);
		return 1;
	}
	if (argc > 2)
	{
		limit = atoi(argv[2]);
	}

	alg = enum_from_name(hash_algorithm_short_names, argv[1]);
	if (alg == -1)
	{
		fprintf(stderr, "unknown hash algorthm: %s\n", argv[1]);
		return 1;
	}
	hasher = lib->crypto->create_hasher(lib->crypto, alg);
	if (!hasher)
	{
		fprintf(stderr, "hash algorthm not supported: %N\n",
				hash_algorithm_names, alg);
		return 1;
	}

	while (TRUE)
	{
		if (!hasher->get_hash(hasher, chunk_from_thing(buffer), buffer))
		{
			fprintf(stderr, "hashing failed!\n");
			return 1;
		}
		if (limit && ++i == limit)
		{
			break;
		}
	}
	hasher->destroy(hasher);
	return 0;
}
예제 #4
0
/*******************************************************************************
 * X509 certificate generation and parsing
 ******************************************************************************/
bool test_cert_x509()
{
    private_key_t *ca_key, *peer_key;
    public_key_t *public;
    certificate_t *ca_cert, *peer_cert, *parsed;
    identification_t *issuer, *subject;
    u_int32_t serial = htonl(0);
    chunk_t encoding;

    issuer = identification_create_from_string("CN=CA, OU=Test, O=strongSwan");
    subject = identification_create_from_string("CN=Peer, OU=Test, O=strongSwan");

    ca_key = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
                                BUILD_KEY_SIZE, 1024, BUILD_END);
    peer_key = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
                                  BUILD_KEY_SIZE, 1024, BUILD_END);
    if (!ca_key)
    {
        return FALSE;
    }
    ca_cert = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_X509,
                                 BUILD_SIGNING_KEY, ca_key,
                                 BUILD_SUBJECT, issuer,
                                 BUILD_SERIAL, chunk_from_thing(serial),
                                 BUILD_X509_FLAG, X509_CA,
                                 BUILD_END);
    if (!ca_cert)
    {
        return FALSE;
    }

    ca_cert->get_encoding(ca_cert, CERT_ASN1_DER, &encoding);
    parsed = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_X509,
                                BUILD_BLOB_ASN1_DER, encoding,
                                BUILD_END);
    chunk_free(&encoding);
    if (!parsed)
    {
        return FALSE;
    }
    if (!parsed->issued_by(parsed, ca_cert, NULL))
    {
        return FALSE;
    }
    parsed->destroy(parsed);

    serial = htonl(ntohl(serial) + 1);
    public = peer_key->get_public_key(peer_key);
예제 #5
0
END_TEST

#define EVENT_COUNT 500

CALLBACK(raise_cb,  vici_message_t*,
	vici_dispatcher_t *dispatcher, char *name, u_int id, vici_message_t *req)
{
	u_int i;

	for (i = 0; i < EVENT_COUNT; i++)
	{
		dispatcher->raise_event(dispatcher, "event", id,
			vici_message_create_from_args(
				 VICI_KEY_VALUE, "counter", chunk_from_thing(i),
				VICI_END));
	}
	return vici_message_create_from_args(VICI_END);
}
예제 #6
0
int main(int argc, char *argv[])
{
	const proposal_token_t *token;
	aead_t *aead;
	crypter_t *crypter;
	char buffer[1024], assoc[8], iv[32];
	size_t bs;
	int i = 0, limit = 0;


	library_init(NULL, "crypt_burn");
	lib->plugins->load(lib->plugins, PLUGINS);
	atexit(library_deinit);

	printf("loaded: %s\n", PLUGINS);

	memset(buffer, 0x12, sizeof(buffer));
	memset(assoc, 0x34, sizeof(assoc));
	memset(iv, 0x56, sizeof(iv));

	if (argc < 2)
	{
		fprintf(stderr, "usage: %s <algorithm>!\n", argv[0]);
		return 1;
	}
	if (argc > 2)
	{
		limit = atoi(argv[2]);
	}

	token = lib->proposal->get_token(lib->proposal, argv[1]);
	if (!token)
	{
		fprintf(stderr, "algorithm '%s' unknown!\n", argv[1]);
		return 1;
	}
	if (token->type != ENCRYPTION_ALGORITHM)
	{
		fprintf(stderr, "'%s' is not an encryption/aead algorithm!\n", argv[1]);
		return 1;
	}

	if (encryption_algorithm_is_aead(token->algorithm))
	{
		aead = lib->crypto->create_aead(lib->crypto,
									token->algorithm, token->keysize / 8, 0);
		if (!aead)
		{
			fprintf(stderr, "aead '%s' not supported!\n", argv[1]);
			return 1;
		}
		while (TRUE)
		{
			if (!aead->encrypt(aead,
				chunk_create(buffer, sizeof(buffer) - aead->get_icv_size(aead)),
				chunk_from_thing(assoc),
				chunk_create(iv, aead->get_iv_size(aead)), NULL))
			{
				fprintf(stderr, "aead encryption failed!\n");
				return 1;
			}
			if (!aead->decrypt(aead, chunk_create(buffer, sizeof(buffer)),
				chunk_from_thing(assoc),
				chunk_create(iv, aead->get_iv_size(aead)), NULL))
			{
				fprintf(stderr, "aead integrity check failed!\n");
				return 1;
			}
			if (limit && ++i == limit)
			{
				break;
			}
		}
		aead->destroy(aead);
	}
	else
	{
		crypter = lib->crypto->create_crypter(lib->crypto,
										token->algorithm, token->keysize / 8);
		if (!crypter)
		{
			fprintf(stderr, "crypter '%s' not supported!\n", argv[1]);
			return 1;
		}
		bs = crypter->get_block_size(crypter);

		while (TRUE)
		{
			if (!crypter->encrypt(crypter,
					chunk_create(buffer, sizeof(buffer) / bs * bs),
					chunk_create(iv, crypter->get_iv_size(crypter)), NULL))
			{
				continue;
			}
			if (!crypter->decrypt(crypter,
					chunk_create(buffer, sizeof(buffer) / bs * bs),
					chunk_create(iv, crypter->get_iv_size(crypter)), NULL))
			{
				continue;
			}
			if (limit && ++i == limit)
			{
				break;
			}
		}
		crypter->destroy(crypter);
	}
	return 0;
}