Skip to content

Commit bb82ed9

Browse files
Add user functions comments
1 parent f7a5fff commit bb82ed9

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ spritz_t - Contain the state.
2222

2323
* Functions
2424
setup() - To setup spritz state (spritz_t).
25-
setupIV() - Usable after setup() to add Nonce.
25+
setupIV() - Usable after setup() to add Nonce (Salt).
2626
stream() - Return random byte that can be used as a key.
2727
hash() - Hash function.
2828
mac() - Message Authentication Code (MAC) function.

SpritzCipher.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,11 @@ void SpritzCipher::absorbNibble(spritz_t *ctx, const byte nibble)
118118
swap(&ctx->s[ctx->a], &ctx->s[SPRITZ_N_HALF + nibble]);
119119
ctx->a++;
120120
}
121-
122121
void SpritzCipher::absorb(spritz_t *ctx, const byte octet)
123122
{
124123
absorbNibble(ctx, octet % 16); /* Low */
125124
absorbNibble(ctx, octet / 16); /* High */
126125
}
127-
128126
void SpritzCipher::absorbBytes(spritz_t *ctx, const byte *buf, unsigned int len)
129127
{
130128
unsigned int i;
@@ -169,28 +167,40 @@ void SpritzCipher::squeeze(spritz_t *ctx, byte *out, byte len)
169167
}
170168

171169

170+
/**************************| USER FUNCTIONS |**************************/
172171

172+
/* Setup spritz state (spritz_t) */
173173
void SpritzCipher::setup(spritz_t *ctx,
174174
const byte *key, unsigned int keyLen)
175175
{
176176
stateInit(ctx);
177177
absorbBytes(ctx, key, keyLen);
178178
}
179179

180-
/* Use setupIV() after setup() to add NONCE */
180+
/* Use setupIV() *after* setup() to add NONCE (Salt) */
181181
void SpritzCipher::setupIV(spritz_t *ctx,
182182
const byte *nonce, unsigned int nonceLen)
183183
{
184184
absorbStop(ctx);
185185
absorbBytes(ctx, nonce, nonceLen);
186186
}
187187

188+
/* Return random byte that can be used as a key */
188189
byte SpritzCipher::stream(spritz_t *ctx)
189190
{
190191
return drip(ctx);
191192
}
192193

193194

195+
/**
196+
* Cryptographic hash function
197+
*
198+
* - digest: Hash output.
199+
* - digestLen: Set hash output size, Value (>=) 32 is recommended.
200+
*
201+
* - data: Data to hash.
202+
* - dataLen: Data size.
203+
*/
194204
void SpritzCipher::hash(byte *digest, byte digestLen,
195205
const byte *data, unsigned int dataLen)
196206
{
@@ -202,6 +212,18 @@ void SpritzCipher::hash(byte *digest, byte digestLen,
202212
squeeze(&ctx, digest, digestLen);
203213
}
204214

215+
/**
216+
* Message Authentication Code (MAC) function
217+
*
218+
* - digest: MAC output.
219+
* - digestLen: Set MAC output size, Value (>=) 32 is recommended.
220+
*
221+
* - msg: Message to be authenticated.
222+
* - msgLen: Message size.
223+
*
224+
* - key: The secret key.
225+
* - keyLen: The secret key size.
226+
*/
205227
void SpritzCipher::mac(byte *digest, byte digestLen,
206228
const byte *msg, unsigned int msgLen,
207229
const byte *key, unsigned int keyLen)

SpritzCipher.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,45 @@ class SpritzCipher
4242
public:
4343
SpritzCipher();
4444

45+
/* Setup spritz state (spritz_t) */
4546
void setup(spritz_t *ctx,
4647
const byte *key, unsigned int keyLen);
48+
49+
/* Use setupIV() *after* setup() to add NONCE (Salt) */
4750
void setupIV(spritz_t *ctx,
4851
const byte *nonce, unsigned int nonceLen);
52+
53+
/* Return random byte that can be used as a key */
4954
byte stream(spritz_t *ctx);
5055

56+
/**
57+
* Cryptographic hash function
58+
*
59+
* - digest: Hash output.
60+
* - digestLen: Set hash output size, Value (>=) 32 is recommended.
61+
*
62+
* - data: Data to hash.
63+
* - dataLen: Data size.
64+
*/
5165
void hash(byte *digest, byte digestLen,
5266
const byte *data, unsigned int dataLen);
67+
/**
68+
* Message Authentication Code (MAC) function
69+
*
70+
* - digest: MAC output.
71+
* - digestLen: Set MAC output size, Value (>=) 32 is recommended.
72+
*
73+
* - msg: Message to be authenticated.
74+
* - msgLen: Message size.
75+
*
76+
* - key: The secret key.
77+
* - keyLen: The secret key size.
78+
*/
5379
void mac(byte *digest, byte digestLen,
5480
const byte *msg, unsigned int msgLen,
5581
const byte *key, unsigned int keyLen);
5682

83+
5784
private:
5885
void swap(byte *a, byte *b);
5986
void stateInit(spritz_t *ctx);

0 commit comments

Comments
 (0)