besser82/libxcrypt

Build fails with Intel OneAPI 2021.3.0 (unsafe conversions)

Opened this issue · 6 comments

When attempting to build with Intel 2021.3.0, the following error messages appear at lib/alg-gost3411-2012-hmac.c lines 48, 53, and 63:

error #2259: non-pointer conversion from "int" to "unsigned char" may lose significant bits.

Thank you for the bug report!

Does the following patch fix your issue?

diff --git a/lib/alg-gost3411-2012-hmac.c b/lib/alg-gost3411-2012-hmac.c
index 45001d2..6549a48 100644
--- a/lib/alg-gost3411-2012-hmac.c
+++ b/lib/alg-gost3411-2012-hmac.c
@@ -45,12 +45,12 @@ gost_hmac256 (const uint8_t *k, size_t n, const uint8_t *t, size_t len,
   assert (n >= GOSTR3411_2012_L && n <= GOSTR3411_2012_B);
 
   for (i = 0; i < sizeof (gostbuf->pad); i++)
-    gostbuf->kstar[i] = i < n ? k[i] : 0;
+    gostbuf->kstar[i] = (unsigned char)(i < n ? k[i] : 0);
 
   GOST34112012Init (&gostbuf->ctx, GOSTR3411_2012_BITS);
 
   for (i = 0; i < sizeof (gostbuf->pad); i++)
-    gostbuf->pad[i] = gostbuf->kstar[i] ^ 0x36; /* ipad */
+    gostbuf->pad[i] = (unsigned char)(gostbuf->kstar[i] ^ 0x36); /* ipad */
 
   GOST34112012Update (&gostbuf->ctx, gostbuf->pad,
                       sizeof (gostbuf->pad));
@@ -60,7 +60,7 @@ gost_hmac256 (const uint8_t *k, size_t n, const uint8_t *t, size_t len,
   GOST34112012Init (&gostbuf->ctx, GOSTR3411_2012_BITS);
 
   for (i = 0; i < sizeof (gostbuf->pad); i++)
-    gostbuf->pad[i] = gostbuf->kstar[i] ^ 0x5c; /* opad */
+    gostbuf->pad[i] = (unsigned char)(gostbuf->kstar[i] ^ 0x5c); /* opad */
 
   GOST34112012Update (&gostbuf->ctx, gostbuf->pad,
                       sizeof (gostbuf->pad));

@besser82 That did get a bit further. Now I am getting a similar error at lib/alg-md4.c, line 203: implicit conversion of a 64-bit integral type to a smaller integral type (potential portability problem).

@DavidHuber-NOAA, please try this:

diff --git a/lib/alg-md4.c b/lib/alg-md4.c
index 0b399fa..410c947 100644
--- a/lib/alg-md4.c
+++ b/lib/alg-md4.c
@@ -200,7 +200,7 @@ void MD4_Update(MD4_CTX *ctx, const void *data, size_t size)
 	unsigned long used, available;
 
 	saved_lo = ctx->lo;
-	if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
+	if ((ctx->lo = (MD4_u32plus)((saved_lo + size) & 0x1fffffff)) < saved_lo)
 		ctx->hi++;
 	ctx->hi += (MD4_u32plus) size >> 29;
 

Be aware that the line in this patch are using tabs for indentation.

I ran into a few more similar issues and pushed to a branch. However, I ran into one I'm not really sure how to fix. Lines 158-164, 1110, 1322, 1335, and 1336 of lib/alg-yescrypt-opt.c produce the following: implicit conversion of a 64-bit integral type to a smaller integral type (potential portability problem).

Cool, would you mind sharing your efforts? I will look into the yescrypt stuff during tomorrow.

Yeah, I linked it to this issue. It can be found here.