libcr51sign: Fixes for compiler warnings

Change-Id: I4053720365be81fff02aebbcf8f0e95d34fe87d9
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/subprojects/libcr51sign/src/libcr51sign_support.c b/subprojects/libcr51sign/src/libcr51sign_support.c
index 81f05c5..4e9c517 100644
--- a/subprojects/libcr51sign/src/libcr51sign_support.c
+++ b/subprojects/libcr51sign/src/libcr51sign_support.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 #include <libcr51sign/libcr51sign_support.h>
+#include <openssl/err.h>
 #include <openssl/evp.h>
 #include <openssl/pem.h>
 #include <openssl/rsa.h>
@@ -25,6 +26,10 @@
 {
 #endif
 
+#ifndef USER_PRINT
+#define CPRINTS(ctx, ...) fprintf(stderr, __VA_ARGS__)
+#endif
+
     // @func hash_init get ready to compute a hash
     //
     // @param[in] ctx - context struct
@@ -117,10 +122,10 @@
         // By default returns error.
         int rv = LIBCR51SIGN_ERROR_INVALID_ARGUMENT;
 
-        printf("\n sig_len %zu sig: ", sig_len);
-        for (int i = 0; i < sig_len; i++)
+        CPRINTS(ctx, "\n sig_len %zu sig: ", sig_len);
+        for (size_t i = 0; i < sig_len; i++)
         {
-            printf("%x", sig[i]);
+            CPRINTS(ctx, "%x", sig[i]);
         }
 
         struct libcr51sign_ctx* lctx = (struct libcr51sign_ctx*)ctx;
@@ -130,14 +135,14 @@
         BIO* bio = BIO_new(BIO_s_mem());
         if (!fp)
         {
-            printf("\n fopen failed: ");
+            CPRINTS(ctx, "\n fopen failed: ");
             goto clean_up;
         }
 
         pkey = PEM_read_PUBKEY(fp, 0, 0, 0);
         if (!pkey)
         {
-            printf("\n Read public key failed: ");
+            CPRINTS(ctx, "\n Read public key failed: ");
             goto clean_up;
         }
 
@@ -149,24 +154,24 @@
         pub_rsa = RSAPublicKey_dup(rsa);
         if (!RSA_print(bio, pub_rsa, 2))
         {
-            printf("\n RSA print failed ");
+            CPRINTS(ctx, "\n RSA print failed ");
         }
         if (!pub_rsa)
         {
-            printf("\n no pub rsa: ");
+            CPRINTS(ctx, "\n no pub rsa: ");
             goto clean_up;
         }
-        printf("\n public rsa \n");
+        CPRINTS(ctx, "\n public rsa \n");
         char buffer[1024];
         while (BIO_read(bio, buffer, sizeof(buffer) - 1) > 0)
         {
-            printf(" %s", buffer);
+            CPRINTS(ctx, " %s", buffer);
         }
         enum hash_type hash_type;
         rv = get_hash_type_from_signature(sig_scheme, &hash_type);
         if (rv != LIBCR51SIGN_SUCCESS)
         {
-            printf("\n Invalid hash_type! \n");
+            CPRINTS(ctx, "\n Invalid hash_type! \n");
             goto clean_up;
         }
         int hash_nid = -1;
@@ -188,25 +193,25 @@
         // OpenSSL RSA_verify returns 1 on success and 0 on failure
         if (!ret)
         {
-            printf("\n OPENSSL_ERROR: %s \n",
-                   ERR_error_string(ERR_get_error(), NULL));
+            CPRINTS(ctx, "\n OPENSSL_ERROR: %s \n",
+                    ERR_error_string(ERR_get_error(), NULL));
             rv = LIBCR51SIGN_ERROR_RUNTIME_FAILURE;
             goto clean_up;
         }
         rv = LIBCR51SIGN_SUCCESS;
-        printf("\n sig: ");
-        for (int i = 0; i < sig_len; i++)
+        CPRINTS(ctx, "\n sig: ");
+        for (size_t i = 0; i < sig_len; i++)
         {
-            printf("%x", sig[i]);
+            CPRINTS(ctx, "%x", sig[i]);
         }
 
-        printf("\n data: ");
-        for (int i = 0; i < data_len; i++)
+        CPRINTS(ctx, "\n data: ");
+        for (size_t i = 0; i < data_len; i++)
         {
-            printf("%x", data[i]);
+            CPRINTS(ctx, "%x", data[i]);
         }
         const unsigned rsa_size = RSA_size(pub_rsa);
-        printf("\n rsa size %d sig_len %d", rsa_size, (uint32_t)sig_len);
+        CPRINTS(ctx, "\n rsa size %d sig_len %d", rsa_size, (uint32_t)sig_len);
 
     clean_up:
         if (fp)