6 void cookie(hash
,key
,keylen
,date
,addr
,action
)
16 unsigned char out
[32];
21 step 1: create seed from key. note that this doesn't have to be
22 cryptographic; it simply has to avoid destroying the user's entropy.
23 if speed turns out to be a problem, switch to a CRC.
25 for (i
= 0;i
< 32;++i
) seed
[i
] = 0;
26 for (j
= 0;j
< 4;++j
) {
27 surfpcs_init(&s
,seed
);
28 surfpcs_add(&s
,key
,keylen
);
30 for (i
= 0;i
< 32;++i
) seed
[i
] = (seed
[i
] << 8) + out
[i
];
36 surfpcs_init(&s
,seed
);
37 surfpcs_add(&s
,date
,str_len(date
) + 1);
38 surfpcs_add(&s
,addr
,str_len(addr
) + 1);
39 surfpcs_add(&s
,action
,1);
43 step 3: extract a readable cookie from the SURF output.
45 for (i
= 0;i
< 20;++i
)
46 hash
[i
] = 'a' + (out
[i
] & 15);