ezmlmx 0.68
ezmlmx
Loading...
Searching...
No Matches
makehash.c
Go to the documentation of this file.
1#include "stralloc.h"
2#include "byte.h"
3#include "surf.h"
4#include "uint_t.h"
5#include "makehash.h"
6#include "idx.h"
7#include "errtxt.h"
8#include "logmsg.h"
9
10#define WHO "makehash"
11
17
18typedef struct {
19 uint32 seed[32];
20 uint32 sum[8];
21 uint32 out[8];
22 uint32 in[12];
23 int todo;
24} surfpcs;
25
26#define SURFPCS_LEN 32
27
28static void die_nomem() { logmsg(WHO,111,FATAL,ERR_NOMEM); }
29
30static void surfpcs_init(surfpcs *s,const uint32 k[32])
31{
32 int i;
33 for (i = 0;i < 32;++i) s->seed[i] = k[i];
34 for (i = 0;i < 8;++i) s->sum[i] = 0;
35 for (i = 0;i < 12;++i) s->in[i] = 0;
36 s->todo = 0;
37}
38
39static uint32 littleendian[8] = {
40 50462976, 117835012, 185207048, 252579084,
41 319951120, 387323156, 454695192, 522067228
42} ;
43#define end ((unsigned char *) littleendian)
44
45#define data ((unsigned char *) s->in)
46#define outdata ((unsigned char *) s->out)
47
56
57static void surfpcs_addlc(surfpcs *s,const unsigned char *x,unsigned int n)
58{
59 unsigned char ch;
60 int i;
61 while (n--) {
62 ch = *x++;
63 if (ch == ' ' || ch == '\t') continue;
64 if (ch >= 'A' && ch <= 'Z')
65 data[end[s->todo++]] = ch - 'A' + 'a';
66 else
67 data[end[s->todo++]] = ch;
68 if (s->todo == 32) {
69 s->todo = 0;
70 if (!++s->in[8])
71 if (!++s->in[9])
72 if (!++s->in[10])
73 ++s->in[11];
74 surf(s->out,s->in,s->seed);
75
76 for (i = 0; i < 8; ++i)
77 s->sum[i] += s->out[i];
78 }
79 }
80}
81
82static void surfpcs_out(surfpcs *s,unsigned char h[32])
83{
84 int i;
85 surfpcs_addlc(s,".",1);
86
87 while (s->todo)
88 surfpcs_addlc(s,"",1);
89
90 for (i = 0; i < 8; ++i) s->in[i] = s->sum[i];
91 for (; i < 12; ++i) s->in[i] = 0;
92 surf(s->out,s->in,s->seed);
93 for (i = 0; i < 32; ++i) h[i] = outdata[end[i]];
94}
95
103
104void makehash(const char *indata,unsigned int inlen,char *hash)
105{
106 unsigned char h[32];
107 surfpcs s;
108 uint32 seed[32];
109 int i;
110
111 for (i = 0; i < 32; ++i) seed[i] = 0;
112 surfpcs_init(&s,seed);
113 surfpcs_addlc(&s,indata,inlen);
114 surfpcs_out(&s,h);
115 for (i = 0; i < 20; ++i)
116 hash[i] = 'a' + (h[i] & 15);
117}
118
119static stralloc dummy = {0};
120
132
133void mkauthhash(const char *s,unsigned int len,char *h)
134{
135 unsigned int i,j,k,l;
136 char ch;
137
138 j = k = l = 0;
139 i = byte_rchr(s,len,'@');
140 if (i < len) { /* if not then i=sa->len, j=k=l=0 */
141 j = i;
142 while (++j < len) { /* if not found, then j=sa->len */
143 ch = s[j];
144 if (ch == '>' || ch == ' ' || ch == ';') break;
145 }
146 k = i;
147 while (k > 0) { /* k <= i */
148 ch = s[--k];
149 if (ch == '<' || ch == ' ' || ch == ';') break;
150 }
151 l = k; /* k <= l <= i; */
152 while (l < i && s[l] != '-')
153 ++l;
154 if (!stralloc_copyb(&dummy,s + k, l - k)) die_nomem();
155 if (!stralloc_catb(&dummy,s + i, j - i)) die_nomem();
156 makehash(dummy.s,dummy.len,h);
157 } else /* use entire line if no '@' found */
158 makehash(s,len,h);
159}
void surf(uint32 out[8], const uint32 in[12], const uint32 seed[32])
Definition surf.c:8
Error messages. If you translate these, I would urge you to keep the English version as well....
#define ERR_NOMEM
Definition errtxt.h:14
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
void die_nomem()
Definition getconf.c:17
#define WHO
Definition author.c:1
stralloc seed
Definition ezmlm-get.c:74
void mkauthhash(const char *s, unsigned int len, char *h)
Definition makehash.c:133
#define end
Definition makehash.c:43
#define data
Definition makehash.c:45
#define outdata
Definition makehash.c:46
void makehash(const char *indata, unsigned int inlen, char *hash)
Definition makehash.c:104
unsigned int len
Definition ezmlm-cron.c:68
buffer in
Definition install.c:114
stralloc dummy
Definition ezmlm-idx.c:48
uint32 sum[8]
Definition surfpcs.h:8
uint32 out[8]
Definition surfpcs.h:9
uint32 in[12]
Definition surfpcs.h:10
int todo
Definition surfpcs.h:11
uint32 seed[32]
Definition surfpcs.h:7
const char * logmsg(const char *dir, unsigned long num, unsigned long listno, unsigned long subs, int done)
Definition loginfo.c:32