Skip to content

Commit fc32d77

Browse files
levittesjaeckel
authored andcommitted
Remove unnecessary casts in the ECC implementation
1 parent 477d09f commit fc32d77

File tree

6 files changed

+22
-22
lines changed

6 files changed

+22
-22
lines changed

src/pk/ecc/ecc_ansi_x963_import.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int ecc_ansi_x963_import_ex(const unsigned char *in, unsigned long inlen, ecc_ke
4343
}
4444

4545
/* load public key */
46-
if ((err = ecc_set_key((unsigned char *)in, inlen, PK_PUBLIC, key)) != CRYPT_OK) { return err; }
46+
if ((err = ecc_set_key(in, inlen, PK_PUBLIC, key)) != CRYPT_OK) { return err; }
4747

4848
/* we're done */
4949
return CRYPT_OK;

src/pk/ecc/ecc_recover_key.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ int ecc_recover_key(const unsigned char *sig, unsigned long siglen,
8181
err = CRYPT_INVALID_PACKET;
8282
goto error;
8383
}
84-
if ((err = mp_read_unsigned_bin(r, (unsigned char *)sig, i)) != CRYPT_OK) { goto error; }
85-
if ((err = mp_read_unsigned_bin(s, (unsigned char *)sig+i, i)) != CRYPT_OK) { goto error; }
84+
if ((err = mp_read_unsigned_bin(r, sig, i)) != CRYPT_OK) { goto error; }
85+
if ((err = mp_read_unsigned_bin(s, sig+i, i)) != CRYPT_OK) { goto error; }
8686
}
8787
else if (sigformat == LTC_ECCSIG_ETH27) {
8888
/* Ethereum (v,r,s) format */
@@ -102,8 +102,8 @@ int ecc_recover_key(const unsigned char *sig, unsigned long siglen,
102102
goto error;
103103
}
104104
recid = i;
105-
if ((err = mp_read_unsigned_bin(r, (unsigned char *)sig, 32)) != CRYPT_OK) { goto error; }
106-
if ((err = mp_read_unsigned_bin(s, (unsigned char *)sig+32, 32)) != CRYPT_OK) { goto error; }
105+
if ((err = mp_read_unsigned_bin(r, sig, 32)) != CRYPT_OK) { goto error; }
106+
if ((err = mp_read_unsigned_bin(s, sig+32, 32)) != CRYPT_OK) { goto error; }
107107
}
108108
#ifdef LTC_SSH
109109
else if (sigformat == LTC_ECCSIG_RFC5656) {
@@ -150,10 +150,10 @@ int ecc_recover_key(const unsigned char *sig, unsigned long siglen,
150150
pbits = mp_count_bits(p);
151151
pbytes = (pbits+7) >> 3;
152152
if (pbits > hashlen*8) {
153-
if ((err = mp_read_unsigned_bin(e, (unsigned char *)hash, hashlen)) != CRYPT_OK) { goto error; }
153+
if ((err = mp_read_unsigned_bin(e, hash, hashlen)) != CRYPT_OK) { goto error; }
154154
}
155155
else if (pbits % 8 == 0) {
156-
if ((err = mp_read_unsigned_bin(e, (unsigned char *)hash, pbytes)) != CRYPT_OK) { goto error; }
156+
if ((err = mp_read_unsigned_bin(e, hash, pbytes)) != CRYPT_OK) { goto error; }
157157
}
158158
else {
159159
shift_right = 8 - pbits % 8;
@@ -162,7 +162,7 @@ int ecc_recover_key(const unsigned char *sig, unsigned long siglen,
162162
ch = (hash[i] << (8-shift_right));
163163
buf[i] = buf[i] ^ (hash[i] >> shift_right);
164164
}
165-
if ((err = mp_read_unsigned_bin(e, (unsigned char *)buf, pbytes)) != CRYPT_OK) { goto error; }
165+
if ((err = mp_read_unsigned_bin(e, buf, pbytes)) != CRYPT_OK) { goto error; }
166166
}
167167

168168
/* decompress point from r=(x mod p) - BEWARE: requires sqrtmod_prime */

src/pk/ecc/ecc_set_key.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int ecc_set_key(const unsigned char *in, unsigned long inlen, int type, ecc_key
2020

2121
if (type == PK_PRIVATE) {
2222
/* load private key */
23-
if ((err = mp_read_unsigned_bin(key->k, (unsigned char *)in, inlen)) != CRYPT_OK) {
23+
if ((err = mp_read_unsigned_bin(key->k, in, inlen)) != CRYPT_OK) {
2424
goto error;
2525
}
2626
if (mp_iszero(key->k) || (mp_cmp(key->k, key->dp.order) != LTC_MP_LT)) {

src/pk/ecc/ecc_sign_hash.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ int ecc_sign_hash_ex(const unsigned char *in, unsigned long inlen,
5555
pbits = mp_count_bits(p);
5656
pbytes = (pbits+7) >> 3;
5757
if (pbits > inlen*8) {
58-
if ((err = mp_read_unsigned_bin(e, (unsigned char *)in, inlen)) != CRYPT_OK) { goto errnokey; }
58+
if ((err = mp_read_unsigned_bin(e, in, inlen)) != CRYPT_OK) { goto errnokey; }
5959
}
6060
else if (pbits % 8 == 0) {
61-
if ((err = mp_read_unsigned_bin(e, (unsigned char *)in, pbytes)) != CRYPT_OK) { goto errnokey; }
61+
if ((err = mp_read_unsigned_bin(e, in, pbytes)) != CRYPT_OK) { goto errnokey; }
6262
}
6363
else {
6464
shift_right = 8 - pbits % 8;
@@ -67,7 +67,7 @@ int ecc_sign_hash_ex(const unsigned char *in, unsigned long inlen,
6767
ch = (in[i] << (8-shift_right));
6868
buf[i] = buf[i] ^ (in[i] >> shift_right);
6969
}
70-
if ((err = mp_read_unsigned_bin(e, (unsigned char *)buf, pbytes)) != CRYPT_OK) { goto errnokey; }
70+
if ((err = mp_read_unsigned_bin(e, buf, pbytes)) != CRYPT_OK) { goto errnokey; }
7171
}
7272

7373
/* make up a key and export the public copy */

src/pk/ecc/ecc_verify_hash.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ int ecc_verify_hash_ex(const unsigned char *sig, unsigned long siglen,
7575
err = CRYPT_INVALID_PACKET;
7676
goto error;
7777
}
78-
if ((err = mp_read_unsigned_bin(r, (unsigned char *)sig, i)) != CRYPT_OK) { goto error; }
79-
if ((err = mp_read_unsigned_bin(s, (unsigned char *)sig+i, i)) != CRYPT_OK) { goto error; }
78+
if ((err = mp_read_unsigned_bin(r, sig, i)) != CRYPT_OK) { goto error; }
79+
if ((err = mp_read_unsigned_bin(s, sig+i, i)) != CRYPT_OK) { goto error; }
8080
}
8181
else if (sigformat == LTC_ECCSIG_ETH27) {
8282
/* Ethereum (v,r,s) format */
@@ -88,8 +88,8 @@ int ecc_verify_hash_ex(const unsigned char *sig, unsigned long siglen,
8888
err = CRYPT_INVALID_PACKET;
8989
goto error;
9090
}
91-
if ((err = mp_read_unsigned_bin(r, (unsigned char *)sig, 32)) != CRYPT_OK) { goto error; }
92-
if ((err = mp_read_unsigned_bin(s, (unsigned char *)sig+32, 32)) != CRYPT_OK) { goto error; }
91+
if ((err = mp_read_unsigned_bin(r, sig, 32)) != CRYPT_OK) { goto error; }
92+
if ((err = mp_read_unsigned_bin(s, sig+32, 32)) != CRYPT_OK) { goto error; }
9393
}
9494
#ifdef LTC_SSH
9595
else if (sigformat == LTC_ECCSIG_RFC5656) {
@@ -130,10 +130,10 @@ int ecc_verify_hash_ex(const unsigned char *sig, unsigned long siglen,
130130
pbits = mp_count_bits(p);
131131
pbytes = (pbits+7) >> 3;
132132
if (pbits > hashlen*8) {
133-
if ((err = mp_read_unsigned_bin(e, (unsigned char *)hash, hashlen)) != CRYPT_OK) { goto error; }
133+
if ((err = mp_read_unsigned_bin(e, hash, hashlen)) != CRYPT_OK) { goto error; }
134134
}
135135
else if (pbits % 8 == 0) {
136-
if ((err = mp_read_unsigned_bin(e, (unsigned char *)hash, pbytes)) != CRYPT_OK) { goto error; }
136+
if ((err = mp_read_unsigned_bin(e, hash, pbytes)) != CRYPT_OK) { goto error; }
137137
}
138138
else {
139139
shift_right = 8 - pbits % 8;
@@ -142,7 +142,7 @@ int ecc_verify_hash_ex(const unsigned char *sig, unsigned long siglen,
142142
ch = (hash[i] << (8-shift_right));
143143
buf[i] = buf[i] ^ (hash[i] >> shift_right);
144144
}
145-
if ((err = mp_read_unsigned_bin(e, (unsigned char *)buf, pbytes)) != CRYPT_OK) { goto error; }
145+
if ((err = mp_read_unsigned_bin(e, buf, pbytes)) != CRYPT_OK) { goto error; }
146146
}
147147

148148
/* w = s^-1 mod n */

src/pk/ecc/ltc_ecc_import_point.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ int ltc_ecc_import_point(const unsigned char *in, unsigned long inlen, void *pri
2121
if (in[0] == 0x04 && (inlen&1) && ((inlen-1)>>1) == size) {
2222
/* read uncompressed point */
2323
/* load x */
24-
if ((err = mp_read_unsigned_bin(x, (unsigned char *)in+1, size)) != CRYPT_OK) { goto cleanup; }
24+
if ((err = mp_read_unsigned_bin(x, in+1, size)) != CRYPT_OK) { goto cleanup; }
2525
/* load y */
26-
if ((err = mp_read_unsigned_bin(y, (unsigned char *)in+1+size, size)) != CRYPT_OK) { goto cleanup; }
26+
if ((err = mp_read_unsigned_bin(y, in+1+size, size)) != CRYPT_OK) { goto cleanup; }
2727
}
2828
else if ((in[0] == 0x02 || in[0] == 0x03) && (inlen-1) == size && ltc_mp.sqrtmod_prime != NULL) {
2929
/* read compressed point - BEWARE: requires sqrtmod_prime */
3030
/* load x */
31-
if ((err = mp_read_unsigned_bin(x, (unsigned char *)in+1, size)) != CRYPT_OK) { goto cleanup; }
31+
if ((err = mp_read_unsigned_bin(x, in+1, size)) != CRYPT_OK) { goto cleanup; }
3232
/* compute x^3 */
3333
if ((err = mp_sqr(x, t1)) != CRYPT_OK) { goto cleanup; }
3434
if ((err = mp_mulmod(t1, x, prime, t1)) != CRYPT_OK) { goto cleanup; }

0 commit comments

Comments
 (0)