RFR 8214262: SunEC native code does not compile with debug on

Weijun Wang weijun.wang at oracle.com
Sat Nov 24 15:03:12 UTC 2018


Oops, when EC_DEBUG is 1 build fails on Windows. Looks like ec.c also calls printf and stdio.h is not included on Windows. Patch updated below. I would just include stdio.h unconditionally.

Thanks
Max

diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ec.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ec.c
--- a/src/jdk.crypto.ec/share/native/libsunec/impl/ec.c
+++ b/src/jdk.crypto.ec/share/native/libsunec/impl/ec.c
@@ -43,11 +43,11 @@
 
 #include <sys/types.h>
 #ifndef _KERNEL
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
 #ifndef _WIN32
-#include <stdio.h>
 #include <strings.h>
 #endif /* _WIN32 */
 
@@ -109,16 +109,16 @@
     printf("\n");
 
         if (k1 != NULL) {
-                mp_tohex(k1, mpstr);
+                mp_tohex((mp_int*)k1, mpstr);
                 printf("ec_points_mul: scalar k1: %s\n", mpstr);
-                mp_todecimal(k1, mpstr);
+                mp_todecimal((mp_int*)k1, mpstr);
                 printf("ec_points_mul: scalar k1: %s (dec)\n", mpstr);
         }
 
         if (k2 != NULL) {
-                mp_tohex(k2, mpstr);
+                mp_tohex((mp_int*)k2, mpstr);
                 printf("ec_points_mul: scalar k2: %s\n", mpstr);
-                mp_todecimal(k2, mpstr);
+                mp_todecimal((mp_int*)k2, mpstr);
                 printf("ec_points_mul: scalar k2: %s (dec)\n", mpstr);
         }
 
diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ecdecode.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ecdecode.c
--- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecdecode.c
+++ b/src/jdk.crypto.ec/share/native/libsunec/impl/ecdecode.c
@@ -49,6 +49,7 @@
 #ifdef _KERNEL
 #include <sys/kmem.h>
 #else
+#include <stdio.h>
 #include <string.h>
 #endif
 #include "ec.h"

Thanks
Max

> On Nov 23, 2018, at 10:31 PM, Weijun Wang <weijun.wang at oracle.com> wrote:
> 
> I was curious in some SunEC internals and turned EC_DEBUG on, and found out the library cannot be built. It looks like back when we switched to warnings-as-errors some codes are not updated. Here is the patch:
> 
> diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ec.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ec.c
> --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ec.c
> +++ b/src/jdk.crypto.ec/share/native/libsunec/impl/ec.c
> @@ -109,16 +109,16 @@
>      printf("\n");
>  
>          if (k1 != NULL) {
> -                mp_tohex(k1, mpstr);
> +                mp_tohex((mp_int*)k1, mpstr);
>                  printf("ec_points_mul: scalar k1: %s\n", mpstr);
> -                mp_todecimal(k1, mpstr);
> +                mp_todecimal((mp_int*)k1, mpstr);
>                  printf("ec_points_mul: scalar k1: %s (dec)\n", mpstr);
>          }
>  
>          if (k2 != NULL) {
> -                mp_tohex(k2, mpstr);
> +                mp_tohex((mp_int*)k2, mpstr);
>                  printf("ec_points_mul: scalar k2: %s\n", mpstr);
> -                mp_todecimal(k2, mpstr);
> +                mp_todecimal((mp_int*)k2, mpstr);
>                  printf("ec_points_mul: scalar k2: %s (dec)\n", mpstr);
>          }
>  
> diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ecdecode.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ecdecode.c
> --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecdecode.c
> +++ b/src/jdk.crypto.ec/share/native/libsunec/impl/ecdecode.c
> @@ -55,6 +55,9 @@
>  #include "ecl-curve.h"
>  #include "ecc_impl.h"
>  
> +#if EC_DEBUG
> +#include <stdio.h>
> +#endif
>  #define MAX_ECKEY_LEN           72
>  #define SEC_ASN1_OBJECT_ID      0x06
> 
> In the first file, k1 and k2 are defined as const mp_int * but mp_tohex accepts a mp_int* as its 1st argument.
> 
> In the second file, there is a printf call in a EC_DEBUG block.
> 
> Noreg-cleanup.
> 
> Thanks
> Max
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/security-dev/attachments/20181124/97db09e2/attachment-0001.html>


More information about the security-dev mailing list