Skip to content

Commit 7bf777e

Browse files
Add spritz_crypt_inplace
1 parent 686c952 commit 7bf777e

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ spritz_random32 KEYWORD2
1414
spritz_random32_uniform KEYWORD2
1515
spritz_add_entropy KEYWORD2
1616
spritz_crypt KEYWORD2
17+
spritz_crypt_inplace KEYWORD2
1718
spritz_hash_setup KEYWORD2
1819
spritz_hash_update KEYWORD2
1920
spritz_hash_final KEYWORD2

src/SpritzCipher.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,26 @@ spritz_crypt(spritz_ctx *ctx,
479479
}
480480
}
481481

482+
/** spritz_crypt_inplace()
483+
* Encrypt or decrypt data chunk by XOR-ing it with the spritz keystream
484+
* and put the output in the same buffer `data`.
485+
* Usable only after calling spritz_setup() or spritz_setup_withiv().
486+
*
487+
* Parameter ctx: The context.
488+
* Parameter data: The data to encrypt or decrypt, also the output.
489+
* Parameter datalen: Length of the data in bytes.
490+
*/
491+
void
492+
spritz_crypt_inplace(spritz_ctx *ctx,
493+
uint8_t *data, uint16_t dataLen)
494+
{
495+
uint16_t i;
496+
497+
for (i = 0; i < dataLen; i++) {
498+
data[i] ^= drip(ctx);
499+
}
500+
}
501+
482502

483503
/** spritz_hash_setup()
484504
* Setup the spritz hash state `spritz_ctx`.

src/SpritzCipher.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern "C" {
3333
*/
3434
#if 0
3535
# define SPRITZ_USE_LIBC
36-
# include <string.h>
36+
# include <string.h> /* For `memset()` */
3737
# if !defined(__GNUC__) && !defined(__clang__) /* Not GCC or Clang. */
3838
# warning "SPRITZ_USE_LIBC warning: Code optimization isn't off in some security functions."
3939
# endif /* Not GCC or Clang. */
@@ -231,6 +231,19 @@ spritz_crypt(spritz_ctx *ctx,
231231
const uint8_t *data, uint16_t dataLen,
232232
uint8_t *dataOut);
233233

234+
/** spritz_crypt_inplace()
235+
* Encrypt or decrypt data chunk by XOR-ing it with the spritz keystream
236+
* and put the output in the same buffer `data`.
237+
* Usable only after calling spritz_setup() or spritz_setup_withiv().
238+
*
239+
* Parameter ctx: The context.
240+
* Parameter data: The data to encrypt or decrypt, also the output.
241+
* Parameter datalen: Length of the data in bytes.
242+
*/
243+
void
244+
spritz_crypt_inplace(spritz_ctx *ctx,
245+
uint8_t *data, uint16_t dataLen);
246+
234247

235248
/** spritz_hash_setup()
236249
* Setup the spritz hash state `spritz_ctx`.

0 commit comments

Comments
 (0)