annotate yarrow.c @ 50:c61e66431001 libtomcrypt

Merge of the normal Dropbear makefile: - Don't include mpi.o, since it does Bad Things (tm) (wrt LTM) - Don't try to make clean in tests if it doesn't exist (infinite looping makefiles, mmmmm)
author Matt Johnston <matt@ucc.asn.au>
date Sat, 07 Aug 2004 16:33:31 +0000
parents b939f2d4431e
children 7ed585a2c53b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
2 *
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
3 * LibTomCrypt is a library that provides various cryptographic
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
4 * algorithms in a highly modular and flexible manner.
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
5 *
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
6 * The library is free for all purposes without any express
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
7 * guarantee it works.
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
8 *
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
9 * Tom St Denis, [email protected], http://libtomcrypt.org
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
10 */
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
11
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
12 #include "mycrypt.h"
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
13
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
14 #ifdef YARROW
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
15
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
16 const struct _prng_descriptor yarrow_desc =
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
17 {
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
18 "yarrow",
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
19 &yarrow_start,
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
20 &yarrow_add_entropy,
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
21 &yarrow_ready,
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
22 &yarrow_read
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
23 };
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
24
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
25 int yarrow_start(prng_state *prng)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
26 {
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
27 int err;
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
28
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
29 _ARGCHK(prng != NULL);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
30
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
31 /* these are the default hash/cipher combo used */
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
32 #ifdef RIJNDAEL
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
33 #if YARROW_AES==0
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
34 prng->yarrow.cipher = register_cipher(&rijndael_enc_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
35 #elif YARROW_AES==1
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
36 prng->yarrow.cipher = register_cipher(&aes_enc_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
37 #elif YARROW_AES==2
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
38 prng->yarrow.cipher = register_cipher(&rijndael_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
39 #elif YARROW_AES==3
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
40 prng->yarrow.cipher = register_cipher(&aes_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
41 #endif
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
42 #elif defined(BLOWFISH)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
43 prng->yarrow.cipher = register_cipher(&blowfish_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
44 #elif defined(TWOFISH)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
45 prng->yarrow.cipher = register_cipher(&twofish_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
46 #elif defined(RC6)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
47 prng->yarrow.cipher = register_cipher(&rc6_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
48 #elif defined(RC5)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
49 prng->yarrow.cipher = register_cipher(&rc5_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
50 #elif defined(SAFERP)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
51 prng->yarrow.cipher = register_cipher(&saferp_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
52 #elif defined(RC2)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
53 prng->yarrow.cipher = register_cipher(&rc2_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
54 #elif defined(NOEKEON)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
55 prng->yarrow.cipher = register_cipher(&noekeon_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
56 #elif defined(CAST5)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
57 prng->yarrow.cipher = register_cipher(&cast5_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
58 #elif defined(XTEA)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
59 prng->yarrow.cipher = register_cipher(&xtea_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
60 #elif defined(SAFER)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
61 prng->yarrow.cipher = register_cipher(&safer_sk128_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
62 #elif defined(DES)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
63 prng->yarrow.cipher = register_cipher(&des3_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
64 #elif
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
65 #error YARROW needs at least one CIPHER
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
66 #endif
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
67 if ((err = cipher_is_valid(prng->yarrow.cipher)) != CRYPT_OK) {
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
68 return err;
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
69 }
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
70
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
71 #ifdef SHA256
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
72 prng->yarrow.hash = register_hash(&sha256_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
73 #elif defined(SHA512)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
74 prng->yarrow.hash = register_hash(&sha512_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
75 #elif defined(TIGER)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
76 prng->yarrow.hash = register_hash(&tiger_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
77 #elif defined(SHA1)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
78 prng->yarrow.hash = register_hash(&sha1_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
79 #elif defined(RIPEMD160)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
80 prng->yarrow.hash = register_hash(&rmd160_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
81 #elif defined(RIPEMD128)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
82 prng->yarrow.hash = register_hash(&rmd128_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
83 #elif defined(MD5)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
84 prng->yarrow.hash = register_hash(&md5_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
85 #elif defined(MD4)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
86 prng->yarrow.hash = register_hash(&md4_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
87 #elif defined(MD2)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
88 prng->yarrow.hash = register_hash(&md2_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
89 #elif defined(WHIRLPOOL)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
90 prng->yarrow.hash = register_hash(&whirlpool_desc);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
91 #else
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
92 #error YARROW needs at least one HASH
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
93 #endif
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
94 if ((err = hash_is_valid(prng->yarrow.hash)) != CRYPT_OK) {
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
95 return err;
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
96 }
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
97
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
98 /* zero the memory used */
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
99 zeromem(prng->yarrow.pool, sizeof(prng->yarrow.pool));
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
100
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
101 return CRYPT_OK;
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
102 }
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
103
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
104 int yarrow_add_entropy(const unsigned char *buf, unsigned long len, prng_state *prng)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
105 {
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
106 hash_state md;
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
107 int err;
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
108
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
109 _ARGCHK(buf != NULL);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
110 _ARGCHK(prng != NULL);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
111
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
112 if ((err = hash_is_valid(prng->yarrow.hash)) != CRYPT_OK) {
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
113 return err;
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
114 }
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
115
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
116 /* start the hash */
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
117 hash_descriptor[prng->yarrow.hash].init(&md);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
118
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
119 /* hash the current pool */
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
120 if ((err = hash_descriptor[prng->yarrow.hash].process(&md, prng->yarrow.pool,
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
121 hash_descriptor[prng->yarrow.hash].hashsize)) != CRYPT_OK) {
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
122 return err;
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
123 }
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
124
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
125 /* add the new entropy */
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
126 if ((err = hash_descriptor[prng->yarrow.hash].process(&md, buf, len)) != CRYPT_OK) {
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
127 return err;
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
128 }
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
129
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
130 /* store result */
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
131 if ((err = hash_descriptor[prng->yarrow.hash].done(&md, prng->yarrow.pool)) != CRYPT_OK) {
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
132 return err;
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
133 }
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
134
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
135 return CRYPT_OK;
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
136 }
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
137
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
138 int yarrow_ready(prng_state *prng)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
139 {
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
140 int ks, err;
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
141
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
142 _ARGCHK(prng != NULL);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
143
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
144 if ((err = hash_is_valid(prng->yarrow.hash)) != CRYPT_OK) {
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
145 return err;
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
146 }
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
147
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
148 if ((err = cipher_is_valid(prng->yarrow.cipher)) != CRYPT_OK) {
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
149 return err;
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
150 }
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
151
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
152 /* setup CTR mode using the "pool" as the key */
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
153 ks = (int)hash_descriptor[prng->yarrow.hash].hashsize;
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
154 if ((err = cipher_descriptor[prng->yarrow.cipher].keysize(&ks)) != CRYPT_OK) {
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
155 return err;
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
156 }
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
157
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
158 if ((err = ctr_start(prng->yarrow.cipher, /* what cipher to use */
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
159 prng->yarrow.pool, /* IV */
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
160 prng->yarrow.pool, ks, /* KEY and key size */
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
161 0, /* number of rounds */
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
162 &prng->yarrow.ctr)) != CRYPT_OK) {
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
163 return err;
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
164 }
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
165 return CRYPT_OK;
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
166 }
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
167
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
168 unsigned long yarrow_read(unsigned char *buf, unsigned long len, prng_state *prng)
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
169 {
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
170 _ARGCHK(buf != NULL);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
171 _ARGCHK(prng != NULL);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
172
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
173 /* put buf in predictable state first */
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
174 zeromem(buf, len);
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
175
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
176 /* now randomize it */
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
177 if (ctr_encrypt(buf, buf, len, &prng->yarrow.ctr) != CRYPT_OK) {
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
178 return 0;
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
179 }
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
180 return len;
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
181 }
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
182
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
183 #endif
b939f2d4431e Include files accidentally zeroed when merging 0.96 release
Matt Johnston <matt@ucc.asn.au>
parents: 16
diff changeset
184