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.4 by root, Sat Jan 10 04:14:21 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/*******************************************************************************/
58void spritz_init (spritz_state *s); 60void spritz_init (spritz_state *s);
59void spritz_update (spritz_state *s); 61void spritz_update (spritz_state *s);
60void spritz_whip (spritz_state *s, uint_fast16_t r); 62void spritz_whip (spritz_state *s, uint_fast16_t r);
61void spritz_crush (spritz_state *s); 63void spritz_crush (spritz_state *s);
62void spritz_shuffle (spritz_state *s); 64void 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); 65void spritz_absorb (spritz_state *s, const void *I, size_t I_len);
65void spritz_absorb_stop (spritz_state *s); 66void 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 */ 67void 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); 68uint8_t spritz_output (spritz_state *s);
68void spritz_squeeze (spritz_state *s, void *P, size_t P_len); 69void spritz_squeeze (spritz_state *s, void *P, size_t P_len);
70 71
71/*******************************************************************************/ 72/*******************************************************************************/
72/* the spritz-xor cipher */ 73/* the spritz-xor cipher */
73 74
74/* no IV is used if IV_len == 0 */ 75/* 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); 76void spritz_cipher_xor_init (spritz_state *s, const void *K, size_t K_len, const void *IV, size_t IV_len);
76 77
77/* can be called multiple times/incrementally */ 78/* can be called multiple times/incrementally */
78/* can work inplace */ 79/* can work inplace */
79/* works for both encryption and decryption */ 80/* works for both encryption and decryption */
80void spritz_xor_crypt (spritz_state *s, const void *I, void *O, size_t len); 81void spritz_cipher_xor_crypt (spritz_state *s, const void *I, void *O, size_t len);
81 82
82/*******************************************************************************/ 83/*******************************************************************************/
83/* the spritz hash */ 84/* the spritz hash */
84 85
85static void spritz_hash_init (spritz_state *s); 86static 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 */ 95static void spritz_mac_finish (spritz_state *s, void *H, size_t H_len); /* must be called at most once at the end */
95 96
96/*******************************************************************************/ 97/*******************************************************************************/
97/* spritz authenticated encryption */ 98/* spritz authenticated encryption */
98 99
99 void spritz_aead_init (spritz_state *s, const void *K, size_t K_len); 100static void spritz_aead_xor_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 */ 101static void spritz_aead_xor_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 */ 102static void spritz_aead_xor_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); 103 void spritz_aead_xor_crypt (spritz_state *s, const void *I, void *O, size_t len);
103/* must be called after associated_data, only once, before finish */ 104/* must be called after associated_data, only once, before finish */
104/* works for both encryption and decryption */ 105/* 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 */ 106static void spritz_aead_xor_finish (spritz_state *s, void *H, size_t H_len); /* must be called at most once at the end */
106 107
107/*******************************************************************************/ 108/*******************************************************************************/
108/* the spritz drbg/csprng */ 109/* the spritz drbg/csprng */
109 110
110/* constructor takes a seed if S_len != 0, same add spritz_prng_put */ 111/* 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); 112 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 */ 113static 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 */ 114static void spritz_prng_get (spritz_state *s, void *R, size_t R_len); /* get random bytes */
114 115
115/*******************************************************************************/ 116/*******************************************************************************/
116/* inline functions - some functions are so simple, they are defined inline */ 117/* inline functions - some functions are so simple, they are defined inline */
117 118
144} 145}
145 146
146/* spritz authenticated encryption inline functions */ 147/* spritz authenticated encryption inline functions */
147 148
148static void 149static void
150spritz_aead_xor_init (spritz_state *s, const void *K, size_t K_len)
151{
152 spritz_mac_init (s, K, K_len);
153}
154
155static void
149spritz_aead_nonce (spritz_state *s, const void *N, size_t N_len) 156spritz_aead_xor_nonce (spritz_state *s, const void *N, size_t N_len)
150{ 157{
151 spritz_absorb_and_stop (s, N, N_len); 158 spritz_absorb_and_stop (s, N, N_len);
152} 159}
153 160
154static void 161static void
155spritz_aead_associated_data (spritz_state *s, const void *D, size_t D_len) 162spritz_aead_xor_associated_data (spritz_state *s, const void *D, size_t D_len)
156{ 163{
157 spritz_absorb_and_stop (s, D, D_len); 164 spritz_absorb_and_stop (s, D, D_len);
158} 165}
159 166
160static void 167static void
161spritz_aead_finish (spritz_state *s, void *H, size_t H_len) 168spritz_aead_xor_finish (spritz_state *s, void *H, size_t H_len)
162{ 169{
163 spritz_mac_finish (s, H, H_len); 170 spritz_mac_finish (s, H, H_len);
164} 171}
165 172
166/* the spritz drbg/csprng inline functions */ 173/* the spritz drbg/csprng inline functions */
167 174
168static void 175static void
169spritz_prng_put (spritz_state *s, const void *S, size_t S_len) 176spritz_prng_add (spritz_state *s, const void *S, size_t S_len)
170{ 177{
171 spritz_absorb (s, S, S_len); 178 spritz_absorb (s, S, S_len);
172} 179}
173 180
174/* get random bytes */ 181/* get random bytes */
176spritz_prng_get (spritz_state *s, void *R, size_t R_len) 183spritz_prng_get (spritz_state *s, void *R, size_t R_len)
177{ 184{
178 spritz_squeeze (s, R, R_len); 185 spritz_squeeze (s, R, R_len);
179} 186}
180 187
188#endif
189

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines