1 /***********************************************************************
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 *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
19 ***********************************************************************/
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
34 typedef struct Ast4_sum_s
48 unsigned char buf
[sizeof(Ast4_sum_t
)];
54 register Ast4_t
* a
= (Ast4_t
*)p
;
56 a
->tot
.sum0
^= a
->cur
.sum0
;
58 a
->tot
.sum1
^= a
->cur
.sum1
;
60 a
->tot
.sum2
^= a
->cur
.sum2
;
62 a
->tot
.sum3
^= a
->cur
.sum3
;
68 ast4_open(const Method_t
* method
, const char* name
)
72 if (p
= newof(0, Ast4_t
, 1, 0))
74 p
->method
= (Method_t
*)method
;
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
;
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
;
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
);
110 ast4_data(Sum_t
* p
, Sumdata_t
* data
)
112 data
->size
= sizeof(((Ast4_t
*)p
)->cur
);
115 swapmem(_ast_intswap
, data
->buf
= ((Ast4_t
*)p
)->buf
, &((Ast4_t
*)p
)->cur
, sizeof(((Ast4_t
*)p
)->cur
));
117 data
->buf
= &((Ast4_t
*)p
)->cur
;