Ejemplo n.º 1
0
void *load_elf_binary(char* buf, int fd)
{
  /*
   * ELFheader is at a fixed location and has paramters
   * required to understand the other components in the
   * ELF file
   *
   * */
  Elf64_Ehdr *elfHeader;
  Elf64_Phdr *phHeader;
  unsigned char *e_ident;
  long pg_size;

  elfHeader = (Elf64_Ehdr *)buf;
  e_ident   = elfHeader->e_ident;

  // validate elf
  validate_elf(e_ident);

  // get program header that has information about parts that
  // needs to be loaded in memory.
  phHeader  = (Elf64_Phdr *)(buf + elfHeader->e_phoff);

  // get the page size
  ASSERT_I( (pg_size = sysconf(_SC_PAGE_SIZE)), "page size" );
  DEBUG("Page size: %ld\n", pg_size);

  int i, prot;
  unsigned long offsetInPg; // we need to add this number to tatal size
  unsigned long alignedPgAddr; // pg_size - 1 == 000000 => will give rounded up bits
  unsigned long mapSize; // total map size. includes bits wasted due to allignment
  unsigned long offsetInFile; // offset in file
  Elf64_Addr p_vaddr;
  int flags = MAP_PRIVATE | MAP_DENYWRITE;
  unsigned long k_bss;
  int base_address_set = 0;

  for (i = 0; i < elfHeader->e_phnum; ++i) {
    // skip if it's not a load
    if (phHeader[i].p_type != PT_LOAD)
      continue;
    p_vaddr       = phHeader[i].p_vaddr;
    offsetInPg    = p_vaddr & (pg_size - 1);
    alignedPgAddr = p_vaddr & ~(pg_size - 1);
    mapSize       = phHeader[i].p_filesz + offsetInPg;
    offsetInFile  = phHeader[i].p_offset - offsetInPg;
    prot          = getProt(phHeader[i].p_flags);

    if (elfHeader->e_type == ET_EXEC)
      flags |= MAP_FIXED;

    char *m_map;
    ASSERT_I( (m_map = mmap((caddr_t)alignedPgAddr, mapSize, prot,
            flags, fd, offsetInFile)), "mmap");
    totalMemoryMapped += mapSize;
    fprintf(stderr, "Mapping aligned virtual address at %li and TMP: %li\n", alignedPgAddr, totalMemoryMapped);

    CMP_AND_FAIL(m_map, (char *)alignedPgAddr, "Couldn't assign asked virtual address");

    // we shift the base address using statuc link.
    if (base_address_set == 0) {
      base_virtual_address = (unsigned long)m_map;
      base_address_set = 1;
    }

    // adjust the bss segment.
    // bss doesn't occupy any space in file where as it does in memory
    // Note that it is actually present as zero bytes in elf too.
    if (phHeader[i].p_memsz > phHeader[i].p_filesz) {
      alignedPgAddr = phHeader[i].p_vaddr + phHeader[i].p_filesz;
      // move to next page and find the boundary
      alignedPgAddr = (alignedPgAddr + pg_size - 1) & ~(pg_size - 1);
      mapSize = phHeader[i].p_memsz - phHeader[i].p_filesz;

      flags |= MAP_ANONYMOUS;
      // map this region to Anonymous which is "zeroed" out
      ASSERT_I( (m_map = mmap((caddr_t)alignedPgAddr, mapSize, prot,
              flags, -1, 0)), "mmap");
      totalMemoryMapped += mapSize;
      fprintf(stderr, "[BSS]Mapping aligned virtual address at %li and TMP: %li\n", alignedPgAddr, totalMemoryMapped);
    }

  }

  // the entry point for program to execute
  DEBUG("Entry Point: %p\n", (void *)elfHeader->e_entry);
  DEBUG("Base aaddress: %li\n", base_virtual_address);

  return (void *)elfHeader->e_entry;
}
Ejemplo n.º 2
0
int main(int argc, char** argv)
{
	string* addr = new string("127.0.0.1");
	uint16_t port = 7766;

	//Determines whether the program is executed in the sender or receiver role
	m_nPID = atoi(argv[1]);
	//the number of OTs that are performed. Has to be initialized to a certain minimum size due to
	uint64_t numOTs = 1000000;
	//bitlength of the values that are transferred - NOTE that when bitlength is not 1 or a multiple of 8, the endianness has to be observed
	uint32_t bitlength = 8;

	uint32_t runs = 1;

	//Use elliptic curve cryptography in the base-OTs
	m_eFType = ECC_FIELD;
	//The symmetric security parameter (80, 112, 128)
	uint32_t m_nSecParam = 128;

	//Number of threads that will be used in OT extension
	m_nNumOTThreads = 1;

	//Specifies which OT flavor should be used
	snd_ot_flavor stype = Snd_OT;
	rec_ot_flavor rtype = Rec_OT;


	m_nBaseOTs = 190;
	m_nChecks = 380;

	m_bUseMinEntCorAssumption = false;

	m_eProt = IKNP;

	read_test_options(&argc, &argv, &m_nPID, &numOTs, &bitlength, &m_nSecParam, addr, &port, &m_eProt, &stype, &rtype,
			&m_nNumOTThreads, &m_nBaseOTs, &m_nChecks, &m_bUseMinEntCorAssumption, &runs);

	/*int32_t read_test_options(int32_t* argcp, char*** argvp, uint32_t* role, uint64_t* numots, uint32_t* bitlen,
			uint32_t* secparam, string* address, uint16_t* port, ot_ext_prot* protocol, snd_ot_flavor* sndflav,
			rec_ot_flavor* rcvflav, uint32_t* nthreads, uint32_t* nbaseots, uint32_t* nchecks, bool* usemecr, uint32_t* runs) {*/

	crypto *crypt = new crypto(m_nSecParam, (uint8_t*) m_cConstSeed[m_nPID]);


	if(m_nPID == SERVER_ID) //Play as OT sender
	{
		InitOTSender(addr->c_str(), port, crypt);

		CBitVector delta, X1, X2;

		//The masking function with which the values that are sent in the last communication step are processed
		m_fMaskFct = new XORMasking(bitlength, delta);

		//creates delta as an array with "numOTs" entries of "bitlength" bit-values and fills delta with random values
		delta.Create(numOTs, bitlength, crypt);

		//Create X1 and X2 as two arrays with "numOTs" entries of "bitlength" bit-values and resets them to 0
		X1.Create(numOTs, bitlength, crypt);
		X2.Create(numOTs, bitlength, crypt);

#ifndef BATCH
		cout << getProt(m_eProt) << " Sender performing " << numOTs << " " << getSndFlavor(stype) << " / " <<
				getRecFlavor(rtype) << " extensions on " << bitlength << " bit elements with " <<	m_nNumOTThreads << " threads, " <<
				getFieldType(m_eFType) << " and" << (m_bUseMinEntCorAssumption ? "": " no" ) << " min-ent-corr-robustness " <<
				runs << " times" << endl;
#endif
		for(uint32_t i = 0; i < runs; i++) {
			ObliviouslySend(X1, X2, numOTs, bitlength, stype, rtype, crypt);
		}
	}
	else //Play as OT receiver
	{
		InitOTReceiver(addr->c_str(), port, crypt);

		CBitVector choices, response;

		//The masking function with which the values that are sent in the last communication step are processed
		m_fMaskFct = new XORMasking(bitlength);

		//Create the bitvector choices as a bitvector with numOTs entries
		choices.Create(numOTs, crypt);

		//Pre-generate the respose vector for the results
		response.Create(numOTs, bitlength);
		response.Reset();

		/* 
		 * The inputs of the receiver in G_OT, C_OT and R_OT are the same. The only difference is the version
		 * variable that has to match the version of the sender. 
		*/
#ifndef BATCH
		cout << getProt(m_eProt) << " Receiver performing " << numOTs << " " << getSndFlavor(stype) << " / " <<
				getRecFlavor(rtype) << " extensions on " << bitlength << " bit elements with " <<	m_nNumOTThreads << " threads, " <<
				getFieldType(m_eFType) << " and" << (m_bUseMinEntCorAssumption ? "": " no" ) << " min-ent-corr-robustness " <<
				runs << " times" << endl;
#endif
		for(uint32_t i = 0; i < runs; i++) {
			ObliviouslyReceive(choices, response, numOTs, bitlength, stype, rtype, crypt);
		}
	}

	//Cleanup();
	delete crypt;

	return 1;
}
Ejemplo n.º 3
0
int main(int argc, char **argv) {
    const char *addr = "127.0.0.1";
    int port = 7766;

    if (argc != 2) {
        cout
            << "Please call with 0 if acting as server or 1 if acting as client"
            << endl;
        return 0;
    }

    // Determines whether the program is executed in the sender or receiver role
    m_nPID = atoi(argv[1]);
    cout << "Playing as role: " << m_nPID << endl;
    assert(m_nPID >= 0 && m_nPID <= 1);

    // The symmetric security parameter (80, 112, 128)
    uint32_t m_nSecParam = 128;

    crypto *crypt = new crypto(m_nSecParam, (uint8_t *)m_cConstSeed[m_nPID]);

    uint32_t m_nBaseOTs = 190;
    uint32_t m_nChecks = 380;

    ot_ext_prot lastprot = PROT_LAST;
    field_type lastfield = FIELD_LAST;

    if (m_nPID == SERVER_ID) // Play as OT sender
    {
        InitSender(addr, port);

        OTExtSnd *sender = NULL;
        for (uint32_t i = 0; i < m_nTests; i++) {
            if (lastprot != tests[i].prot || lastfield != tests[i].ftype) {
                // if(sender) delete sender;
                sender = InitOTExtSnd(tests[i].prot, m_nBaseOTs, m_nChecks,
                                      tests[i].usemecr, tests[i].ftype, crypt);
                lastprot = tests[i].prot;
                lastfield = tests[i].ftype;
            }

            cout << "Test " << i << ": " << getProt(tests[i].prot) << " Sender "
                 << tests[i].numots << " " << getSndFlavor(tests[i].sflavor)
                 << " / " << getRecFlavor(tests[i].rflavor) << " on "
                 << tests[i].bitlen << " bits with " << tests[i].nthreads
                 << " threads, " << getFieldType(tests[i].ftype) << " and"
                 << (tests[i].usemecr ? "" : " no") << " MECR" << endl;

            run_test_sender(tests[i].numots, tests[i].bitlen, tests[i].sflavor,
                            tests[i].rflavor, tests[i].nthreads, crypt, sender);
        }
        delete sender;
    } else // Play as OT receiver
    {
        InitReceiver(addr, port);

        OTExtRec *receiver = NULL;
        for (uint32_t i = 0; i < m_nTests; i++) {
            if (lastprot != tests[i].prot || lastfield != tests[i].ftype) {
                // if(receiver) delete receiver;
                receiver =
                    InitOTExtRec(tests[i].prot, m_nBaseOTs, m_nChecks,
                                 tests[i].usemecr, tests[i].ftype, crypt);
                lastprot = tests[i].prot;
                lastfield = tests[i].ftype;
            }

            cout << "Test " << i << ": " << getProt(tests[i].prot)
                 << " Receiver " << tests[i].numots << " "
                 << getSndFlavor(tests[i].sflavor) << " / "
                 << getRecFlavor(tests[i].rflavor) << " on " << tests[i].bitlen
                 << " bits with " << tests[i].nthreads << " threads, "
                 << getFieldType(tests[i].ftype) << " and"
                 << (tests[i].usemecr ? "" : " no") << " MECR" << endl;

            run_test_receiver(tests[i].numots, tests[i].bitlen,
                              tests[i].sflavor, tests[i].rflavor,
                              tests[i].nthreads, crypt, receiver);
        }
        delete receiver;
    }

    Cleanup();
    delete crypt;

    return 1;
}