17 #define SURFPCS_LEN 32
19 static void surfpcs_init(s,k)
24 for (i = 0;i < 32;++i) s->seed[i] = k[i];
25 for (i = 0;i < 8;++i) s->sum[i] = 0;
26 for (i = 0;i < 12;++i) s->in[i] = 0;
30 static uint32 littleendian[8] = {
31 50462976, 117835012, 185207048, 252579084,
32 319951120, 387323156, 454695192, 522067228
34 #define end ((unsigned char *) littleendian)
36 #define data ((unsigned char *) s->in)
37 #define outdata ((unsigned char *) s->out)
39 static void surfpcs_addlc(s,x,n)
40 /* modified from Dan's surfpcs_add by skipping ' ' & '\t' and */
41 /* case-independence */
46 register unsigned char ch;
50 if (ch == ' ' || ch == '\t') continue;
51 if (ch >= 'A' && ch <= 'Z')
52 data[end[s->todo++]] = ch - 'A' + 'a';
54 data[end[s->todo++]] = ch;
61 surf(s->out,s->in,s->seed);
63 s->sum[i] += s->out[i];
68 static void surfpcs_out(s,h)
73 surfpcs_addlc(s,".",1);
74 while (s->todo) surfpcs_addlc(s,"",1);
75 for (i = 0;i < 8;++i) s->in[i] = s->sum[i];
76 for (;i < 12;++i) s->in[i] = 0;
77 surf(s->out,s->in,s->seed);
78 for (i = 0;i < 32;++i) h[i] = outdata[end[i]];
81 void makehash(indata,inlen,hash)
85 /* makes hash[COOKIE=20] from stralloc *indata, ignoring case and */
93 for (i = 0;i < 32;++i) seed[i] = 0;
94 surfpcs_init(&s,seed);
95 surfpcs_addlc(&s,indata,inlen);
97 for (i = 0;i < 20;++i)
98 hash[i] = 'a' + (h[i] & 15);
101 static stralloc dummy = {0};
103 void mkauthhash(s,len,h)
104 char *s; unsigned int len; char *h;
105 /* This is a string that should be the same for all messages from a given */
106 /* author. Doesn't have to be the real rfc822 address. We look for a '@' */
107 /* and grab everything up to the next '>', ' ', or ';'. We go back the same */
108 /* way, then take everything up to the '@' or the first '-'. The latter */
109 /* avoids problems with posters that band their addresses. */
111 unsigned int i,j,k,l;
115 i = byte_rchr(s,len,'@');
116 if (i < len) { /* if not then i=sa->len, j=k=l=0 */
118 while (++j < len) { /* if not found, then j=sa->len */
120 if (ch == '>' || ch == ' ' || ch == ';') break;
123 while (k > 0) { /* k <= i */
125 if (ch == '<' || ch == ' ' || ch == ';') break;
127 l = k; /* k <= l <= i; */
128 while (l < i && s[l] != '-') ++l;
129 if (!stralloc_copyb(&dummy,s + k, l - k)) die_nomem();
130 if (!stralloc_catb(&dummy,s + i, j - i)) die_nomem();
131 makehash(dummy.s,dummy.len,h);
132 } else /* use entire line if no '@' found */