Esempio n. 1
0
void sk_init(void)
{

#ifndef NO_OT
    if (ot_init() == noErr)
	stack = &ot;
    else
#endif
#if !TARGET_API_MAC_CARBON
    if (mactcp_init() == noErr)
	stack = &mactcp;
    else
#endif
	stack = NULL;
}
Esempio n. 2
0
/* initialization */
NTSTATUS
DriverEntry(IN PDRIVER_OBJECT theDriverObject,
            IN PUNICODE_STRING theRegistryPath)
{
    NTSTATUS status = STATUS_SUCCESS;
	int i;
	UNICODE_STRING name, linkname;

	memtrack_init();
	KeInitializeSpinLock(&g_traffic_guard);

#ifdef USE_TDI_HOOKING
	KdPrint(("[tdi_fw] WARNING! Using unstable working mode: TDI hooking!\n"));
#endif

	status = ot_init();
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: ot_init: 0x%x\n", status));
		goto done;
	}

	status = filter_init();
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: filter_init: 0x%x\n", status));
		goto done;
	}

	status = conn_state_init();
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: conn_state_init: 0x%x\n", status));
		goto done;
	}
	
	for (i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; i++)
		theDriverObject->MajorFunction[i] = DeviceDispatch;

#if DBG
	// register UnLoad procedure
	theDriverObject->DriverUnload = OnUnload;
#endif

	/* create control device and symbolic link */

	RtlInitUnicodeString(&name, L"\\Device\\tdifw");

	status = IoCreateDevice(theDriverObject,
							0,
							&name,
							0,
							0,
							TRUE,		// exclusive!
							&g_devcontrol);
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: IoCreateDevice(control): 0x%x!\n", status));
		goto done;
	}

	RtlInitUnicodeString(&linkname, L"\\??\\tdifw");

	status = IoCreateSymbolicLink(&linkname, &name);
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: IoCreateSymbolicLink: 0x%x!\n", status));
		goto done;
	}

	RtlInitUnicodeString(&name, L"\\Device\\tdifw_nfo");

	status = IoCreateDevice(theDriverObject,
							0,
							&name,
							0,
							0,
							FALSE,		// not exclusive!
							&g_devnfo);
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: IoCreateDevice(nfo): 0x%x!\n", status));
		goto done;
	}

	RtlInitUnicodeString(&linkname, L"\\??\\tdifw_nfo");

	status = IoCreateSymbolicLink(&linkname, &name);
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: IoCreateSymbolicLink: 0x%x!\n", status));
		goto done;
	}

#ifndef USE_TDI_HOOKING

	status = c_n_a_device(theDriverObject, &g_tcpfltobj, &g_tcpoldobj, L"\\Device\\Tcp");
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: c_n_a_device: 0x%x\n", status));
		goto done;
	}

	status = c_n_a_device(theDriverObject, &g_udpfltobj, &g_udpoldobj, L"\\Device\\Udp");
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: c_n_a_device: 0x%x\n", status));
		goto done;
	}

	status = c_n_a_device(theDriverObject, &g_ipfltobj, &g_ipoldobj, L"\\Device\\RawIp");
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: c_n_a_device: 0x%x\n", status));
		goto done;
	}

#else	/* USE_TDI_HOOKING */

	/* get device objects for tcp/udp/ip */

	status = get_device_object(L"\\Device\\Tcp", &g_tcpfltobj);
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: get_device_object(tcp): 0x%x\n", status));
		goto done;
	}
	
	status = get_device_object(L"\\Device\\Udp", &g_udpfltobj);
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: get_device_object(udp): 0x%x\n", status));
		goto done;
	}
	
	status = get_device_object(L"\\Device\\RawIp", &g_ipfltobj);
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: get_device_object(ip): 0x%x\n", status));
		goto done;
	}

	/* hook tcpip */

	status = hook_tcpip(&g_old_DriverObject, TRUE);
	if (status != STATUS_SUCCESS) {
		KdPrint(("[tdi_fw] DriverEntry: hook_driver: 0x%x\n", status));
		goto done;
	}
	g_hooked = TRUE;

#endif	/* USE_TDI_HOOKING */

	status = STATUS_SUCCESS;

done:
	if (status != STATUS_SUCCESS) {
		// cleanup
		OnUnload(theDriverObject);
	}

    return status;
}
void BetterYao2::cut_and_choose2()
{
	step_init();
	double start;

	Bytes bufr;
	vector<Bytes> bufr_chunks;

	m_ot_bit_cnt = Env::node_load();

	EVL_BEGIN
		start = MPI_Wtime();
			m_ot_recv_bits.resize((m_ot_bit_cnt+7)/8);
			for (size_t ix = 0; ix < m_chks.size(); ix++)
			{
				m_ot_recv_bits.set_ith_bit(ix, m_chks[ix]);
			}
		m_timer_evl += MPI_Wtime() - start;
	EVL_END

	ot_init();
	ot_random();

	GEN_BEGIN
		start = MPI_Wtime();
			for (size_t ix = 0; ix < m_ccts.size(); ix++)
			{
				m_rnds[ix] = m_prng.rand(Env::k());
				m_gen_inp_masks[ix] = m_prng.rand(Env::circuit().gen_inp_cnt());
				m_ccts[ix].gen_init(m_ot_keys[ix], m_gen_inp_masks[ix], m_rnds[ix]);
			}
		m_timer_gen += MPI_Wtime() - start;
	GEN_END

	Prng prng;
	G M;

	for (size_t ix = 0; ix < m_ccts.size(); ix++)
	{
		// evaluation-circuit branch of OT
		GEN_BEGIN
			start = MPI_Wtime(); // send group elements representing m_gen_inp
				bufr.clear();
				prng.srand(m_ot_out[2*ix+0]);
				for (size_t bix = 0; bix < Env::circuit().gen_inp_cnt(); bix++)
				{
					byte bit_value = m_gen_inp.get_ith_bit(bix);
					bufr += m_ccts[ix].m_M[2*bix+bit_value].to_bytes();
				}
				bufr ^= prng.rand(bufr.size()*8);
			m_timer_gen += MPI_Wtime() - start;

			start = MPI_Wtime();
				GEN_SEND(bufr);
			m_timer_com += MPI_Wtime() - start;
		GEN_END

		EVL_BEGIN
			start = MPI_Wtime();
				bufr = EVL_RECV();
			m_timer_com += MPI_Wtime() - start;

			start = MPI_Wtime();
				if (m_chks[ix] == 0)
				{
					prng.srand(m_ot_out[ix]);
					bufr ^= prng.rand(bufr.size()*8);
					bufr_chunks = bufr.split(Env::elm_size_in_bytes());
					for (size_t bix = 0; bix < bufr_chunks.size(); bix++)
					{
						M.from_bytes(bufr_chunks[bix]);
						m_ccts[ix].m_M.push_back(M);
					}
				}
			m_timer_evl += MPI_Wtime() - start;
		EVL_END

		m_comm_sz += bufr.size();

		GEN_BEGIN
			start = MPI_Wtime(); // send the masked m_gen_inp
				bufr = m_gen_inp_masks[ix] ^ m_gen_inp;
				bufr ^= prng.rand(bufr.size()*8);
			m_timer_gen += MPI_Wtime() - start;

			start = MPI_Wtime();
				GEN_SEND(bufr);
			m_timer_com += MPI_Wtime() - start;
		GEN_END

		EVL_BEGIN
			start = MPI_Wtime();
				bufr = EVL_RECV();
			m_timer_com += MPI_Wtime() - start;

			start = MPI_Wtime();
				if (m_chks[ix] == 0)
				{
					bufr ^= prng.rand(bufr.size()*8);
					m_gen_inp_masks[ix] = bufr;
				}
			m_timer_evl += MPI_Wtime() - start;
		EVL_END

		m_comm_sz += bufr.size();

		// check-circuit branch of OT
		GEN_BEGIN
			start = MPI_Wtime(); // send the m_gen_inp_masks[ix]
				prng.srand(m_ot_out[2*ix+1]);
				bufr = m_gen_inp_masks[ix];
				bufr ^= prng.rand(bufr.size()*8);
			m_timer_gen += MPI_Wtime() - start;

			start = MPI_Wtime();
				GEN_SEND(bufr);
			m_timer_com += MPI_Wtime() - start;
		GEN_END

		EVL_BEGIN
			start = MPI_Wtime();
				bufr = EVL_RECV();
			m_timer_com += MPI_Wtime() - start;

			start = MPI_Wtime();
				if (m_chks[ix])
				{
					prng.srand(m_ot_out[ix]);
					bufr ^= prng.rand(bufr.size()*8);
					m_gen_inp_masks[ix] = bufr;
				}
			m_timer_evl += MPI_Wtime() - start;
		EVL_END

		m_comm_sz += bufr.size();

		GEN_BEGIN
			start = MPI_Wtime(); // send the masked m_gen_inp
				bufr = m_rnds[ix];
				bufr ^= prng.rand(bufr.size()*8);
			m_timer_gen += MPI_Wtime() - start;

			start = MPI_Wtime();
				GEN_SEND(bufr);
			m_timer_com += MPI_Wtime() - start;
		GEN_END

		EVL_BEGIN
			start = MPI_Wtime();
				bufr = EVL_RECV();
			m_timer_com += MPI_Wtime() - start;

			start = MPI_Wtime();
				if (m_chks[ix])
				{
					bufr ^= prng.rand(bufr.size()*8);
					m_rnds[ix] = bufr;
				}
			m_timer_evl += MPI_Wtime() - start;
		EVL_END

		m_comm_sz += bufr.size();

		GEN_BEGIN
			start = MPI_Wtime(); // send the m_ot_keys
				bufr = Bytes(m_ot_keys[ix]);
				bufr ^= prng.rand(bufr.size()*8);
			m_timer_gen += MPI_Wtime() - start;

			start = MPI_Wtime();
				GEN_SEND(bufr);
			m_timer_com += MPI_Wtime() - start;
		GEN_END

		EVL_BEGIN
			start = MPI_Wtime();
				bufr = EVL_RECV();
			m_timer_com += MPI_Wtime() - start;

			start = MPI_Wtime();
				if (m_chks[ix])
				{
					bufr ^= prng.rand(bufr.size()*8);
					m_ot_keys[ix] = bufr.split(Env::key_size_in_bytes());
				}
			m_timer_evl += MPI_Wtime() - start;
		EVL_END

		m_comm_sz += bufr.size();
	}

	step_report("cut-'n-chk2");
}
Esempio n. 4
0
void
main(void)
{
        hardware_init();

        uint32_t color_idx;
        for (color_idx = 0; color_idx < TEAPOT_POLYGON_CNT; color_idx++) {
                uint32_t idx;
                idx = color_idx;

                uint32_t polygon_idx;
                fix16_vector4_t *polygon[4];
                for (polygon_idx = 0; polygon_idx < 4; polygon_idx++) {
                        uint32_t vertex_idx;
                        vertex_idx = teapot_indices[(4 * idx) + polygon_idx];
                        fix16_vector4_t *vertex;
                        vertex = &teapot_vertices[vertex_idx];

                        polygon[polygon_idx] = vertex;
                }

                fix16_t avg;
                avg = fix16_add(fix16_mul(fix16_add(
                                fix16_add(polygon[0]->z, polygon[1]->z),
                                fix16_add(polygon[2]->z, polygon[3]->z)),
                        F16(1.0f / 4.0f)), F16(0.1f));

                uint16_t color;
                color = fix16_to_int(fix16_add(
                            fix16_mul(fix16_abs(avg), F16(255.0f)),
                            F16(16.0f)));

                colors[color_idx] = RGB888_TO_RGB555(color, color, color);
        }

        ot_init();
        matrix_stack_init();

        matrix_stack_mode(MATRIX_STACK_MODE_PROJECTION);

        fix16_t ratio;
        ratio = F16((float)SCREEN_WIDTH / (float)SCREEN_HEIGHT);

        matrix_stack_orthographic_project(-fix16_mul(F16(1.0f), ratio),
            fix16_mul(F16(1.0f), ratio),
            F16(1.0f), F16(-1.0f),
            F16(1.0f), F16(1.0f));

        matrix_stack_mode(MATRIX_STACK_MODE_MODEL_VIEW);
        matrix_stack_translate(F16(0.0f), F16(0.0f), F16(-10.0f));

        vdp1_cmdt_list_begin(0); {
                struct vdp1_cmdt_local_coord local_coord;

                local_coord.lc_coord.x = SCREEN_WIDTH / 2;
                local_coord.lc_coord.y = SCREEN_HEIGHT / 2;

                vdp1_cmdt_local_coord_set(&local_coord);
                vdp1_cmdt_end();
        } vdp1_cmdt_list_end(0);

        struct vdp1_cmdt_polygon polygon;

        memset(&polygon, 0x00, sizeof(polygon));

        vdp2_tvmd_vblank_out_wait();
        vdp2_tvmd_vblank_in_wait();

        fix16_t angle = F16(0.0f);

        while (true) {
                vdp2_tvmd_vblank_out_wait();

                // Update
                matrix_stack_mode(MATRIX_STACK_MODE_MODEL_VIEW);
                matrix_stack_push(); {
                        matrix_stack_rotate(angle, 0);
                        matrix_stack_rotate(angle, 1);
                        matrix_stack_rotate(angle, 2);

                        angle = fix16_add(angle, F16(-1.0f));

                        model_polygon_project(teapot_vertices, teapot_indices,
                            teapot_normals, TEAPOT_POLYGON_CNT);
                } matrix_stack_pop();

                vdp1_cmdt_list_begin(1); {
                        int32_t idx;
                        for (idx = OT_PRIMITIVE_BUCKETS - 1; idx >= 0; idx--) {
                                /* Skip empty buckets */
                                if (ot_bucket_empty(idx)) {
                                        continue;
                                }

#if POLYGON_SORT == 1
                                ot_bucket_primitive_sort(idx & (OT_PRIMITIVE_BUCKETS - 1),
                                    OT_PRIMITIVE_BUCKET_SORT_INSERTION);
#endif

#if RENDER == 1
                                struct ot_primitive *otp;
                                TAILQ_FOREACH (otp, ot_bucket(idx), otp_entries) {
                                        polygon.cp_color = otp->otp_color;
                                        polygon.cp_mode.transparent_pixel = true;
                                        polygon.cp_mode.end_code = true;

                                        polygon.cp_vertex.a.x = otp->otp_coords[0].x;
                                        polygon.cp_vertex.a.y = otp->otp_coords[0].y;
                                        polygon.cp_vertex.b.x = otp->otp_coords[1].x;
                                        polygon.cp_vertex.b.y = otp->otp_coords[1].y;
                                        polygon.cp_vertex.c.x = otp->otp_coords[2].x;
                                        polygon.cp_vertex.c.y = otp->otp_coords[2].y;
                                        polygon.cp_vertex.d.x = otp->otp_coords[3].x;
                                        polygon.cp_vertex.d.y = otp->otp_coords[3].y;

                                        vdp1_cmdt_polygon_draw(&polygon);
                                }
#endif
                                /* Clear OT bucket */
                                ot_bucket_init(idx);
                        }
                        vdp1_cmdt_end();
                } vdp1_cmdt_list_end(1);

                vdp2_tvmd_vblank_in_wait();

                // Draw
                vdp1_cmdt_list_commit();
        }