~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to helpers/basic_auth/NCSA/crypt_md5.c

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2010-05-04 11:15:49 UTC
  • mfrom: (1.3.1 upstream)
  • mto: (20.3.1 squeeze) (21.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20100504111549-1apjh2g5sndki4te
Tags: upstream-3.1.3
ImportĀ upstreamĀ versionĀ 3.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
static void md5to64(char *s, unsigned long v, int n)
33
33
{
34
34
    while (--n >= 0) {
35
 
        *s++ = itoa64[v & 0x3f];
36
 
        v >>= 6;
 
35
        *s++ = itoa64[v & 0x3f];
 
36
        v >>= 6;
37
37
    }
38
38
}
39
39
 
59
59
    unsigned long l;
60
60
 
61
61
    if (*salt == '$') {
62
 
        magic = salt++;
63
 
        while(*salt && *salt != '$')
64
 
            salt++;
65
 
        if (*salt == '$') {
66
 
            salt++;
67
 
            magiclen = salt - magic;
68
 
        } else {
69
 
            salt = magic;
70
 
            magic = "$1$";
71
 
        }
 
62
        magic = salt++;
 
63
        while (*salt && *salt != '$')
 
64
            salt++;
 
65
        if (*salt == '$') {
 
66
            salt++;
 
67
            magiclen = salt - magic;
 
68
        } else {
 
69
            salt = magic;
 
70
            magic = "$1$";
 
71
        }
72
72
    }
73
73
 
74
74
    /* Refine the Salt first */
76
76
 
77
77
    /* It stops at the first '$', max 8 chars */
78
78
    for (ep = sp; *ep && *ep != '$' && ep < (sp + 8); ep++)
79
 
        continue;
 
79
        continue;
80
80
 
81
81
    /* get the length of the true salt */
82
82
    sl = ep - sp;
99
99
    SquidMD5Update(&ctx1, (unsigned const char *) pw, strlen(pw));
100
100
    SquidMD5Final(final, &ctx1);
101
101
    for (pl = strlen(pw); pl > 0; pl -= 16)
102
 
        SquidMD5Update(&ctx, (unsigned const char *) final, pl > 16 ? 16 : pl);
 
102
        SquidMD5Update(&ctx, (unsigned const char *) final, pl > 16 ? 16 : pl);
103
103
 
104
104
    /* Don't leave anything around in vm they could use. */
105
105
    memset(final, 0, sizeof final);
106
106
 
107
107
    /* Then something really weird... */
108
108
    for (j = 0, i = strlen(pw); i; i >>= 1)
109
 
        if (i & 1)
110
 
            SquidMD5Update(&ctx, (unsigned const char *) final + j, 1);
111
 
        else
112
 
            SquidMD5Update(&ctx, (unsigned const char *) pw + j, 1);
 
109
        if (i & 1)
 
110
            SquidMD5Update(&ctx, (unsigned const char *) final + j, 1);
 
111
        else
 
112
            SquidMD5Update(&ctx, (unsigned const char *) pw + j, 1);
113
113
 
114
114
    /* Now make the output string */
115
115
    memset(passwd, 0, sizeof(passwd));
125
125
     * need 30 seconds to build a 1000 entry dictionary...
126
126
     */
127
127
    for (i = 0; i < 1000; i++) {
128
 
        SquidMD5Init(&ctx1);
129
 
        if (i & 1)
130
 
            SquidMD5Update(&ctx1, (unsigned const char *) pw, strlen(pw));
131
 
        else
132
 
            SquidMD5Update(&ctx1, (unsigned const char *) final, 16);
133
 
 
134
 
        if (i % 3)
135
 
            SquidMD5Update(&ctx1, (unsigned const char *) sp, sl);
136
 
 
137
 
        if (i % 7)
138
 
            SquidMD5Update(&ctx1, (unsigned const char *) pw, strlen(pw));
139
 
 
140
 
        if (i & 1)
141
 
            SquidMD5Update(&ctx1, (unsigned const char *) final, 16);
142
 
        else
143
 
            SquidMD5Update(&ctx1, (unsigned const char *) pw, strlen(pw));
144
 
        SquidMD5Final(final, &ctx1);
 
128
        SquidMD5Init(&ctx1);
 
129
        if (i & 1)
 
130
            SquidMD5Update(&ctx1, (unsigned const char *) pw, strlen(pw));
 
131
        else
 
132
            SquidMD5Update(&ctx1, (unsigned const char *) final, 16);
 
133
 
 
134
        if (i % 3)
 
135
            SquidMD5Update(&ctx1, (unsigned const char *) sp, sl);
 
136
 
 
137
        if (i % 7)
 
138
            SquidMD5Update(&ctx1, (unsigned const char *) pw, strlen(pw));
 
139
 
 
140
        if (i & 1)
 
141
            SquidMD5Update(&ctx1, (unsigned const char *) final, 16);
 
142
        else
 
143
            SquidMD5Update(&ctx1, (unsigned const char *) pw, strlen(pw));
 
144
        SquidMD5Final(final, &ctx1);
145
145
    }
146
146
 
147
147
    p = passwd + strlen(passwd);
175
175
/* Created by Ramon de Carvalho <ramondecarvalho@yahoo.com.br>
176
176
   Refined by Rodrigo Rubira Branco <rodrigo@kernelhacking.com>
177
177
*/
178
 
char *md5sum(const char *s){
179
 
   static unsigned char digest[16];
180
 
   SquidMD5_CTX ctx;
181
 
   int idx;
182
 
   static char sum[33];
183
 
 
184
 
   memset(digest,0,16);
185
 
 
186
 
   SquidMD5Init(&ctx);
187
 
   SquidMD5Update(&ctx,(const unsigned char *)s,strlen(s));
188
 
   SquidMD5Final(digest,&ctx);
189
 
 
190
 
   for(idx=0;idx<16;idx++)
191
 
       sprintf(&sum[idx*2],"%02x",digest[idx]);
192
 
 
193
 
   sum[32]='\0';
194
 
 
195
 
   /* Don't leave anything around in vm they could use. */
196
 
   memset(digest, 0, sizeof digest);
197
 
 
198
 
   return sum;
 
178
char *md5sum(const char *s)
 
179
{
 
180
    static unsigned char digest[16];
 
181
    SquidMD5_CTX ctx;
 
182
    int idx;
 
183
    static char sum[33];
 
184
 
 
185
    memset(digest,0,16);
 
186
 
 
187
    SquidMD5Init(&ctx);
 
188
    SquidMD5Update(&ctx,(const unsigned char *)s,strlen(s));
 
189
    SquidMD5Final(digest,&ctx);
 
190
 
 
191
    for (idx=0; idx<16; idx++)
 
192
        sprintf(&sum[idx*2],"%02x",digest[idx]);
 
193
 
 
194
    sum[32]='\0';
 
195
 
 
196
    /* Don't leave anything around in vm they could use. */
 
197
    memset(digest, 0, sizeof digest);
 
198
 
 
199
    return sum;
199
200
}
200
201