Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F111897483
D33757.id101064.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D33757.id101064.diff
View Options
Index: sys/opencrypto/cryptosoft.c
===================================================================
--- sys/opencrypto/cryptosoft.c
+++ sys/opencrypto/cryptosoft.c
@@ -499,7 +499,7 @@
todo = rounddown2(MIN(resid, MIN(inlen, outlen)),
blksz);
-
+
exf->encrypt_multi(ctx, inblk, outblk, todo);
exf->update(ctx, outblk, todo);
@@ -748,6 +748,7 @@
struct crypto_buffer_cursor cc_in, cc_out;
const u_char *inblk;
u_char *outblk;
+ size_t inlen, outlen, todo;
const struct swcr_auth *swa;
const struct swcr_encdec *swe;
const struct enc_xform *exf;
@@ -808,28 +809,44 @@
/* Do encryption/decryption with MAC */
crypto_cursor_init(&cc_in, &crp->crp_buf);
crypto_cursor_advance(&cc_in, crp->crp_payload_start);
+ inblk = crypto_cursor_segment(&cc_in, &inlen);
if (CRYPTO_HAS_OUTPUT_BUFFER(crp)) {
crypto_cursor_init(&cc_out, &crp->crp_obuf);
crypto_cursor_advance(&cc_out, crp->crp_payload_output_start);
} else
cc_out = cc_in;
- for (resid = crp->crp_payload_length; resid >= blksz; resid -= blksz) {
- inblk = crypto_cursor_segment(&cc_in, &len);
- if (len < blksz) {
+ outblk = crypto_cursor_segment(&cc_out, &outlen);
+
+ for (resid = crp->crp_payload_length; resid >= blksz; resid -= todo) {
+ if (inlen < blksz) {
crypto_cursor_copydata(&cc_in, blksz, blk);
inblk = blk;
- } else
- crypto_cursor_advance(&cc_in, blksz);
+ inlen = blksz;
+ }
+
if (CRYPTO_OP_IS_ENCRYPT(crp->crp_op)) {
- outblk = crypto_cursor_segment(&cc_out, &len);
- if (len < blksz)
+ if (outlen < blksz) {
outblk = blk;
- exf->update(ctx, inblk, blksz);
- exf->encrypt(ctx, inblk, outblk);
- if (outblk == blk)
+ outlen = blksz;
+ }
+
+ todo = rounddown2(MIN(resid, MIN(inlen, outlen)),
+ blksz);
+
+ exf->update(ctx, inblk, todo);
+ exf->encrypt_multi(ctx, inblk, outblk, todo);
+
+ if (outblk == blk) {
crypto_cursor_copyback(&cc_out, blksz, blk);
- else
- crypto_cursor_advance(&cc_out, blksz);
+ outblk = crypto_cursor_segment(&cc_out, &outlen);
+ } else {
+ crypto_cursor_advance(&cc_out, todo);
+ outlen -= todo;
+ outblk += todo;
+ if (outlen == 0)
+ outblk = crypto_cursor_segment(&cc_out,
+ &outlen);
+ }
} else {
/*
* One of the problems with CCM+CBC is that
@@ -839,8 +856,19 @@
* the tag and a second time after the tag is
* verified.
*/
+ todo = blksz;
exf->decrypt(ctx, inblk, blk);
- exf->update(ctx, blk, blksz);
+ exf->update(ctx, blk, todo);
+ }
+
+ if (inblk == blk) {
+ inblk = crypto_cursor_segment(&cc_in, &inlen);
+ } else {
+ crypto_cursor_advance(&cc_in, todo);
+ inlen -= todo;
+ inblk += todo;
+ if (inlen == 0)
+ inblk = crypto_cursor_segment(&cc_in, &inlen);
}
}
if (resid > 0) {
@@ -873,22 +901,48 @@
exf->reinit(ctx, crp->crp_iv, ivlen);
crypto_cursor_init(&cc_in, &crp->crp_buf);
crypto_cursor_advance(&cc_in, crp->crp_payload_start);
- for (resid = crp->crp_payload_length; resid > blksz;
- resid -= blksz) {
- inblk = crypto_cursor_segment(&cc_in, &len);
- if (len < blksz) {
+ inblk = crypto_cursor_segment(&cc_in, &inlen);
+
+ for (resid = crp->crp_payload_length; resid >= blksz;
+ resid -= todo) {
+ if (inlen < blksz) {
crypto_cursor_copydata(&cc_in, blksz, blk);
inblk = blk;
- } else
- crypto_cursor_advance(&cc_in, blksz);
- outblk = crypto_cursor_segment(&cc_out, &len);
- if (len < blksz)
+ inlen = blksz;
+ }
+ if (outlen < blksz) {
outblk = blk;
- exf->decrypt(ctx, inblk, outblk);
- if (outblk == blk)
+ outlen = blksz;
+ }
+
+ todo = rounddown2(MIN(resid, MIN(inlen, outlen)),
+ blksz);
+
+ exf->decrypt_multi(ctx, inblk, outblk, todo);
+
+ if (inblk == blk) {
+ inblk = crypto_cursor_segment(&cc_in, &inlen);
+ } else {
+ crypto_cursor_advance(&cc_in, todo);
+ inlen -= todo;
+ inblk += todo;
+ if (inlen == 0)
+ inblk = crypto_cursor_segment(&cc_in,
+ &inlen);
+ }
+
+ if (outblk == blk) {
crypto_cursor_copyback(&cc_out, blksz, blk);
- else
- crypto_cursor_advance(&cc_out, blksz);
+ outblk = crypto_cursor_segment(&cc_out,
+ &outlen);
+ } else {
+ crypto_cursor_advance(&cc_out, todo);
+ outlen -= todo;
+ outblk += todo;
+ if (outlen == 0)
+ outblk = crypto_cursor_segment(&cc_out,
+ &outlen);
+ }
}
if (resid > 0) {
crypto_cursor_copydata(&cc_in, resid, blk);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Mar 10, 11:30 PM (17 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
17091070
Default Alt Text
D33757.id101064.diff (4 KB)
Attached To
Mode
D33757: cryptosoft: Use multi-block encrypt/decrypt for AES-CCM.
Attached
Detach File
Event Timeline
Log In to Comment