… | |
… | |
68 | uint8_t spritz_output (spritz_state *s); |
68 | uint8_t spritz_output (spritz_state *s); |
69 | void spritz_squeeze (spritz_state *s, void *P, size_t P_len); |
69 | void spritz_squeeze (spritz_state *s, void *P, size_t P_len); |
70 | uint8_t spritz_drip (spritz_state *s); |
70 | uint8_t spritz_drip (spritz_state *s); |
71 | |
71 | |
72 | /*******************************************************************************/ |
72 | /*******************************************************************************/ |
|
|
73 | /* the spritz cipher */ |
|
|
74 | |
|
|
75 | /* no IV is used if IV_len == 0 */ |
|
|
76 | void spritz_cipher_init (spritz_state *s, const void *K, size_t K_len, const void *IV, size_t IV_len); |
|
|
77 | |
|
|
78 | /* can be called multiple times/incrementally */ |
|
|
79 | /* can work inplace */ |
|
|
80 | void spritz_cipher_encrypt (spritz_state *s, const void *I, void *O, size_t len); |
|
|
81 | void spritz_cipher_decrypt (spritz_state *s, const void *I, void *O, size_t len); |
|
|
82 | |
|
|
83 | /*******************************************************************************/ |
73 | /* the spritz-xor cipher */ |
84 | /* the spritz-xor cipher */ |
74 | |
85 | |
75 | /* no IV is used if IV_len == 0 */ |
86 | /* no IV is used if IV_len == 0 */ |
76 | void spritz_cipher_xor_init (spritz_state *s, const void *K, size_t K_len, const void *IV, size_t IV_len); |
87 | static void spritz_cipher_xor_init (spritz_state *s, const void *K, size_t K_len, const void *IV, size_t IV_len); |
77 | |
88 | |
78 | /* can be called multiple times/incrementally */ |
89 | /* can be called multiple times/incrementally */ |
79 | /* can work inplace */ |
90 | /* can work inplace */ |
80 | /* works for both encryption and decryption */ |
91 | /* works for both encryption and decryption */ |
81 | void spritz_cipher_xor_crypt (spritz_state *s, const void *I, void *O, size_t len); |
92 | void spritz_cipher_xor_crypt (spritz_state *s, const void *I, void *O, size_t len); |
82 | |
93 | |
83 | /*******************************************************************************/ |
94 | /*******************************************************************************/ |
84 | /* the spritz hash */ |
95 | /* the spritz hash */ |
85 | |
96 | |
86 | static void spritz_hash_init (spritz_state *s); |
97 | static void spritz_hash_init (spritz_state *s); |
… | |
… | |
94 | static void spritz_mac_add (spritz_state *s, const void *M, size_t M_len); /* can be called multiple times/incrementally */ |
105 | static void spritz_mac_add (spritz_state *s, const void *M, size_t M_len); /* can be called multiple times/incrementally */ |
95 | static void spritz_mac_finish (spritz_state *s, void *H, size_t H_len); /* must be called at most once at the end */ |
106 | static void spritz_mac_finish (spritz_state *s, void *H, size_t H_len); /* must be called at most once at the end */ |
96 | |
107 | |
97 | /*******************************************************************************/ |
108 | /*******************************************************************************/ |
98 | /* spritz authenticated encryption */ |
109 | /* spritz authenticated encryption */ |
|
|
110 | |
|
|
111 | static void spritz_aead_init (spritz_state *s, const void *K, size_t K_len); |
|
|
112 | static void spritz_aead_nonce (spritz_state *s, const void *N, size_t N_len); /* must be called after construction, before associated_data */ |
|
|
113 | static void spritz_aead_associated_data (spritz_state *s, const void *D, size_t D_len); /* must be called after nonce, before crypt */ |
|
|
114 | void spritz_aead_encrypt (spritz_state *s, const void *I, void *O, size_t len); |
|
|
115 | void spritz_aead_decrypt (spritz_state *s, const void *I, void *O, size_t len); |
|
|
116 | /* must be called after associated_data, only once, before finish */ |
|
|
117 | /* works for both encryption and decryption */ |
|
|
118 | static void spritz_aead_finish (spritz_state *s, void *H, size_t H_len); /* must be called at most once at the end */ |
|
|
119 | |
|
|
120 | /*******************************************************************************/ |
|
|
121 | /* spritz authenticated encryption (xor variant) */ |
99 | |
122 | |
100 | static void spritz_aead_xor_init (spritz_state *s, const void *K, size_t K_len); |
123 | static void spritz_aead_xor_init (spritz_state *s, const void *K, size_t K_len); |
101 | static void spritz_aead_xor_nonce (spritz_state *s, const void *N, size_t N_len); /* must be called after construction, before associated_data */ |
124 | static void spritz_aead_xor_nonce (spritz_state *s, const void *N, size_t N_len); /* must be called after construction, before associated_data */ |
102 | static void spritz_aead_xor_associated_data (spritz_state *s, const void *D, size_t D_len); /* must be called after nonce, before crypt */ |
125 | static void spritz_aead_xor_associated_data (spritz_state *s, const void *D, size_t D_len); /* must be called after nonce, before crypt */ |
103 | void spritz_aead_xor_crypt (spritz_state *s, const void *I, void *O, size_t len); |
126 | void spritz_aead_xor_crypt (spritz_state *s, const void *I, void *O, size_t len); |
… | |
… | |
114 | static void spritz_prng_get (spritz_state *s, void *R, size_t R_len); /* get random bytes */ |
137 | static void spritz_prng_get (spritz_state *s, void *R, size_t R_len); /* get random bytes */ |
115 | |
138 | |
116 | /*******************************************************************************/ |
139 | /*******************************************************************************/ |
117 | /* inline functions - some functions are so simple, they are defined inline */ |
140 | /* inline functions - some functions are so simple, they are defined inline */ |
118 | |
141 | |
|
|
142 | /* the spritz-xor cipher inline functions */ |
|
|
143 | |
|
|
144 | static void |
|
|
145 | spritz_cipher_xor_init (spritz_state *s, const void *K, size_t K_len, const void *IV, size_t IV_len) |
|
|
146 | { |
|
|
147 | spritz_cipher_init (s, K, K_len, IV, IV_len); |
|
|
148 | } |
|
|
149 | |
119 | /* the spritz hash inline functions */ |
150 | /* the spritz hash inline functions */ |
120 | |
151 | |
121 | static void |
152 | static void |
122 | spritz_hash_init (spritz_state *s) |
153 | spritz_hash_init (spritz_state *s) |
123 | { |
154 | { |
… | |
… | |
145 | } |
176 | } |
146 | |
177 | |
147 | /* spritz authenticated encryption inline functions */ |
178 | /* spritz authenticated encryption inline functions */ |
148 | |
179 | |
149 | static void |
180 | static void |
|
|
181 | spritz_aead_init (spritz_state *s, const void *K, size_t K_len) |
|
|
182 | { |
|
|
183 | spritz_mac_init (s, K, K_len); |
|
|
184 | } |
|
|
185 | |
|
|
186 | static void |
|
|
187 | spritz_aead_nonce (spritz_state *s, const void *N, size_t N_len) |
|
|
188 | { |
|
|
189 | spritz_absorb_and_stop (s, N, N_len); |
|
|
190 | } |
|
|
191 | |
|
|
192 | static void |
|
|
193 | spritz_aead_associated_data (spritz_state *s, const void *D, size_t D_len) |
|
|
194 | { |
|
|
195 | spritz_absorb_and_stop (s, D, D_len); |
|
|
196 | } |
|
|
197 | |
|
|
198 | static void |
|
|
199 | spritz_aead_finish (spritz_state *s, void *H, size_t H_len) |
|
|
200 | { |
|
|
201 | spritz_mac_finish (s, H, H_len); |
|
|
202 | } |
|
|
203 | |
|
|
204 | /* spritz authenticated encryption (xor variant) inline functions */ |
|
|
205 | |
|
|
206 | static void |
150 | spritz_aead_xor_init (spritz_state *s, const void *K, size_t K_len) |
207 | spritz_aead_xor_init (spritz_state *s, const void *K, size_t K_len) |
151 | { |
208 | { |
152 | spritz_mac_init (s, K, K_len); |
209 | spritz_mac_init (s, K, K_len); |
153 | } |
210 | } |
154 | |
211 | |