Skip to content

Commit

Permalink
Make setupIV() independent from setup() by key arg
Browse files Browse the repository at this point in the history
  • Loading branch information
abderraouf-adjal committed Nov 5, 2015
1 parent cdf2610 commit 62fc2c8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
10 changes: 5 additions & 5 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ Library content for user
spritz_t - The context/ctx (contain the state), holds indices and S-Box.

* Functions
setup(ctx, key, keyLen) - Setup spritz state (spritz_t) with a key.
setupIV(ctx, nonce, nonceLen) - Add NONCE (Salt) to spritz state, Use setupIV() after setup().
wipe_spritz_ctx(ctx) - Wipe spritz context data.
spritz_rand_byte(ctx) - Generates a byte of keystream from spritz state (spritz_t).
hash(digest, digestLen, data, dataLen) - Cryptographic hash function.
setup(ctx, key, keyLen) - Setup spritz state (spritz_t) with a key.
setupIV(ctx, key, keyLen, nonce, nonceLen) - Setup spritz state (spritz_t) with a key and nonce (Salt).
wipe_spritz_ctx(ctx) - Wipe spritz context data.
spritz_rand_byte(ctx) - Generates a byte of keystream from spritz state (spritz_t).
hash(digest, digestLen, data, dataLen) - Cryptographic hash function.
mac(digest, digestLen, msg, msgLen, key, keyLen) - Message Authentication Code (MAC) function.

See <SpritzCipher.h> for the details.
Expand Down
14 changes: 8 additions & 6 deletions SpritzCipher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ SpritzCipher::squeeze(spritz_t *ctx, uint8_t *out, uint8_t len)
/* Setup spritz state (spritz_t) with a key */
void
SpritzCipher::setup(spritz_t *ctx,
const uint8_t *key, uint8_t keyLen)
const uint8_t *key, uint8_t keyLen)
{
uint8_t i;
stateInit(ctx);
Expand All @@ -182,12 +182,14 @@ SpritzCipher::setup(spritz_t *ctx,
}
}

/* Add NONCE (Salt) to spritz state, Use setupIV() after setup() */
/* Setup spritz state (spritz_t) with a key and nonce (Salt) */
void
SpritzCipher::setupIV(spritz_t *ctx,
const uint8_t *nonce, uint8_t nonceLen)
const uint8_t *key, uint8_t keyLen,
const uint8_t *nonce, uint8_t nonceLen)
{
uint8_t i;
setup(ctx, key, keyLen);
absorbStop(ctx);
for (i = 0; i < nonceLen; i++) {
absorb(ctx, nonce[i]);
Expand Down Expand Up @@ -218,7 +220,7 @@ SpritzCipher::spritz_rand_byte(spritz_t *ctx)
/* Cryptographic hash function */
void
SpritzCipher::hash(uint8_t *digest, uint8_t digestLen,
const uint8_t *data, unsigned int dataLen)
const uint8_t *data, unsigned int dataLen)
{
spritz_t ctx;
unsigned int i;
Expand All @@ -237,8 +239,8 @@ SpritzCipher::hash(uint8_t *digest, uint8_t digestLen,
/* Message Authentication Code (MAC) function */
void
SpritzCipher::mac(uint8_t *digest, uint8_t digestLen,
const uint8_t *msg, unsigned int msgLen,
const uint8_t *key, uint8_t keyLen)
const uint8_t *msg, unsigned int msgLen,
const uint8_t *key, uint8_t keyLen)
{
spritz_t ctx;
unsigned int i;
Expand Down
7 changes: 5 additions & 2 deletions SpritzCipher.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,17 @@ class SpritzCipher
const uint8_t *key, uint8_t keyLen);


/** \fn void setupIV(spritz_t *ctx, const uint8_t *nonce, uint8_t nonceLen)
* \brief add NONCE (Salt) to spritz state, Use setupIV() after setup()
/** \fn void setupIV(spritz_t *ctx, const uint8_t *key, uint8_t keyLen, const uint8_t *nonce, uint8_t nonceLen)
* \brief setup spritz state (spritz_t) with a key and nonce (Salt)
* \param ctx the context
* \param key the key
* \param keyLen length of the key in bytes
* \param nonce the nonce (salt)
* \param nonceLen length of the nonce in bytes
*/
void
setupIV(spritz_t *ctx,
const uint8_t *key, uint8_t keyLen,
const uint8_t *nonce, uint8_t nonceLen);


Expand Down

0 comments on commit 62fc2c8

Please sign in to comment.