ezmlmx 0.68
ezmlmx
Loading...
Searching...
No Matches
cookie.c
Go to the documentation of this file.
1#include "cookie.h"
2#include "str.h"
3#include "uint_t.h"
4#include "surfpcs.h"
5
6#define WHO cookie
7
13
14void cookie(char *hash,
15 const char *key,
16 unsigned int keylen,
17 const char *date,
18 const char *addr,
19 const char *action)
20{
21 surfpcs s;
22 uint32 seed[32];
23 unsigned char out[32];
24 int i;
25 int j;
26
27 /* addr may be passed in as a NULL pointer.
28 * Make sure it points to a non-NULL empty string. */
29 if (addr == 0) addr = "";
30
31/*
32step 1: create seed from key. note that this doesn't have to be
33cryptographic; it simply has to avoid destroying the user's entropy.
34if speed turns out to be a problem, switch to a CRC.
35*/
36 for (i = 0; i < 32; ++i) seed[i] = 0;
37 for (j = 0; j < 4; ++j) {
39 surfpcs_add(&s,key,keylen);
40 surfpcs_out(&s,out);
41 for (i = 0;i < 32;++i) seed[i] = (seed[i] << 8) + out[i];
42 }
43
44/*
45step 2: apply SURF.
46*/
48 surfpcs_add(&s,date,str_len(date) + 1);
49 surfpcs_add(&s,addr,str_len(addr) + 1);
50 surfpcs_add(&s,action,1);
51 surfpcs_out(&s,out);
52
53/*
54step 3: extract a readable cookie from the SURF output.
55*/
56 for (i = 0; i < 20; ++i)
57 hash[i] = 'a' + (out[i] & 15);
58}
void surfpcs_add(surfpcs *s, const unsigned char *x, unsigned int n)
Definition surfpcs.c:26
void surfpcs_init(surfpcs *s, const uint32 k[32])
Definition surfpcs.c:8
void surfpcs_out(surfpcs *s, unsigned char h[32])
Definition surfpcs.c:44
stralloc seed
Definition ezmlm-get.c:74
void cookie(char *hash, const char *key, unsigned int keylen, const char *date, const char *addr, const char *action)
Definition cookie.c:14
stralloc addr
Definition ezmlm-cron.c:45
stralloc action
Definition ezmlm-store.c:84