Skip to content
Snippets Groups Projects
Commit 5c7672bd authored by Niels Möller's avatar Niels Möller
Browse files

(process_file): Copy the leftover to the

start of the buffer, when preparing for the final processing.

Rev: src/nettle/examples/rsa-encrypt.c:1.4
parent d661a5a6
No related branches found
No related tags found
No related merge requests found
...@@ -95,8 +95,10 @@ process_file(struct rsa_session *ctx, ...@@ -95,8 +95,10 @@ process_file(struct rsa_session *ctx,
uint8_t buffer[AES_BLOCK_SIZE * 100]; uint8_t buffer[AES_BLOCK_SIZE * 100];
unsigned leftover; unsigned leftover;
unsigned padding; unsigned padding;
for (padding = leftover = 0; padding == 0;) padding = leftover = 0;
for (;;)
{ {
size_t size = fread(buffer, 1, sizeof(buffer), in); size_t size = fread(buffer, 1, sizeof(buffer), in);
if (ferror(in)) if (ferror(in))
...@@ -123,6 +125,14 @@ process_file(struct rsa_session *ctx, ...@@ -123,6 +125,14 @@ process_file(struct rsa_session *ctx,
werror("Writing output failed: %s\n", strerror(errno)); werror("Writing output failed: %s\n", strerror(errno));
return 0; return 0;
} }
if (padding)
{
if (leftover)
memcpy(buffer, buffer + size, leftover);
break;
}
} }
if (padding > 1) if (padding > 1)
yarrow256_random(&ctx->yarrow, padding - 1, buffer + leftover); yarrow256_random(&ctx->yarrow, padding - 1, buffer + leftover);
...@@ -130,6 +140,7 @@ process_file(struct rsa_session *ctx, ...@@ -130,6 +140,7 @@ process_file(struct rsa_session *ctx,
buffer[AES_BLOCK_SIZE - 1] = padding; buffer[AES_BLOCK_SIZE - 1] = padding;
CBC_ENCRYPT(&ctx->aes, aes_encrypt, AES_BLOCK_SIZE, buffer, buffer); CBC_ENCRYPT(&ctx->aes, aes_encrypt, AES_BLOCK_SIZE, buffer, buffer);
hmac_sha1_digest(&ctx->hmac, SHA1_DIGEST_SIZE, buffer + AES_BLOCK_SIZE); hmac_sha1_digest(&ctx->hmac, SHA1_DIGEST_SIZE, buffer + AES_BLOCK_SIZE);
if (!write_string(out, AES_BLOCK_SIZE + SHA1_DIGEST_SIZE, buffer)) if (!write_string(out, AES_BLOCK_SIZE + SHA1_DIGEST_SIZE, buffer))
{ {
werror("Writing output failed: %s\n", strerror(errno)); werror("Writing output failed: %s\n", strerror(errno));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment