~mdw
/
catacomb
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
symm/modes-test.c: Test discarding output by changing encryption order.
[catacomb]
/
symm
/
modes-test.c
diff --git
a/symm/modes-test.c
b/symm/modes-test.c
index
bbda53b
..
b06d230
100644
(file)
--- a/
symm/modes-test.c
+++ b/
symm/modes-test.c
@@
-303,7
+303,8
@@
static int step(size_t *sz_inout, size_t max)
*
* * @enc@ is called to encrypt a source buffer @s@ and write
* the ciphertext to a destination @d@; @sz@ is the common
*
* * @enc@ is called to encrypt a source buffer @s@ and write
* the ciphertext to a destination @d@; @sz@ is the common
- * size of these buffers.
+ * size of these buffers. @d@ might be null, to discard
+ * output; @s@ might be null, to process all-zero input.
*
* * @dec@ is called to decrypt a source buffer @s@ and write
* the recovered plaintext to a destination @d@; @sz@ is the
*
* * @dec@ is called to decrypt a source buffer @s@ and write
* the recovered plaintext to a destination @d@; @sz@ is the
@@
-451,15
+452,21
@@
int test_encmode(const char *name,
sz2 = TEXTSZ - sz1 - sz0;
ok = 1;
sz2 = TEXTSZ - sz1 - sz0;
ok = 1;
- /* Encrypt the three fragments. */
+ /* Encrypt the last fragment first, to check discarding behaviour. */
+ if (sz2) {
+ reset(iv);
+ enc(text, 0, sz0);
+ enc(text + sz0, 0, sz1);
+ enc(text + sz0 + sz1, ct + sz0 + sz1, sz2);
+ }
+
+ /* Encrypt the first two fragments. */
reset(iv);
enc(text, ct, sz0);
if (sz1) {
memcpy(ct + sz0, text + sz0, sz1);
enc(ct + sz0, ct + sz0, sz1);
}
reset(iv);
enc(text, ct, sz0);
if (sz1) {
memcpy(ct + sz0, text + sz0, sz1);
enc(ct + sz0, ct + sz0, sz1);
}
- if (sz2)
- enc(text + sz0 + sz1, ct + sz0 + sz1, sz2);
/* Try to check consistency. We can't do this if (a) the mode is
* non-resumable and the fragments sizes are misaligned, or (b) this is
/* Try to check consistency. We can't do this if (a) the mode is
* non-resumable and the fragments sizes are misaligned, or (b) this is