size_t block_len;
size_t output_len;
size_t written_len;
- size_t rem;
printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096);
if (yaca_malloc(enc_len, (void**)&enc) != YACA_ERROR_NONE)
goto exit;
- written_len = enc_len;
if (yaca_encrypt_update(ctx, lorem4096, LOREM4096_SIZE, enc, &written_len) != YACA_ERROR_NONE)
goto exit;
- rem = enc_len - written_len;
- if (yaca_encrypt_finalize(ctx, enc + written_len, &rem) != YACA_ERROR_NONE)
+ enc_len = written_len;
+
+ if (yaca_encrypt_finalize(ctx, enc + written_len, &written_len) != YACA_ERROR_NONE)
goto exit;
- enc_len = rem + written_len;
+ enc_len += written_len;
dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_len);
if (yaca_malloc(dec_len, (void**)&dec) != YACA_ERROR_NONE)
goto exit;
- written_len = dec_len;
if (yaca_decrypt_update(ctx, enc, enc_len, dec, &written_len) != YACA_ERROR_NONE)
goto exit;
- rem = dec_len - written_len;
- if (yaca_decrypt_finalize(ctx, dec + written_len, &rem) != YACA_ERROR_NONE)
+ dec_len = written_len;
+
+ if (yaca_decrypt_finalize(ctx, dec + written_len, &written_len) != YACA_ERROR_NONE)
goto exit;
- dec_len = rem + written_len;
+ dec_len += written_len;
printf("Decrypted data (16 of %zu bytes): %.16s\n\n", dec_len, dec);
}
size_t block_len;
size_t output_len;
size_t written_len;
- size_t rem;
printf("AES GCM 256bit key encryption/decryption\n");
printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096);
if (yaca_malloc(enc_len, (void**)&enc) != YACA_ERROR_NONE)
goto exit;
- written_len = enc_len;
if (yaca_encrypt_update(ctx, lorem4096, LOREM4096_SIZE, enc, &written_len) != YACA_ERROR_NONE)
goto exit;
- rem = enc_len - written_len;
- if (yaca_encrypt_finalize(ctx, enc + written_len, &rem) != YACA_ERROR_NONE)
+ enc_len = written_len;
+
+ if (yaca_encrypt_finalize(ctx, enc + written_len, &written_len) != YACA_ERROR_NONE)
goto exit;
- enc_len = rem + written_len;
+ enc_len += written_len;
/* Set the tag length and get the tag after final encryption */
if (yaca_context_set_property(ctx, YACA_PROPERTY_GCM_TAG_LEN,
if (yaca_malloc(dec_len, (void**)&dec) != YACA_ERROR_NONE)
goto exit;
- written_len = dec_len;
if (yaca_decrypt_update(ctx, enc, enc_len, dec, &written_len) != YACA_ERROR_NONE)
goto exit;
- rem = dec_len - written_len;
+ dec_len = written_len;
/* Set expected tag value before final decryption */
if (yaca_context_set_property(ctx, YACA_PROPERTY_GCM_TAG, tag, tag_len) != YACA_ERROR_NONE)
goto exit;
- if (yaca_decrypt_finalize(ctx, dec + written_len, &rem) != YACA_ERROR_NONE)
+ if (yaca_decrypt_finalize(ctx, dec + written_len, &written_len) != YACA_ERROR_NONE)
goto exit;
- dec_len = rem + written_len;
+ dec_len += written_len;
printf("Decrypted data (16 of %zu bytes): %.16s\n\n", dec_len, dec);
}
size_t block_len;
size_t output_len;
size_t written_len;
- size_t rem;
size_t len;
printf("AES CCM 256bit key encryption/decryption\n");
if (yaca_malloc(enc_len, (void**)&enc) != YACA_ERROR_NONE)
goto exit;
- written_len = enc_len;
if (yaca_encrypt_update(ctx, lorem4096, LOREM4096_SIZE, enc, &written_len) != YACA_ERROR_NONE)
goto exit;
- rem = enc_len - written_len;
- if (yaca_encrypt_finalize(ctx, enc + written_len, &rem) != YACA_ERROR_NONE)
+ enc_len = written_len;
+
+ if (yaca_encrypt_finalize(ctx, enc + written_len, &written_len) != YACA_ERROR_NONE)
goto exit;
- enc_len = rem + written_len;
+ enc_len += written_len;
/* Get the tag after final encryption */
if (yaca_context_get_property(ctx, YACA_PROPERTY_CCM_TAG, (void**)tag, &tag_len) != YACA_ERROR_NONE)
if (yaca_malloc(dec_len, (void**)&dec) != YACA_ERROR_NONE)
goto exit;
- written_len = dec_len;
/* The tag verify is performed when you call the final yaca_decrypt_update(),
* there is no call to yaca_decrypt_finalize() */
if (yaca_decrypt_update(ctx, enc, enc_len, dec, &written_len) != YACA_ERROR_NONE)
size_t block_len;
size_t output_len;
size_t written_len;
- size_t rem;
printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096);
goto exit;
/* Seal and finalize */
- written_len = enc_len;
if (yaca_seal_update(ctx, lorem4096, LOREM4096_SIZE, enc, &written_len) != YACA_ERROR_NONE)
goto exit;
- rem = enc_len - written_len;
- if (yaca_seal_finalize(ctx, enc + written_len, &rem) != YACA_ERROR_NONE)
+ enc_len = written_len;
+
+ if (yaca_seal_finalize(ctx, enc + written_len, &written_len) != YACA_ERROR_NONE)
goto exit;
- enc_len = rem + written_len;
+ enc_len += written_len;
dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_len);
goto exit;
/* Open and finalize */
- written_len = dec_len;
if (yaca_open_update(ctx, enc, enc_len, dec, &written_len) != YACA_ERROR_NONE)
goto exit;
- rem = dec_len - written_len;
- if (yaca_open_finalize(ctx, dec + written_len, &rem) != YACA_ERROR_NONE)
+ dec_len = written_len;
+
+ if (yaca_open_finalize(ctx, dec + written_len, &written_len) != YACA_ERROR_NONE)
goto exit;
- dec_len = rem + written_len;
+ dec_len += written_len;
printf("Decrypted data (16 of %zu bytes): %.16s\n\n", dec_len, dec);
}
size_t block_len;
size_t output_len;
size_t written_len;
- size_t rem;
printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096);
if (yaca_malloc(enc_len, (void**)&enc) != YACA_ERROR_NONE)
goto exit;
- written_len = enc_len;
if (yaca_seal_update(ctx, lorem4096, LOREM4096_SIZE, enc, &written_len) != YACA_ERROR_NONE)
goto exit;
- rem = enc_len - written_len;
- if (yaca_seal_finalize(ctx, enc + written_len, &rem) != YACA_ERROR_NONE)
+ enc_len = written_len;
+
+ if (yaca_seal_finalize(ctx, enc + written_len, &written_len) != YACA_ERROR_NONE)
goto exit;
- enc_len = rem + written_len;
+ enc_len += written_len;
/* Set the tag length and get the tag after final encryption */
if (yaca_context_set_property(ctx, YACA_PROPERTY_GCM_TAG_LEN,
if (yaca_malloc(dec_len, (void**)&dec) != YACA_ERROR_NONE)
goto exit;
- written_len = dec_len;
if (yaca_open_update(ctx, enc, enc_len, dec, &written_len) != YACA_ERROR_NONE)
goto exit;
- rem = dec_len - written_len;
-
/* Set expected tag value before final decryption */
if (yaca_context_set_property(ctx, YACA_PROPERTY_GCM_TAG, tag, tag_len) != YACA_ERROR_NONE)
goto exit;
- if (yaca_open_finalize(ctx, dec + written_len, &rem) != YACA_ERROR_NONE)
+ dec_len = written_len;
+
+ if (yaca_open_finalize(ctx, dec + written_len, &written_len) != YACA_ERROR_NONE)
goto exit;
- dec_len = rem + written_len;
+ dec_len += written_len;
printf("Decrypted data (16 of %zu bytes): %.16s\n\n", dec_len, dec);
}
size_t block_len;
size_t output_len;
size_t written_len;
- size_t rem;
size_t len;
printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096);
if (yaca_malloc(enc_len, (void**)&enc) != YACA_ERROR_NONE)
goto exit;
- written_len = enc_len;
if (yaca_seal_update(ctx, lorem4096, LOREM4096_SIZE, enc, &written_len) != YACA_ERROR_NONE)
goto exit;
- rem = enc_len - written_len;
- if (yaca_seal_finalize(ctx, enc + written_len, &rem) != YACA_ERROR_NONE)
+ enc_len = written_len;
+
+ if (yaca_seal_finalize(ctx, enc + written_len, &written_len) != YACA_ERROR_NONE)
goto exit;
- enc_len = rem + written_len;
+ enc_len += written_len;
/* Get the tag after final encryption */
if (yaca_context_get_property(ctx, YACA_PROPERTY_CCM_TAG, (void**)tag, &tag_len) != YACA_ERROR_NONE)
if (yaca_malloc(dec_len, (void**)&dec) != YACA_ERROR_NONE)
goto exit;
- written_len = dec_len;
/* The tag verify is performed when you call the final yaca_open_update(),
* there is no call to yaca_open_finalize() */
if (yaca_open_update(ctx, enc, enc_len, dec, &written_len) != YACA_ERROR_NONE)
}
lciphertext_len += out_len;
-
assert(lciphertext_len > 0);
ret = yaca_malloc(lciphertext_len, (void**)&lciphertext);
if (ret != YACA_ERROR_NONE)
goto exit;
- out_len = lciphertext_len;
ret = yaca_encrypt_update(ctx, plaintext, plaintext_len, lciphertext, &out_len);
if (ret != YACA_ERROR_NONE)
goto exit;
assert(out_len <= lciphertext_len);
-
written = out_len;
- out_len = lciphertext_len - written;
+
ret = yaca_encrypt_finalize(ctx, lciphertext + written, &out_len);
if (ret != YACA_ERROR_NONE)
goto exit;
if (ret != YACA_ERROR_NONE)
goto exit;
- out_len = lplaintext_len;
ret = yaca_decrypt_update(ctx, ciphertext, ciphertext_len, lplaintext, &out_len);
if (ret != YACA_ERROR_NONE)
goto exit;
assert(out_len <= lplaintext_len);
-
written = out_len;
- out_len = lplaintext_len - written;
+
ret = yaca_decrypt_finalize(ctx, lplaintext + written, &out_len);
if (ret != YACA_ERROR_NONE)
goto exit;