Ejemplo n.º 1
0
void cantorize_set(sc_memory_context *context, scp_operand *set)
{
    GHashTable *table;
    scp_operand elem, arc;
    MAKE_DEFAULT_ARC_ASSIGN(arc);
    arc.erase = SCP_TRUE;
    MAKE_DEFAULT_OPERAND_ASSIGN(elem);
    table = g_hash_table_new(NULL, NULL);
    scp_iterator3 *it = scp_iterator3_new(context, set, &arc, &elem);
    while (SCP_RESULT_TRUE == scp_iterator3_next(context, it, set, &arc, &elem))
    {
        if (TRUE == g_hash_table_contains(table, MAKE_HASH(elem)))
        {
            arc.param_type = SCP_FIXED;
            eraseEl(context, &arc);
            arc.param_type = SCP_ASSIGN;
        }
        else
        {
            g_hash_table_add(table, MAKE_HASH(elem));
        }
    }
    scp_iterator3_free(it);
    g_hash_table_destroy(table);
}
Ejemplo n.º 2
0
static unsigned int pd_hash_value(ProcDict *pdict, Eterm term) 
{ 
    Uint hash, high;

    hash = MAKE_HASH(term);
    high = hash % (pdict->homeSize*2);
    if (high >= HASH_RANGE(pdict))
	return hash % pdict->homeSize;
    return high;
}
Ejemplo n.º 3
0
void load_set_to_hash(sc_memory_context *context, scp_operand *set, GHashTable *table)
{
    scp_operand arc1, elem;
    scp_iterator3 *it;
    MAKE_DEFAULT_ARC_ASSIGN(arc1);
    MAKE_DEFAULT_OPERAND_ASSIGN(elem);
    it = scp_iterator3_new(context, set, &arc1, &elem);
    while (SCP_RESULT_TRUE == scp_iterator3_next(context, it, set, &arc1, &elem))
    {
        g_hash_table_add(table, MAKE_HASH(elem));
    }
    scp_iterator3_free(it);
}
Ejemplo n.º 4
0
Archivo: spki.c Proyecto: macssh/macssh
struct sexp *
spki_hash_data(struct hash_algorithm *algorithm,
	       int algorithm_name,
	       UINT32 length, UINT8 *data)
{
  struct hash_instance *hash = MAKE_HASH(algorithm);
  struct lsh_string *out = lsh_string_alloc(hash->hash_size);

  HASH_UPDATE(hash, length, data);
  HASH_DIGEST(hash, out->data);

  return sexp_l(3,
		SA(HASH),
		sexp_a(algorithm_name),
		sexp_s(NULL, out), -1);
}  
Ejemplo n.º 5
0
struct randomness_with_poll *
make_arcfour_random(struct random_poll *poller,
		    struct hash_algorithm *hash,
		    struct exception_handler *e)
{
  NEW(arcfour_random, self);
  self->super.super.random = do_arcfour_random_slow;
  self->super.super.quality = 0;

  self->super.poller = poller;
  self->e = e;
  
  self->staging_area = MAKE_HASH(hash);
  self->staging_count = 0;
  
  return &self->super;
}
Ejemplo n.º 6
0
struct randomness *
make_poor_random(struct hash_algorithm *hash,
		 struct lsh_string *init)
{
  NEW(poor_random, self);
  time_t now = time(NULL); 
#ifndef MACOS
  pid_t pid = getpid();
#else
#ifdef __powerc
  pid_t pid = GetPPCTimer();
#else
  pid_t pid = (pid_t)TickCount();
#endif
  Point mouseLoc;
#endif
  
  self->super.random = do_poor_random;
  self->super.quality = 0;
  
  self->hash = MAKE_HASH(hash);
  self->buffer = lsh_space_alloc(hash->hash_size);
  
  HASH_UPDATE(self->hash, sizeof(now), (UINT8 *) &now);
  HASH_UPDATE(self->hash, sizeof(pid), (UINT8 *) &pid);
#ifdef MACOS
  GetMouse(&mouseLoc);
  HASH_UPDATE(self->hash, sizeof(mouseLoc), (UINT8 *) &mouseLoc);
#endif
  
  if (init)
    {
      HASH_UPDATE(self->hash, init->length, init->data);
      lsh_string_free(init);
    }
  HASH_DIGEST(self->hash, self->buffer);

  self->pos = 0;

  return &self->super;
}
Ejemplo n.º 7
0
Archivo: rsa.c Proyecto: macssh/macssh
static void
pkcs1_encode(mpz_t m,
	     struct rsa_algorithm *params,
	     UINT32 length,
	     UINT32 msg_length,
	     const UINT8 *msg)
{
#if ALLOCA_68K_BUG
  ALLOCA_START(alloca_ref);
#endif
  UINT8 *em = alloca(length);
  unsigned i = length;
  
  struct hash_instance *h = MAKE_HASH(params->hash);
  HASH_UPDATE(h, msg_length, msg);

  assert(i >= h->hash_size);
  i -= h->hash_size;

  HASH_DIGEST(h, em + i);
  KILL(h);

  assert(i >= params->prefix_length);
  i -= params->prefix_length;

  memcpy(em + i, params->prefix, params->prefix_length);

  assert(i);
  em[--i] = 0;

  assert(i >= 9);
  em[0] = 1;
  memset(em + 1, 0xff, i - 1);
  
  bignum_parse_u(m, length, em);

  debug("pkcs1_encode: m = %xn\n", m);
#if ALLOCA_68K_BUG
  ALLOCA_FREE(alloca_ref);
#endif
}
Ejemplo n.º 8
0
void delete_vars_from_relation(sc_memory_context *context, scp_operand *set, GHashTable *non_erasable_vars)
{
    scp_operand arc1, arc2, elem, rel_elem;
    scp_iterator5 *it;
    scp_iterator3 *it0;
    MAKE_DEFAULT_ARC_ASSIGN(arc1);
    MAKE_DEFAULT_ARC_ASSIGN(arc2);
    MAKE_DEFAULT_OPERAND_ASSIGN(elem);
    MAKE_DEFAULT_OPERAND_ASSIGN(rel_elem);
    elem.erase = SCP_TRUE;
    rel_elem.erase = SCP_TRUE;

    it0 = scp_iterator3_new(context, set, &arc1, &rel_elem);
    while (SCP_RESULT_TRUE == scp_iterator3_next(context, it0, set, &arc1, &rel_elem))
    {
        rel_elem.param_type = SCP_FIXED;
        it = scp_iterator5_new(context, &rel_elem, &arc1, &elem, &arc2, &rrel_scp_var);
        while (SCP_RESULT_TRUE == scp_iterator5_next(context, it, &rel_elem, &arc1, &elem, &arc2, &rrel_scp_var))
        {
            elem.param_type = SCP_FIXED;
            if (non_erasable_vars != nullptr && FALSE == g_hash_table_contains(non_erasable_vars, MAKE_HASH(elem)))
            {
                eraseEl(context, &elem);
            }
            elem.param_type = SCP_ASSIGN;
        }
        scp_iterator5_free(it);
        eraseEl(context, &rel_elem);
        rel_elem.param_type = SCP_ASSIGN;
    }
    scp_iterator3_free(it0);
}