// // Created by miti on 2019-12-24. // #include "PostLAMessaging.h" // The verifier doesn't receive any messages (in the deployment stage or at all) uint32_t send_secure_msg(uint8_t* input, uint32_t input_size) { uint8_t* output; uint32_t output_size, ret; google::protobuf::MessageLite protobuf_msg; output = (unsigned char*) malloc(output, input_size + 28); // 16 for tag, 12 for IV // TODO: Make sure this is the same as in the PHP extension code. ret = aes_gcm_wrapper(1, input, input_size, output, output_size ); if(ret != 0) return ret; // TODO: Conversion logic to protobuf. Set msg or whatever. if(!protobufReaderWriter.write_msg(protobuf_msg)) return 0x3; return 0; } void set_la_symmetric_key(uint8_t* given_key) { uint32_t counter; for(counter=0; counter<32; counter++) { key[counter] = given_key[counter]; } } void set_fd(int given_fd) { protobufReaderWriter.set_fd(given_fd); } /* int encrypt_decrypt_msgs(int encrypt_decrypt, std::vector &input_msgs, std::vector &output_msgs) { unsigned char *input; unsigned char *output; uint32_t input_size, output_size, ret; output=NULL; for (std::string msg:input_msgs) { input_size = msg.length(); input = (unsigned char*) msg.c_str(); output = (unsigned char*) realloc(output, input_size + 28); // 16 for tag, 12 for IV ret = aes_gcm_wrapper(encrypt_decrypt, input, input_size, output, &output_size ); if(ret!=0) { free(output); printf("Failed to encrypt an input field.\n"); fflush(stdout); return 0x2; } output_msgs.push_back(std::string(reinterpret_cast (output), output_size)); } free(output); return 0; } */ /* * virtual void create_vector_from_protobuf(google::protobuf::MessageLite& protobuf_msg, std::vector &native_msg_list) {} uint32_t receive_secure_msgs(std::vector &plaintext_msg_list) { std::vector ciphertext_msg_list; google::protobuf::MessageLite protobuf_msg; // read encrypted data if(!protobufReaderWriter.read_msg(protobuf_msg)) { printf("Not all of the decryptor's message was read\n"); fflush(stdout); return 0xf3; } create_vector_from_protobuf(protobuf_msg, ciphertext_msg_list); return encrypt_decrypt_ciphertexts(0, &ciphertext_msg_list, plaintext_msg_list); } */ /* uint32_t send_secure_msgs(std::vector &plaintext_msg_list) { uint32_t ret; std::vector ciphertext_msg_list; google::protobuf::MessageLite protobuf_msg; ret=encrypt_decrypt_msgs(1, plaintext_msg_list, &ciphertext_msg_list); if(ret!=0) return ret; create_protobuf_from_vector(ciphertext_msg_list, protobuf_msg); // write message to decryptor if(!protobufReaderWriter.write_msg(protobuf_msg)) { printf("Not all of the client's pub key and ciphertext data was written\n"); fflush(stdout); return 0xfe; } return 0; } */