COSE: Correct compatibility with COSE standard

Corrections to construction of Sig_structure (TBS bytes). These require
an updated QCBOR. Verified against COSE-C implementation (Bug fixes
and substantial change to COSE-C was required so it is not possible
to test t_cose against COSE-C in GitHub)

Change-Id: I477dcf15192ad5df0310ea123bed8d48b3744740
Signed-off-by: Laurence Lundblade <lgl@securitytheory.com>
diff --git a/lib/t_cose/src/t_cose_util.h b/lib/t_cose/src/t_cose_util.h
index 5539862..78b576e 100644
--- a/lib/t_cose/src/t_cose_util.h
+++ b/lib/t_cose/src/t_cose_util.h
@@ -29,6 +29,24 @@
 
 
 /**
+ * The modes in which the payload is passed to create_tbs_hash().  This
+ * exists so the TBS bytes can be hashed in two separate chunks and
+ * avoids needing a second buffer the size of the payload in the
+ * t_cose implementation.
+ */
+enum t_cose_tbs_hash_mode_t {
+    /** The bytes passed for the payload include a wrapping bstr so
+     * one does not need to be added.
+     */
+    T_COSE_TBS_PAYLOAD_IS_BSTR_WRAPPED,
+    /** The bytes passed for the payload do NOT have a wrapping bstr
+     * so one must be added.
+     */
+    T_COSE_TBS_BARE_PAYLOAD
+};
+
+
+/**
  * \brief Return hash algorithm ID from a signature algorithm ID
  *
  * \param[in] cose_sig_alg_id  A COSE signature algorithm identifier.
@@ -64,7 +82,10 @@
  * \param[out] hash             Pointer and length of the
  *                              resulting hash.
  * \param[in] protected_headers The CBOR encoded protected headers.
- * \param[in] payload           The CBOR encoded payload
+ * \param[in] payload_mode      See \ref t_cose_tbs_hash_mode_t.
+ * \param[in] payload           The CBOR encoded payload. It may or may
+ *                              not have a wrapping bstr per
+ *                              \c payload_mode.
  *
  * \return This returns one of the error codes defined by \ref t_cose_err_t.
  *
@@ -86,6 +107,7 @@
                                   struct q_useful_buf buffer_for_hash,
                                   struct q_useful_buf_c *hash,
                                   struct q_useful_buf_c protected_headers,
+                                  enum t_cose_tbs_hash_mode_t payload_mode,
                                   struct q_useful_buf_c payload);