예제 #1
0
파일: relic_cbor.c 프로젝트: tfar/ibce2eiot
cbor_item_t* relic_fp2cbor(const fp_t n) {
	int size = FP_BYTES;
	uint8_t* data = (uint8_t*)malloc(size);
	cbor_item_t* ret = NULL;
	fp_write_bin(data, size, n);
	ret = cbor_build_bytestring(data, size);
	free(data);
	return ret;
}
예제 #2
0
파일: relic_cbor.c 프로젝트: tfar/ibce2eiot
cbor_item_t* relic_bn2cbor(const bn_t n) {
	int size = bn_size_bin(n);
	uint8_t* data = (uint8_t*)malloc(size);
	cbor_item_t* ret = NULL;
	bn_write_bin(data, size, n);
	ret = cbor_build_bytestring(data, size);
	free(data);
	return ret;
}
예제 #3
0
void IoTService::sendQuery(const std::string& target, const std::string& message) {
	LOG(INFO) << "Send signed query '" << message << "' to [" << target << "]:4222";
	auto idVec = std::vector<uint8_t>(id_.begin(), id_.end());
	auto data = std::vector<uint8_t>(message.begin(), message.end());
	LOG(INFO) << "Begin signing message";
	Signature sig = Signature::sign(ibcUser_, idVec, data);
	LOG(INFO) << "End signing message";
	LOG(INFO) << "Begin CBOR encoding query";
	/*
		{
			msg: 'some message',
			sig: [ec, bn, bn]
		}
	*/
	cbor_item_t* root = cbor_new_definite_map(2);
	cbor_map_add(root, (struct cbor_pair) {
		.key = cbor_move(cbor_build_string("msg")),
		.value = cbor_move(cbor_build_bytestring((unsigned char*)message.data(), message.size()))
	});
예제 #4
0
static void test_inline_creation(void **state)
{
	bs = cbor_build_bytestring((cbor_data) "Hello!", 6);
	assert_memory_equal(cbor_bytestring_handle(bs), "Hello!", 6);
	cbor_decref(&bs);
}
예제 #5
0
파일: network.cpp 프로젝트: tfar/ibce2eiot
	LOG(INFO) << "Begin CBOR encoding";
	// build cbor message of TA public key, identity and identity key
	std::vector<uint8_t> clearBuffer;

	ec_t mpk;

	ec_null(mpk); ec_new(mpk);

	cbor_item_t* root = cbor_new_definite_map(3);
	cbor_map_add(root, (struct cbor_pair) {
		.key = cbor_move(cbor_build_string("mpk")),
		.value = cbor_move(relic_ec2cbor_compressed(ta_->kgc_->mpk))
	});
	cbor_map_add(root, (struct cbor_pair) {
		.key = cbor_move(cbor_build_string("id")),
		.value = cbor_move(cbor_build_bytestring(nodeID.data(), nodeID.size()))
	});

	cbor_item_t* idKey_cbor = cbor_new_definite_array(2);
	cbor_array_push(idKey_cbor, cbor_move(relic_ec2cbor_compressed(idKey.user->R)));
	cbor_array_push(idKey_cbor, cbor_move(relic_bn2cbor(idKey.user->s)));

	cbor_map_add(root, (struct cbor_pair) {
		.key = cbor_move(cbor_build_string("key")),
		.value = cbor_move(idKey_cbor)
	});

	LOG(INFO) << "End CBOR encoding";
#if defined(IOT_DEBUG)
	cbor_describe(root, stdout);
	fflush(stdout);