gg-crypto-ucryptolib.c
GG_crypt *crypto_global_init(void) {
  GG_crypt *ggc;
  int dev_urandom;

  /* pre-open urandom so that we can use it later */
  dev_urandom = open("/dev/urandom", O_RDONLY);
  if (dev_urandom == -1) {
    REPORT_ERRNO("Could not open /dev/urandom");
    return NULL;
  }

  ggc = xmalloc(sizeof(GG_crypt));

  *ggc = (GG_crypt) {
    .dev_urandom = dev_urandom,
    .pubkey_bin_len = 0,
    .dh_shared_secret = NULL,
    .remote_key = NULL,
  };

  /* TODO: replace myDH with pointer */
  ggc->myDH = (clBignumModulus) precomputed_dh;

  /* allocate memory for the result of DH_compute_key */
  ggc->dh_shared_secret = xmalloc(ggc->myDH.size);
  ggc->dh_shared_secret_size = ggc->myDH.size;

  /* cryptolib */
  ggc->pubkey_bin = xmalloc(ggc->myDH.size);
  ggc->pubkey_bin_len = ggc->myDH.size;

  ggc->remote_key = xmalloc(ggc->myDH.size);
  ggc->remote_key_len = ggc->myDH.size;

  return ggc;
}
/*
 * Allocate and initialize a GG_crypt structure
 * Return NULL on failure
 *
 * There are two stages, global and worker, this is the first one.
 */
Allocate and initialize a GG_crypt structure
Return NULL on failure

There are two stages, global and worker, this is the first one.
Allocate and initialize a GG_crypt structure Return NULL on failure There are two stages global and worker this is the first one .
GG_crypt *crypto_global_init(void) {
  GG_crypt *ggc;
  int dev_urandom;
  dev_urandom = open("/dev/urandom", O_RDONLY);
  if (dev_urandom == -1) {
    REPORT_ERRNO("Could not open /dev/urandom");
    return NULL;
  }
  ggc = xmalloc(sizeof(GG_crypt));
  *ggc = (GG_crypt) {
    .dev_urandom = dev_urandom,
    .pubkey_bin_len = 0,
    .dh_shared_secret = NULL,
    .remote_key = NULL,
  };
  ggc->myDH = (clBignumModulus) precomputed_dh;
  ggc->dh_shared_secret = xmalloc(ggc->myDH.size);
  ggc->dh_shared_secret_size = ggc->myDH.size;
  ggc->pubkey_bin = xmalloc(ggc->myDH.size);
  ggc->pubkey_bin_len = ggc->myDH.size;
  ggc->remote_key = xmalloc(ggc->myDH.size);
  ggc->remote_key_len = ggc->myDH.size;
  return ggc;
}
GG_crypt * crypto_global_init ( void ) { GG_crypt * ggc ; int dev_urandom ; dev_urandom = open ( " " , O_RDONLY ) ; if ( dev_urandom == -1 ) { REPORT_ERRNO ( " " ) ; return NULL ; } ggc = xmalloc ( sizeof ( GG_crypt ) ) ; * ggc = ( GG_crypt ) { . dev_urandom = dev_urandom , . pubkey_bin_len = 0 , . dh_shared_secret = NULL , . remote_key = NULL , } ; ggc -> myDH = ( clBignumModulus ) precomputed_dh ; ggc -> dh_shared_secret = xmalloc ( ggc -> myDH . size ) ; ggc -> dh_shared_secret_size = ggc -> myDH . size ; ggc -> pubkey_bin = xmalloc ( ggc -> myDH . size ) ; ggc -> pubkey_bin_len = ggc -> myDH . size ; ggc -> remote_key = xmalloc ( ggc -> myDH . size ) ; ggc -> remote_key_len = ggc -> myDH . size ; return ggc ; }
Allocate and initialize a GG_crypt structure
 Return NULL on failure
Allocate and initialize a GG_crypt structure Return NULL on failure
/* pre-open urandom so that we can use it later */ /* TODO: replace myDH with pointer */ /* allocate memory for the result of DH_compute_key */ /* cryptolib */