Attest: Rename useful_buf to q_useful_buf

Set proper namespace to indicate that q_usful_buf
is originated from QCBOR library and to prevent
namespace collison.

Change-Id: I00a10ccc052dd4d4757f1c451d6534385e58ef00
Signed-off-by: Laurence Lundblade <lgl@securitytheory.com>
Co-authored-by: Tamas Ban <tamas.ban@arm.com>
diff --git a/lib/ext/qcbor/inc/UsefulBuf.h b/lib/ext/qcbor/inc/UsefulBuf.h
index 86a7da7..0aaa9b6 100644
--- a/lib/ext/qcbor/inc/UsefulBuf.h
+++ b/lib/ext/qcbor/inc/UsefulBuf.h
@@ -150,7 +150,7 @@
  Eeyore's balloon fits beautifully, "it goes in and out like anything".
 
 */
-typedef struct useful_buf_c {
+typedef struct q_useful_buf_c {
     const void *ptr;
     size_t      len;
 } UsefulBufC;
@@ -161,7 +161,7 @@
  that is to be filled in. The len is the amount of memory,
  not the length of the valid data in the buffer.
  */
-typedef struct useful_buf {
+typedef struct q_useful_buf {
    void  *ptr;
    size_t len;
 } UsefulBuf;
diff --git a/lib/ext/qcbor/inc/q_useful_buf.h b/lib/ext/qcbor/inc/q_useful_buf.h
new file mode 100644
index 0000000..d7e38d4
--- /dev/null
+++ b/lib/ext/qcbor/inc/q_useful_buf.h
@@ -0,0 +1,151 @@
+/*
+ * q_useful_buf.h
+ *
+ * Copyright 2019, Laurence Lundblade
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * See BSD-3-Clause license in README.mdE.
+ */
+
+
+#ifndef __Q_USEFUL_BUF_H__
+#define __Q_USEFUL_BUF_H__
+
+#include "UsefulBuf.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * \file q_useful_buf.h
+ *
+ * \brief This is a TF-M coding style version of UsefulBuf.
+ *        See UsefulBuf for documentation of these functions.
+ */
+
+
+#define NULL_Q_USEFUL_BUF_C  NULLUsefulBufC
+
+#define NULL_Q_USEFUL_BUF    NULLUsefulBuf
+
+
+static inline int q_useful_buf_c_is_null(struct q_useful_buf_c in)
+{
+    return UsefulBuf_IsNULLC(in);
+}
+
+
+static inline int q_useful_buf_is_null(struct q_useful_buf in)
+{
+    return UsefulBuf_IsNULL(in);
+}
+
+
+static inline int q_useful_buf_c_is_empty(struct q_useful_buf_c in)
+{
+    return UsefulBuf_IsEmptyC(in);
+}
+
+static inline int q_useful_buf_is_empty(struct q_useful_buf in)
+{
+    return UsefulBuf_IsEmpty(in);
+}
+
+
+static inline int q_useful_buf_is_null_or_empty(struct q_useful_buf in)
+{
+    return UsefulBuf_IsNULLOrEmpty(in);
+}
+
+
+static inline int q_useful_buf_c_is_null_or_empty(struct q_useful_buf_c in)
+{
+    return UsefulBuf_IsNULLOrEmptyC(in);
+}
+
+
+static inline struct q_useful_buf q_useful_buf_unconst(struct q_useful_buf_c in)
+{
+    return UsefulBuf_Unconst(in);
+}
+
+#define Q_USEFUL_BUF_FROM_SZ_LITERAL UsefulBuf_FROM_SZ_LITERAL
+
+#define Q_USEFUL_BUF_FROM_BYTE_ARRAY_LITERAL  UsefulBuf_FROM_BYTE_ARRAY_LITERAL
+
+#define Q_USEFUL_BUF_MAKE_STACK_UB UsefulBuf_MAKE_STACK_UB
+
+#define Q_USEFUL_BUF_FROM_BYTE_ARRAY UsefulBuf_FROM_BYTE_ARRAY
+
+
+static inline struct q_useful_buf_c q_useful_buf_from_sz(const char *string)
+{
+    return UsefulBuf_FromSZ(string);
+}
+
+static inline struct q_useful_buf_c
+useful_buf_copy_offset(struct q_useful_buf dest,
+                       size_t offset,
+                       struct q_useful_buf_c src)
+{
+    return UsefulBuf_CopyOffset(dest, offset, src);
+}
+
+
+
+static inline struct q_useful_buf_c q_useful_buf_copy(struct q_useful_buf dest,
+                                                     struct q_useful_buf_c src)
+{
+    return UsefulBuf_Copy(dest, src);
+}
+
+
+static inline struct q_useful_buf_c q_useful_buf_set(struct q_useful_buf dest,
+                                                     uint8_t value)
+{
+    return UsefulBuf_Set(dest, value);
+}
+
+
+static inline struct q_useful_buf_c q_useful_buf_copy_ptr(struct q_useful_buf dest,
+                                                          const void *ptr,
+                                                          size_t len)
+{
+    return UsefulBuf_CopyPtr(dest, ptr, len);
+}
+
+
+static inline struct q_useful_buf_c q_useful_buf_head(struct q_useful_buf_c buf,
+                                                      size_t amount)
+{
+    return UsefulBuf_Head(buf, amount);
+}
+
+static inline struct q_useful_buf_c q_useful_buf_tail(struct q_useful_buf_c buf,
+                                                      size_t amount)
+{
+    return UsefulBuf_Tail(buf, amount);
+}
+
+static inline int q_useful_buf_compare(const struct q_useful_buf_c buf1,
+                                       const struct q_useful_buf_c buf2)
+{
+    return UsefulBuf_Compare(buf1, buf2);
+}
+
+static inline size_t
+useful_buf_find_bytes(const struct q_useful_buf_c bytes_to_search,
+                      const struct q_useful_buf_c bytes_to_find)
+{
+    return UsefulBuf_FindBytes(bytes_to_search, bytes_to_find);
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __Q_USEFUL_BUF_H__ */
diff --git a/lib/ext/qcbor/inc/useful_buf.h b/lib/ext/qcbor/inc/useful_buf.h
deleted file mode 100644
index dcb88b8..0000000
--- a/lib/ext/qcbor/inc/useful_buf.h
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * useful_buf.h
- *
- * Copyright 2019, Laurence Lundblade
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * See BSD-3-Clause license in README.mdE.
- */
-
-
-#ifndef __USEFUL_BUF_H__
-#define __USEFUL_BUF_H__
-
-#include "UsefulBuf.h"
-
-
-/**
- * \file useful_buf.h
- *
- * \brief This is a TF-M coding style version of UsefulBuf.
- *        See UsefulBuf for documentation of these functions.
- */
-
-
-#define NULL_USEFUL_BUF_C  NULLUsefulBufC
-
-#define NULL_USEFUL_BUF    NULLUsefulBuf
-
-
-static inline int useful_buf_c_is_null(struct useful_buf_c in)
-{
-    return UsefulBuf_IsNULLC(in);
-}
-
-
-static inline int useful_buf_is_null(struct useful_buf in)
-{
-    return UsefulBuf_IsNULL(in);
-}
-
-
-static inline int useful_buf_c_is_empty(struct useful_buf_c in)
-{
-    return UsefulBuf_IsEmptyC(in);
-}
-
-static inline int useful_buf_is_empty(struct useful_buf in)
-{
-    return UsefulBuf_IsEmpty(in);
-}
-
-
-static inline int useful_buf_is_null_or_empty(struct useful_buf in)
-{
-    return UsefulBuf_IsNULLOrEmpty(in);
-}
-
-
-static inline int useful_buf_c_is_null_or_empty(struct useful_buf_c in)
-{
-    return UsefulBuf_IsNULLOrEmptyC(in);
-}
-
-
-static inline struct useful_buf useful_buf_unconst(struct useful_buf_c in)
-{
-    return UsefulBuf_Unconst(in);
-}
-
-#define USEFUL_BUF_FROM_SZ_LITERAL UsefulBuf_FROM_SZ_LITERAL
-
-#define USEFUL_BUF_FROM_BYTE_ARRAY_LITERAL  UsefulBuf_FROM_BYTE_ARRAY_LITERAL
-
-#define USEFUL_BUF_MAKE_STACK_UB UsefulBuf_MAKE_STACK_UB
-
-#define USEFUL_BUF_FROM_BYTE_ARRAY UsefulBuf_FROM_BYTE_ARRAY
-
-
-static inline struct useful_buf_c useful_buf_from_sz(const char *string)
-{
-    return UsefulBuf_FromSZ(string);
-}
-
-static inline struct
-useful_buf_c useful_buf_copy_offset(struct useful_buf dest,
-                                    size_t offset,
-                                    struct useful_buf_c src)
-{
-    return UsefulBuf_CopyOffset(dest, offset, src);
-}
-
-
-
-static inline struct useful_buf_c useful_buf_copy(struct useful_buf dest,
-                                                  struct useful_buf_c src)
-{
-    return UsefulBuf_Copy(dest, src);
-}
-
-
-static inline struct useful_buf_c useful_buf_set(struct useful_buf dest,
-                                                 uint8_t value)
-{
-    return UsefulBuf_Set(dest, value);
-}
-
-
-static inline struct useful_buf_c useful_buf_copy_ptr(struct useful_buf dest,
-                                                      const void *ptr,
-                                                      size_t len)
-{
-    return UsefulBuf_CopyPtr(dest, ptr, len);
-}
-
-
-static inline struct useful_buf_c useful_buf_head(struct useful_buf_c buf,
-                                                  size_t amount)
-{
-    return UsefulBuf_Head(buf, amount);
-}
-
-static inline struct useful_buf_c useful_buf_tail(struct useful_buf_c buf,
-                                                  size_t amount)
-{
-    return UsefulBuf_Tail(buf, amount);
-}
-
-static inline int useful_buf_compare(const struct useful_buf_c buf1,
-                                     const struct useful_buf_c buf2)
-{
-    return UsefulBuf_Compare(buf1, buf2);
-}
-
-static inline size_t
-useful_buf_find_bytes(const struct useful_buf_c bytes_to_search,
-                      const struct useful_buf_c bytes_to_find)
-{
-    return UsefulBuf_FindBytes(bytes_to_search, bytes_to_find);
-}
-
-
-#endif /* __USEFUL_BUF_H__ */
diff --git a/lib/t_cose/inc/t_cose_common.h b/lib/t_cose/inc/t_cose_common.h
index d509a4b..1459702 100644
--- a/lib/t_cose/inc/t_cose_common.h
+++ b/lib/t_cose/inc/t_cose_common.h
@@ -12,6 +12,9 @@
 #ifndef __T_COSE_COMMON_H__
 #define __T_COSE_COMMON_H__
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 /**
  * \file t_cose_common.h
@@ -143,6 +146,9 @@
     T_COSE_ERR_SHORT_CIRCUIT_SIG
 };
 
+#ifdef __cplusplus
+}
+#endif
 
 
 #endif /* __T_COSE_COMMON_H__ */
diff --git a/lib/t_cose/inc/t_cose_sign1_sign.h b/lib/t_cose/inc/t_cose_sign1_sign.h
index 35b26e5..dbe8896 100644
--- a/lib/t_cose/inc/t_cose_sign1_sign.h
+++ b/lib/t_cose/inc/t_cose_sign1_sign.h
@@ -16,6 +16,10 @@
 #include "qcbor.h"
 #include "t_cose_common.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 
 /**
  * \file t_cose_sign1_sign.h
@@ -59,13 +63,13 @@
  */
 struct t_cose_sign1_ctx {
     /* Private data structure */
-    uint8_t             buffer_for_protected_headers[
-                        T_COSE_SIGN1_MAX_PROT_HEADER];
-    struct useful_buf_c protected_headers;
-    int32_t             cose_algorithm_id;
-    int32_t             key_select;
-    bool                short_circuit_sign;
-    QCBOREncodeContext *cbor_encode_ctx;
+    uint8_t               buffer_for_protected_headers[
+                          T_COSE_SIGN1_MAX_PROT_HEADER];
+    struct q_useful_buf_c protected_headers;
+    int32_t               cose_algorithm_id;
+    int32_t               key_select;
+    bool                  short_circuit_sign;
+    QCBOREncodeContext   *cbor_encode_ctx;
 };
 
 
@@ -175,7 +179,11 @@
  * cbor_encode_ctx by calling \c QCBOREncode_Finish()
  */
 enum t_cose_err_t t_cose_sign1_finish(struct t_cose_sign1_ctx *me,
-                                      struct useful_buf_c payload);
+                                      struct q_useful_buf_c payload);
 
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* __T_COSE_SIGN1_H__ */
diff --git a/lib/t_cose/src/t_cose_crypto.h b/lib/t_cose/src/t_cose_crypto.h
index b77af32..d66f983 100644
--- a/lib/t_cose/src/t_cose_crypto.h
+++ b/lib/t_cose/src/t_cose_crypto.h
@@ -13,10 +13,13 @@
 #define __T_COSE_CRYPTO_H__
 
 #include "t_cose_common.h"
-#include "useful_buf.h"
+#include "q_useful_buf.h"
 #include <stdint.h>
 #include "t_cose_defines.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 /**
  * \file t_cose_crypto.h
@@ -27,8 +30,8 @@
  * This is  small wrapper around the cryptographic functions to:
  * - Map COSE algorithm IDs to TF-M algorithm IDs
  * - Map crypto errors to \ref t_cose_err_t errors
- * - Have inputs and outputs be \c struct \c useful_buf_c and
- *   \c struct \c useful_buf
+ * - Have inputs and outputs be \c struct \c q_useful_buf_c and
+ *   \c struct \c q_useful_buf
  * - Handle key selection
  *
  * The idea is that implementations can be made of these functions
@@ -45,14 +48,14 @@
  * the IANA registry.
  *
  * Binary data is returned to the caller using a \c struct \c
- * useful_buf to pass the buffer to receive the data and its length in
- * and a \c useful_buf_c to return the pointer and length of the
+ * q_useful_buf to pass the buffer to receive the data and its length in
+ * and a \c q_useful_buf_c to return the pointer and length of the
  * returned data. The point of this is coding hygiene. The buffer
  * passed in is not const as it is to be modified.  The \c
- * useful_buf_c returned is const.
+ * q_useful_buf_c returned is const.
  *
- * The pointer in the \c useful_buf_c will always point to the buffer
- * passed in via the \c useful_buf so the lifetime of the data is
+ * The pointer in the \c q_useful_buf_c will always point to the buffer
+ * passed in via the \c q_useful_buf so the lifetime of the data is
  * under control of the caller.
  *
  * This is not intended as any sort of general cryptographic API. It
@@ -137,7 +140,7 @@
  * The key selection depends on the platform / OS.
  *
  * See the note in the Detailed Description (the \\file comment block)
- * for details on how \c useful_buf and \c useful_buf_c are used to
+ * for details on how \c q_useful_buf and \c q_useful_buf_c are used to
  * return the signature.
  *
  * To find out the size of the signature buffer needed, call this with
@@ -148,9 +151,9 @@
 enum t_cose_err_t
 t_cose_crypto_pub_key_sign(int32_t cose_alg_id,
                            int32_t key_select,
-                           struct useful_buf_c hash_to_sign,
-                           struct useful_buf signature_buffer,
-                           struct useful_buf_c *signature);
+                           struct q_useful_buf_c hash_to_sign,
+                           struct q_useful_buf signature_buffer,
+                           struct q_useful_buf_c *signature);
 
 
 /**
@@ -166,7 +169,7 @@
  *                           locally (\c \#define) if the needed one
  *                           hasn't been registered.
  * \param[in] key_select     Verification key selection.
- * \param[in] key_id         A key id or \c NULL_USEFUL_BUF_C.
+ * \param[in] key_id         A key id or \c NULL_Q_USEFUL_BUF_C.
  * \param[in] hash_to_verify The data or hash that is to be verified.
  * \param[in] signature      The signature.
  *
@@ -174,7 +177,7 @@
  * hash_to_verify passed in.
  *
  * The public key used to verify the signature is selected by the \c
- * key_id if it is not \c NULL_USEFUL_BUF_C or the \c key_select if it
+ * key_id if it is not \c NULL_Q_USEFUL_BUF_C or the \c key_select if it
  * is.
  *
  * The key selected must be, or include, a public key of the correct
@@ -206,9 +209,9 @@
 enum t_cose_err_t
 t_cose_crypto_pub_key_verify(int32_t cose_alg_id,
                              int32_t key_select,
-                             struct useful_buf_c key_id,
-                             struct useful_buf_c hash_to_verify,
-                             struct useful_buf_c signature);
+                             struct q_useful_buf_c key_id,
+                             struct q_useful_buf_c hash_to_verify,
+                             struct q_useful_buf_c signature);
 
 
 /**
@@ -228,9 +231,9 @@
  *
  * \param[in] key_select     Used to look up the public
  *                           key to return when \c kid is
- *                           \c NULL_USEFUL_BUF_C.
+ *                           \c NULL_Q_USEFUL_BUF_C.
  * \param[in] kid            A key ID to look up against. May be
- *                           \c NULL_USEFUL_BUF_C. This is typically
+ *                           \c NULL_Q_USEFUL_BUF_C. This is typically
  *                           the kid from the COSE unprotected header.
  * \param[out] cose_curve_id The curve ID of the key returned as
  *                           defined by [COSE (RFC 8152)]
@@ -265,17 +268,17 @@
  * coordinate for the NIST P-256 curve.
  *
  * See the note in the Detailed Description (the \\file comment block)
- * for details on how \c useful_buf and \c useful_buf_c are used to
+ * for details on how \c q_useful_buf and \c q_useful_buf_c are used to
  * return the X and Y coordinates.
  */
 enum t_cose_err_t
 t_cose_crypto_get_ec_pub_key(int32_t key_select,
-                             struct useful_buf_c kid,
+                             struct q_useful_buf_c kid,
                              int32_t *cose_curve_id,
-                             struct useful_buf buf_to_hold_x_coord,
-                             struct useful_buf buf_to_hold_y_coord,
-                             struct useful_buf_c  *x_coord,
-                             struct useful_buf_c  *y_coord);
+                             struct q_useful_buf buf_to_hold_x_coord,
+                             struct q_useful_buf buf_to_hold_y_coord,
+                             struct q_useful_buf_c  *x_coord,
+                             struct q_useful_buf_c  *y_coord);
 
 
 /*
@@ -361,7 +364,7 @@
  * not do anything.
  */
 void t_cose_crypto_hash_update(struct t_cose_crypto_hash *hash_ctx,
-                               struct useful_buf_c data_to_hash);
+                               struct q_useful_buf_c data_to_hash);
 
 
 /**
@@ -386,13 +389,13 @@
  * returned here.
  *
  * See the note in the Detailed Description (the \\file comment block)
- * for details on how \c useful_buf and \c useful_buf_c are used to
+ * for details on how \c q_useful_buf and \c q_useful_buf_c are used to
  * return the hash.
  */
 enum t_cose_err_t
 t_cose_crypto_hash_finish(struct t_cose_crypto_hash *hash_ctx,
-                          struct useful_buf buffer_to_hold_result,
-                          struct useful_buf_c *hash_result);
+                          struct q_useful_buf buffer_to_hold_result,
+                          struct q_useful_buf_c *hash_result);
 
 
 
@@ -410,4 +413,8 @@
 }
 
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* __T_COSE_CRYPTO_H__ */
diff --git a/lib/t_cose/src/t_cose_psa_crypto.c b/lib/t_cose/src/t_cose_psa_crypto.c
index 89c8fa3..56a3b8e 100644
--- a/lib/t_cose/src/t_cose_psa_crypto.c
+++ b/lib/t_cose/src/t_cose_psa_crypto.c
@@ -31,9 +31,9 @@
 enum t_cose_err_t
 t_cose_crypto_pub_key_sign(int32_t cose_alg_id,
                            int32_t key_select,
-                           struct useful_buf_c hash_to_sign,
-                           struct useful_buf signature_buffer,
-                           struct useful_buf_c *signature)
+                           struct q_useful_buf_c hash_to_sign,
+                           struct q_useful_buf signature_buffer,
+                           struct q_useful_buf_c *signature)
 {
     enum t_cose_err_t cose_ret = T_COSE_SUCCESS;
     enum psa_attest_err_t attest_ret;
@@ -84,12 +84,12 @@
 
 enum t_cose_err_t
 t_cose_crypto_get_ec_pub_key(int32_t key_select,
-                             struct useful_buf_c kid,
+                             struct q_useful_buf_c kid,
                              int32_t *cose_curve_id,
-                             struct useful_buf buf_to_hold_x_coord,
-                             struct useful_buf buf_to_hold_y_coord,
-                             struct useful_buf_c *x_coord,
-                             struct useful_buf_c *y_coord)
+                             struct q_useful_buf buf_to_hold_x_coord,
+                             struct q_useful_buf buf_to_hold_y_coord,
+                             struct q_useful_buf_c *x_coord,
+                             struct q_useful_buf_c *y_coord)
 {
     enum tfm_plat_err_t plat_res;
     enum ecc_curve_t cose_curve;
@@ -232,7 +232,7 @@
 }
 
 void t_cose_crypto_hash_update(struct t_cose_crypto_hash *hash_ctx,
-                               struct useful_buf_c data_to_hash)
+                               struct q_useful_buf_c data_to_hash)
 {
     struct t_cose_psa_crypto_hash *psa_hash_ctx;
 
@@ -259,8 +259,8 @@
 
 enum t_cose_err_t
 t_cose_crypto_hash_finish(struct t_cose_crypto_hash *hash_ctx,
-                          struct useful_buf buffer_to_hold_result,
-                          struct useful_buf_c *hash_result)
+                          struct q_useful_buf buffer_to_hold_result,
+                          struct q_useful_buf_c *hash_result)
 {
     enum t_cose_err_t cose_ret = T_COSE_SUCCESS;
     psa_status_t psa_ret;
diff --git a/lib/t_cose/src/t_cose_sign1_sign.c b/lib/t_cose/src/t_cose_sign1_sign.c
index 8f55bc0..47ee795 100644
--- a/lib/t_cose/src/t_cose_sign1_sign.c
+++ b/lib/t_cose/src/t_cose_sign1_sign.c
@@ -46,9 +46,9 @@
  */
 static inline enum t_cose_err_t
 short_circuit_sign(int32_t cose_alg_id,
-                   struct useful_buf_c hash_to_sign,
-                   struct useful_buf signature_buffer,
-                   struct useful_buf_c *signature)
+                   struct q_useful_buf_c hash_to_sign,
+                   struct q_useful_buf signature_buffer,
+                   struct q_useful_buf_c *signature)
 {
     /* approximate stack use on 32-bit machine: local use: 16
      */
@@ -119,28 +119,28 @@
  */
 static enum t_cose_err_t
 t_cose_encode_cose_key(int32_t key_select,
-                       struct useful_buf buffer_for_cose_key,
-                       struct useful_buf_c *cose_key)
+                       struct q_useful_buf buffer_for_cose_key,
+                       struct q_useful_buf_c *cose_key)
 {
     /* approximate stack use on 32-bit machine:
      * local use: 328
      * with calls: 370
      */
-    enum t_cose_err_t         return_value;
-    QCBORError                qcbor_result;
-    QCBOREncodeContext        cbor_encode_ctx;
-    USEFUL_BUF_MAKE_STACK_UB( buffer_for_x_coord,
-                                  T_COSE_CRYPTO_EC_P256_COORD_SIZE);
-    USEFUL_BUF_MAKE_STACK_UB( buffer_for_y_coord,
-                                  T_COSE_CRYPTO_EC_P256_COORD_SIZE);
-    struct useful_buf_c       x_coord;
-    struct useful_buf_c       y_coord;
-    int32_t                   cose_curve_id;
-    struct useful_buf_c       encoded_key_id;
+    enum t_cose_err_t           return_value;
+    QCBORError                  qcbor_result;
+    QCBOREncodeContext          cbor_encode_ctx;
+    Q_USEFUL_BUF_MAKE_STACK_UB( buffer_for_x_coord,
+                                    T_COSE_CRYPTO_EC_P256_COORD_SIZE);
+    Q_USEFUL_BUF_MAKE_STACK_UB( buffer_for_y_coord,
+                                    T_COSE_CRYPTO_EC_P256_COORD_SIZE);
+    struct q_useful_buf_c       x_coord;
+    struct q_useful_buf_c       y_coord;
+    int32_t                     cose_curve_id;
+    struct q_useful_buf_c       encoded_key_id;
 
     /* Get the public key x and y */
     return_value = t_cose_crypto_get_ec_pub_key(key_select,
-                                                NULL_USEFUL_BUF_C,
+                                                NULL_Q_USEFUL_BUF_C,
                                                 &cose_curve_id,
                                                 buffer_for_x_coord,
                                                 buffer_for_y_coord,
@@ -199,9 +199,9 @@
  * Having this as a separate function helps keep stack usage down and
  * is convenient.
  */
-static enum t_cose_err_t quick_sha256(struct useful_buf_c bytes_to_hash,
-                                      struct useful_buf buffer_for_hash,
-                                      struct useful_buf_c *hash)
+static enum t_cose_err_t quick_sha256(struct q_useful_buf_c bytes_to_hash,
+                                      struct q_useful_buf buffer_for_hash,
+                                      struct q_useful_buf_c *hash)
 {
     /* approximate stack use on 32-bit machine:
      local use: 132
@@ -241,18 +241,18 @@
  * created here.
  */
 static inline enum t_cose_err_t get_keyid(int32_t key_select,
-                                          struct useful_buf buffer_for_key_id,
-                                          struct useful_buf_c *key_id)
+                                          struct q_useful_buf buffer_for_key_id,
+                                          struct q_useful_buf_c *key_id)
 {
     /* approximate stack use on 32-bit machine:
      * local use: 100
      * with calls inlined: 560
      * with calls not inlined: 428
      */
-    enum t_cose_err_t           return_value;
-    USEFUL_BUF_MAKE_STACK_UB(   buffer_for_cose_key,
-                                    MAX_ENCODED_COSE_KEY_SIZE);
-    struct useful_buf_c         cose_key;
+    enum t_cose_err_t             return_value;
+    Q_USEFUL_BUF_MAKE_STACK_UB(   buffer_for_cose_key,
+                                      MAX_ENCODED_COSE_KEY_SIZE);
+    struct q_useful_buf_c         cose_key;
 
     /* Doing the COSE encoding and the hashing in separate functions
      * called from here reduces the stack usage in this function by a
@@ -285,28 +285,28 @@
  *                               headers is put.
  *
  * \return The pointer and length of the protected headers is
- * returned, or \c NULL_USEFUL_BUF_C if this fails.
+ * returned, or \c NULL_Q_USEFUL_BUF_C if this fails.
  *
  * The protected headers are returned in fully encoded CBOR format as
  * they are added to the \c COSE_Sign1 as a binary string. This is
  * different from the unprotected headers which are not handled this
  * way.
  *
- * This returns \c NULL_USEFUL_BUF_C if buffer_for_header was too
+ * This returns \c NULL_Q_USEFUL_BUF_C if buffer_for_header was too
  * small. See also definition of \ref T_COSE_SIGN1_MAX_PROT_HEADER
  */
-static inline struct useful_buf_c
+static inline struct q_useful_buf_c
 make_protected_header(int32_t cose_alg_id,
-                      struct useful_buf buffer_for_header)
+                      struct q_useful_buf buffer_for_header)
 {
     /* approximate stack use on 32-bit machine:
      * local use: 170
      * with calls: 210
      */
-    struct useful_buf_c protected_headers;
-    QCBORError          qcbor_result;
-    QCBOREncodeContext  cbor_encode_ctx;
-    struct useful_buf_c return_value;
+    struct q_useful_buf_c protected_headers;
+    QCBORError            qcbor_result;
+    QCBOREncodeContext    cbor_encode_ctx;
+    struct q_useful_buf_c return_value;
 
     QCBOREncode_Init(&cbor_encode_ctx, buffer_for_header);
     QCBOREncode_OpenMap(&cbor_encode_ctx);
@@ -319,7 +319,7 @@
     if(qcbor_result == QCBOR_SUCCESS) {
         return_value = protected_headers;
     } else {
-        return_value = NULL_USEFUL_BUF_C;
+        return_value = NULL_Q_USEFUL_BUF_C;
     }
 
     return return_value;
@@ -338,7 +338,7 @@
  * The unprotected headers added by this are just the key ID
  */
 static inline void add_unprotected_headers(QCBOREncodeContext *cbor_encode_ctx,
-                                           struct useful_buf_c kid)
+                                           struct q_useful_buf_c kid)
 {
     QCBOREncode_OpenMap(cbor_encode_ctx);
     QCBOREncode_AddBytesToMapN(cbor_encode_ctx, COSE_HEADER_PARAM_KID, kid);
@@ -361,11 +361,11 @@
      * with calls not inlined: 500
      */
 
-    int32_t                     hash_alg;
-    enum t_cose_err_t           return_value;
-    USEFUL_BUF_MAKE_STACK_UB(   buffer_for_kid, T_COSE_CRYPTO_SHA256_SIZE);
-    struct useful_buf_c         kid;
-    struct useful_buf           buffer_for_protected_header;
+    int32_t                       hash_alg;
+    enum t_cose_err_t             return_value;
+    Q_USEFUL_BUF_MAKE_STACK_UB(   buffer_for_kid, T_COSE_CRYPTO_SHA256_SIZE);
+    struct q_useful_buf_c         kid;
+    struct q_useful_buf           buffer_for_protected_header;
 
     /* Check the cose_alg_id now by getting the hash alg as an early
      error check even though it is not used until later. */
@@ -398,10 +398,10 @@
 
     /* The protected headers, which are added as a wrapped bstr  */
     buffer_for_protected_header =
-        USEFUL_BUF_FROM_BYTE_ARRAY(me->buffer_for_protected_headers);
+        Q_USEFUL_BUF_FROM_BYTE_ARRAY(me->buffer_for_protected_headers);
     me->protected_headers = make_protected_header(cose_alg_id,
                                                   buffer_for_protected_header);
-    if(useful_buf_c_is_null(me->protected_headers)) {
+    if(q_useful_buf_c_is_null(me->protected_headers)) {
         /* The sizing of storage for protected headers is
           off (should never happen in tested, released code) */
         return_value = T_COSE_SUCCESS;
@@ -427,24 +427,24 @@
  * Public function. See t_cose_sign1_sign.h
  */
 enum t_cose_err_t t_cose_sign1_finish(struct t_cose_sign1_ctx *me,
-                                      struct useful_buf_c signed_payload)
+                                      struct q_useful_buf_c signed_payload)
 {
     /* approximate stack use on 32-bit machine:
      *   local use: 116
      * with calls inline: 500
      * with calls not inlined; 450
      */
-    enum t_cose_err_t          return_value;
+    enum t_cose_err_t            return_value;
     /* pointer and length of the completed tbs hash */
-    struct useful_buf_c        tbs_hash;
+    struct q_useful_buf_c        tbs_hash;
     /* Pointer and length of the completed signature */
-    struct useful_buf_c        signature;
+    struct q_useful_buf_c        signature;
     /* Buffer for the actual signature */
-    USEFUL_BUF_MAKE_STACK_UB(  buffer_for_signature,
-                                   T_COSE_MAX_EC_SIG_SIZE);
+    Q_USEFUL_BUF_MAKE_STACK_UB(  buffer_for_signature,
+                                     T_COSE_MAX_EC_SIG_SIZE);
     /* Buffer for the tbs hash. Only big enough for SHA256 */
-    USEFUL_BUF_MAKE_STACK_UB(  buffer_for_tbs_hash,
-                                   T_COSE_CRYPTO_SHA256_SIZE);
+    Q_USEFUL_BUF_MAKE_STACK_UB(  buffer_for_tbs_hash,
+                                     T_COSE_CRYPTO_SHA256_SIZE);
 
     /* Create the hash of the to-be-signed bytes. Inputs to the hash
      * are the protected headers, the payload that getting signed, the
diff --git a/lib/t_cose/src/t_cose_util.c b/lib/t_cose/src/t_cose_util.c
index ba4910e..4228c2b 100644
--- a/lib/t_cose/src/t_cose_util.c
+++ b/lib/t_cose/src/t_cose_util.c
@@ -76,10 +76,10 @@
  * Public function. See t_cose_util.h
  */
 enum t_cose_err_t create_tbs_hash(int32_t cose_alg_id,
-                                  struct useful_buf buffer_for_hash,
-                                  struct useful_buf_c *hash,
-                                  struct useful_buf_c protected_headers,
-                                  struct useful_buf_c payload)
+                                  struct q_useful_buf buffer_for_hash,
+                                  struct q_useful_buf_c *hash,
+                                  struct q_useful_buf_c protected_headers,
+                                  struct q_useful_buf_c payload)
 {
     /* approximate stack use on 32-bit machine:
      * local use: 320
@@ -88,7 +88,7 @@
     enum t_cose_err_t           return_value;
     QCBOREncodeContext          cbor_encode_ctx;
     UsefulBuf_MAKE_STACK_UB(    buffer_for_TBS_first_part, T_COSE_SIZE_OF_TBS);
-    struct useful_buf_c         tbs_first_part;
+    struct q_useful_buf_c       tbs_first_part;
     QCBORError                  qcbor_result;
     struct t_cose_crypto_hash   hash_ctx;
     int32_t                     hash_alg_id;
@@ -103,14 +103,14 @@
     QCBOREncode_AddBytes(&cbor_encode_ctx,
                          protected_headers);
     /* sign_protected */
-    QCBOREncode_AddBytes(&cbor_encode_ctx, NULL_USEFUL_BUF_C);
+    QCBOREncode_AddBytes(&cbor_encode_ctx, NULL_Q_USEFUL_BUF_C);
     /* external_aad */
-    QCBOREncode_AddBytes(&cbor_encode_ctx, NULL_USEFUL_BUF_C);
+    QCBOREncode_AddBytes(&cbor_encode_ctx, NULL_Q_USEFUL_BUF_C);
     /* fake payload */
-    QCBOREncode_AddBytes(&cbor_encode_ctx, NULL_USEFUL_BUF_C);
+    QCBOREncode_AddBytes(&cbor_encode_ctx, NULL_Q_USEFUL_BUF_C);
     QCBOREncode_CloseArray(&cbor_encode_ctx);
 
-    /* get the result and convert it to struct useful_buf_c representation */
+    /* get the result and convert it to struct q_useful_buf_c representation */
     qcbor_result = QCBOREncode_Finish(&cbor_encode_ctx, &tbs_first_part);
     if(qcbor_result) {
         /* Mainly means that the protected_headers were too big
@@ -137,8 +137,8 @@
      * buffer for the whole cose sign1.
      */
     t_cose_crypto_hash_update(&hash_ctx,
-                              useful_buf_head(tbs_first_part,
-                                              tbs_first_part.len - 2));
+                              q_useful_buf_head(tbs_first_part,
+                                                tbs_first_part.len - 2));
 
     /* Hash the payload */
     t_cose_crypto_hash_update(&hash_ctx, payload);
@@ -157,8 +157,8 @@
  * Public function. See t_cose_util.h
  */
 enum t_cose_err_t
-get_short_circuit_kid(struct useful_buf buffer_for_kid,
-                     struct useful_buf_c *kid)
+get_short_circuit_kid(struct q_useful_buf buffer_for_kid,
+                      struct q_useful_buf_c *kid)
 {
     /* This is a random hard coded key ID that is used to indicate
      * short-circuit signing. It is OK to hard code this as the
@@ -179,11 +179,11 @@
         return T_COSE_ERR_BAD_SHORT_CIRCUIT_KID;
     }
 
-    *kid = useful_buf_copy(buffer_for_kid,
-                           USEFUL_BUF_FROM_BYTE_ARRAY_LITERAL(
-                               defined_short_circuit_kid));
+    *kid = q_useful_buf_copy(buffer_for_kid,
+                             Q_USEFUL_BUF_FROM_BYTE_ARRAY_LITERAL(
+                                 defined_short_circuit_kid));
 
-    return useful_buf_c_is_null(*kid) ?
+    return q_useful_buf_c_is_null(*kid) ?
               T_COSE_ERR_KEY_BUFFER_SIZE :
               T_COSE_SUCCESS;
 }
diff --git a/lib/t_cose/src/t_cose_util.h b/lib/t_cose/src/t_cose_util.h
index 7b39dc3..5539862 100644
--- a/lib/t_cose/src/t_cose_util.h
+++ b/lib/t_cose/src/t_cose_util.h
@@ -13,9 +13,13 @@
 #define __T_COSE_UTIL_H__
 
 #include <stdint.h>
-#include "useful_buf.h"
+#include "q_useful_buf.h"
 #include "t_cose_common.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /**
  * \file t_cose_util.h
  *
@@ -79,10 +83,10 @@
  * "TBS" bytes.
  */
 enum t_cose_err_t create_tbs_hash(int32_t cose_alg_id,
-                                  struct useful_buf buffer_for_hash,
-                                  struct useful_buf_c *hash,
-                                  struct useful_buf_c protected_headers,
-                                  struct useful_buf_c payload);
+                                  struct q_useful_buf buffer_for_hash,
+                                  struct q_useful_buf_c *hash,
+                                  struct q_useful_buf_c protected_headers,
+                                  struct q_useful_buf_c payload);
 
 
 /**
@@ -120,7 +124,11 @@
  *
  */
 enum t_cose_err_t
-get_short_circuit_kid(struct useful_buf buffer_for_kid,
-                      struct useful_buf_c *kid);
+get_short_circuit_kid(struct q_useful_buf buffer_for_kid,
+                      struct q_useful_buf_c *kid);
+
+#ifdef __cplusplus
+}
+#endif
 
 #endif /* __T_COSE_UTIL_H__ */