Skip to content

Commit

Permalink
crypto: testmgr - fix sglen in test_aead for case 'dst != src'
Browse files Browse the repository at this point in the history
Commit d8a32ac (crypto: testmgr - make
test_aead also test 'dst != src' code paths) added support for different
source and destination buffers in test_aead.

This patch modifies the source and destination buffer lengths accordingly:
the lengths are not equal since encryption / decryption adds / removes
the ICV.

Cc: Jussi Kivilinna <[email protected]>
Signed-off-by: Horia Geanta <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
horiag authored and herbertx committed Nov 28, 2013
1 parent 62293a3 commit 8ec25c5
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions crypto/testmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,16 +503,16 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
goto out;
}

sg_init_one(&sg[0], input,
template[i].ilen + (enc ? authsize : 0));

if (diff_dst) {
output = xoutbuf[0];
output += align_offset;
sg_init_one(&sg[0], input, template[i].ilen);
sg_init_one(&sgout[0], output,
template[i].rlen);
} else {
sg_init_one(&sg[0], input,
template[i].ilen +
(enc ? authsize : 0));
} else {
output = input;
}

Expand Down Expand Up @@ -612,26 +612,24 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
memcpy(q, template[i].input + temp,
template[i].tap[k]);

n = template[i].tap[k];
if (k == template[i].np - 1 && enc)
n += authsize;
if (offset_in_page(q) + n < PAGE_SIZE)
q[n] = 0;

sg_set_buf(&sg[k], q, template[i].tap[k]);

if (diff_dst) {
q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
offset_in_page(IDX[k]);

memset(q, 0, template[i].tap[k]);
if (offset_in_page(q) + n < PAGE_SIZE)
q[n] = 0;

sg_set_buf(&sgout[k], q,
template[i].tap[k]);
}

n = template[i].tap[k];
if (k == template[i].np - 1 && enc)
n += authsize;
if (offset_in_page(q) + n < PAGE_SIZE)
q[n] = 0;

temp += template[i].tap[k];
}

Expand All @@ -650,10 +648,10 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
goto out;
}

sg[k - 1].length += authsize;

if (diff_dst)
sgout[k - 1].length += authsize;
else
sg[k - 1].length += authsize;
}

sg_init_table(asg, template[i].anp);
Expand Down

0 comments on commit 8ec25c5

Please sign in to comment.