Browse Source

Remove unnecessary casts in the ECC implementation

Richard Levitte 1 year ago
parent
commit
fc32d77845

+ 1 - 1
src/pk/ecc/ecc_ansi_x963_import.c

@@ -43,7 +43,7 @@ int ecc_ansi_x963_import_ex(const unsigned char *in, unsigned long inlen, ecc_ke
    }
 
    /* load public key */
-   if ((err = ecc_set_key((unsigned char *)in, inlen, PK_PUBLIC, key)) != CRYPT_OK) { return err; }
+   if ((err = ecc_set_key(in, inlen, PK_PUBLIC, key)) != CRYPT_OK)                  { return err; }
 
    /* we're done */
    return CRYPT_OK;

+ 7 - 7
src/pk/ecc/ecc_recover_key.c

@@ -81,8 +81,8 @@ int ecc_recover_key(const unsigned char *sig,  unsigned long siglen,
          err = CRYPT_INVALID_PACKET;
          goto error;
       }
-      if ((err = mp_read_unsigned_bin(r, (unsigned char *)sig,   i)) != CRYPT_OK)                       { goto error; }
-      if ((err = mp_read_unsigned_bin(s, (unsigned char *)sig+i, i)) != CRYPT_OK)                       { goto error; }
+      if ((err = mp_read_unsigned_bin(r, sig,   i)) != CRYPT_OK)                                        { goto error; }
+      if ((err = mp_read_unsigned_bin(s, sig+i, i)) != CRYPT_OK)                                        { goto error; }
    }
    else if (sigformat == LTC_ECCSIG_ETH27) {
       /* Ethereum (v,r,s) format */
@@ -102,8 +102,8 @@ int ecc_recover_key(const unsigned char *sig,  unsigned long siglen,
          goto error;
       }
       recid = i;
-      if ((err = mp_read_unsigned_bin(r, (unsigned char *)sig,  32)) != CRYPT_OK)                       { goto error; }
-      if ((err = mp_read_unsigned_bin(s, (unsigned char *)sig+32, 32)) != CRYPT_OK)                     { goto error; }
+      if ((err = mp_read_unsigned_bin(r, sig,  32)) != CRYPT_OK)                                        { goto error; }
+      if ((err = mp_read_unsigned_bin(s, sig+32, 32)) != CRYPT_OK)                                      { goto error; }
    }
 #ifdef LTC_SSH
    else if (sigformat == LTC_ECCSIG_RFC5656) {
@@ -150,10 +150,10 @@ int ecc_recover_key(const unsigned char *sig,  unsigned long siglen,
    pbits = mp_count_bits(p);
    pbytes = (pbits+7) >> 3;
    if (pbits > hashlen*8) {
-      if ((err = mp_read_unsigned_bin(e, (unsigned char *)hash, hashlen)) != CRYPT_OK)                  { goto error; }
+      if ((err = mp_read_unsigned_bin(e, hash, hashlen)) != CRYPT_OK)                                   { goto error; }
    }
    else if (pbits % 8 == 0) {
-      if ((err = mp_read_unsigned_bin(e, (unsigned char *)hash, pbytes)) != CRYPT_OK)                   { goto error; }
+      if ((err = mp_read_unsigned_bin(e, hash, pbytes)) != CRYPT_OK)                                    { goto error; }
    }
    else {
       shift_right = 8 - pbits % 8;
@@ -162,7 +162,7 @@ int ecc_recover_key(const unsigned char *sig,  unsigned long siglen,
         ch = (hash[i] << (8-shift_right));
         buf[i] = buf[i] ^ (hash[i] >> shift_right);
       }
-      if ((err = mp_read_unsigned_bin(e, (unsigned char *)buf, pbytes)) != CRYPT_OK)                    { goto error; }
+      if ((err = mp_read_unsigned_bin(e, buf, pbytes)) != CRYPT_OK)                                     { goto error; }
    }
 
    /* decompress point from r=(x mod p) - BEWARE: requires sqrtmod_prime */

+ 1 - 1
src/pk/ecc/ecc_set_key.c

@@ -20,7 +20,7 @@ int ecc_set_key(const unsigned char *in, unsigned long inlen, int type, ecc_key
 
    if (type == PK_PRIVATE) {
       /* load private key */
-      if ((err = mp_read_unsigned_bin(key->k, (unsigned char *)in, inlen)) != CRYPT_OK) {
+      if ((err = mp_read_unsigned_bin(key->k, in, inlen)) != CRYPT_OK) {
          goto error;
       }
       if (mp_iszero(key->k) || (mp_cmp(key->k, key->dp.order) != LTC_MP_LT)) {

+ 3 - 3
src/pk/ecc/ecc_sign_hash.c

@@ -55,10 +55,10 @@ int ecc_sign_hash_ex(const unsigned char *in,  unsigned long inlen,
    pbits = mp_count_bits(p);
    pbytes = (pbits+7) >> 3;
    if (pbits > inlen*8) {
-      if ((err = mp_read_unsigned_bin(e, (unsigned char *)in, inlen)) != CRYPT_OK)    { goto errnokey; }
+      if ((err = mp_read_unsigned_bin(e, in, inlen)) != CRYPT_OK)    { goto errnokey; }
    }
    else if (pbits % 8 == 0) {
-      if ((err = mp_read_unsigned_bin(e, (unsigned char *)in, pbytes)) != CRYPT_OK)   { goto errnokey; }
+      if ((err = mp_read_unsigned_bin(e, in, pbytes)) != CRYPT_OK)   { goto errnokey; }
    }
    else {
       shift_right = 8 - pbits % 8;
@@ -67,7 +67,7 @@ int ecc_sign_hash_ex(const unsigned char *in,  unsigned long inlen,
         ch = (in[i] << (8-shift_right));
         buf[i] = buf[i] ^ (in[i] >> shift_right);
       }
-      if ((err = mp_read_unsigned_bin(e, (unsigned char *)buf, pbytes)) != CRYPT_OK)  { goto errnokey; }
+      if ((err = mp_read_unsigned_bin(e, buf, pbytes)) != CRYPT_OK)  { goto errnokey; }
    }
 
    /* make up a key and export the public copy */

+ 7 - 7
src/pk/ecc/ecc_verify_hash.c

@@ -75,8 +75,8 @@ int ecc_verify_hash_ex(const unsigned char *sig,  unsigned long siglen,
          err = CRYPT_INVALID_PACKET;
          goto error;
       }
-      if ((err = mp_read_unsigned_bin(r, (unsigned char *)sig,   i)) != CRYPT_OK)                       { goto error; }
-      if ((err = mp_read_unsigned_bin(s, (unsigned char *)sig+i, i)) != CRYPT_OK)                       { goto error; }
+      if ((err = mp_read_unsigned_bin(r, sig,   i)) != CRYPT_OK)                                        { goto error; }
+      if ((err = mp_read_unsigned_bin(s, sig+i, i)) != CRYPT_OK)                                        { goto error; }
    }
    else if (sigformat == LTC_ECCSIG_ETH27) {
       /* Ethereum (v,r,s) format */
@@ -88,8 +88,8 @@ int ecc_verify_hash_ex(const unsigned char *sig,  unsigned long siglen,
          err = CRYPT_INVALID_PACKET;
          goto error;
       }
-      if ((err = mp_read_unsigned_bin(r, (unsigned char *)sig,  32)) != CRYPT_OK)                       { goto error; }
-      if ((err = mp_read_unsigned_bin(s, (unsigned char *)sig+32, 32)) != CRYPT_OK)                     { goto error; }
+      if ((err = mp_read_unsigned_bin(r, sig,  32)) != CRYPT_OK)                                        { goto error; }
+      if ((err = mp_read_unsigned_bin(s, sig+32, 32)) != CRYPT_OK)                                      { goto error; }
    }
 #ifdef LTC_SSH
    else if (sigformat == LTC_ECCSIG_RFC5656) {
@@ -130,10 +130,10 @@ int ecc_verify_hash_ex(const unsigned char *sig,  unsigned long siglen,
    pbits = mp_count_bits(p);
    pbytes = (pbits+7) >> 3;
    if (pbits > hashlen*8) {
-      if ((err = mp_read_unsigned_bin(e, (unsigned char *)hash, hashlen)) != CRYPT_OK)                  { goto error; }
+      if ((err = mp_read_unsigned_bin(e, hash, hashlen)) != CRYPT_OK)                                   { goto error; }
    }
    else if (pbits % 8 == 0) {
-      if ((err = mp_read_unsigned_bin(e, (unsigned char *)hash, pbytes)) != CRYPT_OK)                   { goto error; }
+      if ((err = mp_read_unsigned_bin(e, hash, pbytes)) != CRYPT_OK)                                    { goto error; }
    }
    else {
       shift_right = 8 - pbits % 8;
@@ -142,7 +142,7 @@ int ecc_verify_hash_ex(const unsigned char *sig,  unsigned long siglen,
         ch = (hash[i] << (8-shift_right));
         buf[i] = buf[i] ^ (hash[i] >> shift_right);
       }
-      if ((err = mp_read_unsigned_bin(e, (unsigned char *)buf, pbytes)) != CRYPT_OK)                    { goto error; }
+      if ((err = mp_read_unsigned_bin(e, buf, pbytes)) != CRYPT_OK)                                     { goto error; }
    }
 
    /*  w  = s^-1 mod n */

+ 3 - 3
src/pk/ecc/ltc_ecc_import_point.c

@@ -21,14 +21,14 @@ int ltc_ecc_import_point(const unsigned char *in, unsigned long inlen, void *pri
    if (in[0] == 0x04 && (inlen&1) && ((inlen-1)>>1) == size) {
       /* read uncompressed point */
       /* load x */
-      if ((err = mp_read_unsigned_bin(x, (unsigned char *)in+1, size)) != CRYPT_OK)      { goto cleanup; }
+      if ((err = mp_read_unsigned_bin(x, in+1, size)) != CRYPT_OK)                       { goto cleanup; }
       /* load y */
-      if ((err = mp_read_unsigned_bin(y, (unsigned char *)in+1+size, size)) != CRYPT_OK) { goto cleanup; }
+      if ((err = mp_read_unsigned_bin(y, in+1+size, size)) != CRYPT_OK)                  { goto cleanup; }
    }
    else if ((in[0] == 0x02 || in[0] == 0x03) && (inlen-1) == size && ltc_mp.sqrtmod_prime != NULL) {
       /* read compressed point - BEWARE: requires sqrtmod_prime */
       /* load x */
-      if ((err = mp_read_unsigned_bin(x, (unsigned char *)in+1, size)) != CRYPT_OK)      { goto cleanup; }
+      if ((err = mp_read_unsigned_bin(x, in+1, size)) != CRYPT_OK)                       { goto cleanup; }
       /* compute x^3 */
       if ((err = mp_sqr(x, t1)) != CRYPT_OK)                                             { goto cleanup; }
       if ((err = mp_mulmod(t1, x, prime, t1)) != CRYPT_OK)                               { goto cleanup; }