| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- //
- // Created by miti on 27/07/19.
- //
- #include "UntrustedInclude/PostLAProtobufNativeTransforms.h"
- #include <string.h>
- void PostLAProtobufNativeTransforms::get_lengths_for_protobuf_serialized_array(extension_to_decryptor_enclosed_msg &protobuf_ext_to_decryptor,
- uint32_t *op_ciphertext_length, uint32_t *op_number_of_ciphertext_fields)
- {
- uint32_t number_of_ciphertext_fields, counter, total_length;
- // Didn't use bytesize() or bytesizelong() for getting the lengths of the public key or the ciphertext string
- // as that gives the *serialized* length of the message which should be an upper-bound.
- // Can switch to that if necessary for time performance reasons.
- total_length=protobuf_ext_to_decryptor.ciphertext_client_public_key().length();
- number_of_ciphertext_fields=protobuf_ext_to_decryptor.ciphertext_fields_size();
- for(counter=0; counter<number_of_ciphertext_fields; counter++)
- total_length+=protobuf_ext_to_decryptor.ciphertext_fields(counter).field().length();
- *op_ciphertext_length=total_length;
- *op_number_of_ciphertext_fields=number_of_ciphertext_fields;
- }
- void PostLAProtobufNativeTransforms::create_array_from_protobuf(extension_to_decryptor_enclosed_msg &protobuf_ext_to_decryptor,
- unsigned char* double_ciphertext_client_data, uint32_t* sizes_array,
- uint32_t* sizes_array_length)
- {
- uint32_t counter, size_of_field, number_of_fields;
- unsigned char* ptr;
- // Set the size of the first element - the public key - and copy it to the output array.
- sizes_array[0] = protobuf_ext_to_decryptor.ciphertext_client_public_key().length();
- memcpy(double_ciphertext_client_data, protobuf_ext_to_decryptor.ciphertext_client_public_key().c_str(),
- sizes_array[0]);
- ptr=double_ciphertext_client_data + sizes_array[0];
- // Start copying past the length copied above, copy all ciphertext fields to the output string array
- // and set their lengths in the output integers array
- number_of_fields=protobuf_ext_to_decryptor.ciphertext_fields_size();
- for(counter=0;counter<number_of_fields;counter++)
- {
- // First element of the LHS array is the length of the client's public key.
- size_of_field = protobuf_ext_to_decryptor.ciphertext_fields(counter).field().length();
- memcpy(ptr, protobuf_ext_to_decryptor.ciphertext_fields(counter).field().c_str(), size_of_field);
- sizes_array[counter + 1] = size_of_field;
- ptr += sizes_array[counter + 1];
- }
- *sizes_array_length=number_of_fields+1;
- }
- void PostLAProtobufNativeTransforms::create_protobuf_from_array( unsigned char* ciphertext_client_data, uint32_t* sizes_array, uint32_t sizes_array_length,
- extension_to_decryptor_enclosed_msg protobuf_extension_decryptor_msg)
- {
- uint32_t counter;
- unsigned char* ptr;
- // Note that we don't care about setting the client public key as we don't include that in the outgoing message
- // to the extension.
- ptr=ciphertext_client_data;
- for(counter=0; counter<sizes_array_length; counter++)
- {
- protobuf_extension_decryptor_msg.mutable_ciphertext_fields(counter)->set_field(ptr, sizes_array[counter]);
- ptr+=sizes_array[counter];
- }
- }
|