From bc6db9a585db8ad5680223912fe1d243441f6cdd Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 1 Jun 2016 04:20:40 +0000 Subject: crypt_r.c: remove casts * missing/crypt_r.c: consitify and remove unnecessary pointer casts. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55241 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- missing/crypt_r.c | 76 ++++++++++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 43 deletions(-) (limited to 'missing') diff --git a/missing/crypt_r.c b/missing/crypt_r.c index 67dd50f062..1b6d62ae6f 100644 --- a/missing/crypt_r.c +++ b/missing/crypt_r.c @@ -129,10 +129,10 @@ static char sccsid[] = "@(#)crypt.c 8.1 (Berkeley) 6/4/93"; { C_block tblk; permute((cpp),&tblk,(p),4); LOAD ((d),(d0),(d1),tblk); } STATIC void -permute(unsigned char *cp, C_block *out, register C_block *p, int chars_in) +permute(const unsigned char *cp, C_block *out, register const C_block *p, int chars_in) { register DCL_BLOCK(D,D0,D1); - register C_block *tp; + register const C_block *tp; register int t; ZERO(D,D0,D1); @@ -304,6 +304,9 @@ static const unsigned char itoa64[] = /* 0..63 => ascii-64 */ STATIC void init_des(struct crypt_data *); STATIC void init_perm(C_block perm[64/CHUNKBITS][1<b,ptabp); + STORE(K&~0x03030303L, K0&~0x03030303L, K1, *ksp); } } @@ -450,20 +446,14 @@ des_setkey_r(const char *key, struct crypt_data *data) * compiler and machine architecture. */ void -des_cipher(const char *in, char *out, long salt, int num_iter) -{ - des_cipher_r(in, out, salt, num_iter, &default_crypt_data); -} - -void -des_cipher_r(const char *in, char *out, long salt, int num_iter, struct crypt_data *data) +des_cipher_r(const unsigned char *in, unsigned char *out, long salt, int num_iter, struct crypt_data *data) { /* variables that we want in registers, most important first */ #if defined(pdp11) register int j; #endif register long L0, L1, R0, R1, k; - register C_block *kp; + register const C_block *kp; register int ks_inc, loop_count; C_block B; @@ -492,26 +482,26 @@ des_cipher_r(const char *in, char *out, long salt, int num_iter, struct crypt_da R1 = (R1 >> 1) & 0x55555555L; L1 = R0 | R1; /* L1 is the odd-numbered input bits */ STORE(L,L0,L1,B); - PERM3264(L,L0,L1,B.b, (C_block *)IE3264); /* even bits */ - PERM3264(R,R0,R1,B.b+4,(C_block *)IE3264); /* odd bits */ + PERM3264(L,L0,L1,B.b, IE3264[0]); /* even bits */ + PERM3264(R,R0,R1,B.b+4,IE3264[0]); /* odd bits */ if (num_iter >= 0) { /* encryption */ kp = &KS[0]; - ks_inc = (int)sizeof(*kp); + ks_inc = +1; } else { /* decryption */ num_iter = -num_iter; kp = &KS[KS_SIZE-1]; - ks_inc = -(int)sizeof(*kp); + ks_inc = -1; } while (--num_iter >= 0) { loop_count = 8; do { -#define SPTAB(t, i) (*(long *)((unsigned char *)(t) + (i)*(sizeof(long)/4))) +#define SPTAB(t, i) (*(const long *)((const unsigned char *)(t) + (i)*(sizeof(long)/4))) #if defined(gould) /* use this if B.b[i] is evaluated just once ... */ #define DOXOR(x,y,i) (x)^=SPTAB(SPE[0][(i)],B.b[(i)]); (y)^=SPTAB(SPE[1][(i)],B.b[(i)]); @@ -529,7 +519,7 @@ des_cipher_r(const char *in, char *out, long salt, int num_iter, struct crypt_da k = ((q0) ^ (q1)) & SALT; \ B.b32.i0 = k ^ (q0) ^ kp->b32.i0; \ B.b32.i1 = k ^ (q1) ^ kp->b32.i1; \ - kp = (C_block *)((char *)kp+ks_inc); \ + kp += ks_inc; \ \ DOXOR((p0), (p1), 0); \ DOXOR((p0), (p1), 1); \ @@ -543,7 +533,7 @@ des_cipher_r(const char *in, char *out, long salt, int num_iter, struct crypt_da CRUNCH(L0, L1, R0, R1); CRUNCH(R0, R1, L0, L1); } while (--loop_count != 0); - kp = (C_block *)((char *)kp-(ks_inc*KS_SIZE)); + kp -= (ks_inc*KS_SIZE); /* swap L and R */ @@ -556,7 +546,7 @@ des_cipher_r(const char *in, char *out, long salt, int num_iter, struct crypt_da L0 = ((L0 >> 3) & 0x0f0f0f0fL) | ((L1 << 1) & 0xf0f0f0f0L); L1 = ((R0 >> 3) & 0x0f0f0f0fL) | ((R1 << 1) & 0xf0f0f0f0L); STORE(L,L0,L1,B); - PERM6464(L,L0,L1,B.b, (C_block *)CF6464); + PERM6464(L,L0,L1,B.b, CF6464[0]); #if defined(MUST_ALIGN) STORE(L,L0,L1,B); out[0] = B.b[0]; out[1] = B.b[1]; out[2] = B.b[2]; out[3] = B.b[3]; @@ -757,7 +747,7 @@ setkey_r(const char *key, struct crypt_data *data) } keyblock.b[i] = k; } - des_setkey_r((char *)keyblock.b, data); + des_setkey_r(keyblock.b, data); } /* @@ -783,7 +773,7 @@ encrypt_r(char *block, int flag, struct crypt_data *data) } cblock.b[i] = k; } - des_cipher_r((char *)&cblock, (char *)&cblock, 0L, (flag ? -1: 1), data); + des_cipher_r(cblock.b, cblock.b, 0L, (flag ? -1: 1), data); for (i = 7; i >= 0; i--) { k = cblock.b[i]; for (j = 7; j >= 0; j--) { -- cgit v1.2.3