static void schedule(void) { int (*peer_run)(void) = bob_function; int res = TEST_CONTINUE; themis_status_t themis_status; /* alice starts */ testsuite_fail_unless(THEMIS_INVALID_PARAMETER == secure_comparator_begin_compare(NULL, shared_mem, ¤t_length), "secure_comparator_begin_compare: invalid context"); testsuite_fail_unless(THEMIS_BUFFER_TOO_SMALL == secure_comparator_begin_compare(alice, NULL, ¤t_length), "secure_comparator_begin_compare: get output size (NULL out buffer)"); current_length--; testsuite_fail_unless(THEMIS_BUFFER_TOO_SMALL == secure_comparator_begin_compare(alice, shared_mem, ¤t_length), "secure_comparator_begin_compare: get output size (small out buffer)"); themis_status = secure_comparator_begin_compare(alice, shared_mem, ¤t_length); if (THEMIS_SCOMPARE_SEND_OUTPUT_TO_PEER != themis_status) { testsuite_fail_if(true, "secure_comparator_begin_compare: failed"); return; } while (TEST_CONTINUE == res) { res = peer_run(); peer_run = (peer_run == alice_function) ? bob_function : alice_function; } testsuite_fail_if(res, "secure comparator: protocol exchange"); }
const data_t& init() { themis_status_t status = THEMIS_FAIL; size_t data_length = 0; status = secure_comparator_begin_compare(comparator_, NULL, &data_length); if (THEMIS_BUFFER_TOO_SMALL != status) { throw themispp::exception_t("Secure Comparator failed to initialize comparison", status); } res_.resize(data_length); status = secure_comparator_begin_compare(comparator_, &res_[0], &data_length); if (THEMIS_SCOMPARE_SEND_OUTPUT_TO_PEER != status) { throw themispp::exception_t("Secure Comparator failed to initialize comparison", status); } return res_; }
void secure_comparator_security_test(void) { const char alice_secret[] = "alice secret"; const char bob_secret[] = "bob secret"; size_t output_length = sizeof(shared_mem); secure_comparator_t alice, bob; if (THEMIS_SUCCESS != secure_comparator_init(&alice)) { testsuite_fail_if(true, "secure_comparator_init failed"); return; } if (THEMIS_SUCCESS != secure_comparator_init(&bob)) { testsuite_fail_if(true, "secure_comparator_init failed"); return; } if (THEMIS_SUCCESS != secure_comparator_append_secret(&alice, alice_secret, sizeof(alice_secret))) { testsuite_fail_if(true, "secure_comparator_append_secret failed"); return; } if (THEMIS_SUCCESS != secure_comparator_append_secret(&bob, bob_secret, sizeof(bob_secret))) { testsuite_fail_if(true, "secure_comparator_append_secret failed"); return; } current_length = sizeof(shared_mem); if (THEMIS_SCOMPARE_SEND_OUTPUT_TO_PEER != secure_comparator_begin_compare(&alice, shared_mem, ¤t_length)) { testsuite_fail_if(true, "secure_comparator_begin_compare failed"); return; } corrupt_alice_step1(&alice, shared_mem); corrupt_bob_step2(&bob, shared_mem, current_length, shared_mem, &output_length); current_length = output_length; output_length = sizeof(shared_mem); if (THEMIS_SCOMPARE_SEND_OUTPUT_TO_PEER != secure_comparator_proceed_compare(&alice, shared_mem, current_length, shared_mem, &output_length)) { testsuite_fail_if(true, "secure_comparator_proceed_compare failed"); return; } current_length = output_length; output_length = sizeof(shared_mem); if (THEMIS_SCOMPARE_SEND_OUTPUT_TO_PEER != secure_comparator_proceed_compare(&bob, shared_mem, current_length, shared_mem, &output_length)) { testsuite_fail_if(true, "secure_comparator_proceed_compare failed"); return; } current_length = output_length; output_length = sizeof(shared_mem); if (THEMIS_SUCCESS != secure_comparator_proceed_compare(&alice, shared_mem, current_length, shared_mem, &output_length)) { testsuite_fail_if(true, "secure_comparator_proceed_compare failed"); return; } testsuite_fail_unless((THEMIS_SCOMPARE_NO_MATCH == secure_comparator_get_result(&alice)) && (THEMIS_SCOMPARE_NO_MATCH == secure_comparator_get_result(&bob)), "compare result no match"); }