ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/spritz/spritz.h
(Generate patch)

Comparing spritz/spritz.h (file contents):
Revision 1.3 by root, Fri Jan 9 23:21:41 2015 UTC vs.
Revision 1.6 by root, Sat Jan 10 13:02:26 2015 UTC

33 * by deleting the provisions above and replace them with the notice 33 * by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL. If you do not delete the 34 * and other provisions required by the GPL. If you do not delete the
35 * provisions above, a recipient may use your version of this file under 35 * provisions above, a recipient may use your version of this file under
36 * either the BSD or the GPL. 36 * either the BSD or the GPL.
37 */ 37 */
38#ifndef SPRITZ_H
39#define SPRITZ_H
38 40
39#include <stdint.h> 41#include <stdint.h>
40#include <sys/types.h> 42#include <sys/types.h>
41 43
42/*******************************************************************************/ 44/*******************************************************************************/
43/* spritz parameters/state type */ 45/* spritz parameters/state type */
44 46
45enum { 47enum {
46 spritz_N = 256 48 spritz_N = 256,
49 spritz_aead_blocksize = spritz_N >> 2 /* 64 */
47}; 50};
48 51
49typedef struct 52typedef struct
50{ 53{
51 uint8_t a, i, j, k, z, w; 54 uint8_t a, i, j, k, z, w;
58void spritz_init (spritz_state *s); 61void spritz_init (spritz_state *s);
59void spritz_update (spritz_state *s); 62void spritz_update (spritz_state *s);
60void spritz_whip (spritz_state *s, uint_fast16_t r); 63void spritz_whip (spritz_state *s, uint_fast16_t r);
61void spritz_crush (spritz_state *s); 64void spritz_crush (spritz_state *s);
62void spritz_shuffle (spritz_state *s); 65void spritz_shuffle (spritz_state *s);
63void spritz_absorb_nibble (spritz_state *s, uint8_t x);
64void spritz_absorb (spritz_state *s, const void *I, size_t I_len); 66void spritz_absorb (spritz_state *s, const void *I, size_t I_len);
65void spritz_absorb_stop (spritz_state *s); 67void spritz_absorb_stop (spritz_state *s);
66void spritz_absorb_and_stop (spritz_state *s, const void *I, size_t I_len); /* commonly used helper function */ 68void spritz_absorb_and_stop (spritz_state *s, const void *I, size_t I_len); /* commonly used helper function */
67uint8_t spritz_output (spritz_state *s); 69uint8_t spritz_output (spritz_state *s);
68void spritz_squeeze (spritz_state *s, void *P, size_t P_len); 70void spritz_squeeze (spritz_state *s, void *P, size_t P_len);
69uint8_t spritz_drip (spritz_state *s); 71uint8_t spritz_drip (spritz_state *s);
70 72
71/*******************************************************************************/ 73/*******************************************************************************/
74/* the spritz cipher */
75
76/* no IV is used if IV_len == 0 */
77void spritz_cipher_init (spritz_state *s, const void *K, size_t K_len, const void *IV, size_t IV_len);
78
79/* can be called multiple times/incrementally */
80/* can work inplace */
81void spritz_cipher_encrypt (spritz_state *s, const void *I, void *O, size_t len);
82void spritz_cipher_decrypt (spritz_state *s, const void *I, void *O, size_t len);
83
84/*******************************************************************************/
72/* the spritz-xor cipher */ 85/* the spritz-xor cipher */
73 86
74/* no IV is used if IV_len == 0 */ 87/* no IV is used if IV_len == 0 */
75void spritz_xor_init (spritz_state *s, const void *K, size_t K_len, const void *IV, size_t IV_len); 88static void spritz_cipher_xor_init (spritz_state *s, const void *K, size_t K_len, const void *IV, size_t IV_len);
76 89
77/* can be called multiple times/incrementally */ 90/* can be called multiple times/incrementally */
78/* can work inplace */ 91/* can work inplace */
79/* works for both encryption and decryption */ 92/* works for both encryption and decryption */
80void spritz_xor_crypt (spritz_state *s, const void *I, void *O, size_t len); 93 void spritz_cipher_xor_crypt (spritz_state *s, const void *I, void *O, size_t len);
81 94
82/*******************************************************************************/ 95/*******************************************************************************/
83/* the spritz hash */ 96/* the spritz hash */
84 97
85static void spritz_hash_init (spritz_state *s); 98static void spritz_hash_init (spritz_state *s);
94static void spritz_mac_finish (spritz_state *s, void *H, size_t H_len); /* must be called at most once at the end */ 107static void spritz_mac_finish (spritz_state *s, void *H, size_t H_len); /* must be called at most once at the end */
95 108
96/*******************************************************************************/ 109/*******************************************************************************/
97/* spritz authenticated encryption */ 110/* spritz authenticated encryption */
98 111
99 void spritz_aead_init (spritz_state *s, const void *K, size_t K_len); 112static void spritz_aead_init (spritz_state *s, const void *K, size_t K_len);
100static void spritz_aead_nonce (spritz_state *s, const void *N, size_t N_len); /* must be called after construction, before associated_data */ 113static void spritz_aead_nonce (spritz_state *s, const void *N, size_t N_len); /* must be called after construction, before associated_data */
101static void spritz_aead_associated_data (spritz_state *s, const void *D, size_t D_len); /* must be called after nonce, before crypt */ 114static void spritz_aead_associated_data (spritz_state *s, const void *D, size_t D_len); /* must be called after nonce, before crypt */
102 void spritz_aead_crypt (spritz_state *s, const void *I, void *O, size_t len); 115 void spritz_aead_encrypt (spritz_state *s, const void *I, void *O, size_t len);
116 void spritz_aead_decrypt (spritz_state *s, const void *I, void *O, size_t len);
103/* must be called after associated_data, only once, before finish */ 117/* must be called after associated_data, only once, before finish */
104/* works for both encryption and decryption */ 118/* works for both encryption and decryption */
105static void spritz_aead_finish (spritz_state *s, void *H, size_t H_len); /* must be called at most once at the end */ 119static void spritz_aead_finish (spritz_state *s, void *H, size_t H_len); /* must be called at most once at the end */
106 120
107/*******************************************************************************/ 121/*******************************************************************************/
122/* spritz authenticated encryption (xor variant) */
123
124static void spritz_aead_xor_init (spritz_state *s, const void *K, size_t K_len);
125static void spritz_aead_xor_nonce (spritz_state *s, const void *N, size_t N_len); /* must be called after construction, before associated_data */
126static void spritz_aead_xor_associated_data (spritz_state *s, const void *D, size_t D_len); /* must be called after nonce, before crypt */
127 void spritz_aead_xor_crypt (spritz_state *s, const void *I, void *O, size_t len);
128/* must be called after associated_data, only once, before finish */
129/* works for both encryption and decryption */
130static void spritz_aead_xor_finish (spritz_state *s, void *H, size_t H_len); /* must be called at most once at the end */
131
132/*******************************************************************************/
108/* the spritz drbg/csprng */ 133/* the spritz drbg/csprng */
109 134
110/* constructor takes a seed if S_len != 0, same add spritz_prng_put */ 135/* constructor takes a seed if S_len != 0, same as spritz_prng_add */
111 void spritz_prng_init (spritz_state *s, const void *S, size_t S_len); 136 void spritz_prng_init (spritz_state *s, const void *S, size_t S_len);
112static void spritz_prng_put (spritz_state *s, const void *S, size_t S_len); /* add additional entropy */ 137static void spritz_prng_add (spritz_state *s, const void *S, size_t S_len); /* add additional entropy */
113static void spritz_prng_get (spritz_state *s, void *R, size_t R_len); /* get random bytes */ 138static void spritz_prng_get (spritz_state *s, void *R, size_t R_len); /* get random bytes */
114 139
115/*******************************************************************************/ 140/*******************************************************************************/
116/* inline functions - some functions are so simple, they are defined inline */ 141/* inline functions - some functions are so simple, they are defined inline */
117 142
143/* the spritz-xor cipher inline functions */
144
145static void
146spritz_cipher_xor_init (spritz_state *s, const void *K, size_t K_len, const void *IV, size_t IV_len)
147{
148 spritz_cipher_init (s, K, K_len, IV, IV_len);
149}
150
118/* the spritz hash inline functions */ 151/* the spritz hash inline functions */
119 152
120static void 153static void
121spritz_hash_init (spritz_state *s) 154spritz_hash_init (spritz_state *s)
122{ 155{
144} 177}
145 178
146/* spritz authenticated encryption inline functions */ 179/* spritz authenticated encryption inline functions */
147 180
148static void 181static void
182spritz_aead_init (spritz_state *s, const void *K, size_t K_len)
183{
184 spritz_mac_init (s, K, K_len);
185}
186
187static void
149spritz_aead_nonce (spritz_state *s, const void *N, size_t N_len) 188spritz_aead_nonce (spritz_state *s, const void *N, size_t N_len)
150{ 189{
151 spritz_absorb_and_stop (s, N, N_len); 190 spritz_absorb_and_stop (s, N, N_len);
152} 191}
153 192
161spritz_aead_finish (spritz_state *s, void *H, size_t H_len) 200spritz_aead_finish (spritz_state *s, void *H, size_t H_len)
162{ 201{
163 spritz_mac_finish (s, H, H_len); 202 spritz_mac_finish (s, H, H_len);
164} 203}
165 204
205/* spritz authenticated encryption (xor variant) inline functions */
206
207static void
208spritz_aead_xor_init (spritz_state *s, const void *K, size_t K_len)
209{
210 spritz_mac_init (s, K, K_len);
211}
212
213static void
214spritz_aead_xor_nonce (spritz_state *s, const void *N, size_t N_len)
215{
216 spritz_absorb_and_stop (s, N, N_len);
217}
218
219static void
220spritz_aead_xor_associated_data (spritz_state *s, const void *D, size_t D_len)
221{
222 spritz_absorb_and_stop (s, D, D_len);
223}
224
225static void
226spritz_aead_xor_finish (spritz_state *s, void *H, size_t H_len)
227{
228 spritz_mac_finish (s, H, H_len);
229}
230
166/* the spritz drbg/csprng inline functions */ 231/* the spritz drbg/csprng inline functions */
167 232
168static void 233static void
169spritz_prng_put (spritz_state *s, const void *S, size_t S_len) 234spritz_prng_add (spritz_state *s, const void *S, size_t S_len)
170{ 235{
171 spritz_absorb (s, S, S_len); 236 spritz_absorb (s, S, S_len);
172} 237}
173 238
174/* get random bytes */ 239/* get random bytes */
176spritz_prng_get (spritz_state *s, void *R, size_t R_len) 241spritz_prng_get (spritz_state *s, void *R, size_t R_len)
177{ 242{
178 spritz_squeeze (s, R, R_len); 243 spritz_squeeze (s, R, R_len);
179} 244}
180 245
246#endif
247

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines