dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libsum / common / sum-ast4.c
blob1285b765dea5f5a8e7bbc1ebf67fedc846e05664
1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1996-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
8 * *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
12 * *
13 * Information and Software Systems Research *
14 * AT&T Research *
15 * Florham Park NJ *
16 * *
17 * Glenn Fowler <gsf@research.att.com> *
18 * *
19 ***********************************************************************/
20 #pragma prototyped
23 * ast4
26 #define ast4_description \
27 "The \bast\b 128 bit PRNG hash generated by catenating 4 separate 32 \
28 bit PNRG hashes. The block count is not printed."
29 #define ast4_options 0
30 #define ast4_match "ast4|32x4|tw"
31 #define ast4_done long_done
32 #define ast4_scale 0
34 typedef struct Ast4_sum_s
36 uint32_t sum0;
37 uint32_t sum1;
38 uint32_t sum2;
39 uint32_t sum3;
40 } Ast4_sum_t;
42 typedef struct Ast4_s
44 _SUM_PUBLIC_
45 _SUM_PRIVATE_
46 Ast4_sum_t cur;
47 Ast4_sum_t tot;
48 unsigned char buf[sizeof(Ast4_sum_t)];
49 } Ast4_t;
51 static int
52 ast4_init(Sum_t* p)
54 register Ast4_t* a = (Ast4_t*)p;
56 a->tot.sum0 ^= a->cur.sum0;
57 a->cur.sum0 = 0;
58 a->tot.sum1 ^= a->cur.sum1;
59 a->cur.sum1 = 0;
60 a->tot.sum2 ^= a->cur.sum2;
61 a->cur.sum2 = 0;
62 a->tot.sum3 ^= a->cur.sum3;
63 a->cur.sum3 = 0;
64 return 0;
67 static Sum_t*
68 ast4_open(const Method_t* method, const char* name)
70 Ast4_t* p;
72 if (p = newof(0, Ast4_t, 1, 0))
74 p->method = (Method_t*)method;
75 p->name = name;
77 return (Sum_t*)p;
80 static int
81 ast4_block(Sum_t* p, const void* s, size_t n)
83 register Ast4_sum_t* a = &((Ast4_t*)p)->cur;
84 register unsigned char* b = (unsigned char*)s;
85 register unsigned char* e = b + n;
86 register int c;
88 while (b < e)
90 c = *b++;
91 a->sum0 = a->sum0 * 0x63c63cd9 + 0x9c39c33d + c;
92 a->sum1 = a->sum1 * 0x00000011 + 0x00017cfb + c;
93 a->sum2 = a->sum2 * 0x12345679 + 0x3ade68b1 + c;
94 a->sum3 = a->sum3 * 0xf1eac01d + 0xcafe10af + c;
96 return 0;
99 static int
100 ast4_print(Sum_t* p, Sfio_t* sp, int flags, size_t scale)
102 register Ast4_sum_t* a;
104 a = (flags & SUM_TOTAL) ? &((Ast4_t*)p)->tot : &((Ast4_t*)p)->cur;
105 sfprintf(sp, "%06..64u%06..64u%06..64u%06..64u", a->sum0, a->sum1, a->sum2, a->sum3);
106 return 0;
109 static int
110 ast4_data(Sum_t* p, Sumdata_t* data)
112 data->size = sizeof(((Ast4_t*)p)->cur);
113 data->num = 0;
114 #if _ast_intswap
115 swapmem(_ast_intswap, data->buf = ((Ast4_t*)p)->buf, &((Ast4_t*)p)->cur, sizeof(((Ast4_t*)p)->cur));
116 #else
117 data->buf = &((Ast4_t*)p)->cur;
118 #endif
119 return 0;