WIP Batch encrypted records to reduce EncryptInit/EncryptFinal costs
This commit is contained in:
+72
-17
@@ -287,14 +287,6 @@ public:
|
||||
void reset()
|
||||
{
|
||||
from = cl->read_op_pos;
|
||||
uint8_t iv[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
|
||||
int r = EVP_DecryptInit_ex(cl->dec_ctx, NULL, NULL, (uint8_t*)msgr->test_osd_aes_key.data(), iv);
|
||||
if (r != 1)
|
||||
{
|
||||
fprintf(stderr, "DecryptInit error: ");
|
||||
ERR_print_errors_fp(stderr);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
bool read(uint8_t *dst, size_t dst_len, int flags) override
|
||||
@@ -340,6 +332,31 @@ public:
|
||||
{
|
||||
// Here, dst == NULL is not allowed
|
||||
assert(dst != NULL);
|
||||
if (cl->dec_batch_size_size < 4)
|
||||
{
|
||||
size_t n = 4-cl->dec_batch_size_size;
|
||||
if (n > bufsize-done)
|
||||
n = bufsize-done;
|
||||
memcpy(&cl->dec_batch_size, curbuf+done, n);
|
||||
cl->dec_batch_size_size += n;
|
||||
done += n;
|
||||
if (cl->dec_batch_size_size < 4)
|
||||
return false;
|
||||
if (!cl->dec_batch_size)
|
||||
{
|
||||
fprintf(stderr, "Client %ju - empty batch received, disconnecting\n", cl->client_id);
|
||||
cl->io_error = true;
|
||||
return false;
|
||||
}
|
||||
uint8_t iv[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
|
||||
int r = EVP_DecryptInit_ex(cl->dec_ctx, NULL, NULL, (uint8_t*)msgr->test_osd_aes_key.data(), iv);
|
||||
if (r != 1)
|
||||
{
|
||||
fprintf(stderr, "DecryptInit error: ");
|
||||
ERR_print_errors_fp(stderr);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
size_t n = dst_len-from;
|
||||
if (n > bufsize-done)
|
||||
n = bufsize-done;
|
||||
@@ -369,6 +386,12 @@ public:
|
||||
|
||||
bool finish() override
|
||||
{
|
||||
if (cl->dec_batch_size > 1)
|
||||
{
|
||||
// No tag yet
|
||||
cl->dec_batch_size--;
|
||||
return true;
|
||||
}
|
||||
if (cl->dec_tag_size+bufsize-done < 16)
|
||||
{
|
||||
// Buffer part of the tag
|
||||
@@ -402,6 +425,8 @@ public:
|
||||
}
|
||||
cl->dec_tag_size = 0;
|
||||
assert(len == 0);
|
||||
cl->dec_batch_size = 0;
|
||||
cl->dec_batch_size_size = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -651,6 +676,8 @@ out_wakeup:
|
||||
{
|
||||
goto out_wakeup;
|
||||
}
|
||||
execute_verified_op(cl, cl->read_op);
|
||||
cl->read_op = NULL;
|
||||
}
|
||||
}
|
||||
cl->read_msg.msg_iovlen = 0;
|
||||
@@ -734,6 +761,28 @@ bool osd_messenger_t::handle_buffer_with(osd_client_t *cl, uint8_t *curbuf, size
|
||||
}
|
||||
break;
|
||||
}
|
||||
if constexpr (std::is_same_v<T, gcm_op_reader_t>)
|
||||
{
|
||||
if (cl->dec_batch_size_size)
|
||||
{
|
||||
// Operation is not verified yet
|
||||
cl->unverified_ops.push_back(cl->read_op);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto & op: cl->unverified_ops)
|
||||
{
|
||||
execute_verified_op(cl, op);
|
||||
}
|
||||
cl->unverified_ops.clear();
|
||||
execute_verified_op(cl, cl->read_op);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
execute_verified_op(cl, cl->read_op);
|
||||
}
|
||||
cl->read_op = NULL;
|
||||
}
|
||||
assert(rdr.get_done() == bufsize);
|
||||
return true;
|
||||
@@ -1039,12 +1088,7 @@ bool osd_messenger_t::handle_finished_op(osd_client_t *cl)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (op->op_type == OSD_OP_IN)
|
||||
{
|
||||
// Operation is ready
|
||||
cl->received_ops.push_back(op);
|
||||
}
|
||||
else
|
||||
if (op->op_type == OSD_OP_OUT)
|
||||
{
|
||||
// Inline decryption
|
||||
if (cl->read_op_inline_decrypt_pos != (size_t)-1)
|
||||
@@ -1052,6 +1096,20 @@ bool osd_messenger_t::handle_finished_op(osd_client_t *cl)
|
||||
op_decrypt_inline(cl);
|
||||
cl->read_op_inline_decrypt_pos = (size_t)-1;
|
||||
}
|
||||
}
|
||||
op_decrypt_free(cl);
|
||||
return true;
|
||||
}
|
||||
|
||||
void osd_messenger_t::execute_verified_op(osd_client_t *cl, osd_op_t *op)
|
||||
{
|
||||
if (op->op_type == OSD_OP_IN)
|
||||
{
|
||||
// Operation is ready
|
||||
cl->received_ops.push_back(op);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Measure subop (outbound op) latency
|
||||
timespec tv_end;
|
||||
clock_gettime(CLOCK_REALTIME, &tv_end);
|
||||
@@ -1066,8 +1124,5 @@ bool osd_messenger_t::handle_finished_op(osd_client_t *cl)
|
||||
(tv_end.tv_nsec - op->tv_begin.tv_nsec)/1000
|
||||
);
|
||||
}
|
||||
op_decrypt_free(cl);
|
||||
set_immediate_ops.push_back(op);
|
||||
cl->read_op = NULL;
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user