summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-06-14 22:11:29 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-06-14 22:11:29 +0000
commite235285c3a36c0e4efe21ec336e7015cd3cf3c62 (patch)
tree3ea4c906634a6a3c5e30ba691b82a56a57d2510d
parent7a762f9dbf80b406fd1ec21966a9de3c3057fd25 (diff)
crypt: code shrink
function old new delta des_crypt - 1682 +1682 md5_crypt - 627 +627 pw_encrypt 3608 1036 -2572 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 0/1 up/down: 2309/-2572) Total: -263 bytes
-rw-r--r--libbb/pw_encrypt_des.c15
-rw-r--r--libbb/pw_encrypt_md5.c17
2 files changed, 11 insertions, 21 deletions
diff --git a/libbb/pw_encrypt_des.c b/libbb/pw_encrypt_des.c
index ab217d8e9..66e607955 100644
--- a/libbb/pw_encrypt_des.c
+++ b/libbb/pw_encrypt_des.c
@@ -400,7 +400,6 @@ des_init(struct des_ctx *ctx, const struct const_des_ctx *cctx)
static void
setup_salt(struct des_ctx *ctx, uint32_t salt)
{
-// const struct const_des_ctx *cctx = const_ctx;
uint32_t obit, saltbit;
int i;
@@ -422,7 +421,6 @@ setup_salt(struct des_ctx *ctx, uint32_t salt)
static void
des_setkey(struct des_ctx *ctx, const char *key)
{
-// const struct const_des_ctx *cctx = const_ctx;
uint32_t k0, k1, rawkey0, rawkey1;
int shifts, round;
@@ -498,7 +496,7 @@ des_setkey(struct des_ctx *ctx, const char *key)
}
-static int
+static void
do_des(struct des_ctx *ctx, uint32_t l_in, uint32_t r_in, uint32_t *l_out, uint32_t *r_out, int count)
{
const struct const_des_ctx *cctx = const_ctx;
@@ -602,12 +600,12 @@ do_des(struct des_ctx *ctx, uint32_t l_in, uint32_t r_in, uint32_t *l_out, uint3
| fp_maskr[5][(r >> 16) & 0xff]
| fp_maskr[6][(r >> 8) & 0xff]
| fp_maskr[7][r & 0xff];
- return 0;
}
#define DES_OUT_BUFSIZE 21
static char *
+NOINLINE
des_crypt(struct des_ctx *ctx, char output[21], const unsigned char *key, const unsigned char *setting)
{
uint32_t salt, l, r0, r1, keybuf[2];
@@ -618,10 +616,11 @@ des_crypt(struct des_ctx *ctx, char output[21], const unsigned char *key, const
* and padding with zeros.
*/
q = (uint8_t *)keybuf;
- while (q - (uint8_t *)keybuf - 8) {
- *q++ = *key << 1;
- if (*(q - 1))
+ while (q - (uint8_t *)keybuf != 8) {
+ *q = *key << 1;
+ if (*q)
key++;
+ q++;
}
des_setkey(ctx, (char *)keybuf);
@@ -658,7 +657,7 @@ des_crypt(struct des_ctx *ctx, char output[21], const unsigned char *key, const
*p++ = ascii64[(l >> 6) & 0x3f];
*p++ = ascii64[l & 0x3f];
- l = (r0 << 16) | ((r1 >> 16) & 0xffff);
+ l = ((r0 << 16) | (r1 >> 16));
*p++ = ascii64[(l >> 18) & 0x3f];
*p++ = ascii64[(l >> 12) & 0x3f];
*p++ = ascii64[(l >> 6) & 0x3f];
diff --git a/libbb/pw_encrypt_md5.c b/libbb/pw_encrypt_md5.c
index 6c94d2d29..8d0a516cf 100644
--- a/libbb/pw_encrypt_md5.c
+++ b/libbb/pw_encrypt_md5.c
@@ -101,7 +101,6 @@ static const unsigned char __md5__magic[] = MD5_MAGIC_STR;
* __md5_Encodes input (uint32_t) into output (unsigned char). Assumes len is
* a multiple of 4.
*/
-
static void
__md5_Encode(unsigned char *output, uint32_t *input, unsigned int len)
{
@@ -119,7 +118,6 @@ __md5_Encode(unsigned char *output, uint32_t *input, unsigned int len)
* __md5_Decodes input (unsigned char) into output (uint32_t). Assumes len is
* a multiple of 4.
*/
-
static void
__md5_Decode(uint32_t *output, const unsigned char *input, unsigned int len)
{
@@ -166,7 +164,6 @@ __md5_Decode(uint32_t *output, const unsigned char *input, unsigned int len)
}
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
-
static void __md5_Init(struct MD5Context *context)
{
context->count[0] = context->count[1] = 0;
@@ -183,7 +180,6 @@ static void __md5_Init(struct MD5Context *context)
* operation, processing another message block, and updating the
* context.
*/
-
static void __md5_Update(struct MD5Context *context, const unsigned char *input, unsigned int inputLen)
{
unsigned int i, idx, partLen;
@@ -218,7 +214,6 @@ static void __md5_Update(struct MD5Context *context, const unsigned char *input,
/*
* MD5 padding. Adds padding followed by original length.
*/
-
static void __md5_Pad(struct MD5Context *context)
{
unsigned char bits[8];
@@ -244,7 +239,6 @@ static void __md5_Pad(struct MD5Context *context)
* MD5 finalization. Ends an MD5 message-digest operation, writing the
* the message digest and zeroizing the context.
*/
-
static void __md5_Final(unsigned char digest[16], struct MD5Context *context)
{
/* Do padding. */
@@ -258,7 +252,6 @@ static void __md5_Final(unsigned char digest[16], struct MD5Context *context)
}
/* MD5 basic transformation. Transforms state based on block. */
-
static void __md5_Transform(uint32_t state[4], const unsigned char block[64])
{
uint32_t a, b, c, d, x[16];
@@ -517,16 +510,15 @@ __md5_to64(char *s, unsigned v, int n)
* Use MD5 for what it is best at...
*/
#define MD5_OUT_BUFSIZE 36
-
static char *
-md5_crypt(char passwd[120], const unsigned char *pw, const unsigned char *salt)
+NOINLINE
+md5_crypt(char passwd[MD5_OUT_BUFSIZE], const unsigned char *pw, const unsigned char *salt)
{
const unsigned char *sp, *ep;
char *p;
unsigned char final[17]; /* final[16] exists only to aid in looping */
int sl, pl, i, pw_len;
struct MD5Context ctx, ctx1;
- unsigned long l;
/* Refine the Salt first */
sp = salt;
@@ -612,11 +604,10 @@ md5_crypt(char passwd[120], const unsigned char *pw, const unsigned char *salt)
/* Add 5*4+2 = 22 bytes of hash, + NUL byte. */
final[16] = final[5];
for (i = 0; i < 5; i++) {
- l = (final[i] << 16) | (final[i+6] << 8) | final[i+12];
+ unsigned l = (final[i] << 16) | (final[i+6] << 8) | final[i+12];
p = __md5_to64(p, l, 4);
}
- l = final[11];
- p = __md5_to64(p, l, 2);
+ p = __md5_to64(p, final[11], 2);
*p = '\0';
/* Don't leave anything around in vm they could use. */