Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Merge branch 'develop' into helpersjava-bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez authored Feb 13, 2019
2 parents be52ad1 + d68cb02 commit df0c5fa
Show file tree
Hide file tree
Showing 34 changed files with 503 additions and 506 deletions.
16 changes: 16 additions & 0 deletions mam/v2/api/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package(default_visibility = ["//visibility:public"])

cc_library(
name = "api",
srcs = ["api.c"],
hdrs = ["api.h"],
deps = [
"//common:errors",
"//common/model:bundle",
"//mam/v2/mam",
"//mam/v2/mam:mam_psk_t_set",
"//mam/v2/mam:mam_types",
"//mam/v2/ntru:mam_ntru_pk_t_set",
"//mam/v2/ntru:mam_ntru_sk_t_set",
],
)
81 changes: 81 additions & 0 deletions mam/v2/api/api.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2018 IOTA Stiftung
* https://github.com/iotaledger/entangled
*
* MAM is based on an original implementation & specification by apmi.bsu.by
* [ITSec Lab]
*
* Refer to the LICENSE file for licensing information
*/

#include "mam/v2/api/api.h"
#include "mam/v2/mam/mam_psk_t_set.h"
#include "mam/v2/ntru/mam_ntru_pk_t_set.h"
#include "mam/v2/ntru/mam_ntru_sk_t_set.h"
#include "mam/v2/prng/prng.h"

retcode_t mam_api_init(mam_api_t *const api, trits_t const prng_secret_key) {
retcode_t ret = RC_OK;

api->version = MAM_API_VERSION;
if ((ret = mam_prng_init(&api->prng, prng_secret_key)) != RC_OK) {
return ret;
}
api->ntru_sks = NULL;
api->ntru_pks = NULL;
api->psks = NULL;

return ret;
}

retcode_t mam_api_destroy(mam_api_t *const api) {
retcode_t ret = RC_OK;

if ((ret = mam_prng_destroy(&api->prng)) != RC_OK) {
return ret;
}
mam_ntru_sk_t_set_free(&api->ntru_sks);
mam_ntru_pk_t_set_free(&api->ntru_pks);
mam_psk_t_set_free(&api->psks);

return RC_OK;
}

retcode_t mam_api_add_ntru_sk(mam_api_t *const api,
mam_ntru_sk_t const *const ntru_sk) {
return mam_ntru_sk_t_set_add(&api->ntru_sks, ntru_sk);
}

retcode_t mam_api_add_ntru_pk(mam_api_t *const api,
mam_ntru_pk_t const *const ntru_pk) {
return mam_ntru_pk_t_set_add(&api->ntru_pks, ntru_pk);
}

retcode_t mam_api_add_psk(mam_api_t *const api, mam_psk_t const *const psk) {
return mam_psk_t_set_add(&api->psks, psk);
}

retcode_t mam_api_bundle_write_msg(
mam_api_t *const api, mam_msg_pubkey_t pubkey, mam_msg_keyload_t keyload,
mam_msg_checksum_t checksum, mam_channel_t const *const cha,
mam_endpoint_t const *const epa, mam_channel_t const *const ch1a,
mam_endpoint_t const *const ep1a, flex_trit_t const *const payload,
bundle_transactions_t *const bundle) {
return RC_MAM2_NOT_IMPLEMENTED;
}

retcode_t mam_api_bundle_write_packet(
mam_api_t *const api, mam_msg_pubkey_t pubkey, mam_msg_keyload_t keyload,
mam_msg_checksum_t checksum, mam_channel_t const *const cha,
mam_endpoint_t const *const epa, mam_channel_t const *const ch1a,
mam_endpoint_t const *const ep1a, flex_trit_t const *const payload,
bundle_transactions_t *const bundle) {
return RC_MAM2_NOT_IMPLEMENTED;
}

retcode_t mam_api_bundle_read(mam_api_t *const api,
mam_channel_t const *const cha,
bundle_transactions_t const *const bundle,
flex_trit_t *const payload) {
return RC_MAM2_NOT_IMPLEMENTED;
}
71 changes: 71 additions & 0 deletions mam/v2/api/api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2018 IOTA Stiftung
* https://github.com/iotaledger/entangled
*
* MAM is based on an original implementation & specification by apmi.bsu.by
* [ITSec Lab]
*
* Refer to the LICENSE file for licensing information
*/

#ifndef __MAM_V2_API_API_H__
#define __MAM_V2_API_API_H__

#include "common/errors.h"
#include "common/model/bundle.h"
#include "common/trinary/flex_trit.h"
#include "mam/v2/mam/mam.h"
#include "mam/v2/mam/mam_types.h"
#include "mam/v2/ntru/ntru_types.h"
#include "mam/v2/prng/prng_types.h"

#define MAM_API_VERSION 0

#ifdef __cplusplus
extern "C" {
#endif

typedef struct mam_api_s {
tryte_t version;
mam_prng_t prng;
mam_ntru_sk_t_set_t ntru_sks;
mam_ntru_pk_t_set_t ntru_pks;
mam_psk_t_set_t psks;
} mam_api_t;

retcode_t mam_api_init(mam_api_t *const api, trits_t const prng_secret_key);

retcode_t mam_api_destroy(mam_api_t *const api);

retcode_t mam_api_add_ntru_sk(mam_api_t *const api,
mam_ntru_sk_t const *const ntru_sk);

retcode_t mam_api_add_ntru_pk(mam_api_t *const api,
mam_ntru_pk_t const *const ntru_pk);

retcode_t mam_api_add_psk(mam_api_t *const api, mam_psk_t const *const psk);

retcode_t mam_api_bundle_write_msg(
mam_api_t *const api, mam_msg_pubkey_t pubkey, mam_msg_keyload_t keyload,
mam_msg_checksum_t checksum, mam_channel_t const *const cha,
mam_endpoint_t const *const epa, mam_channel_t const *const ch1a,
mam_endpoint_t const *const ep1a, flex_trit_t const *const payload,
bundle_transactions_t *const bundle);

retcode_t mam_api_bundle_write_packet(
mam_api_t *const api, mam_msg_pubkey_t pubkey, mam_msg_keyload_t keyload,
mam_msg_checksum_t checksum, mam_channel_t const *const cha,
mam_endpoint_t const *const epa, mam_channel_t const *const ch1a,
mam_endpoint_t const *const ep1a, flex_trit_t const *const payload,
bundle_transactions_t *const bundle);

retcode_t mam_api_bundle_read(mam_api_t *const api,
mam_channel_t const *const cha,
bundle_transactions_t const *const bundle,
flex_trit_t *const payload);

#ifdef __cplusplus
}
#endif

#endif // __MAM_V2_API_API_H__
13 changes: 0 additions & 13 deletions mam/v2/bundle/BUILD

This file was deleted.

36 changes: 0 additions & 36 deletions mam/v2/bundle/bundle.c

This file was deleted.

47 changes: 0 additions & 47 deletions mam/v2/bundle/bundle.h

This file was deleted.

4 changes: 2 additions & 2 deletions mam/v2/mam/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ cc_library(
name = "mam_types",
srcs = ["mam_types.c"],
deps = [
":mam_pre_shared_key_t_set",
":mam_psk_t_set",
":mam_types_hdr",
"//mam/v2:defs",
"//mam/v2/ntru",
Expand All @@ -87,7 +87,7 @@ typed_container_generate(
additional_include_path = "mam/v2/mam/mam_types.h",
container_type = "set",
parent_directory = "mam/v2/mam",
value_type = "mam_pre_shared_key_t",
value_type = "mam_psk_t",
)

typed_container_generate(
Expand Down
16 changes: 8 additions & 8 deletions mam/v2/mam/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ retcode_t mam_channel_unwrap(mam_spongos_t *const spongos,
}

size_t mam_channel_serialized_size(mam_channel_t const *const channel) {
size_t mss_size = mss_stored_size(&channel->mss);
size_t mss_size = mss_serialized_size(&channel->mss);
size_t endpoints_size = mam_endpoints_serialized_size(channel->endpoints);

return pb3_sizeof_ntrytes(MAM2_CHANNEL_ID_SIZE /
Expand All @@ -120,14 +120,14 @@ size_t mam_channel_serialized_size(mam_channel_t const *const channel) {

retcode_t mam_channel_serialize(mam_channel_t const *const channel,
trits_t *const buffer) {
size_t mss_size = mss_stored_size(&channel->mss);
size_t mss_size = mss_serialized_size(&channel->mss);

pb3_encode_ntrytes(trits_from_rep(MAM2_CHANNEL_ID_SIZE, channel->id),
buffer); // id
pb3_encode_size_t(trits_size(channel->name), buffer); // name size
pb3_encode_ntrytes(channel->name, buffer); // name
pb3_encode_size_t(mss_size, buffer); // mss size
mss_save(&channel->mss, trits_take(*buffer, mss_size)); // mss
buffer); // id
pb3_encode_size_t(trits_size(channel->name), buffer); // name size
pb3_encode_ntrytes(channel->name, buffer); // name
pb3_encode_size_t(mss_size, buffer); // mss size
mss_serialize(&channel->mss, trits_take(*buffer, mss_size)); // mss
trits_advance(buffer, mss_size);
mam_endpoints_serialize(channel->endpoints, buffer); // endpoints

Expand Down Expand Up @@ -173,7 +173,7 @@ retcode_t mam_channel_deserialize(trits_t *const buffer, mam_prng_t *const prng,

mss_init(&channel->mss, prng, height, channel->name, trits_null());

if ((ret = mss_load(&channel->mss, buffer)) != RC_OK) {
if ((ret = mss_deserialize(buffer, &channel->mss)) != RC_OK) {
return ret;
}

Expand Down
16 changes: 8 additions & 8 deletions mam/v2/mam/endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ retcode_t mam_endpoints_destroy(mam_endpoint_t_set_t *const endpoints) {
}

size_t mam_endpoint_serialized_size(mam_endpoint_t const *const endpoint) {
size_t mss_size = mss_stored_size(&endpoint->mss);
size_t mss_size = mss_serialized_size(&endpoint->mss);

return pb3_sizeof_ntrytes(MAM2_ENDPOINT_ID_SIZE /
NUMBER_OF_TRITS_IN_A_TRYTE) + // id
Expand All @@ -87,14 +87,14 @@ size_t mam_endpoint_serialized_size(mam_endpoint_t const *const endpoint) {

retcode_t mam_endpoint_serialize(mam_endpoint_t const *const endpoint,
trits_t *const buffer) {
size_t mss_size = mss_stored_size(&endpoint->mss);
size_t mss_size = mss_serialized_size(&endpoint->mss);

pb3_encode_ntrytes(trits_from_rep(MAM2_ENDPOINT_ID_SIZE, endpoint->id),
buffer); // id
pb3_encode_size_t(trits_size(endpoint->name), buffer); // name size
pb3_encode_ntrytes(endpoint->name, buffer); // name
pb3_encode_size_t(mss_size, buffer); // mss size
mss_save(&endpoint->mss, trits_take(*buffer, mss_size)); // mss
buffer); // id
pb3_encode_size_t(trits_size(endpoint->name), buffer); // name size
pb3_encode_ntrytes(endpoint->name, buffer); // name
pb3_encode_size_t(mss_size, buffer); // mss size
mss_serialize(&endpoint->mss, trits_take(*buffer, mss_size)); // mss
trits_advance(buffer, mss_size);

return RC_OK;
Expand Down Expand Up @@ -143,7 +143,7 @@ retcode_t mam_endpoint_deserialize(trits_t *const buffer,

mss_init(&endpoint->mss, prng, height, channel_name, endpoint->name);

if ((ret = mss_load(&endpoint->mss, buffer)) != RC_OK) {
if ((ret = mss_deserialize(buffer, &endpoint->mss)) != RC_OK) {
return ret;
}

Expand Down
Loading

0 comments on commit df0c5fa

Please sign in to comment.