Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 75948
b: refs/heads/master
c: eb6f13e
h: refs/heads/master
v: v3
  • Loading branch information
Tan Swee Heng authored and Herbert Xu committed Jan 10, 2008
1 parent 96c2205 commit b20521b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 7f6813786a6521380e1756ca5b4336bc63c5bf7d
refs/heads/master: eb6f13eb9f812f5812ed5d14f241309da369dee6
34 changes: 23 additions & 11 deletions trunk/crypto/salsa20_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ static void salsa20_encrypt_bytes(struct salsa20_ctx *ctx, u8 *dst,
const u8 *src, unsigned int bytes)
{
u8 buf[64];
int i;

if (dst != src)
memcpy(dst, src, bytes);
Expand All @@ -156,15 +155,11 @@ static void salsa20_encrypt_bytes(struct salsa20_ctx *ctx, u8 *dst,
ctx->input[9] = PLUSONE(ctx->input[9]);

if (bytes <= 64) {
for (i = 0; i < bytes/4; ++i)
((u32*)dst)[i] ^= ((u32*)buf)[i];
for (i = bytes - bytes % 4; i < bytes; ++i)
dst[i] ^= buf[i];
crypto_xor(dst, buf, bytes);
return;
}

for (i = 0; i < 64/4; ++i)
((u32*)dst)[i] ^= ((u32*)buf)[i];
crypto_xor(dst, buf, 64);
bytes -= 64;
dst += 64;
}
Expand Down Expand Up @@ -192,13 +187,30 @@ static int encrypt(struct blkcipher_desc *desc,
int err;

blkcipher_walk_init(&walk, dst, src, nbytes);
err = blkcipher_walk_virt(desc, &walk);
err = blkcipher_walk_virt_block(desc, &walk, 64);

salsa20_ivsetup(ctx, walk.iv);
salsa20_encrypt_bytes(ctx, walk.dst.virt.addr,
walk.src.virt.addr, nbytes);

err = blkcipher_walk_done(desc, &walk, 0);
if (likely(walk.nbytes == nbytes))
{
salsa20_encrypt_bytes(ctx, walk.dst.virt.addr,
walk.src.virt.addr, nbytes);
return blkcipher_walk_done(desc, &walk, 0);
}

while (walk.nbytes >= 64) {
salsa20_encrypt_bytes(ctx, walk.dst.virt.addr,
walk.src.virt.addr,
walk.nbytes - (walk.nbytes % 64));
err = blkcipher_walk_done(desc, &walk, walk.nbytes % 64);
}

if (walk.nbytes) {
salsa20_encrypt_bytes(ctx, walk.dst.virt.addr,
walk.src.virt.addr, walk.nbytes);
err = blkcipher_walk_done(desc, &walk, 0);
}

return err;
}

Expand Down

0 comments on commit b20521b

Please sign in to comment.