示例#1
0
void send_keys(struct network_status *net_stat, struct keypair *keypair)
  /*@ requires [?f0]world(?pub, ?key_clsfy) &*&
               keypair(keypair, ?attacker_id, ?id, ?info, pub) &*&
               proof_obligations(pub) &*&
               network_status(net_stat) &*&
               principal(attacker_id, ?count1) &*&
               true == bad(attacker_id); @*/
  /*@ ensures  [f0]world(pub, key_clsfy) &*&
               keypair(keypair, attacker_id, id, info, pub) &*&
               proof_obligations(pub) &*&
               network_status(net_stat) &*&
               principal(attacker_id, ?count2); @*/
{
  //@ close key_request(attacker_id, 0);
  struct item *key_sym = create_symmetric_key();
  struct item *key_priv = keypair_get_private_key(keypair);
  struct item *key_pub = keypair_get_public_key(keypair);
  //@ assert item(key_sym, ?k_sym, pub);
  //@ assert item(key_pub, ?k_pub, pub);
  //@ assert item(key_priv, ?k_priv, pub);
  //@ open proof_obligations(pub);
  //@ assert is_public_symmetric_key(?proof_sym, pub);
  //@ assert is_public_public_key(?proof_pub, pub);
  //@ assert is_public_private_key(?proof_priv, pub);
  //@ proof_sym(k_sym);
  //@ proof_pub(k_pub);
  //@ proof_priv(k_priv);
  //@ close proof_obligations(pub);
  network_send(net_stat, key_sym);
  network_send(net_stat, key_pub);
  network_send(net_stat, key_priv);
  item_free(key_sym);
  item_free(key_pub);
  item_free(key_priv);
}
示例#2
0
struct item *app_receive(struct item *key)
  /*@ requires [?f0]world(ss_pub) &*&
               item(key, symmetric_key_item(?creator, ?id), ss_pub);
  @*/
  /*@ ensures  [f0]world(ss_pub) &*&
               item(key, symmetric_key_item(creator, id), ss_pub) &*&
               item(result, ?msg, ss_pub) &*& 
               (
                 bad(creator) || 
                 collision_in_run() || 
                 app_send_event(creator, msg)
               );
  @*/
{
    struct network_status *net_stat = network_bind_and_accept(APP_RECEIVE_PORT);
    
    struct item *m = network_receive(net_stat);
    struct item *hash = pair_get_first(m);
    struct item *message = pair_get_second(m);
    //@ assert item(m, pair_item(?hmac_i, ?message_i), ss_pub);
    //@ open [_]ss_pub(pair_item(hmac_i, message_i));
    //@ if (!collision_in_run()) open [_]ss_pub(hmac_i);
    //@ if (!collision_in_run()) open [_]ss_pub(message_i);
    item_free(m);
    hmac_verify(hash, key, message);
    item_free(hash);
    
    network_disconnect(net_stat);
    
    return message;
}
示例#3
0
void app_send(struct item *key, struct item *message)
  /*@ requires [?f0]world(ss_pub) &*&
               item(key, symmetric_key_item(?creator, ?id), ss_pub) &*& 
               item(message, ?msg, ss_pub) &*& [_]ss_pub(msg) &*&
               app_send_event(creator, msg) == true;
  @*/
  /*@ ensures  [f0]world(ss_pub) &*&
               item(key, symmetric_key_item(creator, id), ss_pub) &*&
               item(message, msg, ss_pub);
  @*/
{
    struct network_status *net_stat = 
                                 network_connect("localhost", APP_RECEIVE_PORT);
    
    struct item *hash = create_hmac(key, message);
    //@ assert item(hash, ?h, ss_pub);
    //@ get_info_for_item(h);
    //@ close ss_pub(h);
    //@ leak ss_pub(h);
    struct item *m = create_pair(hash, message);
    //@ assert item(m, ?pmessage, ss_pub);
    //@ get_info_for_item(pmessage);
    //@ close ss_pub(pmessage);
    //@ leak ss_pub(pmessage);
    network_send(net_stat, m);
    item_free(hash);
    item_free(m);
    
    network_disconnect(net_stat);
}
示例#4
0
void send_pair_decomposed(struct network_status *net_stat)
  /*@ requires [?f0]world(?pub, ?key_clsfy) &*&
               proof_obligations(pub) &*&
               network_status(net_stat) &*&
               principal(?principal, ?count1) &*&
               true == bad(principal); @*/
  /*@ ensures  [f0]world(pub, key_clsfy) &*&
               proof_obligations(pub) &*&
               network_status(net_stat) &*&
               principal(principal, ?count2); @*/
{
  struct item *pair = network_receive(net_stat);
  //@ assert item(pair, ?p, pub);
  if (is_pair(pair))
  {
    struct item *first = pair_get_first(pair);
    struct item *second = pair_get_second(pair);
    //@ open proof_obligations(pub);
    //@ assert is_public_pair_decompose(?proof1, pub);
    //@ assert is_public_collision(?proof2, pub);
    //@ proof1(p);
    //@ assert item(first, ?f, pub);
    //@ if (col) proof2(f);
    //@ assert item(second, ?s, pub);
    //@ if (col) proof2(s);
    //@ close proof_obligations(pub);
    network_send(net_stat, first);
    network_send(net_stat, second);
    item_free(first);
    item_free(second);
  }
  item_free(pair);
}
示例#5
0
void send_pair_composed(struct network_status *net_stat)
  /*@ requires [?f0]world(?pub, ?key_clsfy) &*&
               proof_obligations(pub) &*&
               network_status(net_stat) &*&
               principal(?principal, ?count1) &*&
               true == bad(principal); @*/
  /*@ ensures  [f0]world(pub, key_clsfy) &*&
               proof_obligations(pub) &*&
               network_status(net_stat) &*&
               principal(principal, ?count2); @*/
{
  struct item *first = network_receive(net_stat);
  struct item *second = network_receive(net_stat);
  struct item * pair = create_pair(first, second);
  //@ assert item(first, ?f, pub);
  //@ assert item(second, ?s, pub);
  //@ assert item(pair, pair_item(f, s), pub);

  //@ open proof_obligations(pub);
  //@ assert is_public_pair_compose(?proof, pub);
  //@ proof(f, s);
  //@ close proof_obligations(pub);
  network_send(net_stat, pair);
  item_free(pair);
  item_free(first);
  item_free(second);
}
示例#6
0
/* if return item is not NULL, free by caller */
item *item_get(char *key, size_t nkey){
    item *it = NULL;
    DBT dbkey, dbdata;
    bool stop;
    int ret;
    
    /* first, alloc a fixed size */
    it = item_alloc2(settings.item_buf_size);
    if (it == 0) {
        return NULL;
    }

    BDB_CLEANUP_DBT();
    dbkey.data = key;
    dbkey.size = nkey;
    dbdata.ulen = settings.item_buf_size;
    dbdata.data = it;
    dbdata.flags = DB_DBT_USERMEM;

    stop = false;
    /* try to get a item from bdb */
    while (!stop) {
        switch (ret = dbp->get(dbp, NULL, &dbkey, &dbdata, 0)) {
        case DB_BUFFER_SMALL:    /* user mem small */
            /* free the original smaller buffer */
            item_free(it);
            /* alloc the correct size */
            it = item_alloc2(dbdata.size);
            if (it == NULL) {
                return NULL;
            }
            dbdata.ulen = dbdata.size;
            dbdata.data = it;
            break;
        case 0:                  /* Success. */
            stop = true;
            break;
        case DB_NOTFOUND:
            stop = true;
            item_free(it);
            it = NULL;
            break;
        default:
            /* TODO: may cause bug here, if return DB_BUFFER_SMALL then retun non-zero again
             * here 'it' may not a full one. a item buffer larger than item_buf_size may be added to freelist */
            stop = true;
            item_free(it);
            it = NULL;
            if (settings.verbose > 1) {
                fprintf(stderr, "dbp->get: %s\n", db_strerror(ret));
            }
        }
    }
    return it;
}
struct item *asymmetric_authenticated_decryption(char recipient,
                                                 struct item *public_key,
                                                 struct item *private_key, 
                                                 struct item *message)
  /*@ requires [?f]world(?pub) &*&
               generated_values(?principal1, ?count1) &*&
               item(public_key, ?pub_k, pub) &*& 
                 pub_k == public_key_item(?principal2, ?count2) &*&
               item(private_key, ?priv_k, pub) &*& 
                 priv_k == private_key_item(?principal3, ?count3) &*&
               item(message, ?msg, pub); @*/
  /*@ ensures  [f]world(pub) &*&
               generated_values(principal1, count1 + 1) &*&
               item(public_key, pub_k, pub) &*&
               item(private_key, priv_k, pub) &*&
               item(message, msg, pub) &*&
               item(result, ?decrypted, pub) &*& 
               collision_in_run() ?
                 true
               :
                 msg == pair_item(?enc, ?sig) &*& 
                 enc == asymmetric_encrypted_item(?principal4, ?count4, 
                                                  ?pay, _) &*&
                 sig == asymmetric_signature_item(principal2, count2, 
                                                  some(?msg_id), _) &*&
                 msg_id == pair_item(data_item(cons(recipient, nil)), 
                                     hash_item(some(enc))) &*&
                 principal4 == principal3 && count4 == count3 ?
                   pay == some(decrypted)
                 :
                   [_]pub(decrypted)
               ; @*/
{
  check_is_pair(message);
  struct item* encrypted = pair_get_first(message);
  check_is_asymmetric_encrypted(encrypted);
  struct item* signature = pair_get_second(message);
  struct item* rcp = create_data_item_from_char(recipient);  
  struct item* hash = create_hash(encrypted);
  struct item* pair = create_pair(rcp, hash);
  asymmetric_signature_verify(public_key, pair, signature);
  struct item *result = asymmetric_decryption(private_key, encrypted);
  item_free(encrypted);
  item_free(rcp);
  item_free(pair);
  item_free(hash);
  item_free(signature);
  
  return result;
}
示例#8
0
文件: items.c 项目: MediaMath/moxi
void do_item_remove(item *it) {
#ifdef MOXI_ITEM_MALLOC
    item_free(it);
#else
    MEMCACHED_ITEM_REMOVE(ITEM_key(it), it->nkey, it->nbytes);
    assert((it->it_flags & ITEM_SLABBED) == 0);
    if (it->refcount != 0) {
        it->refcount--;
        DEBUG_REFCNT(it, '-');
    }
    if (it->refcount == 0 && (it->it_flags & ITEM_LINKED) == 0) {
        item_free(it);
    }
#endif
}
示例#9
0
void increment_and_send_nonce(struct network_status *net_stat)
  /*@ requires [?f0]world(?pub, ?key_clsfy) &*&
               proof_obligations(pub) &*&
               network_status(net_stat) &*&
               principal(?principal, ?count1) &*&
               true == bad(principal); @*/
  /*@ ensures  [f0]world(pub, key_clsfy) &*&
               proof_obligations(pub) &*&
               network_status(net_stat) &*&
               principal(principal, ?count2); @*/
{
  struct item *nonce = network_receive(net_stat);
  //@ assert item(nonce, ?n, pub);
  if (is_nonce(nonce))
  {
    increment_nonce(nonce);
    //@ assert item(nonce, ?n_inc, pub);
    //@ open proof_obligations(pub);
    /*@ if (col)
        {
          assert is_public_collision(?proof, pub);
          proof(n_inc);
        }
        else
        {
          assert is_public_incremented_nonce(?proof, pub);
          proof(n, n_inc);
        }
    @*/
    //@ close proof_obligations(pub);
    network_send(net_stat, nonce);
  }
  item_free(nonce);
}
示例#10
0
void *sender_t(void* data) //@ : pthread_run_joinable
  //@ requires pthread_run_pre(sender_t)(data, ?x);
  //@ ensures pthread_run_post(sender_t)(data, x) &*& result == 0;
{
  //@ open pthread_run_pre(sender_t)(data, _);
  struct ss_auth_args *args = (void*) data;
  struct item *key = args->key;
  //@ assert principal(?principal, ?count);
  //@ item n = nonce_item(principal, count + 1, 0);
  //@ close ss_auth_pub(n);
  //@ leak ss_auth_pub(n);
  int i = random_int();
  struct item *mess_authage = create_data_item((void*) &i, (int) sizeof(int));
  //@ chars_to_integer(&i);
  //@ assert item(key, private_key_item(?sender, _), ss_auth_pub);
  //@ item datai = data_item(chars_of_int(i));
  //@ assume (app_send_event(sender, datai));
  //@ assert [_]world(ss_auth_pub, ss_auth_key_clsfy);
  //@ close ss_auth_pub(datai);
  //@ leak ss_auth_pub(datai);
  app_send(key, mess_authage);
  //@ close pthread_run_post(sender_t)(data, _);
  item_free(mess_authage);
  return 0;
}
示例#11
0
文件: list.c 项目: jens-na/abook-call
void
move_curitem(int direction)
{
        list_item tmp;

        if(curitem < 0 || curitem > last_item())
                return;

	tmp = item_create();
	item_copy(tmp, db_item_get(curitem));

	switch(direction) {
		case MOVE_ITEM_UP:
			if( curitem < 1 )
				goto out_move;
			item_copy(db_item_get(curitem),
					db_item_get(curitem - 1));
			item_copy(db_item_get(curitem-1), tmp);
			scroll_up();
			break;

		case MOVE_ITEM_DOWN:
			if(curitem >= last_item())
				goto out_move;
			item_copy(db_item_get(curitem),
					db_item_get(curitem + 1));
			item_copy(db_item_get(curitem + 1), tmp);
			scroll_down();
			break;
	}

out_move:
	item_free(&tmp);
}
示例#12
0
文件: database.c 项目: hhirsch/abook
void remove_duplicates()
{
	int i,j,k;
	char *tmpj;
	if(list_is_empty())
		return;

	/* Scan from the last one */
	for(j = LAST_ITEM - 1; j >= 0; j--) {
		tmpj = db_name_get(j);
		for(i = LAST_ITEM; i > j; i--)
			/* Check name and merge if dups */
			if (0 == strcmp(tmpj,db_name_get(i))) {
				item_merge(database[j],database[i]);
				if (curitem == i) curitem--;
				for(k = i; k < LAST_ITEM; k++) {
					item_copy(database[k], database[k + 1]);
				}
				item_free(&database[LAST_ITEM]);
				items--;
			}
	}

	adjust_list_capacity();
}
示例#13
0
文件: database.c 项目: hhirsch/abook
void merge_selected_items()
{
	int i, j;
	int destitem = -1;

	if((list_is_empty()) || (selected_items() < 2))
		return;

	/* Find the top item */
	for(j=0; destitem < 0; j++)
		if(selected[j])
			destitem = j;

	/* Merge pairwise */
	for(j = LAST_ITEM; j > destitem; j--) {
		if(selected[j]) {
			item_merge(database[destitem],database[j]);
			for(i = j; i < LAST_ITEM; i++) {
				/* TODO: this can be done by moving pointers */
				item_copy(database[i], database[i + 1]);
				selected[i] = selected[i + 1];
			}
			item_free(&database[LAST_ITEM]);
			items--;
		}
	}

	if(curitem > LAST_ITEM && items > 0)
		curitem = LAST_ITEM;

	adjust_list_capacity();

	select_none();
}
/*
margin:
    in:
        <0,any,
        0,real matched,
        >0: pts-off>=off && (pts->off-off)<=margin
    out:
        (pts->off-off)

pts:
    out;
*/
int ptslist_lookup(ptslist_mgr_t *mgr, int64_t off, int64_t *pts, int *margin)
{
    struct item *temp;
    struct item *find;
    int reverse = 0;
    int omargin = *margin;
    int err = -1;
    temp = item_alloc(mgr->ptsitem.item_ext_buf_size);
    if (!temp) {
        return -1;
    }
    ITEM_OFF(temp) = off;
    if (mgr->lastoffset - off < off) {
        reverse = 1;
    }
    find = itemlist_find_match_item_ex(&mgr->ptsitem, temp, ptslist_is_wanted, reverse);
    if (!find) {
        err = -2;
        goto errout;
    }
    *pts = ITEM_PTS(find);
    *margin = (int)(ITEM_OFF(find) - off);
    if (omargin < 0 || *margin <= omargin) {
        err = -0;
    } else {
        err = -3;
    }
errout:
    item_free(temp);
    return err;
}
int ptslist_chekin(ptslist_mgr_t *mgr, int64_t off, int64_t pts)
{
    struct item *newitem;
    int ret;
    if (off < 0 || pts < 0) {
        return -1;    //not valied off and pts;
    }
    newitem = item_alloc(mgr->ptsitem.item_ext_buf_size);
    if (!newitem) {
        av_log(NULL, AV_LOG_INFO, "ptslist_chekin-fialed,no memory!\n");
        return AVERROR(ENOMEM);
    }
    newitem->item_data = mgr->index++;
    ITEM_OFF(newitem) = off;
    ITEM_PTS(newitem) = pts;
    mgr->lastoffset = off;
    ret = itemlist_add_tail(&mgr->ptsitem, newitem);
    if (ret) { /*item list fulled,del oldest one.*/
        struct item *t;
        t = itemlist_get_head(&mgr->ptsitem);
        if (t) {
            item_free(t);
        }
        ret = itemlist_add_tail(&mgr->ptsitem, newitem);
    }
    return ret;
}
示例#16
0
void send_data(struct network_status *net_stat)
  /*@ requires [?f0]world(?pub, ?key_clsfy) &*&
               proof_obligations(pub) &*&
               network_status(net_stat) &*&
               principal(?principal, ?count1) &*&
               true == bad(principal); @*/
  /*@ ensures  [f0]world(pub, key_clsfy) &*&
               proof_obligations(pub) &*&
               network_status(net_stat) &*&
               principal(principal, ?count2); @*/
{
  int data_size = random_int_();
  if (data_size > MIN_RANDOM_SIZE)
  {
    char* data = malloc((int) data_size);
    if (data == 0) abort_crypto_lib("malloc failed");
    random_buffer_(data, data_size);
    struct item *item = create_data_item(data, data_size);
    //@ assert item(item, ?i, pub) &*& i == data_item(?d);
    free(data);
    //@ open proof_obligations(pub);
    //@ assert is_public_data(?proof, pub);
    //@ proof(i);
    //@ close proof_obligations(pub);
    network_send(net_stat, item);
    item_free(item);
  }
}
示例#17
0
void
remove_selected_items()
{
	int i, j;

	if(list_is_empty())
		return;

	if(!selected_items())
		selected[curitem] = 1;

	for(j = LAST_ITEM; j >= 0; j--) {
		if(selected[j]) {
			db_free_item(j); /* added for .4 data_s_ */
			for(i = j; i < LAST_ITEM; i++) {
				item_copy(database[i], database[i + 1]);
				selected[i] = selected[i + 1];
			}
			item_free(&database[LAST_ITEM]);
			items--;
		}
	}

	if(curitem > LAST_ITEM && items > 0)
		curitem = LAST_ITEM;

	adjust_list_capacity();

	select_none();
}
示例#18
0
文件: thread.c 项目: alxn/memc3
enum store_item_type do_store_item(item *it, const uint32_t hv) {
    enum store_item_type stored;
    char *key = ITEM_key(it);
    item *old_it = do_item_get(key, it->nkey, hv);
    if (old_it != NULL) {
        assert(old_it != it);

        before_write(old_it);
        do_item_unlink_nolock(old_it, hv);
        //do_item_remove(old_it);         /* release our reference */
        item_free(old_it);
        assert((old_it->it_flags & ITEM_LINKED) == 0);
        assert((old_it->it_flags & ITEM_SLABBED) != 0);
        after_write(old_it);
    } 
    before_write(it);
    int ret = do_item_link_nolock(it, hv);
    after_write(it);

    if (ret == 0) {
        stored = NOT_STORED;
        printf("not stored\n");
    } else {
        stored = STORED;
    }

    return  stored;
}
示例#19
0
int create_principal(struct keypair** keypair)
  /*@ requires world(?pub, ?key_clsfy) &*&
               pointer(keypair, _) &*&
               principals_created(?count); @*/
  /*@ ensures  world(pub, key_clsfy) &*&
               principals_created(result) &*&
               result == count + 1 &*&
               principal(result, 1) &*&
               pointer(keypair, ?p_keypair) &*&
               keypair(p_keypair, result, 1, 0, pub); @*/
{
  //@ open principals_created(count);
  //@ principal_create();
  
  if (counter >= INT_MAX - 1)
  {
    abort_crypto_lib("To many principals generated");
  }
  
  counter++;
  //@ close keypair_request(count + 1, 0);
  struct keypair *k = create_keypair(counter);
  *keypair = k;
  struct item *key = keypair_get_public_key(k);
  register_public_key(counter, key);
  item_free(key);
  
  return counter;
  //@ close principals_created(count + 1);
}
示例#20
0
文件: linklist.c 项目: qiyao/xcc
BOOL
Del_Cur_Item ( LNK_LST *lst )
{
  LST_ITM *p, *last;
  LST_ITM *next_item = LST_nxt(lst);

  if ( LST_Empty(lst) )
    return FALSE; /* not in the list => nothing to delete */

  last = NULL;
  for ( p=LST_first(lst); p!=NULL; p=LST_next(p) ) {

    if ( LST_next(p) == next_item ) {

      if ( last == NULL )	/* it was the first item in the list */
        LST_first(lst) = LST_next(p);
      else      /* it was not the first item in the list */
        LST_next(last) = LST_next(p);

      item_free ( p );	/* put deleted item into the free list */
      decr_LST_len(lst);
      return TRUE;	/* it was deleted from the list => return TRUE */

    }

    last = p;
  }

  /* If we get to here, we went through the list, but we did not find
   *  an item with an LST_next field matching the next item of the list.
   */
  return FALSE;
}
示例#21
0
文件: items.c 项目: jacques/memcached
void item_remove(item *it) {
    assert((it->it_flags & ITEM_SLABBED) == 0);
    if (it->refcount) it->refcount--;
    assert((it->it_flags & ITEM_DELETED) == 0 || it->refcount);
    if (it->refcount == 0 && (it->it_flags & ITEM_LINKED) == 0) {
        item_free(it);
    }
}
示例#22
0
//向slab归还item
void do_item_remove(item *it) {
    MEMCACHED_ITEM_REMOVE(ITEM_key(it), it->nkey, it->nbytes);
    assert((it->it_flags & ITEM_SLABBED) == 0);
    //引用计数为0时归还
    if (refcount_decr(&it->refcount) == 0) {
        item_free(it);
    }
}
示例#23
0
void send_symmetric_encrypted(struct network_status *net_stat, struct keypair *keypair)
  /*@ requires [?f0]world(?pub, ?key_clsfy) &*&
               keypair(keypair, ?attacker_id, ?id, ?info, pub) &*&
               proof_obligations(pub) &*&
               network_status(net_stat) &*&
               principal(attacker_id, ?count1) &*&
               true == bad(attacker_id); @*/
  /*@ ensures  [f0]world(pub, key_clsfy) &*&
               keypair(keypair, attacker_id, id, info, pub) &*&
               proof_obligations(pub) &*&
               network_status(net_stat) &*&
               principal(attacker_id, ?count2); @*/
{
  struct item *key = network_receive(net_stat);
  //@ assert item(key, ?k, pub);
  if (is_symmetric_key(key))
  {
    struct item *pay = network_receive(net_stat);
    //@ assert item(pay, ?p, pub);
    
    //@ open proof_obligations(pub);
    //@ item nonce = nonce_item(attacker_id, count1 + 1, 0);
    //@ assert is_public_nonce(?proof1, pub);
    //@ proof1(nonce);
    struct item *enc = symmetric_encryption(key, pay);
    //@ assert item(enc, ?e, pub);
    /*@ if (col)
        {
          assert is_public_collision(?proof2, pub);
          proof2(e);
        }
        else
        {
          assert is_public_symmetric_encrypted(?proof2, pub);
          proof2(e);
        }
    @*/
    //@ close proof_obligations(pub);
    network_send(net_stat, enc);

    item_free(enc);
    item_free(pay);
  }
  item_free(key);
}
示例#24
0
//remove是把item从slab中释放掉(但是这个释放为提高效率也只是把它放到了slab中的空闲链表中)
void LRU_list::do_item_remove(base_item* it) {
    if ((it->item_flag & Slab::ITEM_SLABBED) != 0)
        return;

    //原子自减
    if (std::atomic_fetch_sub(&(it->refcount), 1u) == 0) {
        item_free(it);
    }
}
示例#25
0
文件: items.c 项目: skypacer210/Ex
void do_item_remove(item *it) {
		syslog(LOG_INFO, "[%s:%s:%d]", __FILE__, __func__, __LINE__);
    MEMCACHED_ITEM_REMOVE(ITEM_key(it), it->nkey, it->nbytes);
    assert((it->it_flags & ITEM_SLABBED) == 0);

    if (refcount_decr(&it->refcount) == 0) {
        item_free(it);
    }
}
示例#26
0
void send_hmac(struct network_status *net_stat, struct keypair *keypair)
  /*@ requires [?f0]world(?pub, ?key_clsfy) &*&
               keypair(keypair, ?attacker_id, ?id, ?info, pub) &*&
               proof_obligations(pub) &*&
               network_status(net_stat) &*&
               principal(attacker_id, ?count1) &*&
               true == bad(attacker_id); @*/
  /*@ ensures  [f0]world(pub, key_clsfy) &*&
               keypair(keypair, attacker_id, id, info, pub) &*&
               proof_obligations(pub) &*&
               network_status(net_stat) &*&
               principal(attacker_id, ?count2); @*/
{
  struct item *key = network_receive(net_stat);
  //@ assert item(key, ?k, pub);
  if (is_symmetric_key(key))
  {
    struct item *pay = network_receive(net_stat);
    //@ assert item(pay, ?p, pub);
    //@ close hash_item_payload(pub, true, p);
    //@ leak hash_item_payload(pub, true, p);
    struct item *mac = create_hmac(key, pay);

    //@ assert item(mac, ?h, pub);
    //@ open proof_obligations(pub);
    /*@ if (col)
        {
          assert is_public_collision(?proof, pub);
          proof(h);
        }
        else
        {
          assert is_public_hmac(?proof, pub);
          proof(h);
        }
    @*/
    //@ close proof_obligations(pub);
    network_send(net_stat, mac);

    item_free(mac);
    item_free(pay);
  }
  item_free(key);
}
示例#27
0
void complete_nread(conn *c) {
    item *it = c->item;
    int comm = c->item_comm;
    item *old_it;
    time_t now = time(0);

    stats.set_cmds++;

    while(1) {
        if (strncmp(ITEM_data(it) + it->nbytes - 2, "\r\n", 2) != 0) {
            out_string(c, "CLIENT_ERROR bad data chunk");
            break;
        }

        old_it = assoc_find(ITEM_key(it));

        if (old_it && settings.oldest_live &&
                old_it->time <= settings.oldest_live) {
            item_unlink(old_it);
            old_it = 0;
        }

        if (old_it && old_it->exptime && old_it->exptime < now) {
            item_unlink(old_it);
            old_it = 0;
        }

        if (old_it && comm==NREAD_ADD) {
            item_update(old_it);
            out_string(c, "NOT_STORED");
            break;
        }

        if (!old_it && comm == NREAD_REPLACE) {
            out_string(c, "NOT_STORED");
            break;
        }

        if (old_it && (old_it->it_flags & ITEM_DELETED) && (comm == NREAD_REPLACE || comm == NREAD_ADD)) {
            out_string(c, "NOT_STORED");
            break;
        }

        if (old_it) {
            item_replace(old_it, it);
        } else item_link(it);

        c->item = 0;
        out_string(c, "STORED");
        return;
    }

    item_free(it);
    c->item = 0;
    return;
}
示例#28
0
文件: items.c 项目: jacques/memcached
void item_unlink(item *it) {
    if (it->it_flags & ITEM_LINKED) {
        it->it_flags &= ~ITEM_LINKED;
        stats.curr_bytes -= ITEM_ntotal(it);
        stats.curr_items -= 1;
        assoc_delete(ITEM_key(it));
        item_unlink_q(it);
    }
    if (it->refcount == 0) item_free(it);
}
示例#29
0
static void _item_remove(struct item *it) {
	assert(it->magic == ITEM_MAGIC);
	assert(!item_is_slabbed(it));
    if (it->refcount != 0) {
        item_release_refcount(it);
    }
    if (it->refcount == 0 && !item_is_linked(it)) {
        item_free(it);
    }
}
示例#30
0
文件: items.c 项目: mohyt/memcached
void do_item_release(struct default_engine *engine, hash_item *it) {
    MEMCACHED_ITEM_REMOVE(item_get_key(it), it->nkey, it->nbytes);
    if (it->refcount != 0) {
        it->refcount--;
        DEBUG_REFCNT(it, '-');
    }
    if (it->refcount == 0 && (it->iflag & ITEM_LINKED) == 0) {
        item_free(engine, it);
    }
}