Ejemplo n.º 1
0
static PubkeyStruct *
pubkey_load_file(const char *pk_file)
{
    char          pk_comment[COMMENTMAXBYTES];
    PubkeyStruct *pubkey_struct;
    FILE         *fp;
    char         *pubkey_s = NULL;
    size_t        pubkey_s_size;

    if ((fp = fopen(pk_file, "r")) == NULL) {
        exit_err(pk_file);
    }
    if (fgets(pk_comment, (int) sizeof pk_comment, fp) == NULL) {
        exit_err(pk_file);
    }
    pubkey_s_size = B64_MAX_LEN_FROM_BIN_LEN(sizeof *pubkey_struct) + 2U;
    pubkey_s = xmalloc(pubkey_s_size);
    if (fgets(pubkey_s, (int) pubkey_s_size, fp) == NULL) {
        exit_err(pk_file);
    }
    trim(pubkey_s);
    xfclose(fp);
    pubkey_struct = pubkey_load_string(pubkey_s);
    free(pubkey_s);

    return pubkey_struct;
}
Ejemplo n.º 2
0
static unsigned char *
message_load(size_t *message_len, const char *message_file, int hashed)
{
    FILE          *fp;
    unsigned char *message;
    off_t          message_len_;

    if (hashed != 0) {
        return message_load_hashed(message_len, message_file);
    }
    if ((fp = fopen(message_file, "rb")) == NULL ||
        fseeko(fp, 0, SEEK_END) != 0 ||
        (message_len_ = ftello(fp)) == (off_t) -1) {
        exit_err(message_file);
    }
    if (hashed == 0 && message_len_ > (off_t) 1L << 30) {
        exit_msg("Data has to be smaller than 1 Gb. Or use the -H option.");
    }
    if ((uintmax_t) message_len_ > (uintmax_t) SIZE_MAX ||
        message_len_ < (off_t) 0) {
        abort();
    }
    message = xmalloc((*message_len = (size_t) message_len_));
    rewind(fp);
    if (fread(message, *message_len, (size_t) 1U, fp) != 1U) {
        exit_err(message_file);
    }
    xfclose(fp);

    return message;
}
Ejemplo n.º 3
0
static unsigned char *
message_load_hashed(size_t *message_len, const char *message_file)
{
    crypto_generichash_state  hs;
    unsigned char             buf[65536U];
    unsigned char            *message;
    FILE                     *fp;
    size_t                    n;

    if ((fp = fopen(message_file, "rb")) == NULL) {
        exit_err(message_file);
    }
    crypto_generichash_init(&hs, NULL, 0U, crypto_generichash_BYTES_MAX);
    while ((n = fread(buf, 1U, sizeof buf, fp)) > 0U) {
        crypto_generichash_update(&hs, buf, n);
    }
    if (!feof(fp)) {
        exit_err(message_file);
    }
    xfclose(fp);
    message = xmalloc(crypto_generichash_BYTES_MAX);
    crypto_generichash_final(&hs, message, crypto_generichash_BYTES_MAX);
    *message_len = crypto_generichash_BYTES_MAX;

    return message;
}
Ejemplo n.º 4
0
void setblocking(int sock)
{
    int opts = fcntl(sock, F_GETFL);
    if (opts < 0) exit_err("fcntl(F_GETFL)");

    opts = (opts & ~O_NONBLOCK);
    if (fcntl(sock, F_SETFL, opts) < 0) exit_err("fcntl(F_SETFL)");
    return;
}
Ejemplo n.º 5
0
void setnonblocking(int sock)
{
    int opts = fcntl(sock, F_GETFL);
    if (opts < 0) {
        printf("%d\n", sock);
        exit_err("fcntl(F_GETFL)");
    }

    opts = (opts | O_NONBLOCK);
    if (fcntl(sock, F_SETFL, opts) < 0) exit_err("fcntl(F_SETFL)");
    return;
}
Ejemplo n.º 6
0
void show_texture(FILE *fp, int id, unsigned short mask, int dump)
{
   unsigned short *img;
   int width, height, frame, maxframe;
   unsigned int ofs, len;
   int x = 0, y = 0, i, j, col;
   char fname[80];


   if (flxx_getitem(fp, id) <= 0)
      return;

   fseek(fp, 0x08, SEEK_CUR);
   fread(&maxframe, 4, 1, fp);

   for (frame=0; frame<maxframe; frame++)
   {
      flxx_getitem(fp, id);
      fseek(fp, 0x10 + frame * 8, SEEK_CUR);
      fread(&ofs, 4, 1, fp);
      fread(&len, 4, 1, fp);
      fseek(fp, ofs - 0x18 - frame * 8, SEEK_CUR);

      fseek(fp, 4, SEEK_CUR);
      fread(&width, 4, 1, fp);
      if ((frame != 0) && (x + width > SCREEN_W))
      {
         x = 0;
         y += height + 2;
      }
      fread(&height, 4, 1, fp);

      img = malloc(width * height * 2);
      if (img == NULL)
         exit_err("out of memory%s\n", "");

      fseek(fp, 8 + 4 * height, SEEK_CUR);
      fread(img, 1, width * height * 2, fp);

      for (j=0; j<height; j++)
         for (i=0; i<width; i++)
         {
            col = img[j*width+i] & mask;
            putpixel(screen, x+i, y+j, col);
         }

      if (dump)
      {
         for (i=0; i<height*width; i++)
            img[i] &= mask;
         sprintf(fname, "u9-%04i-%03i.bmp", id, frame);
         write_bmp16(fname, (char *)img, width, height);
      }


      free(img);

      x += width + 2;
   }
}
Ejemplo n.º 7
0
int	new_player(t_util *util)
{
  t_player *ply;

  if (!(ply = malloc(sizeof(*ply))))
    return (err_msg(": Malloc fail"));
  if (NB_TEAM > 76)
    return (err_msg(": you have put to mutch team ! max val 76"));
  if (util->id + 1 >= MAP_X * MAP_Y)
    return (err_msg(": You have put to mutch player in one time !"));
  util->cycle = 0;
  if (!(ply->target = malloc(sizeof(int) * 2)))
    exit_err(": Malloc faild !\n");
  ply->team = '1' + (util->id % NB_TEAM);
  while (42)
    {
      ply->x = random() % MAP_X;
      ply->y = random() % MAP_Y;
      if ((util->addr)[ply->x + (ply->y * MAP_X)] == '0')
	break;
    }
  lock(util);
  util->addr[ply->x + (ply->y * MAP_X)] = ply->team;
  unlock(util);
  game(util, ply);
  return (0);
}
Ejemplo n.º 8
0
void file2buf(int size) {
	if(bufsize + size > BUFSIZE) {
		exit_err("Instruction too long.\n");
	}
	fread(&buf[bufsize], 1, size, file);
	bufsize += size;
}
Ejemplo n.º 9
0
/********************************************************\
 * Description: parses command line arguments and 	*
 *		processes them.				*
 * Returns:	length of file				*
\********************************************************/
off_t parseArgs(int argc, char *argv[])
{
    extern char *optarg;				/* extern vars for    */
    extern int optind, /*opterr,*/ optopt;		/* getopt()	      */

    int val;						/* counters, etc.     */

							/* get args           */
    while ((val = hgetopt(argc, argv, "a:i:o:r:e")) != -1) 
    {
	switch (val)					/* test args          */
        {
            case 'a':	printHex = FALSE;		/* decimal addresses  */
                        break;
							/* infile             */
	    case 'i':	free(fpINfilename);
			fpINfilename = strdup(optarg);
			break;
							/* outfile            */
	    case 'o':   free(fpOUTfilename);
			fpOUTfilename = strdup(optarg);
			break;

            case 'r':   resize = atoi(optarg);		/* don't resize screen*/
                        break;

            case 'e':   USE_EBCDIC=TRUE;		/*use instead of ascii*/
                        break;
							/* help/invalid args  */
							/* help/invalid args  */
	    case '?':	print_usage();			/* output help        */
                        if ((optopt == 'h') || (optopt == '?'))
			    exit(0);			/* exit               */
			else				/* illegal option     */
			    exit(-1);
        }
    }
    argc -= optind;
    argv += optind;

    if (argv[0])
    {
	free(fpINfilename);
        fpINfilename = strdup(argv[0]);
    }

    if (fpINfilename && strcmp(fpINfilename, ""))
        if ((fpIN = fopen(fpINfilename, "r")) == NULL)
            exit_err("Could not open file");

    return ((fpIN != NULL) ? maxLoc(fpIN):0);		/* return file length */
}
Ejemplo n.º 10
0
static char *
default_trusted_comment(const char *message_file)
{
    char   *ret;
    time_t  ts = time(NULL);

    if (asprintf(&ret, "timestamp:%lu\tfile:%s",
                 (unsigned long) ts, file_basename(message_file)) < 0 ||
        ret == NULL) {
        exit_err("asprintf()");
    }
    return ret;
}
Ejemplo n.º 11
0
static int
output_file(const char *message_file)
{
    unsigned char  buf[65536U];
    FILE          *fp;
    size_t         n;

    if ((fp = fopen(message_file, "rb")) == NULL) {
        exit_err(message_file);
    }
    while ((n = fread(buf, 1U, sizeof buf, fp)) > 0U) {
        if (fwrite(buf, 1U, n, stdout) != n) {
            exit_err(message_file);
        }
    }
    if (!feof(fp) || fflush(stdout) != 0) {
        exit_err(message_file);
    }
    xfclose(fp);

    return 0;
}
Ejemplo n.º 12
0
void read_head(pConnInfo conn_info) {
    int result = read_data(conn_info);
    if(result == RETURN_SUCCESS) {
        apply_next_router(conn_info);
    } else if(result == RETURN_AGAIN) {
        struct epoll_event ev;
        ev.events = EPOLLIN | EPOLLET | EPOLLONESHOT;
        ev.data.ptr = conn_info;
        if(epoll_ctl(conn_info->epollfd, EPOLL_CTL_ADD, conn_info->clientfd, &ev) == -1)
            exit_err("epoll_ctl");
        longjmp(conn_info->jmp_buff, 1);
    } else if(result == RETURN_ERROR) {
        //wow, invalid request
    }
}
Ejemplo n.º 13
0
static Tt_message
create_new_message(char *name, int height, int width)
{
  Tt_message	msg;

  msg = tt_message_create();
  exit_err_ptr(msg);

  exit_err(tt_message_address_set (msg, TT_PROCEDURE));
  exit_err(tt_message_class_set   (msg, TT_REQUEST));
  exit_err(tt_message_scope_set   (msg, TT_SESSION));
  exit_err(tt_message_op_set      (msg, "emacs-make-client-frame"));
  exit_err(tt_message_arg_add     (msg, TT_IN, "string", name));
  exit_err(tt_message_iarg_add    (msg, TT_IN, "int",    height));
  exit_err(tt_message_iarg_add    (msg, TT_IN, "int",    width));
  exit_err(tt_message_callback_add(msg, callback_fn));

  return msg;
}
Ejemplo n.º 14
0
void load_rom(const char *fname, const char *sname, int zoom)
{
    uint8_t *start_of_rom;
    int cart_type;

    init_memory();

    fp = os_open_file_r(fname);
    if (fp == INVALID_FILE_HANDLE)
    {
        os_perr("Couldn't read ROM file");
        exit_err();
    }

    save = os_open_file_rw(sname);
    if (save == INVALID_FILE_HANDLE)
    {
        save = os_create_file_rw(sname);
        if (save == INVALID_FILE_HANDLE)
        {
            os_close_file(fp);
            os_perr("Couldn't create save file");
            exit_err();
        }
    }

    start_of_rom = alloc_mem(0x150);
    if (start_of_rom == NULL)
    {
        os_perr("Couldn't allocate memory");
        exit_err();
    }

    os_file_read(fp, 0x150, start_of_rom);

    if (memcmp(id, start_of_rom + 0x104, sizeof(id)))
    {
        os_eprint("Bad ROM!\n");
        exit_err();
    }

    os_print("Loading \"");
    for (int i = 0x134; i < 0x143; i++)
    {
        if (!start_of_rom[i])
            break;
        os_print("%c", start_of_rom[i]);
    }
    if (start_of_rom[0x143] & 0x80)
        gbc_mode = 1;
    else
        gbc_mode = 0;
    os_print("\", %s...\n", gbc_mode ? "GBC" : "GB");

    cart_type = start_of_rom[0x147];
    rom_size = start_of_rom[0x148];
    ram_size = start_of_rom[0x149];

    switch (rom_size)
    {
        case 0x52:
            rom_size = 72;
            break;
        case 0x53:
            rom_size = 80;
            break;
        case 0x54:
            rom_size = 96;
            break;
        default:
            if (rom_size > 6)
            {
                os_eprint("Invalid ROM size 0x%02X.\n", rom_size);
                exit_err();
            }
            rom_size = 2 << rom_size;
    }

    switch (ram_size)
    {
        case 0:
            ram_size = 0;
            break;
        case 1:
        case 2:
            ram_size = 1;
            break;
        case 3:
            ram_size = 4;
            break;
        case 4:
            ram_size = 16;
            break;
        default:
            os_eprint("Invalid RAM size 0x%02X.\n", ram_size);
            exit_err();
    }

    os_print("%i ROM banks, %i RAM banks.\n", rom_size, ram_size);

    #ifdef MAP_BATTERY
    os_resize_file(save, ram_size * 8192);
    #endif

    switch (cart_type)
    {
        CART_TYPE(0x00, 0, 0, 0, 0, 0);
        CART_TYPE(0x01, 1, 0, 0, 0, 0);
        CART_TYPE(0x02, 1, 1, 0, 0, 0);
        CART_TYPE(0x03, 1, 1, 1, 0, 0);
        CART_TYPE(0x05, 2, 0, 0, 0, 0);
        CART_TYPE(0x06, 2, 0, 1, 0, 0);
        CART_TYPE(0x08, 0, 1, 0, 0, 0);
        CART_TYPE(0x09, 0, 1, 1, 0, 0);
        CART_TYPE(0x0F, 3, 0, 1, 1, 0);
        CART_TYPE(0x10, 3, 1, 1, 1, 0);
        CART_TYPE(0x11, 3, 0, 0, 0, 0);
        CART_TYPE(0x12, 3, 1, 0, 0, 0);
        CART_TYPE(0x13, 3, 1, 1, 0, 0);
        CART_TYPE(0x19, 5, 0, 0, 0, 0);
        CART_TYPE(0x1A, 5, 1, 0, 0, 0);
        CART_TYPE(0x1B, 5, 1, 1, 0, 0);
        CART_TYPE(0x1C, 5, 0, 0, 0, 1);
        CART_TYPE(0x1D, 5, 1, 0, 0, 1);
        CART_TYPE(0x1E, 5, 1, 1, 0, 1);
        default:
            os_eprint("Unknown cartridge type 0x%02X.\n", cart_type);
            exit_err();
    }

    os_print("Cartridge type: ROM");
    if (mbc)
        os_print("+MBC%i", mbc);
    if (ext_ram)
        os_print("+RAM");
    if (batt)
        os_print("+BATT");
    if (rtc)
        os_print("+TIMER");
    if (rmbl)
        os_print("+RUMBLE");
    os_print("\n");

    load_memory();

    run(zoom);
}
Ejemplo n.º 15
0
int main(int argc, char *argv[])
{
   FILE *fp;
   int curritem = 0, numitems, i;
   unsigned short mask = 0xFFFF;
   char ch = '\0';
   int done = 0,
       wind = 0,          /* not as in air */
       mode = 0,
       refresh = 1;

   struct gfx_modes_struct { int w,h; } gfx_modes[NUM_MODES] =
      { {640, 480}, {800, 600}, {1024, 768} };


   if (argc != 0)
   {
      if ( (strchr(argv[1], '?') != NULL) ||
           (strchr(argv[1], 'h') != NULL) ||
           (strchr(argv[1], 'H') != NULL) )
      {
         fprintf(stderr, "usage: %s [gfx-mode-id]\n", argv[0]);
         fprintf(stderr, "gfx-mode-id is one of:\n");
         for (i=0; i<NUM_MODES; i++)
            fprintf(stderr, "  %i => %ix%ix16 %s\n",
                    i, gfx_modes[i].w, gfx_modes[i].h,
                    (i == 0) ? "(default)" : "");
         exit(-1);
      }

      mode = atoi(argv[1]);
      if ((mode < 0) || (mode >= NUM_MODES))
         mode = 0;
   }


   fp = flxx_open(BITMAP_NAME);
   if (fp == NULL)
      exit_err("error opening %s\n", BITMAP_NAME);
   numitems = flxx_numitems(fp);


   allegro_init();
   set_color_depth(16);
   if (set_gfx_mode(GFX_AUTODETECT, gfx_modes[mode].w, gfx_modes[mode].h,
       0, 0) < 0)
      exit_err("error initialising graphics:\n   %s\n", allegro_error);


   while (flxx_getitem(fp, curritem) <= 0)
   {
      curritem++;
      if (curritem > numitems)
         exit_err("no non-zero items found!!\n", "");
   }



   while (!done)
   {
      if (refresh)
      {
         clear(screen);
         show_texture(fp, curritem, mask, 0);
         textprintf(screen, font, 10, SCREEN_H - 20, 0xFFFF,
                    "img %i/%i | mask 0x%X", curritem, numitems-1, mask);
         refresh = 0;
      }

      ch = toupper(getch());
      switch (ch)
      {
         case 0x1B:  done = 1;
                     break;

         case 'V':   wind =  1;       break;
         case 'F':   wind = -1;       break;
         case 'C':   wind =  10;      break;
         case 'D':   wind = -10;      break;
         case 'X':   wind =  100;     break;
         case 'S':   wind = -100;     break;
         case 'Z':   wind =  1000;    break;
         case 'A':   wind = -1000;    break;

         case 0x0D:  clear(screen);
                     show_texture(fp, curritem, mask, 1);
                     textprintf(screen, font, 10, SCREEN_H - 20, 0xFFFF,
                                "dumped.");
                     break;

         case ' ':   mask ^= 0x8400;  /* flip b/w 0xffff and 0x7bff */
                     refresh = 1;
                     break;
      }

      if (wind != 0)
      {
         curritem += wind;

         if (curritem < 0)
            curritem += numitems;
         if (curritem >= numitems)
            curritem -= numitems;

         while (flxx_getitem(fp, curritem) <= 0)
         {
            if (wind < 0)
               curritem--;
            else
               curritem++;

            if (curritem < 0)
               curritem = numitems - 1;
            if (curritem >= numitems)
               curritem = 0;
         }

         wind = 0;
         refresh = 1;
      }

   }

   fclose(fp);

   return 0;
}
Ejemplo n.º 16
0
static int
generate(const char *pk_file, const char *sk_file, const char *comment)
{
    char          *pwd = xsodium_malloc(PASSWORDMAXBYTES);
    char          *pwd2 = xsodium_malloc(PASSWORDMAXBYTES);
    SeckeyStruct  *seckey_struct = xsodium_malloc(sizeof(SeckeyStruct));
    PubkeyStruct  *pubkey_struct = xsodium_malloc(sizeof(PubkeyStruct));
    unsigned char *stream ;
    FILE          *fp;

    randombytes_buf(seckey_struct->keynum_sk.keynum,
                    sizeof seckey_struct->keynum_sk.keynum);
    crypto_sign_keypair(pubkey_struct->keynum_pk.pk,
                        seckey_struct->keynum_sk.sk);
    memcpy(seckey_struct->sig_alg, SIGALG, sizeof seckey_struct->sig_alg);
    memcpy(seckey_struct->kdf_alg, KDFALG, sizeof seckey_struct->kdf_alg);
    memcpy(seckey_struct->chk_alg, CHKALG, sizeof seckey_struct->chk_alg);
    randombytes_buf(seckey_struct->kdf_salt, sizeof seckey_struct->kdf_salt);
    le64_store(seckey_struct->kdf_opslimit_le,
               crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVE);
    le64_store(seckey_struct->kdf_memlimit_le,
               crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVE);
    seckey_chk(seckey_struct->keynum_sk.chk, seckey_struct);
    memcpy(pubkey_struct->keynum_pk.keynum, seckey_struct->keynum_sk.keynum,
           sizeof pubkey_struct->keynum_pk.keynum);
    memcpy(pubkey_struct->sig_alg, SIGALG, sizeof pubkey_struct->sig_alg);

    puts("Please enter a password to protect the secret key.\n");
    if (get_password(pwd, PASSWORDMAXBYTES, "Password: "******"Password (one more time): ") != 0) {
        exit_msg("get_password()");
    }
    if (strcmp(pwd, pwd2) != 0) {
        exit_msg("Passwords don't match");
    }
    printf("Deriving a key from the password in order to encrypt the secret key... ");
    fflush(stdout);
    stream = xsodium_malloc(sizeof seckey_struct->keynum_sk);
    if (crypto_pwhash_scryptsalsa208sha256
        (stream, sizeof seckey_struct->keynum_sk, pwd, strlen(pwd),
         seckey_struct->kdf_salt,
         le64_load(seckey_struct->kdf_opslimit_le),
         le64_load(seckey_struct->kdf_memlimit_le)) != 0) {
        abort();
    }
    sodium_free(pwd);
    sodium_free(pwd2);
    xor_buf((unsigned char *) (void *) &seckey_struct->keynum_sk, stream,
            sizeof seckey_struct->keynum_sk);
    sodium_free(stream);
    puts("done\n");

    if ((fp = fopen_create_useronly(sk_file)) == NULL) {
        exit_err(sk_file);
    }
    xfprintf(fp, "%s%s\n", COMMENT_PREFIX, comment);
    xfput_b64(fp, (unsigned char *) (void *) seckey_struct,
              sizeof *seckey_struct);
    xfclose(fp);
    sodium_free(seckey_struct);

    if ((fp = fopen(pk_file, "w")) == NULL) {
        exit_err(pk_file);
    }
    xfprintf(fp, COMMENT_PREFIX "minisign public key %" PRIX64 "\n",
             le64_load(pubkey_struct->keynum_pk.keynum));
    xfput_b64(fp, (unsigned char *) (void *) pubkey_struct,
              sizeof *pubkey_struct);
    xfclose(fp);

    printf("The secret key was saved as %s - Keep it secret!\n", sk_file);
    printf("The public key was saved as %s - That one can be public.\n\n", pk_file);
    puts("Files signed using this key pair can be verified with the following command:\n");
    printf("minisign -Vm <file> -P ");
    xfput_b64(stdout, (unsigned char *) (void *) pubkey_struct,
              sizeof *pubkey_struct);
    puts("");
    sodium_free(pubkey_struct);

    return 0;
}
Ejemplo n.º 17
0
static int
sign(const char *sk_file, const char *message_file, const char *sig_file,
     const char *comment, const char *trusted_comment, int hashed)
{
    unsigned char  global_sig[crypto_sign_BYTES];
    SigStruct      sig_struct;
    FILE          *fp;
    SeckeyStruct  *seckey_struct;
    unsigned char *message;
    unsigned char *sig_and_trusted_comment;
    size_t         comment_len;
    size_t         trusted_comment_len;
    size_t         message_len;

    seckey_struct = seckey_load(sk_file);
    message = message_load(&message_len, message_file, hashed);
    if (hashed != 0) {
        memcpy(sig_struct.sig_alg, SIGALG_HASHED, sizeof sig_struct.sig_alg);
    } else {
        memcpy(sig_struct.sig_alg, SIGALG, sizeof sig_struct.sig_alg);
    }
    memcpy(sig_struct.keynum, seckey_struct->keynum_sk.keynum,
           sizeof sig_struct.keynum);
    crypto_sign_detached(sig_struct.sig, NULL, message, message_len,
                         seckey_struct->keynum_sk.sk);
    free(message);
    if ((fp = fopen(sig_file, "w")) == NULL) {
        exit_err(sig_file);
    }
    comment_len = strlen(comment);
    assert(strrchr(comment, '\r') == NULL && strrchr(comment, '\n') == NULL);
    assert(COMMENTMAXBYTES > sizeof COMMENT_PREFIX);
    if (comment_len >= COMMENTMAXBYTES - sizeof COMMENT_PREFIX) {
        fprintf(stderr, "Warning: comment too long. "
                "This breaks compatibility with signify.\n");
    }
    xfprintf(fp, "%s%s\n", COMMENT_PREFIX, comment);
    xfput_b64(fp, (unsigned char *) (void *) &sig_struct, sizeof sig_struct);

    xfprintf(fp, "%s%s\n", TRUSTED_COMMENT_PREFIX, trusted_comment);
    trusted_comment_len = strlen(trusted_comment);
    assert(strrchr(trusted_comment, '\r') == NULL &&
           strrchr(trusted_comment, '\n') == NULL);
    if (trusted_comment_len >=
        TRUSTEDCOMMENTMAXBYTES - sizeof TRUSTED_COMMENT_PREFIX) {
        exit_msg("Trusted comment too long");
    }
    sig_and_trusted_comment = xmalloc((sizeof sig_struct.sig) +
                                      trusted_comment_len);
    memcpy(sig_and_trusted_comment, sig_struct.sig, sizeof sig_struct.sig);
    memcpy(sig_and_trusted_comment + sizeof sig_struct.sig, trusted_comment,
           trusted_comment_len);
    crypto_sign_detached(global_sig, NULL, sig_and_trusted_comment,
                         (sizeof sig_struct.sig) + trusted_comment_len,
                         seckey_struct->keynum_sk.sk);
    sodium_free(seckey_struct);
    xfput_b64(fp, (unsigned char *) (void *) &global_sig, sizeof global_sig);
    free(sig_and_trusted_comment);
    xfclose(fp);

    return 0;
}
Ejemplo n.º 18
0
static SeckeyStruct *
seckey_load(const char *sk_file)
{
    char           sk_comment[COMMENTMAXBYTES];
    unsigned char  chk[crypto_generichash_BYTES];
    SeckeyStruct  *seckey_struct;
    FILE          *fp;
    char          *pwd = xsodium_malloc(PASSWORDMAXBYTES);
    char          *seckey_s;
    unsigned char *stream;
    size_t         seckey_s_size;
    size_t         seckey_struct_len;

    if ((fp = fopen(sk_file, "r")) == NULL) {
        exit_err(sk_file);
    }
    if (fgets(sk_comment, (int) sizeof sk_comment, fp) == NULL) {
        exit_err(sk_file);
    }
    sodium_memzero(sk_comment, sizeof sk_comment);
    seckey_s_size = B64_MAX_LEN_FROM_BIN_LEN(sizeof *seckey_struct) + 2U;
    seckey_s = xsodium_malloc(seckey_s_size);
    seckey_struct = xsodium_malloc(sizeof *seckey_struct);
    if (fgets(seckey_s, (int) seckey_s_size, fp) == NULL) {
        exit_err(sk_file);
    }
    trim(seckey_s);
    xfclose(fp);
    if (b64_to_bin((unsigned char *) (void *) seckey_struct, seckey_s,
                   sizeof *seckey_struct, strlen(seckey_s),
                   &seckey_struct_len) == NULL ||
        seckey_struct_len != sizeof *seckey_struct) {
        exit_msg("base64 conversion failed");
    }
    sodium_free(seckey_s);
    if (memcmp(seckey_struct->sig_alg, SIGALG,
               sizeof seckey_struct->sig_alg) != 0) {
        exit_msg("Unsupported signature algorithm");
    }
    if (memcmp(seckey_struct->kdf_alg, KDFALG,
               sizeof seckey_struct->kdf_alg) != 0) {
        exit_msg("Unsupported key derivation function");
    }
    if (memcmp(seckey_struct->chk_alg, CHKALG,
               sizeof seckey_struct->chk_alg) != 0) {
        exit_msg("Unsupported checksum function");
    }
    if (get_password(pwd, PASSWORDMAXBYTES, "Password: "******"get_password()");
    }
    printf("Deriving a key from the password and decrypting the secret key... ");
    fflush(stdout);
    stream = xsodium_malloc(sizeof seckey_struct->keynum_sk);
    if (crypto_pwhash_scryptsalsa208sha256
        (stream, sizeof seckey_struct->keynum_sk, pwd, strlen(pwd),
         seckey_struct->kdf_salt,
         le64_load(seckey_struct->kdf_opslimit_le),
         le64_load(seckey_struct->kdf_memlimit_le)) != 0) {
        abort();
    }
    sodium_free(pwd);
    xor_buf((unsigned char *) (void *) &seckey_struct->keynum_sk, stream,
            sizeof seckey_struct->keynum_sk);
    sodium_free(stream);
    puts("done\n");
    seckey_chk(chk, seckey_struct);
    if (memcmp(chk, seckey_struct->keynum_sk.chk, sizeof chk) != 0) {
        exit_msg("Wrong password for that key");
    }
    sodium_memzero(chk, sizeof chk);

    return seckey_struct;
}
Ejemplo n.º 19
0
int main(int argc, char * argv[])
{

   int rep_tir_cpu;
   int z,i,x,y;
   int * permit_tir;
   var_game_t * var;

   init_var(1,&var);

   permit_tir = (int *)malloc(100*sizeof(int));
   if(permit_tir == NULL)
   {
      fprintf(var->log_erreur,"erreur dans l'allocation de permit_tir\n");
      exit_err(var);
   }
   for(i=0;i<100;i++)
      permit_tir[i] = i;

   clear
   printf("-----------------------------------------------------\n");
   printf("Bienvenue sur la version 0.1 de Navy Battle \n");
   printf("Cette version sert de test pour le moteur du jeu\n");
   printf("attention les cases vont de 0 a 9               \n");
   printf("-----------------------------------------------------\n");
   printf("-----------------------------------------------------\n");
   printf("placement des bateaux CPU\n");
   placement_alea(var);
   printf("-----------------------------------------------------\n");
   printf("placement de vos bateaux\n");
   placement_hum(var);
   printf("-----------------------------------------------------\n");
   printf("DEBUT DU JEU\n");
   clear
   while(var->remain_bat_cpu != 0 && var->remain_bat_hum != 0)
   {
      printf("-----------------------------------------------------\n");
      printf("-----------------------------------------------------\n");
      printf("votre matrice cible \n");
      affic_mat(var->mer_cible_hum,0);
      printf("-----------------------------------------------------\n");
      printf("-----------------------------------------------------\n");
      printf("votre matrice home\n");
      affic_mat(var->mer_home_hum,1);
      printf("-----------------------------------------------------\n");
      printf("-----------------------------------------------------\n");
      printf("A vous de tirer !\n");
      z = tir_humain(var);
      clear
      var->mer_cible_hum[z] = reponse_tir(z,1,var);
      switch(var->mer_cible_hum[z])
      {
         case 0: printf("Votre tir a rate\n");
                 break;
         case 1: printf("Votre tir a touche un bateau\n");
                 break;
         case 2: printf("Votre tir a touche et coule un bateau\n");
                 var->remain_bat_cpu = var->remain_bat_cpu - 1;
                 break;
      }
      printf("Au CPU de tirer\n");
      z = tir_alea(permit_tir, &rep_tir_cpu, var);
      trans1D_2D(z,&x,&y);
      printf("le CPU a tire a la case %d %d \n",x,y);
      switch(rep_tir_cpu)
      {
         case 0: printf("Son tir a rate\n");
                 break;
         case 1: printf("Son tir a touche un de vos bateau\n");
                 break;
         case 2: printf("Son tir a touche et coule un de vos bateau\n");
                 break;
      }
   }
   if(var->remain_bat_cpu == 0)
      printf("Bravo vous avez gagne!!!\n");
   else
      printf("dommage vous avez perdu \n");

   free(var->mer_home_cpu);
   free(var->mer_home_hum);
   free(var->mer_cible_cpu);
   free(var->mer_cible_hum);
   free(permit_tir);
   fclose(var->log_erreur);
   free(var);
   return(EXIT_SUCCESS);
}
Ejemplo n.º 20
0
static SigStruct *
sig_load(const char *sig_file, unsigned char global_sig[crypto_sign_BYTES],
         int *hashed, char trusted_comment[TRUSTEDCOMMENTMAXBYTES],
         size_t trusted_comment_maxlen)
{
    char       comment[COMMENTMAXBYTES];
    SigStruct *sig_struct;
    FILE      *fp;
    char      *global_sig_s;
    char      *sig_s;
    size_t     global_sig_len;
    size_t     global_sig_s_size;
    size_t     sig_s_size;
    size_t     sig_struct_len;

    if ((fp = fopen(sig_file, "r")) == NULL) {
        exit_err(sig_file);
    }
    if (fgets(comment, (int) sizeof comment, fp) == NULL) {
        exit_err(sig_file);
    }
    if (strncmp(comment, COMMENT_PREFIX, (sizeof COMMENT_PREFIX) - 1U) != 0) {
        exit_msg("Untrusted signature comment should start with "
                 "\"" COMMENT_PREFIX "\"");
    }
    sig_s_size = B64_MAX_LEN_FROM_BIN_LEN(sizeof *sig_struct) + 2U;
    sig_s = xmalloc(sig_s_size);
    if (fgets(sig_s, (int) sig_s_size, fp) == NULL) {
        exit_err(sig_file);
    }
    trim(sig_s);
    if (fgets(trusted_comment, (int) trusted_comment_maxlen, fp) == NULL) {
        exit_err(sig_file);
    }
    if (strncmp(trusted_comment, TRUSTED_COMMENT_PREFIX,
                (sizeof TRUSTED_COMMENT_PREFIX) - 1U) != 0) {
        exit_msg("Trusted signature comment should start with "
                 "\"" TRUSTED_COMMENT_PREFIX "\"");
    }
    memmove(trusted_comment,
            trusted_comment + sizeof TRUSTED_COMMENT_PREFIX - 1U,
            strlen(trusted_comment + sizeof TRUSTED_COMMENT_PREFIX - 1U) + 1U);
    trim(trusted_comment);
    global_sig_s_size = B64_MAX_LEN_FROM_BIN_LEN(crypto_sign_BYTES) + 2U;
    global_sig_s = xmalloc(global_sig_s_size);
    if (fgets(global_sig_s, (int) global_sig_s_size, fp) == NULL) {
        exit_err(sig_file);
    }
    trim(global_sig_s);
    xfclose(fp);

    sig_struct = xmalloc(sizeof *sig_struct);
    if (b64_to_bin((unsigned char *) (void *) sig_struct, sig_s,
                   sizeof *sig_struct, strlen(sig_s),
                   &sig_struct_len) == NULL ||
        sig_struct_len != sizeof *sig_struct) {
        exit_msg("base64 conversion failed");
    }
    free(sig_s);
    if (memcmp(sig_struct->sig_alg, SIGALG, sizeof sig_struct->sig_alg) == 0) {
        *hashed = 0;
    } else if (memcmp(sig_struct->sig_alg, SIGALG_HASHED,
                      sizeof sig_struct->sig_alg) == 0) {
        *hashed = 1;
    } else {
        exit_msg("Unsupported signature algorithm");
    }
    if (b64_to_bin(global_sig, global_sig_s, crypto_sign_BYTES,
                   strlen(global_sig_s), &global_sig_len) == NULL ||
        global_sig_len != crypto_sign_BYTES) {
        exit_msg("base64 conversion failed");
    }
    free(global_sig_s);

    return sig_struct;
}
Ejemplo n.º 21
0
int mode_solo(SDL_Surface * fenetre)
{
   int rep_tir_cpu;
   int i,x,y;
   int * permit_tir;
   var_game_t * var;

   init_var(1,&var);
   var->ecran = fenetre;
   SDL_BlitSurface(var->background,NULL,var->ecran,&(var->position_back));
   SDL_Flip(var->ecran);
   permit_tir = (int *)malloc(100*sizeof(int));
   if(permit_tir == NULL)
   {
      fprintf(var->log_erreur,"erreur dans l'allocation de permit_tir\n");
      exit_err(var);
   }
   for(i=0;i<100;i++)
      permit_tir[i] = i;
   
   placement_alea(var);

   message_box(var,"placement de vos bateau");
   placement_hum(var);

   affich_score(var,0);
   affich_score(var,1);
   
   while(var->remain_bat_cpu != 0 && var->remain_bat_hum != 0)
   {
      message_box(var,"A vous de tirer");
      var->z = tir_humain(var);
      var->mer_cible_hum[var->z] = reponse_tir(var->z,1,var);
      if(var->mer_cible_hum[var->z] == 2)
      {
         (var->remain_bat_cpu)--;
	 affich_score(var,1);
      }
      SDL_Delay(2500);
      if(var->remain_bat_hum != 0)
      {
         message_box(var,"Au CPU de tirer");
         var->z = tir_alea(permit_tir, &rep_tir_cpu, var);
         if(rep_tir_cpu == 2)
            affich_score(var,0);
      }
      SDL_Delay(2500);
   }
   if(var->remain_bat_cpu == 0)
   {
      message_box(var,"Bravo vous avez gagne(e)");
      FSOUND_PlaySound(FSOUND_FREE,var->gagne);
   }
   else
   {
      message_box(var,"Dommage vous avez perdu(e)");
      FSOUND_PlaySound(FSOUND_FREE,var->perdu);
   }
   
   SDL_Delay(3000);
   message_box(var,"le menu s'affichera dans 5s");
   SDL_Delay(5000);
   fin(var,0);
   return(EXIT_SUCCESS);
}
Ejemplo n.º 22
0
int main(int argc, char *argv[]) {
	if(argc != 2) {
		printf("Usage: xsvfplayer <filename>\n");
		return 1;
	}
	
	if(NULL == (file = fopen(argv[1], "r"))) {
		printf("Cannot open file.\n");
		return 1;
	}
	fseek(file, 0, SEEK_END);
	filesize = ftell(file);
	rewind(file);
	
	if(NULL == (xsvfprog = xsvfprog_open())) {
		printf("Cannot connect to XSVF player.\n");
		return 1;
	}
	if(SUCCESS != xsvfprog_init(xsvfprog)) {
		printf("Initialization of XSVF player failed.\n");
		xsvfprog_prgend(xsvfprog);
		return 1;
	}

#ifdef DEBUG
	debugfile = fopen("debug.xsvf", "w");
#endif
	printf("Programming...");
	while(!feof(file) && !quit) {
		bufsize = 0;
		/* get command */
		file2buf(1);
#ifdef DEBUG
		printf("instr 0x%02x: ", buf[0]);
#endif
		/* read additional command parameters */
		switch(buf[0]) {
		
		case XCOMPLETE:
			/* quit if XCOMPLETE command reached */
			quit = 1;
			break;
		
		case XREPEAT:
		case XSTATE:
		case XENDIR:
		case XENDDR:
			/* these commands need one additional byte */
			file2buf(1);
#ifdef DEBUG
			printf("par = %d, ", buf[1]);
#endif
			break;
		
		case XRUNTEST:
			/* this command needs four additional bytes */
			file2buf(4);
#ifdef DEBUG
			printf("delay = %d us, ", ntohl(*((long*) &buf[1])));
#endif
			break;
		
		case XTDOMASK:
		case XSDR:
		case XSDRB:
		case XSDRC:
		case XSDRE:
			/* these commands need drSize additional bits */
			file2buf(BITS_TO_BYTES(drSize));
			break;
		
		case XSDRTDO:
		case XSDRTDOB:
		case XSDRTDOC:
		case XSDRTDOE:
			/* these commands need 2x drSize additional bits */
			file2buf(2 * BITS_TO_BYTES(drSize));
			break;
		
		case XSDRSIZE:
			file2buf(4);
			drSize = ntohl(*((long*) &buf[1]));
#ifdef DEBUG
			printf("drSize = %d, ", drSize);
#endif
			if (BITS_TO_BYTES(drSize) > MAX_BITVEC_BYTES) {
				exit_err("\nData Register too long.\n");
			}
			break;
		
		case XSIR:
			file2buf(1);
			irSize = *((unsigned char*) &buf[1]);
#ifdef DEBUG
			printf("irSize = %d, ", irSize);
#endif
			if (BITS_TO_BYTES(irSize) > MAX_BITVEC_BYTES) {
				exit_err("\nInstruction Register too long.\n");
			}
			file2buf(BITS_TO_BYTES(irSize));
			break;
		
		case XSIR2:
			file2buf(2);
			irSize = ntohs(*((short*) &buf[1]));
#ifdef DEBUG
			printf("irSize = %d, ", irSize);
#endif
			if (BITS_TO_BYTES(irSize) > MAX_BITVEC_BYTES) {
				exit_err("\nInstruction Register too long.\n");
			}
			file2buf(BITS_TO_BYTES(irSize));
			break;
		
		case XSETSDRMASKS:
			file2buf(2 * BITS_TO_BYTES(drSize));
			drSize2 = BitStringOnes(drSize, &buf[1 + BITS_TO_BYTES(drSize)]);
#ifdef DEBUG
			printf("drSize2 = %d, ", drSize2);
#endif
			if (BITS_TO_BYTES(drSize2) > MAX_BITVEC_BYTES) {
				exit_err("\nData Register2 too long.\n");
			}
			break;
		
		case XSDRINC:
			file2buf(BITS_TO_BYTES(drSize) + 1);
			int num = *((unsigned char*) &buf[1 + BITS_TO_BYTES(drSize)]);
			file2buf(num * BITS_TO_BYTES(drSize2));
			break;
		
		case XCOMMENT:
			do {
				ch = fgetc(file);
			} while(ch != 0 && ch != EOF);
			/* we don't send comments to the programmer... */
			continue;
			break;
		
		default:
			exit_err("\nIllegal XSVF command.\n");
			break;
		
		}
		
#ifdef DEBUG
		printf("%d bytes long\n", bufsize);
		fwrite(buf, 1, bufsize, debugfile);
#endif
		
		ret = xsvfprog_exec(xsvfprog, buf, bufsize);
#ifdef DEBUG
		printf("%d\n", ret);
#endif

		switch(ret) {
		
		case 0:
			/* success, do nothing, just go on */
			break;
		
		case UNKNOWN_COMMAND:
			exit_err("\nProgramming error: Unknown command.\n");
			break;
		
		case XE_TDOMISMATCH:
			exit_err("\nProgramming error: Captured TDO value differs from expected TDO value.\n");
			break;
		
		case XE_ILLEGALCMD:
			exit_err("\nProgramming error: Illegal XSVF command.\n");
			break;
		
		case XE_ILLEGALSTATE:
			exit_err("\nProgramming error: Illegal TAP state.\n");
			break;
		
		case XE_DATAOVERFLOW:
			exit_err("\nProgramming error: Bit string overflow.\n");
			break;
		
		case XE_DATAUNDERFLOW:
			exit_err("\nProgramming error: End of command buffer reached expecting more data.\n");
			break;
		
		default:
			exit_err("\nUnknown programming error.\n");
			break;
		
		}

		filepos += bufsize;
		printf("\rProgramming... %3u%%", 100*filepos/filesize);
		fflush(stdout);
	}
	xsvfprog_prgend(xsvfprog);
	printf("\nDone.\n");
	
	fclose(file);
#ifdef DEBUG
	fclose(debugfile);
#endif
	xsvfprog_close(xsvfprog);
}
Ejemplo n.º 23
0
void placement_alea(var_game_t * var)
{
   int * permit_h = (int*) malloc(90*sizeof(int));
   int * permit_v = (int*) malloc(90*sizeof(int));

   int libre_h = 90;
   int libre_v = 90;

   int x=0,y=0,i,j,k,z,bateau;

   srand(time(NULL));

   if( permit_h == NULL || permit_v == NULL)
   {
      fprintf(var->log_erreur,"Erreur dans l'allocation des matrices de permitivite lors du placement alea\n");
      exit_err(var);
   }
   
   /*initialisation des matrices de permitivite*/
   for(i=0;i<90;i++)      /*init permit_v*/
   {
      permit_v[i]= i ;
   }

   for(i=0;i<90;i++)     /*init permit_h*/
   {
      if(x == 9)
      {
         ++y;
         x = 0;
      }
      permit_h[i]= y*10 + x++;
   }
   /*fin initialisation*/


   for(bateau=0;bateau<5;bateau++)
   {
      /*debut placement bateau*/
      /*correctif version 1.1 */

      if(libre_h == 0 || libre_v == 0)
      {
         if(libre_h == 0)
           var->flotte_cpu[bateau].sens=1;
         else
           var->flotte_cpu[bateau].sens=0;
      }
      else
         var->flotte_cpu[bateau].sens = rand()%2;
      /*fin correctif*/

      if(var->flotte_cpu[bateau].sens == 0) /*si sens horizontal*/
      {
         z= choix_alea(permit_h,libre_h);
         trans1D_2D(z,&x,&y);
         var->flotte_cpu[bateau].x = x;
         var->flotte_cpu[bateau].y = y;

         /*positionnement du bateau*/
         for(i=0;i<var->flotte_cpu[bateau].taille;i++)
            var->mer_home_cpu[z+i] = bateau;

         /*mise a jour de la matrice de permitivite */
         /* a cause du placement du bateau          */
         for(i=-1;i<=1;i++)
         {
            for(j=-1;j<=var->flotte_cpu[bateau].taille;j++)
            {
               suppr_point(permit_h,&libre_h,j+x,i+y);
               suppr_point(permit_v,&libre_v,j+x,i+y);
            }
         }
      }
      else /*si sens vertical*/
      {
         z= choix_alea(permit_v,libre_v);
         trans1D_2D(z,&x,&y);
         var->flotte_cpu[bateau].x = x;
         var->flotte_cpu[bateau].y = y;

         /*positionnement du bateau*/
         for(i=0;i<var->flotte_cpu[bateau].taille;i++)
            var->mer_home_cpu[z+10*i] = bateau;

         /*mise a jour de la matrice de permitivite */
         /* a cause du placement du bateau          */
         for(i=-1;i<=1;i++)
         {
            for(j=-1;j<=var->flotte_cpu[bateau].taille;j++)
            {
               suppr_point(permit_h,&libre_h,i+x,j+y);
               suppr_point(permit_v,&libre_v,i+x,j+y);
            }
         }
      }
      /*fin placement bateau*/

      /*debut maj des matrices de permitivites */
      if(bateau != 4)
      {
         /*on supprime les points selon la taille du bateau suivant*/
         /* pour la matrice horizontale*/
         for(j=1;j<var->flotte_cpu[bateau+1].taille;j++)
         {
            for(i=0;i<10;i++)
               suppr_point(permit_h,&libre_h,10-j,i);
         }

         /*pour la matrice verticale*/
         for(i=1;i<var->flotte_cpu[bateau+1].taille;i++)
         {
            for(j=0;j<10;j++)
               suppr_point(permit_v,&libre_v,j,10-i);
         }

         /*MAJ matrices selon les bateaux precedent*/
         for(k=bateau;k>=0;k--)
         {
            if(var->flotte_cpu[k].sens == 0) /*cas bateau horizontal*/
            {
               /*pour la partie horizontale*/
               for(j=2;j<=var->flotte_cpu[bateau+1].taille;j++)
               {
                  for(i=-1;i<=1;i++)
                     suppr_point(permit_h,&libre_h,var->flotte_cpu[k].x -j,var->flotte_cpu[k].y +i);
               }
               /*pour la partie verticale*/
               for(j=-1;j<=var->flotte_cpu[k].taille;j++)
               {
                  for(i=2;i<=var->flotte_cpu[bateau+1].taille;i++)
                     suppr_point(permit_v,&libre_v,var->flotte_cpu[k].x +j,var->flotte_cpu[k].y -i);
               }
            }
            else /*cas bateau vertical*/
            {
               /*pour la partie horizontale*/
               for(j=2;j<=var->flotte_cpu[bateau+1].taille;j++)
               {
                  for(i=-1;i<=var->flotte_cpu[k].taille;i++)
                     suppr_point(permit_h,&libre_h,var->flotte_cpu[k].x-j,var->flotte_cpu[k].y +i);
               }
               /*pour la partie verticale*/
               for(j=-1;j<=1;j++)
               {
                  for(i=2;i<=var->flotte_cpu[bateau+1].taille;i++)
                     suppr_point(permit_v,&libre_v,var->flotte_cpu[k].x +j,var->flotte_cpu[k].y -i);
               }
             }
         } 
       }
   }
   free(permit_v);
   free(permit_h);

}
Ejemplo n.º 24
0
void init_var(int cpu,var_game_t ** var)
{
  int i;

  /*allocation de la structure de variable*/
   *var = (var_game_t *)malloc(sizeof(var_game_t));

   if(*var == NULL)
      exit(EXIT_FAILURE);

   /*affectation des valeurs aux variables de la structure*/
   (*var)->remain_bat_hum = 5;
   (*var)->remain_bat_cpu = 5;

   /*initialisation du fichier d'erreur*/
   init_fic_erreur(*var);

   (*var)->mer_cible_hum = (int *)malloc(100*sizeof(int));
   (*var)->mer_home_hum = (int *)malloc(100*sizeof(int));

   /*correctif 1.1*/
   if( (*var)->mer_cible_hum == NULL || (*var)->mer_home_hum == NULL)
   {
      fprintf((*var)->log_erreur,"Erreur dans l'allocation des mers hum \n");
      exit_err(*var);
   }
   /*fin correctif 1.1*/

   for(i=0;i<100;i++)
   {
      (*var)->mer_cible_hum[i] = -1;
      (*var)->mer_home_hum[i] = -1;
   }

   if(cpu == 1)
   {
      (*var)->mer_home_cpu = (int *)malloc(100*sizeof(int));
      (*var)->mer_cible_cpu = (int *)malloc(100*sizeof(int));
        /*correctif 1.1*/
      if( (*var)->mer_cible_cpu == NULL || (*var)->mer_home_cpu == NULL)
      {
         fprintf((*var)->log_erreur,"Erreur dans l'allocation des mers cpu\n");
         exit_err(*var);
      }
        /*fin correctif 1.1*/
      for(i=0;i<100;i++)
      {
         (*var)->mer_cible_cpu[i] = -1;
         (*var)->mer_home_cpu[i] = -1;
      }
   }


   /*initialisation des flottes*/
   /*1er bateau*/
   (*var)->flotte_hum[0].vie = 2;
   (*var)->flotte_cpu[0].vie = 2;
   (*var)->flotte_hum[0].taille = 2;
   (*var)->flotte_cpu[0].taille = 2;

   /*2ieme bateau*/
   (*var)->flotte_hum[1].vie = 3;
   (*var)->flotte_cpu[1].vie = 3;
   (*var)->flotte_hum[1].taille = 3;
   (*var)->flotte_cpu[1].taille = 3;

   /*3ieme bateau*/
   (*var)->flotte_hum[2].vie = 3;
   (*var)->flotte_cpu[2].vie = 3;
   (*var)->flotte_hum[2].taille = 3;
   (*var)->flotte_cpu[2].taille = 3;

   /*4ieme bateau*/
   (*var)->flotte_hum[3].vie = 4;
   (*var)->flotte_cpu[3].vie = 4;
   (*var)->flotte_hum[3].taille = 4;
   (*var)->flotte_cpu[3].taille = 4;

   /*5ieme bateau*/
   (*var)->flotte_hum[4].vie = 6;
   (*var)->flotte_cpu[4].vie = 6;
   (*var)->flotte_hum[4].taille = 6;
   (*var)->flotte_cpu[4].taille = 6;

   /*init parametre son*/
   (*var)->mute = 1;
   #ifdef __WIN32__
      (*var)->tir_sound = FSOUND_Sample_Load(FSOUND_FREE, ".\\son\\tir.mp3", 0, 0, 0);
   #else
      (*var)->tir_sound = FSOUND_Sample_Load(FSOUND_FREE, "./son/tir.mp3", 0, 0, 0);
   #endif
   if((*var)->tir_sound == NULL)
   {
      fprintf((*var)->log_erreur,"fichier musique tir non trouve\n");
      exit_err(*var);
   }
   
   #ifdef __WIN32__
      (*var)->rate_sound = FSOUND_Sample_Load(FSOUND_FREE, ".\\son\\rate.wav", 0, 0, 0);
   #else
      (*var)->rate_sound = FSOUND_Sample_Load(FSOUND_FREE, "./son/rate.wav", 0, 0, 0);
   #endif
   if((*var)->rate_sound == NULL)
   {
      fprintf((*var)->log_erreur,"fichier musique rate non trouve\n");
      exit_err(*var);
   }
   
   #ifdef __WIN32__
      (*var)->coule_sound = FSOUND_Sample_Load(FSOUND_FREE, ".\\son\\coule.wav", 0, 0, 0);
   #else
      (*var)->coule_sound = FSOUND_Sample_Load(FSOUND_FREE, "./son/coule.wav", 0, 0, 0);
   #endif
   if((*var)->coule_sound == NULL)
   {
      fprintf((*var)->log_erreur,"fichier musique coule non trouve\n");
      exit_err(*var);
   }
   
   #ifdef __WIN32__
      (*var)->touche_sound = FSOUND_Sample_Load(FSOUND_FREE, ".\\son\\touche.wav", 0, 0, 0);
   #else
      (*var)->touche_sound = FSOUND_Sample_Load(FSOUND_FREE, "./son/touche.wav", 0, 0, 0);
   #endif
   if((*var)->touche_sound == NULL)
   {
      fprintf((*var)->log_erreur,"fichier musique touche non trouve\n");
      exit_err(*var);
   }
   
   #ifdef __WIN32__
      (*var)->place_sound = FSOUND_Sample_Load(FSOUND_FREE, ".\\son\\place.wav", 0, 0, 0);
   #else
      (*var)->place_sound = FSOUND_Sample_Load(FSOUND_FREE, "./son/place.wav", 0, 0, 0);
   #endif
   if((*var)->place_sound == NULL)
   {
      fprintf((*var)->log_erreur,"fichier musique place non trouve\n");
      exit_err(*var);
   }
   
   #ifdef __WIN32__
      (*var)->gagne = FSOUND_Sample_Load(FSOUND_FREE, ".\\son\\gagne.wav", 0, 0, 0);
   #else
      (*var)->gagne = FSOUND_Sample_Load(FSOUND_FREE, "./son/gagne.wav", 0, 0, 0);
   #endif
   if((*var)->gagne == NULL)
   {
      fprintf((*var)->log_erreur,"fichier musique gagne non trouve\n");
      exit_err(*var);
   }
   
   #ifdef __WIN32__
   (*var)->perdu = FSOUND_Sample_Load(FSOUND_FREE, ".\\son\\perdu.wav", 0, 0, 0);
   #else
      (*var)->perdu = FSOUND_Sample_Load(FSOUND_FREE, "./son/perdu.wav", 0, 0, 0);
   #endif
   if((*var)->perdu == NULL)
   {
      fprintf((*var)->log_erreur,"fichier musique perdu non trouve\n");
      exit_err(*var);
   }
  
   /*fin init parametre son*/
   /*init parametres video*/
   
   /*allocation des parametres de la message_box*/
   
   #ifdef __WIN32__
      (*var)->message_img = IMG_Load(".\\dessin\\box.jpg");
   #else
      (*var)->message_img = IMG_Load("./dessin/box.jpg");
   #endif
   if((*var)->message_img == NULL)
   {
      fprintf((*var)->log_erreur,"erreur chargement image box\n");
      exit_err(*var);
   }
   (*var)->box_position.x = 100;
   (*var)->box_position.y = 725;
   #ifdef __WIN32__
      (*var)->police_box = TTF_OpenFont(".\\police\\game_over.ttf",80);
   #else
      (*var)->police_box = TTF_OpenFont("./police/game_over.ttf",80);
   #endif
   if((*var)->police_box == NULL)
   {
      fprintf((*var)->log_erreur,"erreur chargement police game_over\n");
      exit_err(*var);
   }
   
   /*allocation des parametres de l'affichage des scores*/
   #ifdef __WIN32__
      (*var)->score = IMG_Load(".\\dessin\\score.jpg");
   #else
      (*var)->score = IMG_Load("./dessin/score.jpg");
   #endif
   if((*var)->score == NULL)
   {
      fprintf((*var)->log_erreur,"erreur chargement image score\n");
      exit_err(*var);
   }
   (*var)->score_position.x = 100;
   #ifdef __WIN32__
      (*var)->police_score = TTF_OpenFont(".\\police\\score.ttf",100);
   #else
      (*var)->police_score = TTF_OpenFont("./police/score.ttf",100);
   #endif
   if((*var)->police_score == NULL)
   {
      fprintf((*var)->log_erreur,"erreur chargement police score\n");
      exit_err(*var);
   }
   
   
   /*allocation des parametre d'affiche des boutons mute/unmute*/
  
   /*mise en pause pour une version suivante
   (*var)->mute_button = IMG_Load("mute.jpg");
   if((*var)->mute_button == NULL)
   {
      fprintf((*var)->log_erreur,"erreur chargement image mute\n");
      exit_err(*var);
   }
   (*var)->unmute_button = IMG_Load("unmute.jpg");
   if((*var)->unmute_button == NULL)
   {
      fprintf((*var)->log_erreur,"erreur chargement image unmute\n");
      exit_err(*var);
   }
   (*var)->mute_position.x = 725;
   (*var)->mute_position.y = 25;
   fonctionnalite a develloper prochaine version*/
   
   /*allocation des affichages rate/touche/fragments_bateau des mers*/
   #ifdef __WIN32__
      (*var)->rate = IMG_Load(".\\dessin\\rate.jpg");
   #else
      (*var)->rate = IMG_Load("./dessin/rate.jpg");
   #endif
   if((*var)->rate == NULL)
   {
      fprintf((*var)->log_erreur,"erreur chargement image rate\n");
      exit_err(*var);
   }
   #ifdef __WIN32__
      (*var)->touche = IMG_Load(".\\dessin\\touche.jpg");
   #else
      (*var)->touche = IMG_Load("./dessin/touche.jpg");
   #endif
   if((*var)->touche == NULL)
   {
      fprintf((*var)->log_erreur,"erreur chargement image touche\n");
      exit_err(*var);
   }
   #ifdef __WIN32__
      (*var)->frag_bat = IMG_Load(".\\dessin\\fragbat.jpg");
   #else
      (*var)->frag_bat = IMG_Load("./dessin/fragbat.jpg");
   #endif
   if((*var)->frag_bat == NULL)
   {
      fprintf((*var)->log_erreur,"erreur chargement image fragment bateau\n");
      exit_err(*var);
   }
   /*allocation fond d'ecran*/
   #ifdef __WIN32__
      (*var)->background = IMG_Load(".\\dessin\\background.jpg");
   #else
      (*var)->background = IMG_Load("./dessin/background.jpg");
   #endif
   if((*var)->background == NULL)
   {
      fprintf((*var)->log_erreur,"erreur chargement image background\n");
      exit_err(*var);
   }
   (*var)->position_back.x = 0;
   (*var)->position_back.y = 0;
   
}