--- spritz/spritz.h 2015/01/10 04:14:21 1.4 +++ spritz/spritz.h 2015/01/10 08:29:03 1.5 @@ -70,15 +70,26 @@ uint8_t spritz_drip (spritz_state *s); /*******************************************************************************/ +/* the spritz cipher */ + +/* no IV is used if IV_len == 0 */ +void spritz_cipher_init (spritz_state *s, const void *K, size_t K_len, const void *IV, size_t IV_len); + +/* can be called multiple times/incrementally */ +/* can work inplace */ +void spritz_cipher_encrypt (spritz_state *s, const void *I, void *O, size_t len); +void spritz_cipher_decrypt (spritz_state *s, const void *I, void *O, size_t len); + +/*******************************************************************************/ /* the spritz-xor cipher */ /* no IV is used if IV_len == 0 */ -void spritz_cipher_xor_init (spritz_state *s, const void *K, size_t K_len, const void *IV, size_t IV_len); +static void spritz_cipher_xor_init (spritz_state *s, const void *K, size_t K_len, const void *IV, size_t IV_len); /* can be called multiple times/incrementally */ /* can work inplace */ /* works for both encryption and decryption */ -void spritz_cipher_xor_crypt (spritz_state *s, const void *I, void *O, size_t len); + void spritz_cipher_xor_crypt (spritz_state *s, const void *I, void *O, size_t len); /*******************************************************************************/ /* the spritz hash */ @@ -97,6 +108,18 @@ /*******************************************************************************/ /* spritz authenticated encryption */ +static void spritz_aead_init (spritz_state *s, const void *K, size_t K_len); +static void spritz_aead_nonce (spritz_state *s, const void *N, size_t N_len); /* must be called after construction, before associated_data */ +static void spritz_aead_associated_data (spritz_state *s, const void *D, size_t D_len); /* must be called after nonce, before crypt */ + void spritz_aead_encrypt (spritz_state *s, const void *I, void *O, size_t len); + void spritz_aead_decrypt (spritz_state *s, const void *I, void *O, size_t len); +/* must be called after associated_data, only once, before finish */ +/* works for both encryption and decryption */ +static void spritz_aead_finish (spritz_state *s, void *H, size_t H_len); /* must be called at most once at the end */ + +/*******************************************************************************/ +/* spritz authenticated encryption (xor variant) */ + static void spritz_aead_xor_init (spritz_state *s, const void *K, size_t K_len); static void spritz_aead_xor_nonce (spritz_state *s, const void *N, size_t N_len); /* must be called after construction, before associated_data */ static void spritz_aead_xor_associated_data (spritz_state *s, const void *D, size_t D_len); /* must be called after nonce, before crypt */ @@ -116,6 +139,14 @@ /*******************************************************************************/ /* inline functions - some functions are so simple, they are defined inline */ +/* the spritz-xor cipher inline functions */ + +static void +spritz_cipher_xor_init (spritz_state *s, const void *K, size_t K_len, const void *IV, size_t IV_len) +{ + spritz_cipher_init (s, K, K_len, IV, IV_len); +} + /* the spritz hash inline functions */ static void @@ -147,6 +178,32 @@ /* spritz authenticated encryption inline functions */ static void +spritz_aead_init (spritz_state *s, const void *K, size_t K_len) +{ + spritz_mac_init (s, K, K_len); +} + +static void +spritz_aead_nonce (spritz_state *s, const void *N, size_t N_len) +{ + spritz_absorb_and_stop (s, N, N_len); +} + +static void +spritz_aead_associated_data (spritz_state *s, const void *D, size_t D_len) +{ + spritz_absorb_and_stop (s, D, D_len); +} + +static void +spritz_aead_finish (spritz_state *s, void *H, size_t H_len) +{ + spritz_mac_finish (s, H, H_len); +} + +/* spritz authenticated encryption (xor variant) inline functions */ + +static void spritz_aead_xor_init (spritz_state *s, const void *K, size_t K_len) { spritz_mac_init (s, K, K_len);