Beispiel #1
0
void test_ophcrack_preload_all7() {
  table_t *tables[] = {
    // vista probabilistic free (ntprobafree)
    table_alloc(0xbb00950e, ".", 0),
    table_alloc(0xbb00950e, ".", 1),
    table_alloc(0xbb00950e, ".", 2),
  };

  int ntables = sizeof(tables) / sizeof(table_t*);
  ophcrack_t *crack = create_crack_4test(tables, ntables);

  crack->freeram = table_preload_size(tables[0], preload_init) / 2;

  preload_4test(crack, tables, ntables);

  assert(crack->active->size == 0);
  assert(crack->remaining->size == 0);

  assert(crack->sched->ntasks == 1);

  check_preload_task(crack->sched, NULL, preload_none);

  check_preload_message(NULL, 0, 0, 0);
  assert(message_tryget() == NULL);

  free_crack_4test(crack);
}
Beispiel #2
0
void test_ophcrack_preload_all1() {
  table_t *tables[] = {
    // vista probabilistic 10G (ntproba10g)
    table_alloc(0x47000fdf, ".", 0),
    table_alloc(0x47000fdf, ".", 1),
    table_alloc(0x47000fdf, ".", 2),
    table_alloc(0x47000fdf, ".", 3)
  };

  int ntables = sizeof(tables) / sizeof(table_t*);
  ophcrack_t *crack = create_crack_4test(tables, ntables);

  // Assume we have enough RAM to load everything but the .start files

  uint64_t preload_size =
    table_preload_size(tables[0], preload_full - preload_srt) +
    table_preload_size(tables[1], preload_full - preload_srt) +
    table_preload_size(tables[2], preload_full - preload_srt) +
    table_preload_size(tables[3], preload_full - preload_srt);

  crack->freeram =
    preload_size -
    table_preload_size(tables[1], preload_init) -
    table_preload_size(tables[2], preload_init) -
    table_preload_size(tables[3], preload_init);

  // Perform preload

  preload_4test(crack, tables, ntables);

  assert(crack->active->size == ntables);
  assert(crack->remaining->size == 0);
  assert(crack->remaining->size == crack->enabled->size - crack->active->size);

  // Check the tasks

  assert(crack->sched->ntasks == 1 + 4*3 + 1);
  check_unload_task(crack->sched, NULL);

  check_preload_task(crack->sched, tables[0], preload_full - preload_srt);
  check_preload_task(crack->sched, tables[1], preload_full - preload_srt);
  check_preload_task(crack->sched, tables[2], preload_full - preload_srt);
  check_preload_task(crack->sched, tables[3], preload_full - preload_srt);

  check_preload_task(crack->sched, NULL, preload_none);
  assert(crack->sched->ntasks == 0);

  // Check the messages

  check_preload_message(NULL, ntables, 0, preload_size);

  message_t *msg = message_tryget();
  assert(msg == NULL);

  // Free memory

  free_crack_4test(crack);
}
Beispiel #3
0
void test_ophcrack_preload_all0() {
  // Create and initialise a crack object

  table_t *tables[] = {
    // xp free fast (lmalphanum5k)
    table_alloc(0x0fa2031c, ".", 0),
    table_alloc(0x0fa2031c, ".", 1),
    table_alloc(0x0fa2031c, ".", 2),
    table_alloc(0x0fa2031c, ".", 3),
  };

  int ntables = sizeof(tables) / sizeof(table_t*);
  ophcrack_t *crack = create_crack_4test(tables, ntables);

  assert(crack->enabled->size == ntables);

  // Assume we have enough RAM for all tables

  uint64_t preload_size = 0;

  for (int i=0; i<ntables; ++i)
    preload_size += table_preload_size(tables[i], preload_full);

  crack->freeram = preload_size;

  // Perform preload

  preload_4test(crack, tables, ntables);

  assert(crack->active->size == 4);
  assert(crack->remaining->size == 0);
  assert(crack->remaining->size == crack->enabled->size - crack->active->size);

  // Check the tasks

  assert(crack->sched->ntasks == 18);

  check_unload_task(crack->sched, NULL);

  for (int i=0; i<ntables; ++i)
    check_preload_task(crack->sched, tables[i], preload_full);

  check_preload_task(crack->sched, NULL, preload_none);

  assert(crack->sched->ntasks == 0);

  // Check the messages

  check_preload_message(NULL, ntables, 0, preload_size);

  message_t *msg = message_tryget();
  assert(msg == NULL);

  // Free memory

  free_crack_4test(crack);
}
Beispiel #4
0
void test_ophcrack_preload_all5() {
  table_t *tables[] = {
    // vista seven (ntseven)
    table_alloc(0x9542377a, ".", 0),
    // vista probabilistic 60G (ntproba60g)
    table_alloc(0x2c002335, ".", 0),
    // vista probabilistic free (ntprobafree)
    table_alloc(0xbb00950e, ".", 0),
    // xp free fast (lmalphanum5k)
    table_alloc(0x0fa2031c, ".", 0)
  };

  int ntables = sizeof(tables) / sizeof(table_t*);
  ophcrack_t *crack = create_crack_4test(tables, ntables);

  uint64_t preload_size =
    table_preload_size(tables[0], preload_full - preload_srt) +
    table_preload_size(tables[1], preload_full - preload_srt - preload_end) +
    table_preload_size(tables[2], preload_none) +
    table_preload_size(tables[3], preload_full - preload_srt);

  crack->freeram = 
    table_preload_size(tables[0], preload_full - preload_srt) +
    table_preload_size(tables[1], preload_full - preload_srt - preload_end) +
    table_preload_size(tables[2], preload_full - preload_srt - preload_end);
    table_preload_size(tables[3], preload_full - preload_srt - preload_end);

  preload_4test(crack, tables, ntables);

  assert(crack->active->size == 3);
  assert(crack->remaining->size == 1);
  assert(crack->enabled->size == crack->active->size + crack->remaining->size);

  assert(crack->sched->ntasks == 1 + 3 + 2 + 0 + 3 + 1);

  check_unload_task(crack->sched, NULL);
  check_preload_task(crack->sched, tables[0], preload_full - preload_srt);
  check_preload_task(crack->sched, tables[1], preload_full - preload_srt - preload_end);
  check_preload_task(crack->sched, tables[3], preload_full - preload_srt);
  check_preload_task(crack->sched, NULL, preload_none);

  check_preload_message(NULL, 3, 0, preload_size);
  assert(message_tryget() == NULL);

  free_crack_4test(crack);
}
void ssl_scache_shmht_init(server_rec *s, pool *p)
{
    SSLModConfigRec *mc = myModConfig();
    AP_MM *mm;
    table_t *ta;
    int ta_errno;
    int avail;
    int n;

    /*
     * Create shared memory segment
     */
    if (mc->szSessionCacheDataFile == NULL) {
        ssl_log(s, SSL_LOG_ERROR, "SSLSessionCache required");
        ssl_die();
    }
    if ((mm = ap_mm_create(mc->nSessionCacheDataSize, 
                           mc->szSessionCacheDataFile)) == NULL) {
        ssl_log(s, SSL_LOG_ERROR, 
                "Cannot allocate shared memory: %s", ap_mm_error());
        ssl_die();
    }
    mc->pSessionCacheDataMM = mm;

    /* 
     * Make sure the childs have access to the underlaying files
     */
    ap_mm_permission(mm, SSL_MM_FILE_MODE, ap_user_id, -1);

    /*
     * Create hash table in shared memory segment
     */
    avail = ap_mm_available(mm);
    n = (avail/2) / 1024;
    n = n < 10 ? 10 : n;
    if ((ta = table_alloc(n, &ta_errno, 
                          ssl_scache_shmht_malloc,  
                          ssl_scache_shmht_calloc, 
                          ssl_scache_shmht_realloc, 
                          ssl_scache_shmht_free    )) == NULL) {
        ssl_log(s, SSL_LOG_ERROR,
                "Cannot allocate hash table in shared memory: %s",
                table_strerror(ta_errno));
        ssl_die();
    }
    table_attr(ta, TABLE_FLAG_AUTO_ADJUST|TABLE_FLAG_ADJUST_DOWN);
    table_set_data_alignment(ta, sizeof(char *));
    table_clear(ta);
    mc->tSessionCacheDataTable = ta;

    /*
     * Log the done work
     */
    ssl_log(s, SSL_LOG_INFO, 
            "Init: Created hash-table (%d buckets) "
            "in shared memory (%d bytes) for SSL session cache", n, avail);
    return;
}
Beispiel #6
0
void test_ophcrack_preload_all3() {
  table_t *tables[] = {
    // xp free fast (lmalphanum5k)
    table_alloc(0x0fa2031c, ".", 0),
    table_alloc(0x0fa2031c, ".", 1),
    table_alloc(0x0fa2031c, ".", 2),
    table_alloc(0x0fa2031c, ".", 3)
  };

  int ntables = sizeof(tables) / sizeof(table_t*);
  ophcrack_t *crack = create_crack_4test(tables, ntables);

  // Assume no RAM is available

  crack->freeram = 0;

  // Perform preload

  preload_4test(crack, tables, ntables);

  assert(crack->active->size == 1);
  assert(crack->remaining->size == ntables-1);
  assert(crack->remaining->size == crack->enabled->size - crack->active->size);

  // Check the tasks

  assert(crack->sched->ntasks == 1 + 1 + 1);

  check_unload_task(crack->sched, NULL);
  check_preload_task(crack->sched, tables[0], preload_init);
  check_preload_task(crack->sched, NULL, preload_none);

  assert(crack->sched->ntasks == 0);

  // Check the messages

  check_preload_message(NULL, 1, 0, 0);

  message_t *msg = message_tryget();
  assert(msg == NULL);

  // Free memory

  free_crack_4test(crack);
}
Beispiel #7
0
table_t *table_stack_grow (table_stack_t *stack)
{
	table_t *table;
	assert(stack != NULL);
	table = table_alloc(TABLE_HASH);
	table->next = stack->tables;
	stack->tables = table;
	return table;
}
Beispiel #8
0
void test_ophcrack_preload_all6() {
  table_t *tables[] = {
    // vista seven
    table_alloc(0x9542377a, ".", 0),
    // vista eight xl (nteightxl)
    table_alloc(0x229e1899, ".", 0),
    // xp free fast (lmalphanum5k)
    table_alloc(0x0fa2031c, ".", 0),
  };

  int ntables = sizeof(tables) / sizeof(table_t*);
  ophcrack_t *crack = create_crack_4test(tables, ntables);

  uint64_t preload_size =
    table_preload_size(tables[0], preload_full - preload_srt) +
    table_preload_size(tables[1], preload_init) +
    table_preload_size(tables[2], preload_none);

  crack->freeram = 
    table_preload_size(tables[0], preload_full - preload_srt) +
    table_preload_size(tables[1], preload_init) +
    table_preload_size(tables[2], preload_full - preload_srt) - 10;

  preload_4test(crack, tables, ntables);

  assert(crack->active->size == 2);
  assert(crack->remaining->size == 1);
  assert(crack->enabled->size == crack->active->size + crack->remaining->size);

  assert(crack->sched->ntasks == 1 + 3 + 1 + 0 + 1);

  check_unload_task(crack->sched, NULL);
  check_preload_task(crack->sched, tables[0], preload_full - preload_srt);
  check_preload_task(crack->sched, tables[1], preload_init);
  check_preload_task(crack->sched, NULL, preload_none);

  check_preload_message(NULL, 2, 0, preload_size);
  assert(message_tryget() == NULL);

  free_crack_4test(crack);
}
Beispiel #9
0
/*-------Environment-------*/
pointer environment_make2(VM, pointer rib, pointer env) {
  pointer t;
  save(vm, rib);
  save(vm, env);
  t = table_alloc(vm);
  
  while (!AR_ISNIL(rib)) {
    table_insert(vm, t, caar(rib), cdar(rib));
    rib = cdr(rib);
  }
  unsave(vm, 2);
  
  return tagged_alloc(vm, vm->s_environment, cons(t,AR_ISNIL(env)?vm->nil:rep(env)));
}
Beispiel #10
0
int
main ()
{
    table_t* tablePtr;
    long hash[] = {3, 1, 4, 1, 5, 9, 2, 6, 8, 7, -1};
    long i;

    bool_t status = memory_init(1, 4, 2);
    assert(status);

    puts("Starting...");

    tablePtr = table_alloc(8, NULL);

    for (i = 0; hash[i] >= 0; i++ ) {
        bool_t status = table_insert(tablePtr,
                                     (ulong_t)hash[i],
                                     (void*)&hash[i])
        assert(status);
        printTable(tablePtr);
        puts("");
    }

    for (i = 0; hash[i] >= 0; i++ ) {
        bool_t status = table_remove(tablePtr,
                                     (ulong_t)hash[i],
                                     (void*)&hash[i])
        assert(status);
        printTable(tablePtr);
        puts("");
    }

    table_free(tablePtr);

    puts("Done.");

    return 0;
}
Beispiel #11
0
int test_table(){
  write_cstr(1, ">>> table >>>\n");
	struct table *tbl;
	tbl = table_alloc();
	int hash = 0;
	puts("--- testing hash ---");
	hash = hash_key(tbl, "hi");
	printf("result hi %d\n", hash);
	hash = hash_key(tbl, "hello");
	printf("result hello %d\n", hash);
	hash = hash_key(tbl, "denial");
	printf("result denial %d\n", hash);
	hash = hash_key(tbl, "I was a donkey once upon a time");
	printf("result I was a donkey once upon a time %d\n", hash);
	hash = hash_key(tbl, "dominence");
	printf("result what's dominence %d\n", hash);
	hash = hash_key(tbl, "power up it's drinking time");
	printf("result power up it's drinking time %d\n", hash);

	puts("--- testing size by level ---");
	printf("size by level 1:%d\n", size_by_level(1));
	printf("size by level 2:%d\n", size_by_level(2));
	printf("size by level 3:%d\n", size_by_level(3));

	puts("--- testing values and add ---");

	table_add(tbl, string_copy("hello"), string_copy("there"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("apple"), string_copy("tree"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("bannana"), string_copy("split"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("lash"), string_copy("O'Ninetails"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("fire"), string_copy("crow"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("denial"), string_copy("is hidden"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("one"), string_copy("1"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("two"), string_copy("2"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("three"), string_copy("3"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("four"), string_copy("4"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("five"), string_copy("5"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("six"), string_copy("6"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("seven"), string_copy("7"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("eight"), string_copy("8"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("nine"), string_copy("9"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("ten"), string_copy("10"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("eleven"), string_copy("11"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("twelve"), string_copy("12"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("thirteen"), string_copy("13"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("fourteen"), string_copy("14"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("fifteen"), string_copy("15"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("sixteen"), string_copy("16"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("seventeen"), string_copy("17"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("eighteen"), string_copy("18"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("nineteen"), string_copy("19"));
	table_print_debug(tbl, stdout);
	table_add(tbl, string_copy("twenty"), string_copy("20"));
	table_print_debug(tbl, stdout);

	puts("--- testing get ---");
	struct table_item *item = table_get(tbl, "hello");
	if(item != NULL){
		fprintf(stdout, "%s->%s\n", item->key_val, item->content);
	}
	struct table_item *item2 = table_get(tbl, "not here");
	if(item2 != NULL){
		fprintf(stdout, "%s->%s\n", item2->key_val, item2->content);
	}else{
		puts("item is null");
	}
	struct table_item *item3 = table_get(tbl, "bannana");
	if(item3 != NULL){
		fprintf(stdout, "%s->%s\n", item3->key_val, item3->content);
	}
	struct table_item *item4 = table_get(tbl, "one");
	if(item4 != NULL){
		fprintf(stdout, "%s->%s\n", item4->key_val, item4->content);
	}

	return 0;
}
Beispiel #12
0
/* =============================================================================
 * sequencer_alloc
 * -- Returns NULL on failure
 * =============================================================================
 */
sequencer_t*
sequencer_alloc (long geneLength, long segmentLength, segments_t* segmentsPtr)
{
    sequencer_t* sequencerPtr;
    long maxNumUniqueSegment = geneLength - segmentLength + 1;
    long i;

    sequencerPtr = (sequencer_t*)malloc(sizeof(sequencer_t));
    if (sequencerPtr == NULL) {
        return NULL;
    }

    sequencerPtr->uniqueSegmentsPtr =
        hashtable_alloc(geneLength, &hashSegment, &compareSegment, -1, -1);
    if (sequencerPtr->uniqueSegmentsPtr == NULL) {
        return NULL;
    }

    /* For finding a matching entry */
    sequencerPtr->endInfoEntries =
        (endInfoEntry_t*)malloc(maxNumUniqueSegment * sizeof(endInfoEntry_t));
    for (i = 0; i < maxNumUniqueSegment; i++) {
        endInfoEntry_t* endInfoEntryPtr = &sequencerPtr->endInfoEntries[i];
        endInfoEntryPtr->isEnd = TRUE;
        endInfoEntryPtr->jumpToNext = 1;
    }
    sequencerPtr->startHashToConstructEntryTables =
        (table_t**)malloc(segmentLength * sizeof(table_t*));
    if (sequencerPtr->startHashToConstructEntryTables == NULL) {
        return NULL;
    }
    for (i = 1; i < segmentLength; i++) { /* 0 is dummy entry */
        sequencerPtr->startHashToConstructEntryTables[i] =
            table_alloc(geneLength, NULL);
        if (sequencerPtr->startHashToConstructEntryTables[i] == NULL) {
            return NULL;
        }
    }
    sequencerPtr->segmentLength = segmentLength;

    /* For constructing sequence */
    sequencerPtr->constructEntries =
        (constructEntry_t*)malloc(maxNumUniqueSegment * sizeof(constructEntry_t));
    if (sequencerPtr->constructEntries == NULL) {
        return NULL;
    }
    for (i= 0; i < maxNumUniqueSegment; i++) {
        constructEntry_t* constructEntryPtr = &sequencerPtr->constructEntries[i];
        constructEntryPtr->isStart = TRUE;
        constructEntryPtr->segment = NULL;
        constructEntryPtr->endHash = 0;
        constructEntryPtr->startPtr = constructEntryPtr;
        constructEntryPtr->nextPtr = NULL;
        constructEntryPtr->endPtr = constructEntryPtr;
        constructEntryPtr->overlap = 0;
        constructEntryPtr->length = segmentLength;
    }
    sequencerPtr->hashToConstructEntryTable = table_alloc(geneLength, NULL);
    if (sequencerPtr->hashToConstructEntryTable == NULL) {
        return NULL;
    }

    sequencerPtr->segmentsPtr = segmentsPtr;

    return sequencerPtr;
}
Beispiel #13
0
void test_ophcrack_preload_all2() {
  table_t *tables[] = {
    // xp free fast (lmalphanum5k)
    table_alloc(0x0fa2031c, ".", 0),
    table_alloc(0x0fa2031c, ".", 1),
    table_alloc(0x0fa2031c, ".", 2),
    table_alloc(0x0fa2031c, ".", 3),

    // vista probabilistic 10G (ntproba10g)
    table_alloc(0x47000fdf, ".", 0),
    table_alloc(0x47000fdf, ".", 1),
    table_alloc(0x47000fdf, ".", 2),
    table_alloc(0x47000fdf, ".", 3)
  };

  int ntables = sizeof(tables) / sizeof(table_t*);
  ophcrack_t *crack = create_crack_4test(tables, ntables);

  // Assume a specific amount of RAM is available

  uint64_t preload_size = 
    table_preload_size(tables[0], preload_full) +
    table_preload_size(tables[1], preload_full) +
    table_preload_size(tables[2], preload_full) +
    table_preload_size(tables[3], preload_full - preload_srt) +
    table_preload_size(tables[4], preload_full - preload_srt) +
    table_preload_size(tables[5], preload_full - preload_srt) +
    table_preload_size(tables[6], preload_full - preload_srt) +
    table_preload_size(tables[7], preload_full - preload_srt);

  crack->freeram = 
    preload_size +
    table_preload_size(tables[3], preload_srt) / 2 -
    table_preload_size(tables[5], preload_init) -
    table_preload_size(tables[6], preload_init) -
    table_preload_size(tables[7], preload_init);

  // Perform two consecutive preloads

  for (int s=0; s<2; ++s) {
    // Perform preload

    if (s == 0)
      preload_4test(crack, tables, ntables);
    else
      preload_4test(crack, NULL, 0);

    assert(crack->active->size == ntables);
    assert(crack->remaining->size == 0);
    assert(crack->remaining->size == crack->enabled->size - crack->active->size);

    // Check the tasks

    if (s == 0) {
      assert(crack->sched->ntasks == 1 + 3*4 + 5*3 + 1);
      check_unload_task(crack->sched, NULL);

      check_preload_task(crack->sched, tables[0], preload_full);
      check_preload_task(crack->sched, tables[1], preload_full);
      check_preload_task(crack->sched, tables[2], preload_full);
      check_preload_task(crack->sched, tables[3], preload_full - preload_srt);
      check_preload_task(crack->sched, tables[4], preload_full - preload_srt);
      check_preload_task(crack->sched, tables[5], preload_full - preload_srt);
      check_preload_task(crack->sched, tables[6], preload_full - preload_srt);
      check_preload_task(crack->sched, tables[7], preload_full - preload_srt);
    }
    else {
      assert(crack->sched->ntasks == 1 + 4*4 + 4*3 + 1);
      check_unload_task(crack->sched, NULL);

      check_preload_task(crack->sched, tables[0], preload_full);
      check_preload_task(crack->sched, tables[1], preload_full);
      check_preload_task(crack->sched, tables[2], preload_full);
      check_preload_task(crack->sched, tables[3], preload_full);
      check_preload_task(crack->sched, tables[4], preload_full - preload_srt);
      check_preload_task(crack->sched, tables[5], preload_full - preload_srt);
      check_preload_task(crack->sched, tables[6], preload_full - preload_srt);
      check_preload_task(crack->sched, tables[7], preload_full - preload_srt);
    }

    check_preload_task(crack->sched, NULL, preload_none);
    assert(crack->sched->ntasks == 0);

    // Check the messages

    check_preload_message(NULL, ntables, 0, preload_size);

    message_t *msg = message_tryget();
    assert(msg == NULL);

    if (s == 0) {
      // Assume a bit more RAM is now available

      crack->freeram += table_preload_size(tables[3], preload_srt);
      preload_size += table_preload_size(tables[3], preload_srt);
    }
  }

  // Free memory

  free_crack_4test(crack);
}
Beispiel #14
0
int	main(int argc, char ** argv)
{
  table_t	*tab;
  int		ret, iter_n = ITERATIONS, alignment = 0;
  long		seed;
  
  argc--, argv++;
  
  /* set default seed */
  seed = time(NULL);
  
  /* process the args */
  for (; *argv != NULL; argv++, argc--) {
    if (**argv != '-') {
      continue;
    }
    
    switch (*(*argv + 1)) {
      
    case 'a':
      auto_adjust_b = 1;
      break;
      
    case 'A':
      if (argc > 0) {
	argv++, argc--;
	if (argc == 0) {
	  usage();
	}
	alignment = atoi(*argv);
      }
      break;
      
    case 'i':
      if (argc > 0) {
	argv++, argc--;
	if (argc == 0) {
	  usage();
	}
	iter_n = atoi(*argv);
      }
      break;
      
    case 'l':
      large_b = 1;
      break;
      
    case 's':
      if (argc > 0) {
	argv++, argc--;
	if (argc == 0) {
	  usage();
	}
	seed = atol(*argv);
      }
      break;
      
    case 'v':
      verbose_b = 1;
      break;
      
    default:
      usage();
      break;
    }
  }
  
  if (argc > 0) {
    usage();
  }
  
  (void)srandom(seed);
  (void)printf("Seed for random is %ld\n", seed);
  
  /* alloc the test table */
  call_c++;
  tab = table_alloc(0, &ret);
  if (tab == NULL) {
    (void)printf("table_alloc returned: %s\n", table_strerror(ret));
    exit(1);
  }
  
  if (auto_adjust_b) {
    ret = table_attr(tab, TABLE_FLAG_AUTO_ADJUST);
    if (ret != TABLE_ERROR_NONE) {
      (void)fprintf(stderr, "ERROR: could not set table for auto-adjust: %s\n",
		    table_strerror(ret));
      exit(1);
    }
  }
  
  if (alignment > 0) {
    ret = table_set_data_alignment(tab, alignment);
    if (ret != TABLE_ERROR_NONE) {
      (void)fprintf(stderr, "ERROR: could not set data alignment to %d: %s\n",
		    alignment, table_strerror(ret));
      exit(1);
    }
  }
  
  basic(tab);
  stress(tab, iter_n, 0);
  io_test(tab);
  order_test(tab);
  
  call_c++;
  ret = table_free(tab);
  if (ret != TABLE_ERROR_NONE) {
    (void)fprintf(stderr, "ERROR in table_free: %s\n", table_strerror(ret));
  }
  
  (void)fputc('\n', stdout);
  (void)printf("Test program performed %d table calls\n", call_c);
  
  exit(0);
}
void ssl_scache_shmht_init(server_rec *s, apr_pool_t *p)
{
    SSLModConfigRec *mc = myModConfig(s);
    table_t *ta;
    int ta_errno;
    apr_size_t avail;
    int n;
    apr_status_t rv;

    /*
     * Create shared memory segment
     */
    if (mc->szSessionCacheDataFile == NULL) {
        ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
                     "SSLSessionCache required");
        ssl_die();
    }

    if ((rv = apr_shm_create(&(mc->pSessionCacheDataMM), 
                   mc->nSessionCacheDataSize, 
                   mc->szSessionCacheDataFile, mc->pPool)) != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
                     "Cannot allocate shared memory");
        ssl_die();
    }

    if ((rv = apr_rmm_init(&(mc->pSessionCacheDataRMM), NULL,
                   apr_shm_baseaddr_get(mc->pSessionCacheDataMM),
                   mc->nSessionCacheDataSize, mc->pPool)) != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
                     "Cannot initialize rmm");
        ssl_die();
    }
    ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
                 "initialize MM %pp RMM %pp",
                 mc->pSessionCacheDataMM, mc->pSessionCacheDataRMM);

    /*
     * Create hash table in shared memory segment
     */
    avail = mc->nSessionCacheDataSize;
    n = (avail/2) / 1024;
    n = n < 10 ? 10 : n;

    /*
     * Passing server_rec as opt_param to table_alloc so that we can do
     * logging if required ssl_util_table. Otherwise, mc is sufficient.
     */ 
    if ((ta = table_alloc(n, &ta_errno, 
                          ssl_scache_shmht_malloc,  
                          ssl_scache_shmht_calloc, 
                          ssl_scache_shmht_realloc, 
                          ssl_scache_shmht_free, s )) == NULL) {
        ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
                     "Cannot allocate hash table in shared memory: %s",
                     table_strerror(ta_errno));
        ssl_die();
    }

    table_attr(ta, TABLE_FLAG_AUTO_ADJUST|TABLE_FLAG_ADJUST_DOWN);
    table_set_data_alignment(ta, sizeof(char *));
    table_clear(ta);
    mc->tSessionCacheDataTable = ta;

    /*
     * Log the done work
     */
    ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, 
                 "Init: Created hash-table (%d buckets) "
                 "in shared memory (%" APR_SIZE_T_FMT 
                 " bytes) for SSL session cache",
                 n, avail);
    return;
}
Beispiel #16
0
void test_ophcrack_preload_all4() {
  table_t *tables[] = {
    // xp free fast (lmalphanum5k)
    table_alloc(0x0fa2031c, ".", 0),
    table_alloc(0x0fa2031c, ".", 1),
    table_alloc(0x0fa2031c, ".", 2),
    table_alloc(0x0fa2031c, ".", 3)
  };

  int ntables = sizeof(tables) / sizeof(table_t*);
  ophcrack_t *crack = create_crack_4test(tables, ntables);

  // Assume a specific amount of RAM is availble

  uint64_t preload_size =
    table_preload_size(tables[0], preload_full) +
    table_preload_size(tables[1], preload_full) +
    table_preload_size(tables[2], preload_full) +
    table_preload_size(tables[3], preload_full);

  crack->freeram = preload_size;

  for (int s=0; s<2; ++s) {
    // Perform preload

    if (s == 0) {
      assert(crack->enabled->size == ntables);
      preload_4test(crack, tables, ntables);

      assert(crack->active->size == ntables);
      assert(crack->remaining->size == 0);
    }
    else {
      for (int i=0; i<ntables; ++i)
	tables[i]->enabled = 0;

      list_clear(crack->enabled);

      assert(crack->enabled->size == 0);
      preload_4test(crack, tables, 0);

      assert(crack->active->size == 0);
      assert(crack->remaining->size == 0);
    }

    assert(crack->remaining->size == crack->enabled->size - crack->active->size);

    // Check the tasks

    if (s == 0) {
      assert(crack->sched->ntasks == 1 + 4*4 + 1);

      while (crack->sched->ntasks > 0) {
	ophtask_t *task = scheduler_get(crack->sched, 0);
	ophtask_free(task);
	scheduler_done(crack->sched, 0);
      }
    }
    else {
      assert(crack->sched->ntasks == 1);
      check_preload_task(crack->sched, NULL, preload_none);
    }

    assert(crack->sched->ntasks == 0);

    // Check the messages

    if (s == 0)
      check_preload_message(NULL, ntables, 0, preload_size);
    else
      check_preload_message(NULL, 0, 0, 0);

    message_t *msg = message_tryget();
    assert(msg == NULL);
  }

  // Free memory

  free_crack_4test(crack);
}
Beispiel #17
0
/* =============================================================================
 * sequencer_alloc
 * -- Returns NULL on failure
 * =============================================================================
 */
sequencer_t*
sequencer_alloc (long geneLength, long segmentLength, segments_t* segmentsPtr)
{
    sequencer_t* sequencerPtr;
    long maxNumUniqueSegment = geneLength - segmentLength + 1;
    long i;
    sequencerPtr = (sequencer_t*)SEQ_MALLOC(sizeof(sequencer_t));
    if (sequencerPtr == NULL) {
        return NULL;
    }
    
    sequencerPtr->uniqueSegmentsPtr =
        hashtable_alloc(geneLength, &hashSegment, &sequencer_comparesegment, -1, -1);
    if (sequencerPtr->uniqueSegmentsPtr == NULL) {
        return NULL;
    }
    
    /* For finding a matching entry */
    sequencerPtr->endInfoEntries =
        (endInfoEntry_t*)SEQ_MALLOC(maxNumUniqueSegment * sizeof(endInfoEntry_t));
    for (i = 0; i < maxNumUniqueSegment; i++) {
        endInfoEntry_t* endInfoEntryPtr = &sequencerPtr->endInfoEntries[i];
        endInfoEntryPtr->isEnd = TRUE;
        endInfoEntryPtr->jumpToNext = 1;
	//hcaddconstraint((void*)&(endInfoEntryPtr->isEnd), (void*)&(endInfoEntryPtr->jumpToNext));
	//hcaddconstraint((void*)&(endInfoEntryPtr->jumpToNext), (void*)&(endInfoEntryPtr->isEnd));
    }
     
   sequencerPtr->startHashToConstructEntryTables =
        (table_t**)SEQ_MALLOC(segmentLength * sizeof(table_t*));
    if (sequencerPtr->startHashToConstructEntryTables == NULL) {
        return NULL;
    }
    for (i = 1; i < segmentLength; i++) { /* 0 is dummy entry */
        sequencerPtr->startHashToConstructEntryTables[i] =
            table_alloc(geneLength, NULL);
        if (sequencerPtr->startHashToConstructEntryTables[i] == NULL) {
            return NULL;
        }
    }
    sequencerPtr->segmentLength = segmentLength;
       /* For constructing sequence */
    sequencerPtr->constructEntries =
        (constructEntry_t*)SEQ_MALLOC(maxNumUniqueSegment * sizeof(constructEntry_t));
    if (sequencerPtr->constructEntries == NULL) {
        return NULL;
    }
    
    for (i= 0; i < maxNumUniqueSegment; i++) {
        constructEntry_t* constructEntryPtr = &sequencerPtr->constructEntries[i];

        /*printf("mallc 2 %p\n", &(constructEntryPtr->isStart));
        printf("mallc 3 %p\n", &(constructEntryPtr->segment));
        printf("mallc 4 %p\n", &(constructEntryPtr->endHash));
        printf("mallc 5 %p\n", &(constructEntryPtr->startPtr));
        printf("mallc 6 %p\n", &(constructEntryPtr->nextPtr));
        printf("mallc 7 %p\n", &(constructEntryPtr->endPtr));
        printf("mallc 8 %p\n", &(constructEntryPtr->overlap));
        printf("mallc 9 %p\n", &(constructEntryPtr->length));
	*/
	hcaddconstraint((unsigned long long *)&(constructEntryPtr->nextPtr), (unsigned long long*)&(constructEntryPtr->startPtr));
	hcaddconstraint((unsigned long long *)&(constructEntryPtr->startPtr), (unsigned long long*)&(constructEntryPtr->nextPtr));
	/*	hcaddconstraint((unsigned long long *)&(constructEntryPtr->endHash), (unsigned long long*)&(constructEntryPtr->segment));
	hcaddconstraint((unsigned long long *)&(constructEntryPtr->overlap), (unsigned long long*)&(constructEntryPtr->endPtr));
	hcaddconstraint((unsigned long long *)&(constructEntryPtr->segment), (unsigned long long*)&(constructEntryPtr->endHash));
	hcaddconstraint((unsigned long long *)&(constructEntryPtr->endPtr), (unsigned long long*)&(constructEntryPtr->overlap));
	*/		//hcaddconstraint((unsigned long long*)&(endInfoEntryPtr->jumpToNext), (unsigned long long*)&(endInfoEntryPtr->isEnd));
	//printf("ptrs %p %p\n", &(constructEntryPtr->endHash), (unsigned long long*)&(constructEntryPtr->segment));
	//printf("ptrs %p %p\n", &(constructEntryPtr->endPtr), (unsigned long long*)&(constructEntryPtr->overlap));
	//printf("ptrs %p %p\n", &(constructEntryPtr->nextPtr), (unsigned long long*)&(constructEntryPtr->startPtr));/*
	//printf("ptrs %p %p", &(constructEntryPtr->endHash), (unsigned long long*)&(constructEntryPtr->segment));
	//printf("ptrs %p %p", &(constructEntryPtr->endHash), (unsigned long long*)&(constructEntryPtr->segment));*/

        constructEntryPtr->isStart = TRUE;
        constructEntryPtr->segment = NULL;
        constructEntryPtr->endHash = 0;
        constructEntryPtr->startPtr = constructEntryPtr;
        constructEntryPtr->nextPtr = NULL;
        constructEntryPtr->endPtr = constructEntryPtr;
        constructEntryPtr->overlap = 0;
        constructEntryPtr->length = segmentLength;
    }
    sequencerPtr->hashToConstructEntryTable = table_alloc(geneLength, NULL);
    if (sequencerPtr->hashToConstructEntryTable == NULL) {
        return NULL;
    }

    sequencerPtr->segmentsPtr = segmentsPtr;

    return sequencerPtr;
}