Bug 1639033 - Used unsigned int instead of int in a few places in ec.c to eliminate signed-unsigned comparison warnings. r=kjacobs
authorJeff Walden <jwalden@mit.edu>
Thu, 21 May 2020 20:41:52 +0000
changeset 15630 0d778b0e778fa3326421b23e07bc31348f951053
parent 15629 df5c8f6430a027353c46103a26e057cfa1a760db
child 15631 e23fe363fa058e9b289ae03cd352fc1f9e057146
push id3751
push userkjacobs@mozilla.com
push dateFri, 22 May 2020 20:56:57 +0000
reviewerskjacobs
bugs1639033
Bug 1639033 - Used unsigned int instead of int in a few places in ec.c to eliminate signed-unsigned comparison warnings. r=kjacobs Depends on D75846 Differential Revision: https://phabricator.services.mozilla.com/D75847
lib/freebl/ec.c
--- a/lib/freebl/ec.c
+++ b/lib/freebl/ec.c
@@ -57,17 +57,17 @@ SECStatus
 ec_points_mul(const ECParams *params, const mp_int *k1, const mp_int *k2,
               const SECItem *pointP, SECItem *pointQ)
 {
     mp_int Px, Py, Qx, Qy;
     mp_int Gx, Gy, order, irreducible, a, b;
     ECGroup *group = NULL;
     SECStatus rv = SECFailure;
     mp_err err = MP_OKAY;
-    int len;
+    unsigned int len;
 
 #if EC_DEBUG
     int i;
     char mpstr[256];
 
     printf("ec_points_mul: params [len=%d]:", params->DEREncoding.len);
     for (i = 0; i < params->DEREncoding.len; i++)
         printf("%02x:", params->DEREncoding.data[i]);
@@ -91,17 +91,17 @@ ec_points_mul(const ECParams *params, co
         printf("ec_points_mul: pointP [len=%d]:", pointP->len);
         for (i = 0; i < pointP->len; i++)
             printf("%02x:", pointP->data[i]);
         printf("\n");
     }
 #endif
 
     /* NOTE: We only support uncompressed points for now */
-    len = (params->fieldID.size + 7) >> 3;
+    len = (((unsigned int)params->fieldID.size) + 7) >> 3;
     if (pointP != NULL) {
         if ((pointP->data[0] != EC_POINT_FORM_UNCOMPRESSED) ||
             (pointP->len != (2 * len + 1))) {
             PORT_SetError(SEC_ERROR_UNSUPPORTED_EC_POINT_FORM);
             return SECFailure;
         };
     }
 
@@ -423,17 +423,17 @@ cleanup:
  */
 SECStatus
 EC_ValidatePublicKey(ECParams *ecParams, SECItem *publicValue)
 {
     mp_int Px, Py;
     ECGroup *group = NULL;
     SECStatus rv = SECFailure;
     mp_err err = MP_OKAY;
-    int len;
+    unsigned int len;
 
     if (!ecParams || ecParams->name == ECCurve_noName ||
         !publicValue || !publicValue->len) {
         PORT_SetError(SEC_ERROR_INVALID_ARGS);
         return SECFailure;
     }
 
     /* Uses curve specific code for point validation. */
@@ -443,17 +443,17 @@ EC_ValidatePublicKey(ECParams *ecParams,
             /* unknown curve */
             PORT_SetError(SEC_ERROR_INVALID_ARGS);
             return SECFailure;
         }
         return method->validate(publicValue);
     }
 
     /* NOTE: We only support uncompressed points for now */
-    len = (ecParams->fieldID.size + 7) >> 3;
+    len = (((unsigned int)ecParams->fieldID.size) + 7) >> 3;
     if (publicValue->data[0] != EC_POINT_FORM_UNCOMPRESSED) {
         PORT_SetError(SEC_ERROR_UNSUPPORTED_EC_POINT_FORM);
         return SECFailure;
     } else if (publicValue->len != (2 * len + 1)) {
         PORT_SetError(SEC_ERROR_BAD_KEY);
         return SECFailure;
     }