]> granicus.if.org Git - esp-idf/commitdiff
Protocomm : Added unit tests and protobuf-c generated files
authorAmey Inamdar <amey@espressif.com>
Mon, 30 Jul 2018 16:05:03 +0000 (21:35 +0530)
committerAnurag Kar <anurag.kar@espressif.com>
Tue, 2 Oct 2018 13:37:28 +0000 (19:07 +0530)
Co-Authored-By: Amey Inamdar <amey@espressif.com>
Co-Authored-By: Anurag Kar <anurag.kar@espressif.com>
15 files changed:
components/protocomm/component.mk
components/protocomm/proto-c/constants.pb-c.c [new file with mode: 0644]
components/protocomm/proto-c/constants.pb-c.h [new file with mode: 0644]
components/protocomm/proto-c/sec0.pb-c.c [new file with mode: 0644]
components/protocomm/proto-c/sec0.pb-c.h [new file with mode: 0644]
components/protocomm/proto-c/sec1.pb-c.c [new file with mode: 0644]
components/protocomm/proto-c/sec1.pb-c.h [new file with mode: 0644]
components/protocomm/proto-c/session.pb-c.c [new file with mode: 0644]
components/protocomm/proto-c/session.pb-c.h [new file with mode: 0644]
components/protocomm/python/constants_pb2.py [new file with mode: 0644]
components/protocomm/python/sec0_pb2.py [new file with mode: 0644]
components/protocomm/python/sec1_pb2.py [new file with mode: 0644]
components/protocomm/python/session_pb2.py [new file with mode: 0644]
components/protocomm/test/component.mk [new file with mode: 0644]
components/protocomm/test/test_protocomm.c [new file with mode: 0644]

index ed8c4b7c0906e058a20d82143baaf0b3d242a11a..7941a8e3bae7bc3e6a2c8c5fdee2b4727c8c625a 100644 (file)
@@ -1,3 +1,3 @@
-COMPONENT_ADD_INCLUDEDIRS := include/common include/security
-COMPONENT_PRIV_INCLUDEDIRS := proto-c src/common
+COMPONENT_ADD_INCLUDEDIRS := include/common include/security proto-c
+COMPONENT_PRIV_INCLUDEDIRS := src/common
 COMPONENT_SRCDIRS := src/common src/security proto-c
diff --git a/components/protocomm/proto-c/constants.pb-c.c b/components/protocomm/proto-c/constants.pb-c.c
new file mode 100644 (file)
index 0000000..3b06d5f
--- /dev/null
@@ -0,0 +1,49 @@
+/* Generated by the protocol buffer compiler.  DO NOT EDIT! */
+/* Generated from: constants.proto */
+
+/* Do not generate deprecated warnings for self */
+#ifndef PROTOBUF_C__NO_DEPRECATED
+#define PROTOBUF_C__NO_DEPRECATED
+#endif
+
+#include "constants.pb-c.h"
+static const ProtobufCEnumValue status__enum_values_by_number[8] =
+{
+  { "Success", "STATUS__Success", 0 },
+  { "InvalidSecScheme", "STATUS__InvalidSecScheme", 1 },
+  { "InvalidProto", "STATUS__InvalidProto", 2 },
+  { "TooManySessions", "STATUS__TooManySessions", 3 },
+  { "InvalidArgument", "STATUS__InvalidArgument", 4 },
+  { "InternalError", "STATUS__InternalError", 5 },
+  { "CryptoError", "STATUS__CryptoError", 6 },
+  { "InvalidSession", "STATUS__InvalidSession", 7 },
+};
+static const ProtobufCIntRange status__value_ranges[] = {
+{0, 0},{0, 8}
+};
+static const ProtobufCEnumValueIndex status__enum_values_by_name[8] =
+{
+  { "CryptoError", 6 },
+  { "InternalError", 5 },
+  { "InvalidArgument", 4 },
+  { "InvalidProto", 2 },
+  { "InvalidSecScheme", 1 },
+  { "InvalidSession", 7 },
+  { "Success", 0 },
+  { "TooManySessions", 3 },
+};
+const ProtobufCEnumDescriptor status__descriptor =
+{
+  PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC,
+  "Status",
+  "Status",
+  "Status",
+  "",
+  8,
+  status__enum_values_by_number,
+  8,
+  status__enum_values_by_name,
+  1,
+  status__value_ranges,
+  NULL,NULL,NULL,NULL   /* reserved[1234] */
+};
diff --git a/components/protocomm/proto-c/constants.pb-c.h b/components/protocomm/proto-c/constants.pb-c.h
new file mode 100644 (file)
index 0000000..6fa9702
--- /dev/null
@@ -0,0 +1,53 @@
+/* Generated by the protocol buffer compiler.  DO NOT EDIT! */
+/* Generated from: constants.proto */
+
+#ifndef PROTOBUF_C_constants_2eproto__INCLUDED
+#define PROTOBUF_C_constants_2eproto__INCLUDED
+
+#include <protobuf-c/protobuf-c.h>
+
+PROTOBUF_C__BEGIN_DECLS
+
+#if PROTOBUF_C_VERSION_NUMBER < 1003000
+# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers.
+#elif 1003000 < PROTOBUF_C_MIN_COMPILER_VERSION
+# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c.
+#endif
+
+
+
+
+/* --- enums --- */
+
+/*
+ * Allowed values for the status
+ * of a protocomm instance 
+ */
+typedef enum _Status {
+  STATUS__Success = 0,
+  STATUS__InvalidSecScheme = 1,
+  STATUS__InvalidProto = 2,
+  STATUS__TooManySessions = 3,
+  STATUS__InvalidArgument = 4,
+  STATUS__InternalError = 5,
+  STATUS__CryptoError = 6,
+  STATUS__InvalidSession = 7
+    PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(STATUS)
+} Status;
+
+/* --- messages --- */
+
+/* --- per-message closures --- */
+
+
+/* --- services --- */
+
+
+/* --- descriptors --- */
+
+extern const ProtobufCEnumDescriptor    status__descriptor;
+
+PROTOBUF_C__END_DECLS
+
+
+#endif  /* PROTOBUF_C_constants_2eproto__INCLUDED */
diff --git a/components/protocomm/proto-c/sec0.pb-c.c b/components/protocomm/proto-c/sec0.pb-c.c
new file mode 100644 (file)
index 0000000..dd520f0
--- /dev/null
@@ -0,0 +1,293 @@
+/* Generated by the protocol buffer compiler.  DO NOT EDIT! */
+/* Generated from: sec0.proto */
+
+/* Do not generate deprecated warnings for self */
+#ifndef PROTOBUF_C__NO_DEPRECATED
+#define PROTOBUF_C__NO_DEPRECATED
+#endif
+
+#include "sec0.pb-c.h"
+void   s0_session_cmd__init
+                     (S0SessionCmd         *message)
+{
+  static const S0SessionCmd init_value = S0_SESSION_CMD__INIT;
+  *message = init_value;
+}
+size_t s0_session_cmd__get_packed_size
+                     (const S0SessionCmd *message)
+{
+  assert(message->base.descriptor == &s0_session_cmd__descriptor);
+  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t s0_session_cmd__pack
+                     (const S0SessionCmd *message,
+                      uint8_t       *out)
+{
+  assert(message->base.descriptor == &s0_session_cmd__descriptor);
+  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t s0_session_cmd__pack_to_buffer
+                     (const S0SessionCmd *message,
+                      ProtobufCBuffer *buffer)
+{
+  assert(message->base.descriptor == &s0_session_cmd__descriptor);
+  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+S0SessionCmd *
+       s0_session_cmd__unpack
+                     (ProtobufCAllocator  *allocator,
+                      size_t               len,
+                      const uint8_t       *data)
+{
+  return (S0SessionCmd *)
+     protobuf_c_message_unpack (&s0_session_cmd__descriptor,
+                                allocator, len, data);
+}
+void   s0_session_cmd__free_unpacked
+                     (S0SessionCmd *message,
+                      ProtobufCAllocator *allocator)
+{
+  if(!message)
+    return;
+  assert(message->base.descriptor == &s0_session_cmd__descriptor);
+  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+void   s0_session_resp__init
+                     (S0SessionResp         *message)
+{
+  static const S0SessionResp init_value = S0_SESSION_RESP__INIT;
+  *message = init_value;
+}
+size_t s0_session_resp__get_packed_size
+                     (const S0SessionResp *message)
+{
+  assert(message->base.descriptor == &s0_session_resp__descriptor);
+  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t s0_session_resp__pack
+                     (const S0SessionResp *message,
+                      uint8_t       *out)
+{
+  assert(message->base.descriptor == &s0_session_resp__descriptor);
+  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t s0_session_resp__pack_to_buffer
+                     (const S0SessionResp *message,
+                      ProtobufCBuffer *buffer)
+{
+  assert(message->base.descriptor == &s0_session_resp__descriptor);
+  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+S0SessionResp *
+       s0_session_resp__unpack
+                     (ProtobufCAllocator  *allocator,
+                      size_t               len,
+                      const uint8_t       *data)
+{
+  return (S0SessionResp *)
+     protobuf_c_message_unpack (&s0_session_resp__descriptor,
+                                allocator, len, data);
+}
+void   s0_session_resp__free_unpacked
+                     (S0SessionResp *message,
+                      ProtobufCAllocator *allocator)
+{
+  if(!message)
+    return;
+  assert(message->base.descriptor == &s0_session_resp__descriptor);
+  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+void   sec0_payload__init
+                     (Sec0Payload         *message)
+{
+  static const Sec0Payload init_value = SEC0_PAYLOAD__INIT;
+  *message = init_value;
+}
+size_t sec0_payload__get_packed_size
+                     (const Sec0Payload *message)
+{
+  assert(message->base.descriptor == &sec0_payload__descriptor);
+  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t sec0_payload__pack
+                     (const Sec0Payload *message,
+                      uint8_t       *out)
+{
+  assert(message->base.descriptor == &sec0_payload__descriptor);
+  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t sec0_payload__pack_to_buffer
+                     (const Sec0Payload *message,
+                      ProtobufCBuffer *buffer)
+{
+  assert(message->base.descriptor == &sec0_payload__descriptor);
+  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+Sec0Payload *
+       sec0_payload__unpack
+                     (ProtobufCAllocator  *allocator,
+                      size_t               len,
+                      const uint8_t       *data)
+{
+  return (Sec0Payload *)
+     protobuf_c_message_unpack (&sec0_payload__descriptor,
+                                allocator, len, data);
+}
+void   sec0_payload__free_unpacked
+                     (Sec0Payload *message,
+                      ProtobufCAllocator *allocator)
+{
+  if(!message)
+    return;
+  assert(message->base.descriptor == &sec0_payload__descriptor);
+  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+#define s0_session_cmd__field_descriptors NULL
+#define s0_session_cmd__field_indices_by_name NULL
+#define s0_session_cmd__number_ranges NULL
+const ProtobufCMessageDescriptor s0_session_cmd__descriptor =
+{
+  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
+  "S0SessionCmd",
+  "S0SessionCmd",
+  "S0SessionCmd",
+  "",
+  sizeof(S0SessionCmd),
+  0,
+  s0_session_cmd__field_descriptors,
+  s0_session_cmd__field_indices_by_name,
+  0,  s0_session_cmd__number_ranges,
+  (ProtobufCMessageInit) s0_session_cmd__init,
+  NULL,NULL,NULL    /* reserved[123] */
+};
+static const ProtobufCFieldDescriptor s0_session_resp__field_descriptors[1] =
+{
+  {
+    "status",
+    1,
+    PROTOBUF_C_LABEL_NONE,
+    PROTOBUF_C_TYPE_ENUM,
+    0,   /* quantifier_offset */
+    offsetof(S0SessionResp, status),
+    &status__descriptor,
+    NULL,
+    0,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+};
+static const unsigned s0_session_resp__field_indices_by_name[] = {
+  0,   /* field[0] = status */
+};
+static const ProtobufCIntRange s0_session_resp__number_ranges[1 + 1] =
+{
+  { 1, 0 },
+  { 0, 1 }
+};
+const ProtobufCMessageDescriptor s0_session_resp__descriptor =
+{
+  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
+  "S0SessionResp",
+  "S0SessionResp",
+  "S0SessionResp",
+  "",
+  sizeof(S0SessionResp),
+  1,
+  s0_session_resp__field_descriptors,
+  s0_session_resp__field_indices_by_name,
+  1,  s0_session_resp__number_ranges,
+  (ProtobufCMessageInit) s0_session_resp__init,
+  NULL,NULL,NULL    /* reserved[123] */
+};
+static const ProtobufCFieldDescriptor sec0_payload__field_descriptors[3] =
+{
+  {
+    "msg",
+    1,
+    PROTOBUF_C_LABEL_NONE,
+    PROTOBUF_C_TYPE_ENUM,
+    0,   /* quantifier_offset */
+    offsetof(Sec0Payload, msg),
+    &sec0_msg_type__descriptor,
+    NULL,
+    0,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+  {
+    "sc",
+    20,
+    PROTOBUF_C_LABEL_NONE,
+    PROTOBUF_C_TYPE_MESSAGE,
+    offsetof(Sec0Payload, payload_case),
+    offsetof(Sec0Payload, sc),
+    &s0_session_cmd__descriptor,
+    NULL,
+    0 | PROTOBUF_C_FIELD_FLAG_ONEOF,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+  {
+    "sr",
+    21,
+    PROTOBUF_C_LABEL_NONE,
+    PROTOBUF_C_TYPE_MESSAGE,
+    offsetof(Sec0Payload, payload_case),
+    offsetof(Sec0Payload, sr),
+    &s0_session_resp__descriptor,
+    NULL,
+    0 | PROTOBUF_C_FIELD_FLAG_ONEOF,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+};
+static const unsigned sec0_payload__field_indices_by_name[] = {
+  0,   /* field[0] = msg */
+  1,   /* field[1] = sc */
+  2,   /* field[2] = sr */
+};
+static const ProtobufCIntRange sec0_payload__number_ranges[2 + 1] =
+{
+  { 1, 0 },
+  { 20, 1 },
+  { 0, 3 }
+};
+const ProtobufCMessageDescriptor sec0_payload__descriptor =
+{
+  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
+  "Sec0Payload",
+  "Sec0Payload",
+  "Sec0Payload",
+  "",
+  sizeof(Sec0Payload),
+  3,
+  sec0_payload__field_descriptors,
+  sec0_payload__field_indices_by_name,
+  2,  sec0_payload__number_ranges,
+  (ProtobufCMessageInit) sec0_payload__init,
+  NULL,NULL,NULL    /* reserved[123] */
+};
+static const ProtobufCEnumValue sec0_msg_type__enum_values_by_number[2] =
+{
+  { "S0_Session_Command", "SEC0_MSG_TYPE__S0_Session_Command", 0 },
+  { "S0_Session_Response", "SEC0_MSG_TYPE__S0_Session_Response", 1 },
+};
+static const ProtobufCIntRange sec0_msg_type__value_ranges[] = {
+{0, 0},{0, 2}
+};
+static const ProtobufCEnumValueIndex sec0_msg_type__enum_values_by_name[2] =
+{
+  { "S0_Session_Command", 0 },
+  { "S0_Session_Response", 1 },
+};
+const ProtobufCEnumDescriptor sec0_msg_type__descriptor =
+{
+  PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC,
+  "Sec0MsgType",
+  "Sec0MsgType",
+  "Sec0MsgType",
+  "",
+  2,
+  sec0_msg_type__enum_values_by_number,
+  2,
+  sec0_msg_type__enum_values_by_name,
+  1,
+  sec0_msg_type__value_ranges,
+  NULL,NULL,NULL,NULL   /* reserved[1234] */
+};
diff --git a/components/protocomm/proto-c/sec0.pb-c.h b/components/protocomm/proto-c/sec0.pb-c.h
new file mode 100644 (file)
index 0000000..82779e2
--- /dev/null
@@ -0,0 +1,178 @@
+/* Generated by the protocol buffer compiler.  DO NOT EDIT! */
+/* Generated from: sec0.proto */
+
+#ifndef PROTOBUF_C_sec0_2eproto__INCLUDED
+#define PROTOBUF_C_sec0_2eproto__INCLUDED
+
+#include <protobuf-c/protobuf-c.h>
+
+PROTOBUF_C__BEGIN_DECLS
+
+#if PROTOBUF_C_VERSION_NUMBER < 1003000
+# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers.
+#elif 1003000 < PROTOBUF_C_MIN_COMPILER_VERSION
+# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c.
+#endif
+
+#include "constants.pb-c.h"
+
+typedef struct _S0SessionCmd S0SessionCmd;
+typedef struct _S0SessionResp S0SessionResp;
+typedef struct _Sec0Payload Sec0Payload;
+
+
+/* --- enums --- */
+
+/*
+ * A message must be of type Cmd or Resp 
+ */
+typedef enum _Sec0MsgType {
+  SEC0_MSG_TYPE__S0_Session_Command = 0,
+  SEC0_MSG_TYPE__S0_Session_Response = 1
+    PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(SEC0_MSG_TYPE)
+} Sec0MsgType;
+
+/* --- messages --- */
+
+/*
+ * Data structure of Session command/request packet 
+ */
+struct  _S0SessionCmd
+{
+  ProtobufCMessage base;
+};
+#define S0_SESSION_CMD__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&s0_session_cmd__descriptor) \
+     }
+
+
+/*
+ * Data structure of Session response packet 
+ */
+struct  _S0SessionResp
+{
+  ProtobufCMessage base;
+  Status status;
+};
+#define S0_SESSION_RESP__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&s0_session_resp__descriptor) \
+    , STATUS__Success }
+
+
+typedef enum {
+  SEC0_PAYLOAD__PAYLOAD__NOT_SET = 0,
+  SEC0_PAYLOAD__PAYLOAD_SC = 20,
+  SEC0_PAYLOAD__PAYLOAD_SR = 21
+    PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(SEC0_PAYLOAD__PAYLOAD)
+} Sec0Payload__PayloadCase;
+
+/*
+ * Payload structure of session data 
+ */
+struct  _Sec0Payload
+{
+  ProtobufCMessage base;
+  /*
+   *!< Type of message 
+   */
+  Sec0MsgType msg;
+  Sec0Payload__PayloadCase payload_case;
+  union {
+    /*
+     *!< Payload data interpreted as Cmd 
+     */
+    S0SessionCmd *sc;
+    /*
+     *!< Payload data interpreted as Resp 
+     */
+    S0SessionResp *sr;
+  };
+};
+#define SEC0_PAYLOAD__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&sec0_payload__descriptor) \
+    , SEC0_MSG_TYPE__S0_Session_Command, SEC0_PAYLOAD__PAYLOAD__NOT_SET, {0} }
+
+
+/* S0SessionCmd methods */
+void   s0_session_cmd__init
+                     (S0SessionCmd         *message);
+size_t s0_session_cmd__get_packed_size
+                     (const S0SessionCmd   *message);
+size_t s0_session_cmd__pack
+                     (const S0SessionCmd   *message,
+                      uint8_t             *out);
+size_t s0_session_cmd__pack_to_buffer
+                     (const S0SessionCmd   *message,
+                      ProtobufCBuffer     *buffer);
+S0SessionCmd *
+       s0_session_cmd__unpack
+                     (ProtobufCAllocator  *allocator,
+                      size_t               len,
+                      const uint8_t       *data);
+void   s0_session_cmd__free_unpacked
+                     (S0SessionCmd *message,
+                      ProtobufCAllocator *allocator);
+/* S0SessionResp methods */
+void   s0_session_resp__init
+                     (S0SessionResp         *message);
+size_t s0_session_resp__get_packed_size
+                     (const S0SessionResp   *message);
+size_t s0_session_resp__pack
+                     (const S0SessionResp   *message,
+                      uint8_t             *out);
+size_t s0_session_resp__pack_to_buffer
+                     (const S0SessionResp   *message,
+                      ProtobufCBuffer     *buffer);
+S0SessionResp *
+       s0_session_resp__unpack
+                     (ProtobufCAllocator  *allocator,
+                      size_t               len,
+                      const uint8_t       *data);
+void   s0_session_resp__free_unpacked
+                     (S0SessionResp *message,
+                      ProtobufCAllocator *allocator);
+/* Sec0Payload methods */
+void   sec0_payload__init
+                     (Sec0Payload         *message);
+size_t sec0_payload__get_packed_size
+                     (const Sec0Payload   *message);
+size_t sec0_payload__pack
+                     (const Sec0Payload   *message,
+                      uint8_t             *out);
+size_t sec0_payload__pack_to_buffer
+                     (const Sec0Payload   *message,
+                      ProtobufCBuffer     *buffer);
+Sec0Payload *
+       sec0_payload__unpack
+                     (ProtobufCAllocator  *allocator,
+                      size_t               len,
+                      const uint8_t       *data);
+void   sec0_payload__free_unpacked
+                     (Sec0Payload *message,
+                      ProtobufCAllocator *allocator);
+/* --- per-message closures --- */
+
+typedef void (*S0SessionCmd_Closure)
+                 (const S0SessionCmd *message,
+                  void *closure_data);
+typedef void (*S0SessionResp_Closure)
+                 (const S0SessionResp *message,
+                  void *closure_data);
+typedef void (*Sec0Payload_Closure)
+                 (const Sec0Payload *message,
+                  void *closure_data);
+
+/* --- services --- */
+
+
+/* --- descriptors --- */
+
+extern const ProtobufCEnumDescriptor    sec0_msg_type__descriptor;
+extern const ProtobufCMessageDescriptor s0_session_cmd__descriptor;
+extern const ProtobufCMessageDescriptor s0_session_resp__descriptor;
+extern const ProtobufCMessageDescriptor sec0_payload__descriptor;
+
+PROTOBUF_C__END_DECLS
+
+
+#endif  /* PROTOBUF_C_sec0_2eproto__INCLUDED */
diff --git a/components/protocomm/proto-c/sec1.pb-c.c b/components/protocomm/proto-c/sec1.pb-c.c
new file mode 100644 (file)
index 0000000..c749db4
--- /dev/null
@@ -0,0 +1,549 @@
+/* Generated by the protocol buffer compiler.  DO NOT EDIT! */
+/* Generated from: sec1.proto */
+
+/* Do not generate deprecated warnings for self */
+#ifndef PROTOBUF_C__NO_DEPRECATED
+#define PROTOBUF_C__NO_DEPRECATED
+#endif
+
+#include "sec1.pb-c.h"
+void   session_cmd1__init
+                     (SessionCmd1         *message)
+{
+  static const SessionCmd1 init_value = SESSION_CMD1__INIT;
+  *message = init_value;
+}
+size_t session_cmd1__get_packed_size
+                     (const SessionCmd1 *message)
+{
+  assert(message->base.descriptor == &session_cmd1__descriptor);
+  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t session_cmd1__pack
+                     (const SessionCmd1 *message,
+                      uint8_t       *out)
+{
+  assert(message->base.descriptor == &session_cmd1__descriptor);
+  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t session_cmd1__pack_to_buffer
+                     (const SessionCmd1 *message,
+                      ProtobufCBuffer *buffer)
+{
+  assert(message->base.descriptor == &session_cmd1__descriptor);
+  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+SessionCmd1 *
+       session_cmd1__unpack
+                     (ProtobufCAllocator  *allocator,
+                      size_t               len,
+                      const uint8_t       *data)
+{
+  return (SessionCmd1 *)
+     protobuf_c_message_unpack (&session_cmd1__descriptor,
+                                allocator, len, data);
+}
+void   session_cmd1__free_unpacked
+                     (SessionCmd1 *message,
+                      ProtobufCAllocator *allocator)
+{
+  if(!message)
+    return;
+  assert(message->base.descriptor == &session_cmd1__descriptor);
+  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+void   session_resp1__init
+                     (SessionResp1         *message)
+{
+  static const SessionResp1 init_value = SESSION_RESP1__INIT;
+  *message = init_value;
+}
+size_t session_resp1__get_packed_size
+                     (const SessionResp1 *message)
+{
+  assert(message->base.descriptor == &session_resp1__descriptor);
+  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t session_resp1__pack
+                     (const SessionResp1 *message,
+                      uint8_t       *out)
+{
+  assert(message->base.descriptor == &session_resp1__descriptor);
+  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t session_resp1__pack_to_buffer
+                     (const SessionResp1 *message,
+                      ProtobufCBuffer *buffer)
+{
+  assert(message->base.descriptor == &session_resp1__descriptor);
+  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+SessionResp1 *
+       session_resp1__unpack
+                     (ProtobufCAllocator  *allocator,
+                      size_t               len,
+                      const uint8_t       *data)
+{
+  return (SessionResp1 *)
+     protobuf_c_message_unpack (&session_resp1__descriptor,
+                                allocator, len, data);
+}
+void   session_resp1__free_unpacked
+                     (SessionResp1 *message,
+                      ProtobufCAllocator *allocator)
+{
+  if(!message)
+    return;
+  assert(message->base.descriptor == &session_resp1__descriptor);
+  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+void   session_cmd0__init
+                     (SessionCmd0         *message)
+{
+  static const SessionCmd0 init_value = SESSION_CMD0__INIT;
+  *message = init_value;
+}
+size_t session_cmd0__get_packed_size
+                     (const SessionCmd0 *message)
+{
+  assert(message->base.descriptor == &session_cmd0__descriptor);
+  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t session_cmd0__pack
+                     (const SessionCmd0 *message,
+                      uint8_t       *out)
+{
+  assert(message->base.descriptor == &session_cmd0__descriptor);
+  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t session_cmd0__pack_to_buffer
+                     (const SessionCmd0 *message,
+                      ProtobufCBuffer *buffer)
+{
+  assert(message->base.descriptor == &session_cmd0__descriptor);
+  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+SessionCmd0 *
+       session_cmd0__unpack
+                     (ProtobufCAllocator  *allocator,
+                      size_t               len,
+                      const uint8_t       *data)
+{
+  return (SessionCmd0 *)
+     protobuf_c_message_unpack (&session_cmd0__descriptor,
+                                allocator, len, data);
+}
+void   session_cmd0__free_unpacked
+                     (SessionCmd0 *message,
+                      ProtobufCAllocator *allocator)
+{
+  if(!message)
+    return;
+  assert(message->base.descriptor == &session_cmd0__descriptor);
+  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+void   session_resp0__init
+                     (SessionResp0         *message)
+{
+  static const SessionResp0 init_value = SESSION_RESP0__INIT;
+  *message = init_value;
+}
+size_t session_resp0__get_packed_size
+                     (const SessionResp0 *message)
+{
+  assert(message->base.descriptor == &session_resp0__descriptor);
+  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t session_resp0__pack
+                     (const SessionResp0 *message,
+                      uint8_t       *out)
+{
+  assert(message->base.descriptor == &session_resp0__descriptor);
+  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t session_resp0__pack_to_buffer
+                     (const SessionResp0 *message,
+                      ProtobufCBuffer *buffer)
+{
+  assert(message->base.descriptor == &session_resp0__descriptor);
+  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+SessionResp0 *
+       session_resp0__unpack
+                     (ProtobufCAllocator  *allocator,
+                      size_t               len,
+                      const uint8_t       *data)
+{
+  return (SessionResp0 *)
+     protobuf_c_message_unpack (&session_resp0__descriptor,
+                                allocator, len, data);
+}
+void   session_resp0__free_unpacked
+                     (SessionResp0 *message,
+                      ProtobufCAllocator *allocator)
+{
+  if(!message)
+    return;
+  assert(message->base.descriptor == &session_resp0__descriptor);
+  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+void   sec1_payload__init
+                     (Sec1Payload         *message)
+{
+  static const Sec1Payload init_value = SEC1_PAYLOAD__INIT;
+  *message = init_value;
+}
+size_t sec1_payload__get_packed_size
+                     (const Sec1Payload *message)
+{
+  assert(message->base.descriptor == &sec1_payload__descriptor);
+  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t sec1_payload__pack
+                     (const Sec1Payload *message,
+                      uint8_t       *out)
+{
+  assert(message->base.descriptor == &sec1_payload__descriptor);
+  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t sec1_payload__pack_to_buffer
+                     (const Sec1Payload *message,
+                      ProtobufCBuffer *buffer)
+{
+  assert(message->base.descriptor == &sec1_payload__descriptor);
+  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+Sec1Payload *
+       sec1_payload__unpack
+                     (ProtobufCAllocator  *allocator,
+                      size_t               len,
+                      const uint8_t       *data)
+{
+  return (Sec1Payload *)
+     protobuf_c_message_unpack (&sec1_payload__descriptor,
+                                allocator, len, data);
+}
+void   sec1_payload__free_unpacked
+                     (Sec1Payload *message,
+                      ProtobufCAllocator *allocator)
+{
+  if(!message)
+    return;
+  assert(message->base.descriptor == &sec1_payload__descriptor);
+  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+static const ProtobufCFieldDescriptor session_cmd1__field_descriptors[1] =
+{
+  {
+    "client_verify_data",
+    2,
+    PROTOBUF_C_LABEL_NONE,
+    PROTOBUF_C_TYPE_BYTES,
+    0,   /* quantifier_offset */
+    offsetof(SessionCmd1, client_verify_data),
+    NULL,
+    NULL,
+    0,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+};
+static const unsigned session_cmd1__field_indices_by_name[] = {
+  0,   /* field[0] = client_verify_data */
+};
+static const ProtobufCIntRange session_cmd1__number_ranges[1 + 1] =
+{
+  { 2, 0 },
+  { 0, 1 }
+};
+const ProtobufCMessageDescriptor session_cmd1__descriptor =
+{
+  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
+  "SessionCmd1",
+  "SessionCmd1",
+  "SessionCmd1",
+  "",
+  sizeof(SessionCmd1),
+  1,
+  session_cmd1__field_descriptors,
+  session_cmd1__field_indices_by_name,
+  1,  session_cmd1__number_ranges,
+  (ProtobufCMessageInit) session_cmd1__init,
+  NULL,NULL,NULL    /* reserved[123] */
+};
+static const ProtobufCFieldDescriptor session_resp1__field_descriptors[2] =
+{
+  {
+    "status",
+    1,
+    PROTOBUF_C_LABEL_NONE,
+    PROTOBUF_C_TYPE_ENUM,
+    0,   /* quantifier_offset */
+    offsetof(SessionResp1, status),
+    &status__descriptor,
+    NULL,
+    0,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+  {
+    "device_verify_data",
+    3,
+    PROTOBUF_C_LABEL_NONE,
+    PROTOBUF_C_TYPE_BYTES,
+    0,   /* quantifier_offset */
+    offsetof(SessionResp1, device_verify_data),
+    NULL,
+    NULL,
+    0,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+};
+static const unsigned session_resp1__field_indices_by_name[] = {
+  1,   /* field[1] = device_verify_data */
+  0,   /* field[0] = status */
+};
+static const ProtobufCIntRange session_resp1__number_ranges[2 + 1] =
+{
+  { 1, 0 },
+  { 3, 1 },
+  { 0, 2 }
+};
+const ProtobufCMessageDescriptor session_resp1__descriptor =
+{
+  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
+  "SessionResp1",
+  "SessionResp1",
+  "SessionResp1",
+  "",
+  sizeof(SessionResp1),
+  2,
+  session_resp1__field_descriptors,
+  session_resp1__field_indices_by_name,
+  2,  session_resp1__number_ranges,
+  (ProtobufCMessageInit) session_resp1__init,
+  NULL,NULL,NULL    /* reserved[123] */
+};
+static const ProtobufCFieldDescriptor session_cmd0__field_descriptors[1] =
+{
+  {
+    "client_pubkey",
+    1,
+    PROTOBUF_C_LABEL_NONE,
+    PROTOBUF_C_TYPE_BYTES,
+    0,   /* quantifier_offset */
+    offsetof(SessionCmd0, client_pubkey),
+    NULL,
+    NULL,
+    0,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+};
+static const unsigned session_cmd0__field_indices_by_name[] = {
+  0,   /* field[0] = client_pubkey */
+};
+static const ProtobufCIntRange session_cmd0__number_ranges[1 + 1] =
+{
+  { 1, 0 },
+  { 0, 1 }
+};
+const ProtobufCMessageDescriptor session_cmd0__descriptor =
+{
+  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
+  "SessionCmd0",
+  "SessionCmd0",
+  "SessionCmd0",
+  "",
+  sizeof(SessionCmd0),
+  1,
+  session_cmd0__field_descriptors,
+  session_cmd0__field_indices_by_name,
+  1,  session_cmd0__number_ranges,
+  (ProtobufCMessageInit) session_cmd0__init,
+  NULL,NULL,NULL    /* reserved[123] */
+};
+static const ProtobufCFieldDescriptor session_resp0__field_descriptors[3] =
+{
+  {
+    "status",
+    1,
+    PROTOBUF_C_LABEL_NONE,
+    PROTOBUF_C_TYPE_ENUM,
+    0,   /* quantifier_offset */
+    offsetof(SessionResp0, status),
+    &status__descriptor,
+    NULL,
+    0,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+  {
+    "device_pubkey",
+    2,
+    PROTOBUF_C_LABEL_NONE,
+    PROTOBUF_C_TYPE_BYTES,
+    0,   /* quantifier_offset */
+    offsetof(SessionResp0, device_pubkey),
+    NULL,
+    NULL,
+    0,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+  {
+    "device_random",
+    3,
+    PROTOBUF_C_LABEL_NONE,
+    PROTOBUF_C_TYPE_BYTES,
+    0,   /* quantifier_offset */
+    offsetof(SessionResp0, device_random),
+    NULL,
+    NULL,
+    0,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+};
+static const unsigned session_resp0__field_indices_by_name[] = {
+  1,   /* field[1] = device_pubkey */
+  2,   /* field[2] = device_random */
+  0,   /* field[0] = status */
+};
+static const ProtobufCIntRange session_resp0__number_ranges[1 + 1] =
+{
+  { 1, 0 },
+  { 0, 3 }
+};
+const ProtobufCMessageDescriptor session_resp0__descriptor =
+{
+  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
+  "SessionResp0",
+  "SessionResp0",
+  "SessionResp0",
+  "",
+  sizeof(SessionResp0),
+  3,
+  session_resp0__field_descriptors,
+  session_resp0__field_indices_by_name,
+  1,  session_resp0__number_ranges,
+  (ProtobufCMessageInit) session_resp0__init,
+  NULL,NULL,NULL    /* reserved[123] */
+};
+static const ProtobufCFieldDescriptor sec1_payload__field_descriptors[5] =
+{
+  {
+    "msg",
+    1,
+    PROTOBUF_C_LABEL_NONE,
+    PROTOBUF_C_TYPE_ENUM,
+    0,   /* quantifier_offset */
+    offsetof(Sec1Payload, msg),
+    &sec1_msg_type__descriptor,
+    NULL,
+    0,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+  {
+    "sc0",
+    20,
+    PROTOBUF_C_LABEL_NONE,
+    PROTOBUF_C_TYPE_MESSAGE,
+    offsetof(Sec1Payload, payload_case),
+    offsetof(Sec1Payload, sc0),
+    &session_cmd0__descriptor,
+    NULL,
+    0 | PROTOBUF_C_FIELD_FLAG_ONEOF,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+  {
+    "sr0",
+    21,
+    PROTOBUF_C_LABEL_NONE,
+    PROTOBUF_C_TYPE_MESSAGE,
+    offsetof(Sec1Payload, payload_case),
+    offsetof(Sec1Payload, sr0),
+    &session_resp0__descriptor,
+    NULL,
+    0 | PROTOBUF_C_FIELD_FLAG_ONEOF,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+  {
+    "sc1",
+    22,
+    PROTOBUF_C_LABEL_NONE,
+    PROTOBUF_C_TYPE_MESSAGE,
+    offsetof(Sec1Payload, payload_case),
+    offsetof(Sec1Payload, sc1),
+    &session_cmd1__descriptor,
+    NULL,
+    0 | PROTOBUF_C_FIELD_FLAG_ONEOF,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+  {
+    "sr1",
+    23,
+    PROTOBUF_C_LABEL_NONE,
+    PROTOBUF_C_TYPE_MESSAGE,
+    offsetof(Sec1Payload, payload_case),
+    offsetof(Sec1Payload, sr1),
+    &session_resp1__descriptor,
+    NULL,
+    0 | PROTOBUF_C_FIELD_FLAG_ONEOF,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+};
+static const unsigned sec1_payload__field_indices_by_name[] = {
+  0,   /* field[0] = msg */
+  1,   /* field[1] = sc0 */
+  3,   /* field[3] = sc1 */
+  2,   /* field[2] = sr0 */
+  4,   /* field[4] = sr1 */
+};
+static const ProtobufCIntRange sec1_payload__number_ranges[2 + 1] =
+{
+  { 1, 0 },
+  { 20, 1 },
+  { 0, 5 }
+};
+const ProtobufCMessageDescriptor sec1_payload__descriptor =
+{
+  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
+  "Sec1Payload",
+  "Sec1Payload",
+  "Sec1Payload",
+  "",
+  sizeof(Sec1Payload),
+  5,
+  sec1_payload__field_descriptors,
+  sec1_payload__field_indices_by_name,
+  2,  sec1_payload__number_ranges,
+  (ProtobufCMessageInit) sec1_payload__init,
+  NULL,NULL,NULL    /* reserved[123] */
+};
+static const ProtobufCEnumValue sec1_msg_type__enum_values_by_number[4] =
+{
+  { "Session_Command0", "SEC1_MSG_TYPE__Session_Command0", 0 },
+  { "Session_Response0", "SEC1_MSG_TYPE__Session_Response0", 1 },
+  { "Session_Command1", "SEC1_MSG_TYPE__Session_Command1", 2 },
+  { "Session_Response1", "SEC1_MSG_TYPE__Session_Response1", 3 },
+};
+static const ProtobufCIntRange sec1_msg_type__value_ranges[] = {
+{0, 0},{0, 4}
+};
+static const ProtobufCEnumValueIndex sec1_msg_type__enum_values_by_name[4] =
+{
+  { "Session_Command0", 0 },
+  { "Session_Command1", 2 },
+  { "Session_Response0", 1 },
+  { "Session_Response1", 3 },
+};
+const ProtobufCEnumDescriptor sec1_msg_type__descriptor =
+{
+  PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC,
+  "Sec1MsgType",
+  "Sec1MsgType",
+  "Sec1MsgType",
+  "",
+  4,
+  sec1_msg_type__enum_values_by_number,
+  4,
+  sec1_msg_type__enum_values_by_name,
+  1,
+  sec1_msg_type__value_ranges,
+  NULL,NULL,NULL,NULL   /* reserved[1234] */
+};
diff --git a/components/protocomm/proto-c/sec1.pb-c.h b/components/protocomm/proto-c/sec1.pb-c.h
new file mode 100644 (file)
index 0000000..650be50
--- /dev/null
@@ -0,0 +1,268 @@
+/* Generated by the protocol buffer compiler.  DO NOT EDIT! */
+/* Generated from: sec1.proto */
+
+#ifndef PROTOBUF_C_sec1_2eproto__INCLUDED
+#define PROTOBUF_C_sec1_2eproto__INCLUDED
+
+#include <protobuf-c/protobuf-c.h>
+
+PROTOBUF_C__BEGIN_DECLS
+
+#if PROTOBUF_C_VERSION_NUMBER < 1003000
+# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers.
+#elif 1003000 < PROTOBUF_C_MIN_COMPILER_VERSION
+# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c.
+#endif
+
+#include "constants.pb-c.h"
+
+typedef struct _SessionCmd1 SessionCmd1;
+typedef struct _SessionResp1 SessionResp1;
+typedef struct _SessionCmd0 SessionCmd0;
+typedef struct _SessionResp0 SessionResp0;
+typedef struct _Sec1Payload Sec1Payload;
+
+
+/* --- enums --- */
+
+/*
+ * A message must be of type Cmd0 / Cmd1 / Resp0 / Resp1 
+ */
+typedef enum _Sec1MsgType {
+  SEC1_MSG_TYPE__Session_Command0 = 0,
+  SEC1_MSG_TYPE__Session_Response0 = 1,
+  SEC1_MSG_TYPE__Session_Command1 = 2,
+  SEC1_MSG_TYPE__Session_Response1 = 3
+    PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(SEC1_MSG_TYPE)
+} Sec1MsgType;
+
+/* --- messages --- */
+
+/*
+ * Data structure of Session command1 packet 
+ */
+struct  _SessionCmd1
+{
+  ProtobufCMessage base;
+  ProtobufCBinaryData client_verify_data;
+};
+#define SESSION_CMD1__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&session_cmd1__descriptor) \
+    , {0,NULL} }
+
+
+/*
+ * Data structure of Session response1 packet 
+ */
+struct  _SessionResp1
+{
+  ProtobufCMessage base;
+  Status status;
+  ProtobufCBinaryData device_verify_data;
+};
+#define SESSION_RESP1__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&session_resp1__descriptor) \
+    , STATUS__Success, {0,NULL} }
+
+
+/*
+ * Data structure of Session command0 packet 
+ */
+struct  _SessionCmd0
+{
+  ProtobufCMessage base;
+  ProtobufCBinaryData client_pubkey;
+};
+#define SESSION_CMD0__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&session_cmd0__descriptor) \
+    , {0,NULL} }
+
+
+/*
+ * Data structure of Session response0 packet 
+ */
+struct  _SessionResp0
+{
+  ProtobufCMessage base;
+  Status status;
+  ProtobufCBinaryData device_pubkey;
+  ProtobufCBinaryData device_random;
+};
+#define SESSION_RESP0__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&session_resp0__descriptor) \
+    , STATUS__Success, {0,NULL}, {0,NULL} }
+
+
+typedef enum {
+  SEC1_PAYLOAD__PAYLOAD__NOT_SET = 0,
+  SEC1_PAYLOAD__PAYLOAD_SC0 = 20,
+  SEC1_PAYLOAD__PAYLOAD_SR0 = 21,
+  SEC1_PAYLOAD__PAYLOAD_SC1 = 22,
+  SEC1_PAYLOAD__PAYLOAD_SR1 = 23
+    PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(SEC1_PAYLOAD__PAYLOAD)
+} Sec1Payload__PayloadCase;
+
+/*
+ * Payload structure of session data 
+ */
+struct  _Sec1Payload
+{
+  ProtobufCMessage base;
+  /*
+   *!< Type of message 
+   */
+  Sec1MsgType msg;
+  Sec1Payload__PayloadCase payload_case;
+  union {
+    /*
+     *!< Payload data interpreted as Cmd0 
+     */
+    SessionCmd0 *sc0;
+    /*
+     *!< Payload data interpreted as Resp0 
+     */
+    SessionResp0 *sr0;
+    /*
+     *!< Payload data interpreted as Cmd1 
+     */
+    SessionCmd1 *sc1;
+    /*
+     *!< Payload data interpreted as Resp1 
+     */
+    SessionResp1 *sr1;
+  };
+};
+#define SEC1_PAYLOAD__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&sec1_payload__descriptor) \
+    , SEC1_MSG_TYPE__Session_Command0, SEC1_PAYLOAD__PAYLOAD__NOT_SET, {0} }
+
+
+/* SessionCmd1 methods */
+void   session_cmd1__init
+                     (SessionCmd1         *message);
+size_t session_cmd1__get_packed_size
+                     (const SessionCmd1   *message);
+size_t session_cmd1__pack
+                     (const SessionCmd1   *message,
+                      uint8_t             *out);
+size_t session_cmd1__pack_to_buffer
+                     (const SessionCmd1   *message,
+                      ProtobufCBuffer     *buffer);
+SessionCmd1 *
+       session_cmd1__unpack
+                     (ProtobufCAllocator  *allocator,
+                      size_t               len,
+                      const uint8_t       *data);
+void   session_cmd1__free_unpacked
+                     (SessionCmd1 *message,
+                      ProtobufCAllocator *allocator);
+/* SessionResp1 methods */
+void   session_resp1__init
+                     (SessionResp1         *message);
+size_t session_resp1__get_packed_size
+                     (const SessionResp1   *message);
+size_t session_resp1__pack
+                     (const SessionResp1   *message,
+                      uint8_t             *out);
+size_t session_resp1__pack_to_buffer
+                     (const SessionResp1   *message,
+                      ProtobufCBuffer     *buffer);
+SessionResp1 *
+       session_resp1__unpack
+                     (ProtobufCAllocator  *allocator,
+                      size_t               len,
+                      const uint8_t       *data);
+void   session_resp1__free_unpacked
+                     (SessionResp1 *message,
+                      ProtobufCAllocator *allocator);
+/* SessionCmd0 methods */
+void   session_cmd0__init
+                     (SessionCmd0         *message);
+size_t session_cmd0__get_packed_size
+                     (const SessionCmd0   *message);
+size_t session_cmd0__pack
+                     (const SessionCmd0   *message,
+                      uint8_t             *out);
+size_t session_cmd0__pack_to_buffer
+                     (const SessionCmd0   *message,
+                      ProtobufCBuffer     *buffer);
+SessionCmd0 *
+       session_cmd0__unpack
+                     (ProtobufCAllocator  *allocator,
+                      size_t               len,
+                      const uint8_t       *data);
+void   session_cmd0__free_unpacked
+                     (SessionCmd0 *message,
+                      ProtobufCAllocator *allocator);
+/* SessionResp0 methods */
+void   session_resp0__init
+                     (SessionResp0         *message);
+size_t session_resp0__get_packed_size
+                     (const SessionResp0   *message);
+size_t session_resp0__pack
+                     (const SessionResp0   *message,
+                      uint8_t             *out);
+size_t session_resp0__pack_to_buffer
+                     (const SessionResp0   *message,
+                      ProtobufCBuffer     *buffer);
+SessionResp0 *
+       session_resp0__unpack
+                     (ProtobufCAllocator  *allocator,
+                      size_t               len,
+                      const uint8_t       *data);
+void   session_resp0__free_unpacked
+                     (SessionResp0 *message,
+                      ProtobufCAllocator *allocator);
+/* Sec1Payload methods */
+void   sec1_payload__init
+                     (Sec1Payload         *message);
+size_t sec1_payload__get_packed_size
+                     (const Sec1Payload   *message);
+size_t sec1_payload__pack
+                     (const Sec1Payload   *message,
+                      uint8_t             *out);
+size_t sec1_payload__pack_to_buffer
+                     (const Sec1Payload   *message,
+                      ProtobufCBuffer     *buffer);
+Sec1Payload *
+       sec1_payload__unpack
+                     (ProtobufCAllocator  *allocator,
+                      size_t               len,
+                      const uint8_t       *data);
+void   sec1_payload__free_unpacked
+                     (Sec1Payload *message,
+                      ProtobufCAllocator *allocator);
+/* --- per-message closures --- */
+
+typedef void (*SessionCmd1_Closure)
+                 (const SessionCmd1 *message,
+                  void *closure_data);
+typedef void (*SessionResp1_Closure)
+                 (const SessionResp1 *message,
+                  void *closure_data);
+typedef void (*SessionCmd0_Closure)
+                 (const SessionCmd0 *message,
+                  void *closure_data);
+typedef void (*SessionResp0_Closure)
+                 (const SessionResp0 *message,
+                  void *closure_data);
+typedef void (*Sec1Payload_Closure)
+                 (const Sec1Payload *message,
+                  void *closure_data);
+
+/* --- services --- */
+
+
+/* --- descriptors --- */
+
+extern const ProtobufCEnumDescriptor    sec1_msg_type__descriptor;
+extern const ProtobufCMessageDescriptor session_cmd1__descriptor;
+extern const ProtobufCMessageDescriptor session_resp1__descriptor;
+extern const ProtobufCMessageDescriptor session_cmd0__descriptor;
+extern const ProtobufCMessageDescriptor session_resp0__descriptor;
+extern const ProtobufCMessageDescriptor sec1_payload__descriptor;
+
+PROTOBUF_C__END_DECLS
+
+
+#endif  /* PROTOBUF_C_sec1_2eproto__INCLUDED */
diff --git a/components/protocomm/proto-c/session.pb-c.c b/components/protocomm/proto-c/session.pb-c.c
new file mode 100644 (file)
index 0000000..59e8447
--- /dev/null
@@ -0,0 +1,147 @@
+/* Generated by the protocol buffer compiler.  DO NOT EDIT! */
+/* Generated from: session.proto */
+
+/* Do not generate deprecated warnings for self */
+#ifndef PROTOBUF_C__NO_DEPRECATED
+#define PROTOBUF_C__NO_DEPRECATED
+#endif
+
+#include "session.pb-c.h"
+void   session_data__init
+                     (SessionData         *message)
+{
+  static const SessionData init_value = SESSION_DATA__INIT;
+  *message = init_value;
+}
+size_t session_data__get_packed_size
+                     (const SessionData *message)
+{
+  assert(message->base.descriptor == &session_data__descriptor);
+  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t session_data__pack
+                     (const SessionData *message,
+                      uint8_t       *out)
+{
+  assert(message->base.descriptor == &session_data__descriptor);
+  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t session_data__pack_to_buffer
+                     (const SessionData *message,
+                      ProtobufCBuffer *buffer)
+{
+  assert(message->base.descriptor == &session_data__descriptor);
+  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+SessionData *
+       session_data__unpack
+                     (ProtobufCAllocator  *allocator,
+                      size_t               len,
+                      const uint8_t       *data)
+{
+  return (SessionData *)
+     protobuf_c_message_unpack (&session_data__descriptor,
+                                allocator, len, data);
+}
+void   session_data__free_unpacked
+                     (SessionData *message,
+                      ProtobufCAllocator *allocator)
+{
+  if(!message)
+    return;
+  assert(message->base.descriptor == &session_data__descriptor);
+  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+static const ProtobufCFieldDescriptor session_data__field_descriptors[3] =
+{
+  {
+    "sec_ver",
+    2,
+    PROTOBUF_C_LABEL_NONE,
+    PROTOBUF_C_TYPE_ENUM,
+    0,   /* quantifier_offset */
+    offsetof(SessionData, sec_ver),
+    &sec_scheme_version__descriptor,
+    NULL,
+    0,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+  {
+    "sec0",
+    10,
+    PROTOBUF_C_LABEL_NONE,
+    PROTOBUF_C_TYPE_MESSAGE,
+    offsetof(SessionData, proto_case),
+    offsetof(SessionData, sec0),
+    &sec0_payload__descriptor,
+    NULL,
+    0 | PROTOBUF_C_FIELD_FLAG_ONEOF,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+  {
+    "sec1",
+    11,
+    PROTOBUF_C_LABEL_NONE,
+    PROTOBUF_C_TYPE_MESSAGE,
+    offsetof(SessionData, proto_case),
+    offsetof(SessionData, sec1),
+    &sec1_payload__descriptor,
+    NULL,
+    0 | PROTOBUF_C_FIELD_FLAG_ONEOF,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+};
+static const unsigned session_data__field_indices_by_name[] = {
+  1,   /* field[1] = sec0 */
+  2,   /* field[2] = sec1 */
+  0,   /* field[0] = sec_ver */
+};
+static const ProtobufCIntRange session_data__number_ranges[2 + 1] =
+{
+  { 2, 0 },
+  { 10, 1 },
+  { 0, 3 }
+};
+const ProtobufCMessageDescriptor session_data__descriptor =
+{
+  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
+  "SessionData",
+  "SessionData",
+  "SessionData",
+  "",
+  sizeof(SessionData),
+  3,
+  session_data__field_descriptors,
+  session_data__field_indices_by_name,
+  2,  session_data__number_ranges,
+  (ProtobufCMessageInit) session_data__init,
+  NULL,NULL,NULL    /* reserved[123] */
+};
+static const ProtobufCEnumValue sec_scheme_version__enum_values_by_number[2] =
+{
+  { "SecScheme0", "SEC_SCHEME_VERSION__SecScheme0", 0 },
+  { "SecScheme1", "SEC_SCHEME_VERSION__SecScheme1", 1 },
+};
+static const ProtobufCIntRange sec_scheme_version__value_ranges[] = {
+{0, 0},{0, 2}
+};
+static const ProtobufCEnumValueIndex sec_scheme_version__enum_values_by_name[2] =
+{
+  { "SecScheme0", 0 },
+  { "SecScheme1", 1 },
+};
+const ProtobufCEnumDescriptor sec_scheme_version__descriptor =
+{
+  PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC,
+  "SecSchemeVersion",
+  "SecSchemeVersion",
+  "SecSchemeVersion",
+  "",
+  2,
+  sec_scheme_version__enum_values_by_number,
+  2,
+  sec_scheme_version__enum_values_by_name,
+  1,
+  sec_scheme_version__value_ranges,
+  NULL,NULL,NULL,NULL   /* reserved[1234] */
+};
diff --git a/components/protocomm/proto-c/session.pb-c.h b/components/protocomm/proto-c/session.pb-c.h
new file mode 100644 (file)
index 0000000..50bded1
--- /dev/null
@@ -0,0 +1,114 @@
+/* Generated by the protocol buffer compiler.  DO NOT EDIT! */
+/* Generated from: session.proto */
+
+#ifndef PROTOBUF_C_session_2eproto__INCLUDED
+#define PROTOBUF_C_session_2eproto__INCLUDED
+
+#include <protobuf-c/protobuf-c.h>
+
+PROTOBUF_C__BEGIN_DECLS
+
+#if PROTOBUF_C_VERSION_NUMBER < 1003000
+# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers.
+#elif 1003000 < PROTOBUF_C_MIN_COMPILER_VERSION
+# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c.
+#endif
+
+#include "sec0.pb-c.h"
+#include "sec1.pb-c.h"
+
+typedef struct _SessionData SessionData;
+
+
+/* --- enums --- */
+
+/*
+ * Allowed values for the type of security
+ * being used in a protocomm session 
+ */
+typedef enum _SecSchemeVersion {
+  /*
+   *!< Unsecured - plaintext communication 
+   */
+  SEC_SCHEME_VERSION__SecScheme0 = 0,
+  /*
+   *!< Security scheme 1 - Curve25519 + AES-256-CTR
+   */
+  SEC_SCHEME_VERSION__SecScheme1 = 1
+    PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(SEC_SCHEME_VERSION)
+} SecSchemeVersion;
+
+/* --- messages --- */
+
+typedef enum {
+  SESSION_DATA__PROTO__NOT_SET = 0,
+  SESSION_DATA__PROTO_SEC0 = 10,
+  SESSION_DATA__PROTO_SEC1 = 11
+    PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(SESSION_DATA__PROTO)
+} SessionData__ProtoCase;
+
+/*
+ * Data structure exchanged when establishing
+ * secure session between Host and Client 
+ */
+struct  _SessionData
+{
+  ProtobufCMessage base;
+  /*
+   *!< Type of security 
+   */
+  SecSchemeVersion sec_ver;
+  SessionData__ProtoCase proto_case;
+  union {
+    /*
+     *!< Payload data in case of security 0 
+     */
+    Sec0Payload *sec0;
+    /*
+     *!< Payload data in case of security 1 
+     */
+    Sec1Payload *sec1;
+  };
+};
+#define SESSION_DATA__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&session_data__descriptor) \
+    , SEC_SCHEME_VERSION__SecScheme0, SESSION_DATA__PROTO__NOT_SET, {0} }
+
+
+/* SessionData methods */
+void   session_data__init
+                     (SessionData         *message);
+size_t session_data__get_packed_size
+                     (const SessionData   *message);
+size_t session_data__pack
+                     (const SessionData   *message,
+                      uint8_t             *out);
+size_t session_data__pack_to_buffer
+                     (const SessionData   *message,
+                      ProtobufCBuffer     *buffer);
+SessionData *
+       session_data__unpack
+                     (ProtobufCAllocator  *allocator,
+                      size_t               len,
+                      const uint8_t       *data);
+void   session_data__free_unpacked
+                     (SessionData *message,
+                      ProtobufCAllocator *allocator);
+/* --- per-message closures --- */
+
+typedef void (*SessionData_Closure)
+                 (const SessionData *message,
+                  void *closure_data);
+
+/* --- services --- */
+
+
+/* --- descriptors --- */
+
+extern const ProtobufCEnumDescriptor    sec_scheme_version__descriptor;
+extern const ProtobufCMessageDescriptor session_data__descriptor;
+
+PROTOBUF_C__END_DECLS
+
+
+#endif  /* PROTOBUF_C_session_2eproto__INCLUDED */
diff --git a/components/protocomm/python/constants_pb2.py b/components/protocomm/python/constants_pb2.py
new file mode 100644 (file)
index 0000000..ed5a47f
--- /dev/null
@@ -0,0 +1,87 @@
+# Generated by the protocol buffer compiler.  DO NOT EDIT!
+# source: constants.proto
+
+import sys
+_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
+from google.protobuf.internal import enum_type_wrapper
+from google.protobuf import descriptor as _descriptor
+from google.protobuf import message as _message
+from google.protobuf import reflection as _reflection
+from google.protobuf import symbol_database as _symbol_database
+from google.protobuf import descriptor_pb2
+# @@protoc_insertion_point(imports)
+
+_sym_db = _symbol_database.Default()
+
+
+
+
+DESCRIPTOR = _descriptor.FileDescriptor(
+  name='constants.proto',
+  package='',
+  syntax='proto3',
+  serialized_pb=_b('\n\x0f\x63onstants.proto*\x9f\x01\n\x06Status\x12\x0b\n\x07Success\x10\x00\x12\x14\n\x10InvalidSecScheme\x10\x01\x12\x10\n\x0cInvalidProto\x10\x02\x12\x13\n\x0fTooManySessions\x10\x03\x12\x13\n\x0fInvalidArgument\x10\x04\x12\x11\n\rInternalError\x10\x05\x12\x0f\n\x0b\x43ryptoError\x10\x06\x12\x12\n\x0eInvalidSession\x10\x07\x62\x06proto3')
+)
+
+_STATUS = _descriptor.EnumDescriptor(
+  name='Status',
+  full_name='Status',
+  filename=None,
+  file=DESCRIPTOR,
+  values=[
+    _descriptor.EnumValueDescriptor(
+      name='Success', index=0, number=0,
+      options=None,
+      type=None),
+    _descriptor.EnumValueDescriptor(
+      name='InvalidSecScheme', index=1, number=1,
+      options=None,
+      type=None),
+    _descriptor.EnumValueDescriptor(
+      name='InvalidProto', index=2, number=2,
+      options=None,
+      type=None),
+    _descriptor.EnumValueDescriptor(
+      name='TooManySessions', index=3, number=3,
+      options=None,
+      type=None),
+    _descriptor.EnumValueDescriptor(
+      name='InvalidArgument', index=4, number=4,
+      options=None,
+      type=None),
+    _descriptor.EnumValueDescriptor(
+      name='InternalError', index=5, number=5,
+      options=None,
+      type=None),
+    _descriptor.EnumValueDescriptor(
+      name='CryptoError', index=6, number=6,
+      options=None,
+      type=None),
+    _descriptor.EnumValueDescriptor(
+      name='InvalidSession', index=7, number=7,
+      options=None,
+      type=None),
+  ],
+  containing_type=None,
+  options=None,
+  serialized_start=20,
+  serialized_end=179,
+)
+_sym_db.RegisterEnumDescriptor(_STATUS)
+
+Status = enum_type_wrapper.EnumTypeWrapper(_STATUS)
+Success = 0
+InvalidSecScheme = 1
+InvalidProto = 2
+TooManySessions = 3
+InvalidArgument = 4
+InternalError = 5
+CryptoError = 6
+InvalidSession = 7
+
+
+DESCRIPTOR.enum_types_by_name['Status'] = _STATUS
+_sym_db.RegisterFileDescriptor(DESCRIPTOR)
+
+
+# @@protoc_insertion_point(module_scope)
diff --git a/components/protocomm/python/sec0_pb2.py b/components/protocomm/python/sec0_pb2.py
new file mode 100644 (file)
index 0000000..123d1dc
--- /dev/null
@@ -0,0 +1,196 @@
+# Generated by the protocol buffer compiler.  DO NOT EDIT!
+# source: sec0.proto
+
+import sys
+_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
+from google.protobuf.internal import enum_type_wrapper
+from google.protobuf import descriptor as _descriptor
+from google.protobuf import message as _message
+from google.protobuf import reflection as _reflection
+from google.protobuf import symbol_database as _symbol_database
+from google.protobuf import descriptor_pb2
+# @@protoc_insertion_point(imports)
+
+_sym_db = _symbol_database.Default()
+
+
+import constants_pb2 as constants__pb2
+
+
+DESCRIPTOR = _descriptor.FileDescriptor(
+  name='sec0.proto',
+  package='',
+  syntax='proto3',
+  serialized_pb=_b('\n\nsec0.proto\x1a\x0f\x63onstants.proto\"\x0e\n\x0cS0SessionCmd\"(\n\rS0SessionResp\x12\x17\n\x06status\x18\x01 \x01(\x0e\x32\x07.Status\"n\n\x0bSec0Payload\x12\x19\n\x03msg\x18\x01 \x01(\x0e\x32\x0c.Sec0MsgType\x12\x1b\n\x02sc\x18\x14 \x01(\x0b\x32\r.S0SessionCmdH\x00\x12\x1c\n\x02sr\x18\x15 \x01(\x0b\x32\x0e.S0SessionRespH\x00\x42\t\n\x07payload*>\n\x0bSec0MsgType\x12\x16\n\x12S0_Session_Command\x10\x00\x12\x17\n\x13S0_Session_Response\x10\x01\x62\x06proto3')
+  ,
+  dependencies=[constants__pb2.DESCRIPTOR,])
+
+_SEC0MSGTYPE = _descriptor.EnumDescriptor(
+  name='Sec0MsgType',
+  full_name='Sec0MsgType',
+  filename=None,
+  file=DESCRIPTOR,
+  values=[
+    _descriptor.EnumValueDescriptor(
+      name='S0_Session_Command', index=0, number=0,
+      options=None,
+      type=None),
+    _descriptor.EnumValueDescriptor(
+      name='S0_Session_Response', index=1, number=1,
+      options=None,
+      type=None),
+  ],
+  containing_type=None,
+  options=None,
+  serialized_start=201,
+  serialized_end=263,
+)
+_sym_db.RegisterEnumDescriptor(_SEC0MSGTYPE)
+
+Sec0MsgType = enum_type_wrapper.EnumTypeWrapper(_SEC0MSGTYPE)
+S0_Session_Command = 0
+S0_Session_Response = 1
+
+
+
+_S0SESSIONCMD = _descriptor.Descriptor(
+  name='S0SessionCmd',
+  full_name='S0SessionCmd',
+  filename=None,
+  file=DESCRIPTOR,
+  containing_type=None,
+  fields=[
+  ],
+  extensions=[
+  ],
+  nested_types=[],
+  enum_types=[
+  ],
+  options=None,
+  is_extendable=False,
+  syntax='proto3',
+  extension_ranges=[],
+  oneofs=[
+  ],
+  serialized_start=31,
+  serialized_end=45,
+)
+
+
+_S0SESSIONRESP = _descriptor.Descriptor(
+  name='S0SessionResp',
+  full_name='S0SessionResp',
+  filename=None,
+  file=DESCRIPTOR,
+  containing_type=None,
+  fields=[
+    _descriptor.FieldDescriptor(
+      name='status', full_name='S0SessionResp.status', index=0,
+      number=1, type=14, cpp_type=8, label=1,
+      has_default_value=False, default_value=0,
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      options=None, file=DESCRIPTOR),
+  ],
+  extensions=[
+  ],
+  nested_types=[],
+  enum_types=[
+  ],
+  options=None,
+  is_extendable=False,
+  syntax='proto3',
+  extension_ranges=[],
+  oneofs=[
+  ],
+  serialized_start=47,
+  serialized_end=87,
+)
+
+
+_SEC0PAYLOAD = _descriptor.Descriptor(
+  name='Sec0Payload',
+  full_name='Sec0Payload',
+  filename=None,
+  file=DESCRIPTOR,
+  containing_type=None,
+  fields=[
+    _descriptor.FieldDescriptor(
+      name='msg', full_name='Sec0Payload.msg', index=0,
+      number=1, type=14, cpp_type=8, label=1,
+      has_default_value=False, default_value=0,
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      options=None, file=DESCRIPTOR),
+    _descriptor.FieldDescriptor(
+      name='sc', full_name='Sec0Payload.sc', index=1,
+      number=20, type=11, cpp_type=10, label=1,
+      has_default_value=False, default_value=None,
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      options=None, file=DESCRIPTOR),
+    _descriptor.FieldDescriptor(
+      name='sr', full_name='Sec0Payload.sr', index=2,
+      number=21, type=11, cpp_type=10, label=1,
+      has_default_value=False, default_value=None,
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      options=None, file=DESCRIPTOR),
+  ],
+  extensions=[
+  ],
+  nested_types=[],
+  enum_types=[
+  ],
+  options=None,
+  is_extendable=False,
+  syntax='proto3',
+  extension_ranges=[],
+  oneofs=[
+    _descriptor.OneofDescriptor(
+      name='payload', full_name='Sec0Payload.payload',
+      index=0, containing_type=None, fields=[]),
+  ],
+  serialized_start=89,
+  serialized_end=199,
+)
+
+_S0SESSIONRESP.fields_by_name['status'].enum_type = constants__pb2._STATUS
+_SEC0PAYLOAD.fields_by_name['msg'].enum_type = _SEC0MSGTYPE
+_SEC0PAYLOAD.fields_by_name['sc'].message_type = _S0SESSIONCMD
+_SEC0PAYLOAD.fields_by_name['sr'].message_type = _S0SESSIONRESP
+_SEC0PAYLOAD.oneofs_by_name['payload'].fields.append(
+  _SEC0PAYLOAD.fields_by_name['sc'])
+_SEC0PAYLOAD.fields_by_name['sc'].containing_oneof = _SEC0PAYLOAD.oneofs_by_name['payload']
+_SEC0PAYLOAD.oneofs_by_name['payload'].fields.append(
+  _SEC0PAYLOAD.fields_by_name['sr'])
+_SEC0PAYLOAD.fields_by_name['sr'].containing_oneof = _SEC0PAYLOAD.oneofs_by_name['payload']
+DESCRIPTOR.message_types_by_name['S0SessionCmd'] = _S0SESSIONCMD
+DESCRIPTOR.message_types_by_name['S0SessionResp'] = _S0SESSIONRESP
+DESCRIPTOR.message_types_by_name['Sec0Payload'] = _SEC0PAYLOAD
+DESCRIPTOR.enum_types_by_name['Sec0MsgType'] = _SEC0MSGTYPE
+_sym_db.RegisterFileDescriptor(DESCRIPTOR)
+
+S0SessionCmd = _reflection.GeneratedProtocolMessageType('S0SessionCmd', (_message.Message,), dict(
+  DESCRIPTOR = _S0SESSIONCMD,
+  __module__ = 'sec0_pb2'
+  # @@protoc_insertion_point(class_scope:S0SessionCmd)
+  ))
+_sym_db.RegisterMessage(S0SessionCmd)
+
+S0SessionResp = _reflection.GeneratedProtocolMessageType('S0SessionResp', (_message.Message,), dict(
+  DESCRIPTOR = _S0SESSIONRESP,
+  __module__ = 'sec0_pb2'
+  # @@protoc_insertion_point(class_scope:S0SessionResp)
+  ))
+_sym_db.RegisterMessage(S0SessionResp)
+
+Sec0Payload = _reflection.GeneratedProtocolMessageType('Sec0Payload', (_message.Message,), dict(
+  DESCRIPTOR = _SEC0PAYLOAD,
+  __module__ = 'sec0_pb2'
+  # @@protoc_insertion_point(class_scope:Sec0Payload)
+  ))
+_sym_db.RegisterMessage(Sec0Payload)
+
+
+# @@protoc_insertion_point(module_scope)
diff --git a/components/protocomm/python/sec1_pb2.py b/components/protocomm/python/sec1_pb2.py
new file mode 100644 (file)
index 0000000..cc305b8
--- /dev/null
@@ -0,0 +1,335 @@
+# Generated by the protocol buffer compiler.  DO NOT EDIT!
+# source: sec1.proto
+
+import sys
+_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
+from google.protobuf.internal import enum_type_wrapper
+from google.protobuf import descriptor as _descriptor
+from google.protobuf import message as _message
+from google.protobuf import reflection as _reflection
+from google.protobuf import symbol_database as _symbol_database
+from google.protobuf import descriptor_pb2
+# @@protoc_insertion_point(imports)
+
+_sym_db = _symbol_database.Default()
+
+
+import constants_pb2 as constants__pb2
+
+
+DESCRIPTOR = _descriptor.FileDescriptor(
+  name='sec1.proto',
+  package='',
+  syntax='proto3',
+  serialized_pb=_b('\n\nsec1.proto\x1a\x0f\x63onstants.proto\")\n\x0bSessionCmd1\x12\x1a\n\x12\x63lient_verify_data\x18\x02 \x01(\x0c\"C\n\x0cSessionResp1\x12\x17\n\x06status\x18\x01 \x01(\x0e\x32\x07.Status\x12\x1a\n\x12\x64\x65vice_verify_data\x18\x03 \x01(\x0c\"$\n\x0bSessionCmd0\x12\x15\n\rclient_pubkey\x18\x01 \x01(\x0c\"U\n\x0cSessionResp0\x12\x17\n\x06status\x18\x01 \x01(\x0e\x32\x07.Status\x12\x15\n\rdevice_pubkey\x18\x02 \x01(\x0c\x12\x15\n\rdevice_random\x18\x03 \x01(\x0c\"\xa9\x01\n\x0bSec1Payload\x12\x19\n\x03msg\x18\x01 \x01(\x0e\x32\x0c.Sec1MsgType\x12\x1b\n\x03sc0\x18\x14 \x01(\x0b\x32\x0c.SessionCmd0H\x00\x12\x1c\n\x03sr0\x18\x15 \x01(\x0b\x32\r.SessionResp0H\x00\x12\x1b\n\x03sc1\x18\x16 \x01(\x0b\x32\x0c.SessionCmd1H\x00\x12\x1c\n\x03sr1\x18\x17 \x01(\x0b\x32\r.SessionResp1H\x00\x42\t\n\x07payload*g\n\x0bSec1MsgType\x12\x14\n\x10Session_Command0\x10\x00\x12\x15\n\x11Session_Response0\x10\x01\x12\x14\n\x10Session_Command1\x10\x02\x12\x15\n\x11Session_Response1\x10\x03\x62\x06proto3')
+  ,
+  dependencies=[constants__pb2.DESCRIPTOR,])
+
+_SEC1MSGTYPE = _descriptor.EnumDescriptor(
+  name='Sec1MsgType',
+  full_name='Sec1MsgType',
+  filename=None,
+  file=DESCRIPTOR,
+  values=[
+    _descriptor.EnumValueDescriptor(
+      name='Session_Command0', index=0, number=0,
+      options=None,
+      type=None),
+    _descriptor.EnumValueDescriptor(
+      name='Session_Response0', index=1, number=1,
+      options=None,
+      type=None),
+    _descriptor.EnumValueDescriptor(
+      name='Session_Command1', index=2, number=2,
+      options=None,
+      type=None),
+    _descriptor.EnumValueDescriptor(
+      name='Session_Response1', index=3, number=3,
+      options=None,
+      type=None),
+  ],
+  containing_type=None,
+  options=None,
+  serialized_start=440,
+  serialized_end=543,
+)
+_sym_db.RegisterEnumDescriptor(_SEC1MSGTYPE)
+
+Sec1MsgType = enum_type_wrapper.EnumTypeWrapper(_SEC1MSGTYPE)
+Session_Command0 = 0
+Session_Response0 = 1
+Session_Command1 = 2
+Session_Response1 = 3
+
+
+
+_SESSIONCMD1 = _descriptor.Descriptor(
+  name='SessionCmd1',
+  full_name='SessionCmd1',
+  filename=None,
+  file=DESCRIPTOR,
+  containing_type=None,
+  fields=[
+    _descriptor.FieldDescriptor(
+      name='client_verify_data', full_name='SessionCmd1.client_verify_data', index=0,
+      number=2, type=12, cpp_type=9, label=1,
+      has_default_value=False, default_value=_b(""),
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      options=None, file=DESCRIPTOR),
+  ],
+  extensions=[
+  ],
+  nested_types=[],
+  enum_types=[
+  ],
+  options=None,
+  is_extendable=False,
+  syntax='proto3',
+  extension_ranges=[],
+  oneofs=[
+  ],
+  serialized_start=31,
+  serialized_end=72,
+)
+
+
+_SESSIONRESP1 = _descriptor.Descriptor(
+  name='SessionResp1',
+  full_name='SessionResp1',
+  filename=None,
+  file=DESCRIPTOR,
+  containing_type=None,
+  fields=[
+    _descriptor.FieldDescriptor(
+      name='status', full_name='SessionResp1.status', index=0,
+      number=1, type=14, cpp_type=8, label=1,
+      has_default_value=False, default_value=0,
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      options=None, file=DESCRIPTOR),
+    _descriptor.FieldDescriptor(
+      name='device_verify_data', full_name='SessionResp1.device_verify_data', index=1,
+      number=3, type=12, cpp_type=9, label=1,
+      has_default_value=False, default_value=_b(""),
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      options=None, file=DESCRIPTOR),
+  ],
+  extensions=[
+  ],
+  nested_types=[],
+  enum_types=[
+  ],
+  options=None,
+  is_extendable=False,
+  syntax='proto3',
+  extension_ranges=[],
+  oneofs=[
+  ],
+  serialized_start=74,
+  serialized_end=141,
+)
+
+
+_SESSIONCMD0 = _descriptor.Descriptor(
+  name='SessionCmd0',
+  full_name='SessionCmd0',
+  filename=None,
+  file=DESCRIPTOR,
+  containing_type=None,
+  fields=[
+    _descriptor.FieldDescriptor(
+      name='client_pubkey', full_name='SessionCmd0.client_pubkey', index=0,
+      number=1, type=12, cpp_type=9, label=1,
+      has_default_value=False, default_value=_b(""),
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      options=None, file=DESCRIPTOR),
+  ],
+  extensions=[
+  ],
+  nested_types=[],
+  enum_types=[
+  ],
+  options=None,
+  is_extendable=False,
+  syntax='proto3',
+  extension_ranges=[],
+  oneofs=[
+  ],
+  serialized_start=143,
+  serialized_end=179,
+)
+
+
+_SESSIONRESP0 = _descriptor.Descriptor(
+  name='SessionResp0',
+  full_name='SessionResp0',
+  filename=None,
+  file=DESCRIPTOR,
+  containing_type=None,
+  fields=[
+    _descriptor.FieldDescriptor(
+      name='status', full_name='SessionResp0.status', index=0,
+      number=1, type=14, cpp_type=8, label=1,
+      has_default_value=False, default_value=0,
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      options=None, file=DESCRIPTOR),
+    _descriptor.FieldDescriptor(
+      name='device_pubkey', full_name='SessionResp0.device_pubkey', index=1,
+      number=2, type=12, cpp_type=9, label=1,
+      has_default_value=False, default_value=_b(""),
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      options=None, file=DESCRIPTOR),
+    _descriptor.FieldDescriptor(
+      name='device_random', full_name='SessionResp0.device_random', index=2,
+      number=3, type=12, cpp_type=9, label=1,
+      has_default_value=False, default_value=_b(""),
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      options=None, file=DESCRIPTOR),
+  ],
+  extensions=[
+  ],
+  nested_types=[],
+  enum_types=[
+  ],
+  options=None,
+  is_extendable=False,
+  syntax='proto3',
+  extension_ranges=[],
+  oneofs=[
+  ],
+  serialized_start=181,
+  serialized_end=266,
+)
+
+
+_SEC1PAYLOAD = _descriptor.Descriptor(
+  name='Sec1Payload',
+  full_name='Sec1Payload',
+  filename=None,
+  file=DESCRIPTOR,
+  containing_type=None,
+  fields=[
+    _descriptor.FieldDescriptor(
+      name='msg', full_name='Sec1Payload.msg', index=0,
+      number=1, type=14, cpp_type=8, label=1,
+      has_default_value=False, default_value=0,
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      options=None, file=DESCRIPTOR),
+    _descriptor.FieldDescriptor(
+      name='sc0', full_name='Sec1Payload.sc0', index=1,
+      number=20, type=11, cpp_type=10, label=1,
+      has_default_value=False, default_value=None,
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      options=None, file=DESCRIPTOR),
+    _descriptor.FieldDescriptor(
+      name='sr0', full_name='Sec1Payload.sr0', index=2,
+      number=21, type=11, cpp_type=10, label=1,
+      has_default_value=False, default_value=None,
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      options=None, file=DESCRIPTOR),
+    _descriptor.FieldDescriptor(
+      name='sc1', full_name='Sec1Payload.sc1', index=3,
+      number=22, type=11, cpp_type=10, label=1,
+      has_default_value=False, default_value=None,
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      options=None, file=DESCRIPTOR),
+    _descriptor.FieldDescriptor(
+      name='sr1', full_name='Sec1Payload.sr1', index=4,
+      number=23, type=11, cpp_type=10, label=1,
+      has_default_value=False, default_value=None,
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      options=None, file=DESCRIPTOR),
+  ],
+  extensions=[
+  ],
+  nested_types=[],
+  enum_types=[
+  ],
+  options=None,
+  is_extendable=False,
+  syntax='proto3',
+  extension_ranges=[],
+  oneofs=[
+    _descriptor.OneofDescriptor(
+      name='payload', full_name='Sec1Payload.payload',
+      index=0, containing_type=None, fields=[]),
+  ],
+  serialized_start=269,
+  serialized_end=438,
+)
+
+_SESSIONRESP1.fields_by_name['status'].enum_type = constants__pb2._STATUS
+_SESSIONRESP0.fields_by_name['status'].enum_type = constants__pb2._STATUS
+_SEC1PAYLOAD.fields_by_name['msg'].enum_type = _SEC1MSGTYPE
+_SEC1PAYLOAD.fields_by_name['sc0'].message_type = _SESSIONCMD0
+_SEC1PAYLOAD.fields_by_name['sr0'].message_type = _SESSIONRESP0
+_SEC1PAYLOAD.fields_by_name['sc1'].message_type = _SESSIONCMD1
+_SEC1PAYLOAD.fields_by_name['sr1'].message_type = _SESSIONRESP1
+_SEC1PAYLOAD.oneofs_by_name['payload'].fields.append(
+  _SEC1PAYLOAD.fields_by_name['sc0'])
+_SEC1PAYLOAD.fields_by_name['sc0'].containing_oneof = _SEC1PAYLOAD.oneofs_by_name['payload']
+_SEC1PAYLOAD.oneofs_by_name['payload'].fields.append(
+  _SEC1PAYLOAD.fields_by_name['sr0'])
+_SEC1PAYLOAD.fields_by_name['sr0'].containing_oneof = _SEC1PAYLOAD.oneofs_by_name['payload']
+_SEC1PAYLOAD.oneofs_by_name['payload'].fields.append(
+  _SEC1PAYLOAD.fields_by_name['sc1'])
+_SEC1PAYLOAD.fields_by_name['sc1'].containing_oneof = _SEC1PAYLOAD.oneofs_by_name['payload']
+_SEC1PAYLOAD.oneofs_by_name['payload'].fields.append(
+  _SEC1PAYLOAD.fields_by_name['sr1'])
+_SEC1PAYLOAD.fields_by_name['sr1'].containing_oneof = _SEC1PAYLOAD.oneofs_by_name['payload']
+DESCRIPTOR.message_types_by_name['SessionCmd1'] = _SESSIONCMD1
+DESCRIPTOR.message_types_by_name['SessionResp1'] = _SESSIONRESP1
+DESCRIPTOR.message_types_by_name['SessionCmd0'] = _SESSIONCMD0
+DESCRIPTOR.message_types_by_name['SessionResp0'] = _SESSIONRESP0
+DESCRIPTOR.message_types_by_name['Sec1Payload'] = _SEC1PAYLOAD
+DESCRIPTOR.enum_types_by_name['Sec1MsgType'] = _SEC1MSGTYPE
+_sym_db.RegisterFileDescriptor(DESCRIPTOR)
+
+SessionCmd1 = _reflection.GeneratedProtocolMessageType('SessionCmd1', (_message.Message,), dict(
+  DESCRIPTOR = _SESSIONCMD1,
+  __module__ = 'sec1_pb2'
+  # @@protoc_insertion_point(class_scope:SessionCmd1)
+  ))
+_sym_db.RegisterMessage(SessionCmd1)
+
+SessionResp1 = _reflection.GeneratedProtocolMessageType('SessionResp1', (_message.Message,), dict(
+  DESCRIPTOR = _SESSIONRESP1,
+  __module__ = 'sec1_pb2'
+  # @@protoc_insertion_point(class_scope:SessionResp1)
+  ))
+_sym_db.RegisterMessage(SessionResp1)
+
+SessionCmd0 = _reflection.GeneratedProtocolMessageType('SessionCmd0', (_message.Message,), dict(
+  DESCRIPTOR = _SESSIONCMD0,
+  __module__ = 'sec1_pb2'
+  # @@protoc_insertion_point(class_scope:SessionCmd0)
+  ))
+_sym_db.RegisterMessage(SessionCmd0)
+
+SessionResp0 = _reflection.GeneratedProtocolMessageType('SessionResp0', (_message.Message,), dict(
+  DESCRIPTOR = _SESSIONRESP0,
+  __module__ = 'sec1_pb2'
+  # @@protoc_insertion_point(class_scope:SessionResp0)
+  ))
+_sym_db.RegisterMessage(SessionResp0)
+
+Sec1Payload = _reflection.GeneratedProtocolMessageType('Sec1Payload', (_message.Message,), dict(
+  DESCRIPTOR = _SEC1PAYLOAD,
+  __module__ = 'sec1_pb2'
+  # @@protoc_insertion_point(class_scope:Sec1Payload)
+  ))
+_sym_db.RegisterMessage(Sec1Payload)
+
+
+# @@protoc_insertion_point(module_scope)
diff --git a/components/protocomm/python/session_pb2.py b/components/protocomm/python/session_pb2.py
new file mode 100644 (file)
index 0000000..a30e794
--- /dev/null
@@ -0,0 +1,125 @@
+# Generated by the protocol buffer compiler.  DO NOT EDIT!
+# source: session.proto
+
+import sys
+_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
+from google.protobuf.internal import enum_type_wrapper
+from google.protobuf import descriptor as _descriptor
+from google.protobuf import message as _message
+from google.protobuf import reflection as _reflection
+from google.protobuf import symbol_database as _symbol_database
+from google.protobuf import descriptor_pb2
+# @@protoc_insertion_point(imports)
+
+_sym_db = _symbol_database.Default()
+
+
+import sec0_pb2 as sec0__pb2
+import sec1_pb2 as sec1__pb2
+
+
+DESCRIPTOR = _descriptor.FileDescriptor(
+  name='session.proto',
+  package='',
+  syntax='proto3',
+  serialized_pb=_b('\n\rsession.proto\x1a\nsec0.proto\x1a\nsec1.proto\"v\n\x0bSessionData\x12\"\n\x07sec_ver\x18\x02 \x01(\x0e\x32\x11.SecSchemeVersion\x12\x1c\n\x04sec0\x18\n \x01(\x0b\x32\x0c.Sec0PayloadH\x00\x12\x1c\n\x04sec1\x18\x0b \x01(\x0b\x32\x0c.Sec1PayloadH\x00\x42\x07\n\x05proto*2\n\x10SecSchemeVersion\x12\x0e\n\nSecScheme0\x10\x00\x12\x0e\n\nSecScheme1\x10\x01\x62\x06proto3')
+  ,
+  dependencies=[sec0__pb2.DESCRIPTOR,sec1__pb2.DESCRIPTOR,])
+
+_SECSCHEMEVERSION = _descriptor.EnumDescriptor(
+  name='SecSchemeVersion',
+  full_name='SecSchemeVersion',
+  filename=None,
+  file=DESCRIPTOR,
+  values=[
+    _descriptor.EnumValueDescriptor(
+      name='SecScheme0', index=0, number=0,
+      options=None,
+      type=None),
+    _descriptor.EnumValueDescriptor(
+      name='SecScheme1', index=1, number=1,
+      options=None,
+      type=None),
+  ],
+  containing_type=None,
+  options=None,
+  serialized_start=161,
+  serialized_end=211,
+)
+_sym_db.RegisterEnumDescriptor(_SECSCHEMEVERSION)
+
+SecSchemeVersion = enum_type_wrapper.EnumTypeWrapper(_SECSCHEMEVERSION)
+SecScheme0 = 0
+SecScheme1 = 1
+
+
+
+_SESSIONDATA = _descriptor.Descriptor(
+  name='SessionData',
+  full_name='SessionData',
+  filename=None,
+  file=DESCRIPTOR,
+  containing_type=None,
+  fields=[
+    _descriptor.FieldDescriptor(
+      name='sec_ver', full_name='SessionData.sec_ver', index=0,
+      number=2, type=14, cpp_type=8, label=1,
+      has_default_value=False, default_value=0,
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      options=None, file=DESCRIPTOR),
+    _descriptor.FieldDescriptor(
+      name='sec0', full_name='SessionData.sec0', index=1,
+      number=10, type=11, cpp_type=10, label=1,
+      has_default_value=False, default_value=None,
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      options=None, file=DESCRIPTOR),
+    _descriptor.FieldDescriptor(
+      name='sec1', full_name='SessionData.sec1', index=2,
+      number=11, type=11, cpp_type=10, label=1,
+      has_default_value=False, default_value=None,
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      options=None, file=DESCRIPTOR),
+  ],
+  extensions=[
+  ],
+  nested_types=[],
+  enum_types=[
+  ],
+  options=None,
+  is_extendable=False,
+  syntax='proto3',
+  extension_ranges=[],
+  oneofs=[
+    _descriptor.OneofDescriptor(
+      name='proto', full_name='SessionData.proto',
+      index=0, containing_type=None, fields=[]),
+  ],
+  serialized_start=41,
+  serialized_end=159,
+)
+
+_SESSIONDATA.fields_by_name['sec_ver'].enum_type = _SECSCHEMEVERSION
+_SESSIONDATA.fields_by_name['sec0'].message_type = sec0__pb2._SEC0PAYLOAD
+_SESSIONDATA.fields_by_name['sec1'].message_type = sec1__pb2._SEC1PAYLOAD
+_SESSIONDATA.oneofs_by_name['proto'].fields.append(
+  _SESSIONDATA.fields_by_name['sec0'])
+_SESSIONDATA.fields_by_name['sec0'].containing_oneof = _SESSIONDATA.oneofs_by_name['proto']
+_SESSIONDATA.oneofs_by_name['proto'].fields.append(
+  _SESSIONDATA.fields_by_name['sec1'])
+_SESSIONDATA.fields_by_name['sec1'].containing_oneof = _SESSIONDATA.oneofs_by_name['proto']
+DESCRIPTOR.message_types_by_name['SessionData'] = _SESSIONDATA
+DESCRIPTOR.enum_types_by_name['SecSchemeVersion'] = _SECSCHEMEVERSION
+_sym_db.RegisterFileDescriptor(DESCRIPTOR)
+
+SessionData = _reflection.GeneratedProtocolMessageType('SessionData', (_message.Message,), dict(
+  DESCRIPTOR = _SESSIONDATA,
+  __module__ = 'session_pb2'
+  # @@protoc_insertion_point(class_scope:SessionData)
+  ))
+_sym_db.RegisterMessage(SessionData)
+
+
+# @@protoc_insertion_point(module_scope)
diff --git a/components/protocomm/test/component.mk b/components/protocomm/test/component.mk
new file mode 100644 (file)
index 0000000..7a27118
--- /dev/null
@@ -0,0 +1,2 @@
+COMPONENT_PRIV_INCLUDEDIRS := ../proto-c/
+COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive
diff --git a/components/protocomm/test/test_protocomm.c b/components/protocomm/test/test_protocomm.c
new file mode 100644 (file)
index 0000000..cc85006
--- /dev/null
@@ -0,0 +1,1089 @@
+// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include <esp_err.h>
+#include <esp_log.h>
+#include <esp_system.h>
+#include <sys/random.h>
+#include <unity.h>
+
+#include <mbedtls/aes.h>
+#include <mbedtls/sha256.h>
+#include <mbedtls/entropy.h>
+#include <mbedtls/ctr_drbg.h>
+#include <mbedtls/ecdh.h>
+#include <mbedtls/error.h>
+#include <mbedtls/ssl_internal.h>
+
+#include <protocomm.h>
+#include <protocomm_security.h>
+#include <protocomm_security0.h>
+#include <protocomm_security1.h>
+
+#include "session.pb-c.h"
+
+#ifdef DO_HEAP_TRACING
+    #include <esp_heap_trace.h>
+    #define NUM_RECORDS 100
+    static heap_trace_record_t trace_record[NUM_RECORDS]; // This buffer must be in internal RAM
+#endif
+
+#define PUBLIC_KEY_LEN  32
+#define SZ_RANDOM       16
+
+typedef struct {
+    uint32_t id;
+    uint8_t  sec_ver;
+    uint8_t  weak;
+    const protocomm_security_pop_t *pop;
+    uint8_t device_pubkey[PUBLIC_KEY_LEN];
+    uint8_t client_pubkey[PUBLIC_KEY_LEN];
+    uint8_t sym_key[PUBLIC_KEY_LEN];
+    uint8_t rand[SZ_RANDOM];
+
+    /* mbedtls context data for Curve25519 */
+    mbedtls_ecdh_context ctx_client;
+    mbedtls_entropy_context entropy;
+    mbedtls_ctr_drbg_context ctr_drbg;
+
+    /* mbedtls context data for AES */
+    mbedtls_aes_context ctx_aes;
+    unsigned char stb[16];
+    size_t nc_off;
+} session_t;
+
+static const char *TAG = "protocomm_test";
+
+static protocomm_t *test_pc = NULL;
+static const protocomm_security_t *test_sec = NULL;
+static uint32_t test_priv_data = 1234;
+
+static void flip_endian(uint8_t *data, size_t len)
+{
+    uint8_t swp_buf;
+    for (int i = 0; i < len/2; i++) {
+        swp_buf = data[i];
+        data[i] = data[len - i - 1];
+        data[len - i - 1] = swp_buf;
+    }
+}
+
+static void hexdump(const char *msg, uint8_t *buf, int len)
+{
+    ESP_LOGI(TAG, "%s:", msg);
+    ESP_LOG_BUFFER_HEX(TAG, buf, len);
+}
+
+static esp_err_t prepare_command0(session_t *session, SessionData *req)
+{
+    Sec1Payload *in = (Sec1Payload *) malloc(sizeof(Sec1Payload));
+    if (in == NULL) {
+        ESP_LOGE(TAG, "Error allocating memory for request");
+        return ESP_ERR_NO_MEM;
+    }
+
+    SessionCmd0 *in_req = (SessionCmd0 *) malloc(sizeof(SessionCmd0));
+    if (in_req == NULL) {
+        ESP_LOGE(TAG, "Error allocating memory for request");
+        free(in);
+        return ESP_ERR_NO_MEM;
+    }
+
+    sec1_payload__init(in);
+    session_cmd0__init(in_req);
+
+    in_req->client_pubkey.data = session->client_pubkey;
+    in_req->client_pubkey.len = PUBLIC_KEY_LEN;
+
+    in->msg = SEC1_MSG_TYPE__Session_Command0;
+    in->payload_case = SEC1_PAYLOAD__PAYLOAD_SC0;
+    in->sc0 = in_req;
+
+    req->proto_case = SESSION_DATA__PROTO_SEC1;
+    req->sec_ver = protocomm_security1.ver;
+    req->sec1 = in;
+
+    return ESP_OK;
+}
+
+static void cleanup_command0(SessionData *req)
+{
+    free(req->sec1->sc0);
+    free(req->sec1);
+}
+
+static esp_err_t verify_response0(session_t *session, SessionData *resp)
+{
+    if ((resp->proto_case != SESSION_DATA__PROTO_SEC1) ||
+        (resp->sec1->msg  != SEC1_MSG_TYPE__Session_Response0)) {
+        ESP_LOGE(TAG, "Invalid response type");
+        return ESP_ERR_INVALID_ARG;
+    }
+
+    int ret;
+    Sec1Payload *in = (Sec1Payload *) resp->sec1;
+
+    if (in->sr0->device_pubkey.len != PUBLIC_KEY_LEN) {
+        ESP_LOGE(TAG, "Device public key length as not as expected");
+        return ESP_FAIL;
+    }
+
+    if (in->sr0->device_random.len != SZ_RANDOM) {
+        ESP_LOGE(TAG, "Device random data length is not as expected");
+        return ESP_FAIL;
+    }
+
+    uint8_t *cli_pubkey = session->client_pubkey;
+    uint8_t *dev_pubkey = session->device_pubkey;
+    memcpy(session->device_pubkey, in->sr0->device_pubkey.data, in->sr0->device_pubkey.len);
+
+    hexdump("Device pubkey", dev_pubkey, PUBLIC_KEY_LEN);
+    hexdump("Client pubkey", cli_pubkey, PUBLIC_KEY_LEN);
+
+    ret = mbedtls_mpi_lset(&session->ctx_client.Qp.Z, 1);
+    if (ret != 0) {
+        ESP_LOGE(TAG, "Failed at mbedtls_mpi_lset with error code : %d", ret);
+        return ESP_FAIL;
+    }
+
+    flip_endian(session->device_pubkey, PUBLIC_KEY_LEN);
+    ret = mbedtls_mpi_read_binary(&session->ctx_client.Qp.X, dev_pubkey, PUBLIC_KEY_LEN);
+    flip_endian(session->device_pubkey, PUBLIC_KEY_LEN);
+    if (ret != 0) {
+        ESP_LOGE(TAG, "Failed at mbedtls_mpi_read_binary with error code : %d", ret);
+        return ESP_FAIL;
+    }
+
+    ret = mbedtls_ecdh_compute_shared(&session->ctx_client.grp,
+                                      &session->ctx_client.z,
+                                      &session->ctx_client.Qp,
+                                      &session->ctx_client.d,
+                                      mbedtls_ctr_drbg_random,
+                                      &session->ctr_drbg);
+    if (ret != 0) {
+        ESP_LOGE(TAG, "Failed at mbedtls_ecdh_compute_shared with error code : %d", ret);
+        return ESP_FAIL;
+    }
+
+    ret = mbedtls_mpi_write_binary(&session->ctx_client.z, session->sym_key, PUBLIC_KEY_LEN);
+    if (ret != 0) {
+        ESP_LOGE(TAG, "Failed at mbedtls_mpi_write_binary with error code : %d", ret);
+        return ESP_FAIL;
+    }
+    flip_endian(session->sym_key, PUBLIC_KEY_LEN);
+
+    const protocomm_security_pop_t *pop = session->pop;
+    if (pop != NULL && pop->data != NULL && pop->len != 0) {
+        ESP_LOGD(TAG, "Adding proof of possession");
+        uint8_t sha_out[PUBLIC_KEY_LEN];
+
+        ret = mbedtls_sha256_ret((const unsigned char *) pop->data, pop->len, sha_out, 0);
+        if (ret != 0) {
+            ESP_LOGE(TAG, "Failed at mbedtls_sha256_ret with error code : %d", ret);
+            return ESP_FAIL;
+        }
+
+        for (int i = 0; i < PUBLIC_KEY_LEN; i++) {
+            session->sym_key[i] ^= sha_out[i];
+        }
+    }
+
+    hexdump("Shared key", session->sym_key, PUBLIC_KEY_LEN);
+
+    memcpy(session->rand, in->sr0->device_random.data, in->sr0->device_random.len);
+    hexdump("Dev random", session->rand, sizeof(session->rand));
+    return ESP_OK;
+}
+
+static esp_err_t prepare_command1(session_t *session, SessionData *req)
+{
+    int ret;
+    uint8_t *outbuf = (uint8_t *) malloc(PUBLIC_KEY_LEN);
+    if (!outbuf) {
+        ESP_LOGE(TAG, "Error allocating ciphertext buffer");
+        return ESP_ERR_NO_MEM;
+    }
+
+    /* Initialise crypto context */
+    mbedtls_aes_init(&session->ctx_aes);
+    memset(session->stb, 0, sizeof(session->stb));
+    session->nc_off = 0;
+
+    ret = mbedtls_aes_setkey_enc(&session->ctx_aes, session->sym_key,
+                                 sizeof(session->sym_key)*8);
+    if (ret != 0) {
+        ESP_LOGE(TAG, "Failed at mbedtls_aes_setkey_enc with erro code : %d", ret);
+        free(outbuf);
+        return ESP_FAIL;
+    }
+
+    ret = mbedtls_aes_crypt_ctr(&session->ctx_aes, PUBLIC_KEY_LEN,
+                                &session->nc_off, session->rand,
+                                session->stb, session->device_pubkey, outbuf);
+    if (ret != 0) {
+        ESP_LOGE(TAG, "Failed at mbedtls_aes_crypt_ctr with erro code : %d", ret);
+        free(outbuf);
+        return ESP_FAIL;
+    }
+
+    Sec1Payload *out = (Sec1Payload *) malloc(sizeof(Sec1Payload));
+    if (!out) {
+        ESP_LOGE(TAG, "Error allocating out buffer");
+        free(outbuf);
+        return ESP_ERR_NO_MEM;
+    }
+    sec1_payload__init(out);
+
+    SessionCmd1 *out_req = (SessionCmd1 *) malloc(sizeof(SessionCmd1));
+    if (!out_req) {
+        ESP_LOGE(TAG, "Error allocating out_req buffer");
+        free(outbuf);
+        free(out);
+        return ESP_ERR_NO_MEM;
+    }
+    session_cmd1__init(out_req);
+
+    out_req->client_verify_data.data = outbuf;
+    out_req->client_verify_data.len = PUBLIC_KEY_LEN;
+    hexdump("Client verify data", outbuf, PUBLIC_KEY_LEN);
+
+    out->msg = SEC1_MSG_TYPE__Session_Command1;
+    out->payload_case = SEC1_PAYLOAD__PAYLOAD_SC1;
+    out->sc1 = out_req;
+
+    req->proto_case = SESSION_DATA__PROTO_SEC1;
+    req->sec_ver = protocomm_security1.ver;
+    req->sec1 = out;
+
+    return ESP_OK;
+}
+
+static void cleanup_command1(SessionData *req)
+{
+    free(req->sec1->sc1->client_verify_data.data);
+    free(req->sec1->sc1);
+    free(req->sec1);
+}
+
+static esp_err_t verify_response1(session_t *session, SessionData *resp)
+{
+    uint8_t *cli_pubkey = session->client_pubkey;
+    uint8_t *dev_pubkey = session->device_pubkey;
+
+    hexdump("Device pubkey", dev_pubkey, PUBLIC_KEY_LEN);
+    hexdump("Client pubkey", cli_pubkey, PUBLIC_KEY_LEN);
+
+    if ((resp->proto_case != SESSION_DATA__PROTO_SEC1) ||
+        (resp->sec1->msg  != SEC1_MSG_TYPE__Session_Response1)) {
+        ESP_LOGE(TAG, "Invalid response type");
+        return ESP_ERR_INVALID_ARG;
+    }
+
+    uint8_t check_buf[PUBLIC_KEY_LEN];
+    Sec1Payload *in = (Sec1Payload *) resp->sec1;
+
+    int ret = mbedtls_aes_crypt_ctr(&session->ctx_aes, PUBLIC_KEY_LEN,
+                                    &session->nc_off, session->rand, session->stb,
+                                    in->sr1->device_verify_data.data, check_buf);
+    if (ret != 0) {
+        ESP_LOGE(TAG, "Failed at mbedtls_aes_crypt_ctr with erro code : %d", ret);
+        return ESP_FAIL;
+    }
+    hexdump("Dec Device verifier", check_buf, sizeof(check_buf));
+
+    if (memcmp(check_buf, session->client_pubkey, sizeof(session->client_pubkey)) != 0) {
+        ESP_LOGE(TAG, "Key mismatch. Close connection");
+        return ESP_FAIL;
+    }
+
+    return ESP_OK;
+}
+
+static esp_err_t test_new_session(session_t *session)
+{
+    if (session->sec_ver == 0) {
+        return ESP_OK;
+    }
+
+    if (!test_sec || !test_sec->new_transport_session) {
+        return ESP_ERR_INVALID_STATE;
+    }
+
+    uint32_t session_id = session->id;
+    if (test_sec->new_transport_session(session_id) != ESP_OK) {
+        ESP_LOGE(TAG, "Failed to launch new transport session");
+        return ESP_FAIL;
+    }
+    return ESP_OK;
+}
+
+static esp_err_t test_sec_endpoint(session_t *session)
+{
+    if (session->sec_ver == 0) {
+        return ESP_OK;
+    }
+
+    uint32_t session_id = session->id;
+
+    int ret = ESP_FAIL;
+    SessionData req;
+    SessionData *resp;
+    ssize_t  inlen = 0;
+    uint8_t *inbuf = NULL;
+    ssize_t  outlen = 0;
+    uint8_t *outbuf = NULL;
+
+    mbedtls_ecdh_init(&session->ctx_client);
+    mbedtls_ctr_drbg_init(&session->ctr_drbg);
+
+    mbedtls_entropy_init(&session->entropy);
+    ret = mbedtls_ctr_drbg_seed(&session->ctr_drbg, mbedtls_entropy_func,
+                                &session->entropy, NULL, 0);
+    if (ret != 0) {
+        ESP_LOGE(TAG, "Failed at mbedtls_ctr_drbg_seed with error code : %d", ret);
+        goto abort_test_sec_endpoint;
+    }
+
+    ret = mbedtls_ecp_group_load(&session->ctx_client.grp, MBEDTLS_ECP_DP_CURVE25519);
+    if (ret != 0) {
+        ESP_LOGE(TAG, "Failed at mbedtls_ecp_group_load with error code : %d", ret);
+        goto abort_test_sec_endpoint;
+    }
+
+    ret = mbedtls_ecdh_gen_public(&session->ctx_client.grp,
+                                  &session->ctx_client.d,
+                                  &session->ctx_client.Q,
+                                  mbedtls_ctr_drbg_random,
+                                  &session->ctr_drbg);
+    if (ret != 0) {
+        ESP_LOGE(TAG, "Failed at mbedtls_ecdh_gen_public with error code : %d", ret);
+        goto abort_test_sec_endpoint;
+    }
+
+    if (session->weak) {
+        /* Read zero client public key */
+        ret = mbedtls_mpi_read_binary(&session->ctx_client.Q.X,
+                                      session->client_pubkey,
+                                      PUBLIC_KEY_LEN);
+        if (ret != 0) {
+            ESP_LOGE(TAG, "Failed at mbedtls_mpi_read_binary with error code : %d", ret);
+            goto abort_test_sec_endpoint;
+        }
+    }
+    ret = mbedtls_mpi_write_binary(&session->ctx_client.Q.X,
+                                   session->client_pubkey,
+                                   PUBLIC_KEY_LEN);
+    if (ret != 0) {
+        ESP_LOGE(TAG, "Failed at mbedtls_mpi_write_binary with error code : %d", ret);
+        goto abort_test_sec_endpoint;
+    }
+    flip_endian(session->client_pubkey, PUBLIC_KEY_LEN);
+
+    /*********** Transaction0 = SessionCmd0 + SessionResp0 ****************/
+    session_data__init(&req);
+    if (prepare_command0(session, &req) != ESP_OK) {
+        ESP_LOGE(TAG, "Failed in prepare_command0");
+        goto abort_test_sec_endpoint;
+    }
+
+    inlen = session_data__get_packed_size(&req);
+    inbuf = (uint8_t *) malloc(inlen);
+    if (!inbuf) {
+        ESP_LOGE(TAG, "Failed to allocate inbuf");
+        goto abort_test_sec_endpoint;
+    }
+
+    session_data__pack(&req, inbuf);
+    cleanup_command0(&req);
+
+    outlen = 0;
+    outbuf = NULL;
+    ret = protocomm_req_handle(test_pc, "test-sec", session_id,
+                               inbuf, inlen, &outbuf, &outlen);
+
+    free(inbuf);
+    if (ret != ESP_OK) {
+        ESP_LOGE(TAG, "test-sec handler failed");
+        free(outbuf);
+        goto abort_test_sec_endpoint;
+    }
+
+    resp = session_data__unpack(NULL, outlen, outbuf);
+    free(outbuf);
+    if (!resp) {
+        ESP_LOGE(TAG, "Unable to unpack SessionResp0");
+        goto abort_test_sec_endpoint;
+    }
+
+    if (verify_response0(session, resp) != ESP_OK) {
+        ESP_LOGE(TAG, "Invalid response 0");
+        session_data__free_unpacked(resp, NULL);
+        goto abort_test_sec_endpoint;
+    }
+
+    session_data__free_unpacked(resp, NULL);
+
+    /*********** Transaction1 = SessionCmd1 + SessionResp1 ****************/
+    session_data__init(&req);
+    if (prepare_command1(session, &req) != ESP_OK) {
+        ESP_LOGE(TAG, "Failed in prepare_command1");
+        goto abort_test_sec_endpoint;
+    }
+
+    inlen = session_data__get_packed_size(&req);
+    inbuf = (uint8_t *) malloc(inlen);
+    if (!inbuf) {
+        ESP_LOGE(TAG, "Failed to allocate inbuf");
+        goto abort_test_sec_endpoint;
+    }
+
+    session_data__pack(&req, inbuf);
+    cleanup_command1(&req);
+
+    outlen = 0;
+    outbuf = NULL;
+    ret = protocomm_req_handle(test_pc, "test-sec", session_id,
+                               inbuf, inlen, &outbuf, &outlen);
+
+    free(inbuf);
+    if (ret != ESP_OK) {
+        ESP_LOGE(TAG, "test-sec handler failed");
+        free(outbuf);
+        goto abort_test_sec_endpoint;
+    }
+
+    resp = session_data__unpack(NULL, outlen, outbuf);
+    free(outbuf);
+    if (!resp) {
+        ESP_LOGE(TAG, "Unable to unpack SessionResp0");
+        goto abort_test_sec_endpoint;
+    }
+
+    if (verify_response1(session, resp) != ESP_OK) {
+        ESP_LOGE(TAG, "Invalid response 1");
+        session_data__free_unpacked(resp, NULL);
+        goto abort_test_sec_endpoint;
+    }
+
+    session_data__free_unpacked(resp, NULL);
+    mbedtls_ecdh_free(&session->ctx_client);
+    mbedtls_ctr_drbg_free(&session->ctr_drbg);
+    mbedtls_entropy_free(&session->entropy);
+    return ESP_OK;
+
+abort_test_sec_endpoint:
+    mbedtls_ecdh_free(&session->ctx_client);
+    mbedtls_ctr_drbg_free(&session->ctr_drbg);
+    mbedtls_entropy_free(&session->entropy);
+    return ESP_FAIL;
+}
+
+static esp_err_t test_req_endpoint(session_t *session)
+{
+    uint32_t session_id = session->id;
+
+    uint8_t rand_test_data[512], enc_test_data[512];
+    getrandom(rand_test_data, sizeof(rand_test_data), 0);
+
+    if (session->sec_ver == 0) {
+        memcpy(enc_test_data, rand_test_data, sizeof(rand_test_data));
+    }
+    else if (session->sec_ver == 1) {
+        mbedtls_aes_crypt_ctr(&session->ctx_aes, sizeof(rand_test_data), &session->nc_off,
+                              session->rand, session->stb, rand_test_data, enc_test_data);
+    }
+
+    ssize_t  verify_data_len = 0;
+    uint8_t *enc_verify_data = NULL;
+
+    esp_err_t ret = protocomm_req_handle(test_pc, "test-ep", session_id,
+                                         enc_test_data, sizeof(enc_test_data),
+                                         &enc_verify_data, &verify_data_len);
+
+    if (ret != ESP_OK) {
+        ESP_LOGE(TAG, "test-ep handler failed");
+        return ESP_FAIL;
+    }
+
+    uint8_t *verify_data = malloc(verify_data_len);
+    if (!verify_data) {
+        ESP_LOGE(TAG, "error allocating memory for decrypted data");
+        free(enc_verify_data);
+        return ESP_FAIL;
+    }
+
+    if (session->sec_ver == 0) {
+        memcpy(verify_data, enc_verify_data, verify_data_len);
+    }
+    else if (session->sec_ver == 1) {
+        mbedtls_aes_crypt_ctr(&session->ctx_aes, verify_data_len, &session->nc_off,
+                              session->rand, session->stb, enc_verify_data, verify_data);
+    }
+    free(enc_verify_data);
+
+    hexdump("Sent data", rand_test_data, sizeof(rand_test_data));
+    hexdump("Recv data", verify_data,    verify_data_len);
+
+    ESP_LOGI(TAG, "verify data len   : %d", verify_data_len);
+    ESP_LOGI(TAG, "expected data len : %d", sizeof(rand_test_data));
+
+    if (verify_data_len != sizeof(rand_test_data)) {
+        ESP_LOGE(TAG, "incorrect response length from test-ep");
+        free(verify_data);
+        return ESP_FAIL;
+    }
+    if (memcmp(rand_test_data, verify_data, verify_data_len)) {
+        ESP_LOGE(TAG, "incorrect response data from test-ep");
+        free(verify_data);
+        return ESP_FAIL;
+    }
+    free(verify_data);
+    return ESP_OK;
+}
+
+esp_err_t test_req_handler (uint32_t session_id,
+                            const uint8_t *inbuf, ssize_t inlen,
+                            uint8_t **outbuf, ssize_t *outlen,
+                            void *priv_data)
+{
+    *outbuf = malloc(inlen);
+    if (*outbuf) {
+        *outlen = inlen;
+        memcpy(*outbuf, inbuf, inlen);
+    } else {
+        ESP_LOGE(TAG, "Error allocating response outbuf");
+        *outbuf = NULL;
+        *outlen = 0;
+    }
+
+    uint32_t *priv = (uint32_t *) priv_data;
+    if ((&test_priv_data != priv) || (test_priv_data != *priv)) {
+        ESP_LOGE(TAG, "Handler private data doesn't match");
+        return ESP_FAIL;
+    }
+    return ESP_OK;
+}
+
+static esp_err_t start_test_service(uint8_t sec_ver, const protocomm_security_pop_t *pop)
+{
+    test_pc = protocomm_new();
+    if (test_pc == NULL) {
+        ESP_LOGE(TAG, "Failed to create new protocomm instance");
+        return ESP_FAIL;
+    }
+
+    if (sec_ver == 0) {
+        if (protocomm_set_security(test_pc, "test-sec", &protocomm_security0, NULL) != ESP_OK) {
+            ESP_LOGE(TAG, "Failed to set Security0");
+            return ESP_FAIL;
+        }
+        test_sec = &protocomm_security0;
+    } else if (sec_ver == 1) {
+        if (protocomm_set_security(test_pc, "test-sec", &protocomm_security1, pop) != ESP_OK) {
+            ESP_LOGE(TAG, "Failed to set Security1");
+            return ESP_FAIL;
+        }
+        test_sec = &protocomm_security1;
+    }
+
+    if (protocomm_add_endpoint(test_pc, "test-ep",
+                               test_req_handler,
+                               (void *) &test_priv_data) != ESP_OK) {
+        ESP_LOGE(TAG, "Failed to set test-ep endpoint handler");
+        return ESP_FAIL;
+    }
+    return ESP_OK;
+}
+
+static void stop_test_service(void)
+{
+    protocomm_remove_endpoint(test_pc, "test-ep");
+    protocomm_unset_security(test_pc, "test-sec");
+    test_sec = NULL;
+    protocomm_delete(test_pc);
+    test_pc = NULL;
+}
+
+static esp_err_t test_security1_no_encryption (void)
+{
+    ESP_LOGI(TAG, "Starting Security 1 no encryption test");
+
+    const char *pop_data = "test pop";
+    protocomm_security_pop_t pop = {
+        .data = (const uint8_t *)pop_data,
+        .len  = strlen(pop_data)
+    };
+
+    session_t *session = calloc(1, sizeof(session_t));
+    if (session == NULL) {
+        ESP_LOGE(TAG, "Error allocating session");
+        return ESP_ERR_NO_MEM;
+    }
+
+    session->id        = 1;
+    session->sec_ver   = 1;
+    session->pop       = &pop;
+
+    // Start protocomm service
+    if (start_test_service(1, &pop) != ESP_OK) {
+        ESP_LOGE(TAG, "Error starting test");
+        free(session);
+        return ESP_ERR_INVALID_STATE;
+    }
+
+    // Intialise protocomm session with zero public keys
+    if (test_new_session(session) != ESP_OK) {
+        ESP_LOGE(TAG, "Error creating new session");
+        stop_test_service();
+        free(session);
+        return ESP_FAIL;
+    }
+
+    // Perform 25519 security handshake to set public keys
+    if (test_sec_endpoint(session) != ESP_OK) {
+        ESP_LOGE(TAG, "Error testing security endpoint");
+        stop_test_service();
+        free(session);
+        return ESP_FAIL;
+    }
+
+    // Force endpoint with un-encrypted data
+    session->sec_ver = 0;
+
+    // Send unencrypted request data to echo endpoint.
+    // Response would be encrypted causing echoed back
+    // data to not match that which was sent, hence failing.
+    if (test_req_endpoint(session) == ESP_OK) {
+        ESP_LOGE(TAG, "Error testing request endpoint");
+        stop_test_service();
+        free(session);
+        return ESP_FAIL;
+    }
+
+    stop_test_service();
+    free(session);
+    ESP_LOGI(TAG, "Protocomm test successful");
+    return ESP_OK;
+}
+
+static esp_err_t test_security1_session_overflow (void)
+{
+    ESP_LOGI(TAG, "Starting Security 1 session overflow test");
+
+    const char *pop_data = "test pop";
+    protocomm_security_pop_t pop = {
+        .data = (const uint8_t *)pop_data,
+        .len  = strlen(pop_data)
+    };
+
+    session_t *session1 = calloc(1, sizeof(session_t));
+    if (session1 == NULL) {
+        ESP_LOGE(TAG, "Error allocating session");
+        return ESP_ERR_NO_MEM;
+    }
+
+    session1->id        = 2;
+    session1->sec_ver   = 1;
+    session1->pop       = &pop;
+
+    session_t *session2 = calloc(1, sizeof(session_t));
+    if (session2 == NULL) {
+        ESP_LOGE(TAG, "Error allocating session");
+        free(session1);
+        return ESP_ERR_NO_MEM;
+    }
+
+    session2->id         = 3;
+    session2->sec_ver    = 1;
+    session2->pop        = NULL;
+
+    // Start protocomm service
+    if (start_test_service(1, &pop) != ESP_OK) {
+        ESP_LOGE(TAG, "Error starting test");
+        free(session1);
+        free(session2);
+        return ESP_FAIL;
+    }
+
+    // Intialise protocomm session with zero public keys
+    if (test_new_session(session1) != ESP_OK) {
+        ESP_LOGE(TAG, "Error creating new session");
+        stop_test_service();
+        free(session1);
+        free(session2);
+        return ESP_FAIL;
+    }
+
+    // Perform 25519 security handshake to set public keys
+    if (test_sec_endpoint(session1) != ESP_OK) {
+        ESP_LOGE(TAG, "Error testing security endpoint");
+        stop_test_service();
+        free(session1);
+        free(session2);
+        return ESP_FAIL;
+    }
+
+    // Try to perform security handshake again with different
+    // session ID without registering new session, hence failing
+    if (test_sec_endpoint(session2) == ESP_OK) {
+        ESP_LOGE(TAG, "Error testing security endpoint");
+        stop_test_service();
+        free(session1);
+        free(session2);
+        return ESP_FAIL;
+    }
+
+    stop_test_service();
+    free(session1);
+    free(session2);
+
+    ESP_LOGI(TAG, "Protocomm test successful");
+    return ESP_OK;
+}
+
+static esp_err_t test_security1_wrong_pop (void)
+{
+    ESP_LOGI(TAG, "Starting Security 1 wrong auth test");
+
+    const char *pop_data = "test pop";
+    protocomm_security_pop_t pop = {
+        .data = (const uint8_t *)pop_data,
+        .len  = strlen(pop_data)
+    };
+
+    session_t *session = calloc(1, sizeof(session_t));
+    if (session == NULL) {
+        ESP_LOGE(TAG, "Error allocating session");
+        return ESP_ERR_NO_MEM;
+    }
+
+    session->id        = 4;
+    session->sec_ver   = 1;
+    session->pop       = &pop;
+
+    // Start protocomm service
+    if (start_test_service(1, &pop) != ESP_OK) {
+        ESP_LOGE(TAG, "Error starting test");
+        free(session);
+        return ESP_FAIL;
+    }
+
+    // Intialise protocomm session with zero public keys
+    if (test_new_session(session) != ESP_OK) {
+        ESP_LOGE(TAG, "Error creating new session");
+        stop_test_service();
+        free(session);
+        return ESP_FAIL;
+    }
+
+    const char *wrong_pop_data = "wrong pop";
+    protocomm_security_pop_t wrong_pop = {
+        .data = (const uint8_t *)wrong_pop_data,
+        .len  = strlen(wrong_pop_data)
+    };
+
+    // Force wrong pop during authentication
+    session->pop = &wrong_pop;
+
+    // Perform 25519 security handshake with
+    // wrong pop, hence failing
+    if (test_sec_endpoint(session) == ESP_OK) {
+        ESP_LOGE(TAG, "Error testing security endpoint");
+        stop_test_service();
+        free(session);
+        return ESP_FAIL;
+    }
+
+    stop_test_service();
+    free(session);
+
+    ESP_LOGI(TAG, "Protocomm test successful");
+    return ESP_OK;
+}
+
+static esp_err_t test_security1_insecure_client (void)
+{
+    ESP_LOGI(TAG, "Starting Security 1 insecure client test");
+
+    const char *pop_data = "test pop";
+    protocomm_security_pop_t pop = {
+        .data = (const uint8_t *)pop_data,
+        .len  = strlen(pop_data)
+    };
+
+    session_t *session = calloc(1, sizeof(session_t));
+    if (session == NULL) {
+        ESP_LOGE(TAG, "Error allocating session");
+        return ESP_ERR_NO_MEM;
+    }
+
+    session->id      = 5;
+    session->sec_ver = 1;
+    session->pop     = &pop;
+
+    // Start protocomm service
+    if (start_test_service(1, &pop) != ESP_OK) {
+        ESP_LOGE(TAG, "Error starting test");
+        free(session);
+        return ESP_FAIL;
+    }
+
+    // Perform 25519 security handshake without
+    // initialising session, hence failing
+    if (test_sec_endpoint(session) == ESP_OK) {
+        ESP_LOGE(TAG, "Error testing security endpoint");
+        stop_test_service();
+        free(session);
+        return ESP_FAIL;
+    }
+
+    // Communicating with request endpoint without
+    // initialising session, hence failing
+    if (test_req_endpoint(session) == ESP_OK) {
+        ESP_LOGE(TAG, "Error testing request endpoint");
+        stop_test_service();
+        free(session);
+        return ESP_FAIL;
+    }
+
+    stop_test_service();
+    free(session);
+
+    ESP_LOGI(TAG, "Protocomm test successful");
+    return ESP_OK;
+}
+
+static esp_err_t test_security1_weak_session (void)
+{
+    ESP_LOGI(TAG, "Starting Security 1 weak session test");
+
+    const char *pop_data = "test pop";
+    protocomm_security_pop_t pop = {
+        .data = (const uint8_t *)pop_data,
+        .len  = strlen(pop_data)
+    };
+
+    session_t *session = calloc(1, sizeof(session_t));
+    if (session == NULL) {
+        ESP_LOGE(TAG, "Error allocating session");
+        return ESP_ERR_NO_MEM;
+    }
+
+    session->id        = 6;
+    session->sec_ver   = 1;
+    session->pop       = &pop;
+    session->weak      = 1;
+
+    // Start protocomm service
+    if (start_test_service(1, &pop) != ESP_OK) {
+        ESP_LOGE(TAG, "Error starting test");
+        free(session);
+        return ESP_FAIL;
+    }
+
+    // Intialise protocomm session with zero public keys
+    if (test_new_session(session) != ESP_OK) {
+        ESP_LOGE(TAG, "Error creating new session");
+        stop_test_service();
+        free(session);
+        return ESP_FAIL;
+    }
+
+    // Perform 25519 security handshake with weak (zero)
+    // client public key, hence failing
+    if (test_sec_endpoint(session) == ESP_OK) {
+        ESP_LOGE(TAG, "Error testing security endpoint");
+        stop_test_service();
+        free(session);
+        return ESP_FAIL;
+    }
+
+    // Sending request data to echo endpoint encrypted with zero
+    // public keys on both client and server side should pass
+    if (test_req_endpoint(session) != ESP_OK) {
+        ESP_LOGE(TAG, "Error testing request endpoint");
+        stop_test_service();
+        free(session);
+        return ESP_FAIL;
+    }
+
+    stop_test_service();
+    free(session);
+
+    ESP_LOGI(TAG, "Protocomm test successful");
+    return ESP_OK;
+}
+
+static esp_err_t test_protocomm (session_t *session)
+{
+    ESP_LOGI(TAG, "Starting Protocomm test");
+
+    // Start protocomm service
+    if (start_test_service(session->sec_ver, session->pop) != ESP_OK) {
+        ESP_LOGE(TAG, "Error starting test");
+        return ESP_FAIL;
+    }
+
+    // Intialise protocomm session with zero public keys
+    if (test_new_session(session) != ESP_OK) {
+        ESP_LOGE(TAG, "Error creating new session");
+        stop_test_service();
+        return ESP_FAIL;
+    }
+
+    // Perform 25519 security handshake to set public keys
+    if (test_sec_endpoint(session) != ESP_OK) {
+        ESP_LOGE(TAG, "Error testing security endpoint");
+        stop_test_service();
+        return ESP_FAIL;
+    }
+
+    // Send request data to echo endpoint encrypted with
+    // the set public keys on both client and server side
+    if (test_req_endpoint(session) != ESP_OK) {
+        ESP_LOGE(TAG, "Error testing request endpoint");
+        stop_test_service();
+        return ESP_FAIL;
+    }
+
+    // Stop protocomm service
+    stop_test_service();
+    ESP_LOGI(TAG, "Protocomm test successful");
+    return ESP_OK;
+}
+
+static esp_err_t test_security1 (void)
+{
+    ESP_LOGI(TAG, "Starting Sec1 test");
+
+    const char *pop_data = "test pop";
+    protocomm_security_pop_t pop = {
+        .data = (const uint8_t *)pop_data,
+        .len  = strlen(pop_data)
+    };
+
+    session_t *session = calloc(1, sizeof(session_t));
+    if (session == NULL) {
+        ESP_LOGE(TAG, "Error allocating session");
+        return ESP_ERR_NO_MEM;
+    }
+
+    session->id        = 7;
+    session->sec_ver   = 1;
+    session->pop       = &pop;
+
+    if (test_protocomm (session) != ESP_OK) {
+        ESP_LOGE(TAG, "Sec1 test failed");
+        free(session);
+        return ESP_FAIL;
+    }
+
+    ESP_LOGI(TAG, "Sec1 test successful");
+    free(session);
+    return ESP_OK;
+}
+
+static esp_err_t test_security0 (void)
+{
+    ESP_LOGI(TAG, "Starting Sec0 test");
+
+    session_t *session = calloc(1, sizeof(session_t));
+    if (session == NULL) {
+        ESP_LOGE(TAG, "Error allocating session");
+        return ESP_ERR_NO_MEM;
+    }
+
+    session->id        = 8;
+    session->sec_ver   = 0;
+    session->pop       = NULL;
+
+    if (test_protocomm (session) != ESP_OK) {
+        ESP_LOGE(TAG, "Sec0 test failed");
+        free(session);
+        return ESP_FAIL;
+    }
+
+    ESP_LOGI(TAG, "Sec0 test successful");
+    free(session);
+    return ESP_OK;
+}
+
+TEST_CASE("leak test", "[PROTOCOMM]")
+{
+#ifdef DO_HEAP_TRACING
+    heap_trace_init_standalone(trace_record, NUM_RECORDS);
+#endif
+
+    unsigned pre_start_mem = esp_get_free_heap_size();
+
+#ifdef DO_HEAP_TRACING
+    heap_trace_start(HEAP_TRACE_LEAKS);
+#endif
+
+    test_security0();
+    test_security1();
+
+#ifdef DO_HEAP_TRACING
+    heap_trace_stop();
+    heap_trace_dump();
+#endif
+
+    unsigned post_stop_mem = esp_get_free_heap_size();
+
+    if (pre_start_mem != post_stop_mem) {
+        ESP_LOGE(TAG, "Mismatch in free heap size");
+    }
+
+#ifdef DO_HEAP_TRACING
+    TEST_ASSERT(pre_start_mem != post_stop_mem);
+#endif
+}
+
+TEST_CASE("security 0 basic test", "[PROTOCOMM]")
+{
+    TEST_ASSERT(test_security0() == ESP_OK);
+}
+
+TEST_CASE("security 1 basic test", "[PROTOCOMM]")
+{
+    TEST_ASSERT(test_security1() == ESP_OK);
+}
+
+TEST_CASE("security 1 no encryption test", "[PROTOCOMM]")
+{
+    TEST_ASSERT(test_security1_no_encryption() == ESP_OK);
+}
+
+TEST_CASE("security 1 session overflow test", "[PROTOCOMM]")
+{
+    TEST_ASSERT(test_security1_session_overflow() == ESP_OK);
+}
+
+TEST_CASE("security 1 wrong pop test", "[PROTOCOMM]")
+{
+    TEST_ASSERT(test_security1_wrong_pop() == ESP_OK);
+}
+
+TEST_CASE("security 1 insecure client test", "[PROTOCOMM]")
+{
+    TEST_ASSERT(test_security1_insecure_client() == ESP_OK);
+}
+
+TEST_CASE("security 1 weak session test", "[PROTOCOMM]")
+{
+    TEST_ASSERT(test_security1_weak_session() == ESP_OK);
+}