Exemplo n.º 1
0
static int map_md5(fmap_t *map, const void *data, unsigned int len, uint8_t *md5) {
    if(!fmap_need_ptr_once(map, data, len)) {
	cli_dbgmsg("map_md5: failed to read hash data\n");
	return 1;
    }
    return (cl_hash_data("md5", data, len, md5, NULL) == NULL);
}
Exemplo n.º 2
0
uint32_t uniq_get(struct uniq *U, const char *key, uint32_t key_len, char **rhash) {
  uint8_t digest[16];
  struct UNIQMD5 *m = NULL;

  cl_hash_data("md5", key, key_len, digest, NULL);

  if(!U->items || U->md5s[U->idx[*digest]].md5[0]!=*digest)
    return 0;

  for(m=&U->md5s[U->idx[*digest]]; m; m=m->next) {
    if(memcmp(&digest[1], &m->md5[1], 15)) continue;
    if(rhash) *rhash = m->name;
    return m->count;
  }

  return 0;
}
Exemplo n.º 3
0
uint32_t uniq_add(struct uniq *U, const char *key, uint32_t key_len, char **rhash) {
  unsigned int i;
  uint8_t digest[16];
  struct UNIQMD5 *m = NULL;

  cl_hash_data("md5", key, key_len, digest, NULL);

  if(U->items && U->md5s[U->idx[*digest]].md5[0]==*digest)
    for(m=&U->md5s[U->idx[*digest]]; m; m=m->next)
      if(!memcmp(&digest[1], &m->md5[1], 15)) break;
  
  if(!m) {
    const char HEX[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

    m = &U->md5s[U->items];
    m->count = 0;

    if(U->items && U->md5s[U->idx[*digest]].md5[0]==*digest)
      m->next = &U->md5s[U->idx[*digest]];
    else
      m->next = NULL;

    U->idx[*digest]=U->items;

    for(i = 0; i < 16; i++) {
      m->name[i*2] = HEX[digest[i]>>4 & 0xf];
      m->name[i*2+1] = HEX[digest[i] & 0xf];
      m->md5[i] = digest[i];
    }
    m->name[32] = '\0';
  }

  U->items++;
  if(rhash) *rhash = m->name;
  return m->count++;
}