Пример #1
0
static void
cmpfail(const void *gen, size_t genlen, const void *ref, size_t reflen)
{
	int i;

	for (i = 0; i < genlen; i++)
		if (((u_int8_t *)gen)[i] != ((u_int8_t *)ref)[i]) {
			printk("first difference at byte %u\n", i);
			break;
		}
	dumpdata("Generated", gen, genlen);
	dumpdata("Reference", ref, reflen);
}
Пример #2
0
void
dumpobj(void)
{
	bout = Bopen(outfile, OWRITE);
	if(bout == nil) {
		flusherrors();
		print("can't create %s: %r\n", outfile);
		errorexit();
	}

	Bprint(bout, "go object %s %s %s %s\n", getgoos(), thestring, getgoversion(), expstring());
	Bprint(bout, "  exports automatically generated from\n");
	Bprint(bout, "  %s in package \"%s\"\n", curio.infile, localpkg->name);
	dumpexport();
	Bprint(bout, "\n!\n");

	outhist(bout);

	dumpglobls();
	dumptypestructs();
	dumpdata();
	dumpfuncs();

	Bterm(bout);
}
Пример #3
0
void dumpri(struct romfh *ri, struct filenode *n, FILE *f) {
    int len;

    len = strlen(n->name) + 1;
    memcpy(bigbuf, ri, sizeof(*ri));
    memcpy(bigbuf + 16, n->name, len);

    if(len & 15) {
        memset(bigbuf + 16 + len, 0, 16 - (len & 15));
        len += 16 - (len & 15);
    }

    len += 16;
    ri = (struct romfh *)bigbuf;

    if(n->offset)
        fixsum(ri, len);

    dumpdata(bigbuf, len, f);
#if 0
    fprintf(stderr, "RI: [at %06x] %08lx, %08lx, %08lx, %08lx [%s]\n",
            n->offset,
            ntohl(ri->nextfh), ntohl(ri->spec),
            ntohl(ri->size), ntohl(ri->checksum),
            n->name);
#endif
}
Пример #4
0
void
dumpobj(void)
{
	bout = Bopen(outfile, OWRITE);
	if(bout == nil)
		fatal("cant open %s", outfile);

	Bprint(bout, "%s\n", thestring);
	Bprint(bout, "  exports automatically generated from\n");
	Bprint(bout, "  %s in package \"%s\"\n", curio.infile, localpkg->name);
	dumpexport();
	Bprint(bout, "\n!\n");

	outhist(bout);

	// add nil plist w AEND to catch
	// auto-generated trampolines, data
	newplist();

	dumpglobls();
	dumptypestructs();
	dumpdata();
	dumpfuncs();

	Bterm(bout);
}
Пример #5
0
bool savestate(const char *filename)
#endif
{
	int tag_number;
	int totalsize=0;
	int mysize;
	
	#if !MOVIEPLAYER
	save_ptr file = dest;
	#else
	bool retval=false;
	save_ptr file;
	file=FAT_fopen(filename,"r+b");

	//indicate that no blocks have been saved (this is done for the "restore_variables" function)
	blocks_loaded = 0;

	if (file==NO_FILE)
	{
		file=FAT_fopen(filename,"wb");
	}
	if (file!=NO_FILE)
	#endif
	{
		//Messes up the variables, but encodes them in a way that contains no internal pointers
		prepare_variables_for_savestate();
		
		for (tag_number=0;tag_number<NUM_TAGS;tag_number++)
		{
			//inidcate that the block has been saved  (so "restore_variables" doesn't try to guess values)
			blocks_loaded |= (1<<tag_number);
			mysize=dumpdata(&file,tag_number);
			totalsize+=mysize;
		}
		
		#if MOVIEPLAYER
		FAT_fclose(file);
//		build_chr_decode(); //BECAUSE OF POSSIBLE STACK OVERFLOW
		retval=true;
		#endif
		
		//Restores the variables so we can run the emulator again
		restore_variables_for_loadstate();
	}
	
#if !MOVIEPLAYER
	return totalsize;
#else
	return retval;
#endif
}
Пример #6
0
static int
dispatchsearch(int n, int *e, int nblue, int nred)
/* Multiple tries at solution */
{
    int i,status;
    addrval *valptr;
    boolean ok;
    nauty_counter remaininglimit;

    ok = propagate(n,e,&nblue,&nred);

#if DEBUG
    if (ok) dumpdata(0,nblue,nred,n);
    else { printf("FAIL\n"); ++nphases[0]; return NO; }
#else
    if (!ok) { ++nphases[0]; return NO; }
#endif

    valptr = valstacktop;

    remaininglimit = totallimit;

    for (i = 0; i < NUMLIMITS; ++i)
    {
	if (totallimit > 0)
	{
	    limit = locallimit[i];
            if (limit == 0 || limit > remaininglimit) limit = remaininglimit;
	    remaininglimit -= limit;
            if (limit == 0) limit = 1;
	}
	else
	    limit = locallimit[i];

	nodes = 0;

	status = searchnode(1,n,e,nblue,nred);
	if (status != TIMEOUT)
        {
	    ++nphases[i+1];
	    return status;
	}
	while (valstacktop > valptr) UNSETVAL;
    }
    
    ++ntimeouts;
    return TIMEOUT;
}
Пример #7
0
void
shmqueue_dump_tsv(struct shmqueue *shmq_header)
{
	struct shmqueue_header *header;
	struct shmqueue_item *item;

	header = shmq_header->header;

	for (item = RTAILQ_FIRST(&header->sha_lrulist, shmqueue_item);
	    item != NULL;
	    item = RTAILQ_NEXT(item, &header->sha_lrulist, shmqueue_item, shi_list)) {

		printf("%s\t", KEYVALUE_KEY(&item->shi_keyvalue));
		dumpdata(KEYVALUE_STORAGE(&item->shi_keyvalue), item->shi_keyvalue.kv_storagesize);
		printf("\n");
	}
}
Пример #8
0
int
main(int argc, char *argv[])
{
	int i;

	openfiles();

	if (argc > 1) {
		for (i=1; i<argc; i++) {
			readfile(argv[i]);
		}
	}
	else {
		readfile(NULL);
	}

	dumpdata();

	closefiles();
	return 0;
}
int prase_modbus_protocol(char * pbuf,unsigned int len)
{
	int ret = 0; //返回应答的数据长度
	modbus_tcp_head * phead = (modbus_tcp_head *)pbuf;

	if(DUMP_DATA_INFO)dumpdata(pbuf,len);

	//判断是否modbus/tcp协议
	if(len < sizeof(modbus_tcp_head)) {
		DEBUGMSG(THISERROR,("modbus/tcp data len error!\r\n"));
		return 0;
	}
	//获取数据长度
	len = phead->lengthh;len <<= 8;
	len |= phead->lengthl;
	switch(phead->function_code) {
		case 0x01:
		case 0x02:
		{
			//modbus_type_fc1_cmd * pcmd = (modbus_type_fc1_cmd *)GET_MODBUS_DATA(phead);
			DEBUGMSG(THISINFO,("modbus 0x01:\r\n"));
			if(len < 4) {
				DEBUGMSG(THISERROR,("len < 4 error\r\n"));
				break;
			} else {
				if(phead->function_code == 0x01) {
				    len = ReadCoilStatus(GET_MODBUS_DATA(phead));
				} else if(phead->function_code == 0x02) {
					len = ReadInputDiscretes(GET_MODBUS_DATA(phead));
				}
				if(len > 0) {
					DEBUGMSG(THISINFO,("ReadCoilStatus Ok ret len(%d)\r\n",len));
					phead->lengthl = len & 0xFF;
					phead->lengthh = len >> 8;
					return len + sizeof(modbus_tcp_head) - 2;
				} else {
					DEBUGMSG(THISERROR,("ReadCoilStatus Ko\r\n"));
				}
			}
		}
Пример #10
0
void
dumpobj(void)
{
	NodeList *externs, *tmp;

	bout = Bopen(outfile, OWRITE);
	if(bout == nil) {
		flusherrors();
		print("can't create %s: %r\n", outfile);
		errorexit();
	}

	Bprint(bout, "go object %s %s %s %s\n", getgoos(), thestring, getgoversion(), expstring());
	Bprint(bout, "  exports automatically generated from\n");
	Bprint(bout, "  %s in package \"%s\"\n", curio.infile, localpkg->name);
	dumpexport();
	Bprint(bout, "\n!\n");

	outhist(bout);

	externs = nil;
	if(externdcl != nil)
		externs = externdcl->end;

	dumpglobls();
	dumptypestructs();

	// Dump extra globals.
	tmp = externdcl;
	if(externs != nil)
		externdcl = externs->next;
	dumpglobls();
	externdcl = tmp;

	dumpdata();
	dumpfuncs();

	Bterm(bout);
}
Пример #11
0
static int
searchnode(int level, int n, int *e, int nblue, int nred)
{
    boolean ok;
    int i,status,nbest;
    addrval *valptr;
    int best,score,bestscore;
    int fe,fc;
    long ran;
     
    ok = propagate(n,e,&nblue,&nred);

#if DEBUG
    if (ok) dumpdata(level,nblue,nred,n);
    else { printf("FAIL\n"); return NO; }
#else
    if (!ok) return NO;
#endif

    if (nblue == n && nred == n) return YES;

#if FISHTAIL
    status = fishtail(n,&nblue,&nred);
    if (status == NO) return NO;
    if (status == YES) return searchnode(level+1,n,e,nblue,nred);
#endif

    valptr = valstacktop;

    bestscore = -1;
    nbest = 0;
    for (i = 0; i < 2*n; ++i)
	if (colour[i] == WHITE)
        {
	    score = (bluedeg[v1[i]] == 1) + (bluedeg[v2[i]] == 1) +
                    (reddeg[v1[i]] == 1) + (reddeg[v2[i]] == 1);
	    if (score > bestscore)
	    {
		bestscore = score;
		beste[0] = i;
		nbest = 1;
	    }
	    else if (score == bestscore)
	        beste[nbest++] = i;
        }

    if (bestscore == 0 && nred + nblue > 0)
	return FALSE;   /* Disconnected */

    ran = KRAN(2*nbest);
    best = beste[ran/2];

    if ((ran&1))
    {
        if (makeblue(best,nblue==n-1))
        {
#if DEBUG
            printf("   setting %d(%d-%d) blue\n",best,v1[best],v2[best]);
#endif
	    status = searchnode(level+1,n,e,nblue+1,nred);
	    if (status != NO) return status;
	    while (valstacktop > valptr) UNSETVAL;
        }

        if (++nodes == limit) return TIMEOUT;

        if (makered(best,nred==n-1))
        {
#if DEBUG
            printf("   setting %d(%d-%d) red\n",best,v1[best],v2[best]);
#endif
	    status = searchnode(level+1,n,e,nblue,nred+1);
	    if (status != NO) return status;
	    while (valstacktop > valptr) UNSETVAL;
        }
    }
    else
    {
        if (makered(best,nred==n-1))
        {
#if DEBUG
            printf("   setting %d(%d-%d) red\n",best,v1[best],v2[best]);
#endif
	    status = searchnode(level+1,n,e,nblue,nred+1);
	    if (status != NO) return status;
	    while (valstacktop > valptr) UNSETVAL;
        }

        if (++nodes == limit) return TIMEOUT;

        if (makeblue(best,nblue==n-1))
        {
#if DEBUG
            printf("   setting %d(%d-%d) blue\n",best,v1[best],v2[best]);
#endif
	    status = searchnode(level+1,n,e,nblue+1,nred);
	    if (status != NO) return status;
	    while (valstacktop > valptr) UNSETVAL;
        }
    }

    return NO;
}
Пример #12
0
int
main(int argc, char **argv)
{
	report_desc_t r;
	char *table = NULL;
	char devnam[100], *dev = NULL;
	int f;
	int all = 0;
	int ch;
	int repdump = 0;
	int loop = 0;

	while ((ch = getopt(argc, argv, "af:lnrt:vwxz")) != -1) {
		switch(ch) {
		case 'a':
			all++;
			break;
		case 'f':
			dev = optarg;
			break;
		case 'l':
			loop ^= 1;
			break;
		case 'n':
			noname++;
			break;
		case 'r':
			repdump++;
			break;
		case 't':
			table = optarg;
			break;
		case 'v':
			verbose++;
			break;
		case 'w':
			wflag = 1;
			break;
		case 'x':
			hexdump = 1;
			break;
		case 'z':
			zflag = 1;
			break;
		case '?':
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;
	if (dev == NULL)
		usage();

	if (argc == 0 && !all && !repdump)
		usage();

	if (dev[0] != '/') {
		if (isdigit(dev[0]))
			snprintf(devnam, sizeof(devnam), "/dev/uhid%s", dev);
		else
			snprintf(devnam, sizeof(devnam), "/dev/%s", dev);
		dev = devnam;
	}

	hid_init(table);

	f = open(dev, O_RDWR);
	if (f < 0)
		err(1, "%s", dev);

	r = hid_get_report_desc(f);
	if (r == 0)
		errx(1, "USB_GET_REPORT_DESC");

	if (repdump) {
		printf("Report descriptor:\n");
		dumpitems(r);
	}
	if (argc != 0 || all) {
		parceargs(r, all, argc, argv);
		if (wflag)
			writedata(f, r);
		else
			dumpdata(f, r, loop);
	}

	hid_dispose_report_desc(r);
	exit(0);
}
Пример #13
0
static int
runtest(struct ieee80211vap *vap, struct ciphertest *t)
{
	struct ieee80211_key *key;
	struct sk_buff *skb = NULL;
	const struct ieee80211_cipher *cip;
	u_int8_t mac[IEEE80211_ADDR_LEN];
	struct tkip_ctx *ctx;
	int hdrlen;

	printk("%s: ", t->name);

	if (!ieee80211_crypto_available(vap, t->cipher)) {
		printk("FAIL: ieee80211_crypto_available failed\n");
		return 0;
	}

	/*
	 * Setup key.
	 */
	key = &vap->iv_nw_keys[t->keyix];
	key->wk_keyix = t->keyix;
	if (!ieee80211_crypto_newkey(vap, t->cipher,
				     IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV,
				     key)) {
		printk("FAIL: ieee80211_crypto_newkey failed\n");
		goto bad;
	}

	memcpy(key->wk_key, t->key, t->key_len);
	key->wk_keylen = 128 / NBBY;
	memset(key->wk_keyrsc, 0, sizeof(key->wk_keyrsc));
	key->wk_keytsc = 0;
	if (!ieee80211_crypto_setkey(vap, key, mac, NULL)) {
		printk("FAIL: ieee80211_crypto_setkey failed\n");
		goto bad;
	}

	/*
	 * Craft frame from plaintext data.  Note that
	 * we leave the MIC off as we'll add it ourself
	 * and then check it against the reference data.
	 */
	cip = key->wk_cipher;
	skb = ieee80211_dev_alloc_skb(t->plaintext_len +
		cip->ic_miclen + cip->ic_header + cip->ic_trailer);
	if (skb == NULL) {
		printk("FAIL: unable to allocate skbuff\n");
		goto bad;
	}
	skb_reserve(skb, cip->ic_header);
	memcpy(skb_put(skb, t->plaintext_len - cip->ic_miclen),
		t->plaintext, t->plaintext_len - cip->ic_miclen);

	/*
	 * Add MIC.
	 */
	if (!ieee80211_crypto_enmic(vap, key, skb, 0)) {
		printk("FAIL: tkip enmic failed\n");
		goto bad;
	}
	/*
	 * Verify: frame length, frame contents.
	 */
	if (skb->len != t->plaintext_len) {
		printk("FAIL: enmic botch; length mismatch\n");
		cmpfail(skb->data, skb->len,
			t->plaintext, t->plaintext_len);
		goto bad;
	}
	if (memcmp(skb->data, t->plaintext, t->plaintext_len)) {
		printk("FAIL: enmic botch\n");
		cmpfail(skb->data, skb->len,
			t->plaintext, t->plaintext_len);
		goto bad;
	}
	/*
	 * Encrypt frame w/ MIC.
	 */
	if (!(*cip->ic_encap)(key, skb, t->keyix << 6)) {
		printk("FAIL: tkip encap failed\n");
		goto bad;
	}
	/*
	 * Verify: phase1, phase2, frame length, frame contents.
	 */
	ctx = key->wk_private;
	if (memcmp(ctx->tx_ttak, t->phase1, t->phase1_len)) {
		printk("FAIL: encrypt phase1 botch\n");
		cmpfail(ctx->tx_ttak, sizeof(ctx->tx_ttak),
			t->phase1, t->phase1_len);
		goto bad;
	} else if (memcmp(ctx->tx_rc4key, t->phase2, t->phase2_len)) {
		printf("FAIL: encrypt phase2 botch\n");
		cmpfail(ctx->tx_rc4key, sizeof(ctx->tx_rc4key),
			t->phase2, t->phase2_len);
		goto bad;
	} else if (skb->len != t->encrypted_len) {
		printk("FAIL: encrypt data length mismatch\n");
		cmpfail(skb->data, skb->len,
			t->encrypted, t->encrypted_len);
		goto bad;
	} else if (memcmp(skb->data, t->encrypted, skb->len)) {
		printk("FAIL: encrypt data does not compare\n");
		cmpfail(skb->data, skb->len,
			t->encrypted, t->encrypted_len);
		dumpdata("Plaintext", t->plaintext, t->plaintext_len);
		goto bad;
	}

	/*
	 * Decrypt frame.
	 */
	hdrlen = ieee80211_hdrspace(vap->iv_ic, skb->data);
	if (!(*cip->ic_decap)(key, skb, hdrlen)) {
		printk("FAIL: tkip decap failed\n");
		/*
		 * Check reason for failure: phase1, phase2, frame data (ICV).
		 */
		if (memcmp(ctx->rx_ttak, t->phase1, t->phase1_len)) {
			printk("decrypt phase1 botch\n");
			cmpfail(ctx->rx_ttak, sizeof(ctx->rx_ttak),
				t->phase1, t->phase1_len);
		} else if (memcmp(ctx->rx_rc4key, t->phase2, t->phase2_len)) {
			printf("decrypt phase2 botch\n");
			cmpfail(ctx->rx_rc4key, sizeof(ctx->rx_rc4key),
				t->phase2, t->phase2_len);
		} else {
			printk("decrypt data does not compare\n");
			cmpfail(skb->data, skb->len,
				t->plaintext, t->plaintext_len);
		}
		goto bad;
	}
	/*
	 * Verify: frame length, frame contents.
	 */
	if (skb->len != t->plaintext_len) {
		printk("FAIL: decap botch; length mismatch\n");
		cmpfail(skb->data, skb->len,
			t->plaintext, t->plaintext_len);
		goto bad;
	}
	if (memcmp(skb->data, t->plaintext, t->plaintext_len)) {
		printk("FAIL: decap botch; data does not compare\n");
		cmpfail(skb->data, skb->len,
			t->plaintext, t->plaintext_len);
		goto bad;
	}
	/*
	 * De-MIC decrypted frame.
	 */
	if (!ieee80211_crypto_demic(vap, key, skb, hdrlen, 0)) {
		printk("FAIL: tkip demic failed\n");
		goto bad;
	}
	/* XXX check frame length and contents... */
	ieee80211_dev_kfree_skb(&skb);
	ieee80211_crypto_delkey(vap, key, NULL);
	printk("PASS\n");
	return 1;
bad:
	if (skb != NULL)
		ieee80211_dev_kfree_skb(&skb);
	ieee80211_crypto_delkey(vap, key, NULL);
	return 0;
}
Пример #14
0
static int
runtest(struct ieee80211vap *vap, struct ciphertest *t)
{
	struct ieee80211_key *key;
	struct sk_buff *skb = NULL;
	const struct ieee80211_cipher *cip;
	u_int8_t mac[IEEE80211_ADDR_LEN];
	int hdrlen;

	printk("%s: ", t->name);

	if (!ieee80211_crypto_available(vap, t->cipher)) {
		printk("FAIL: ieee80211_crypto_available failed\n");
		return 0;
	}

	/*
	 * Setup key.
	 */
	key = &vap->iv_nw_keys[t->keyix];
	key->wk_keyix = t->keyix;
	if (!ieee80211_crypto_newkey(vap, t->cipher,
				     IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV,
				     key)) {
		printk("FAIL: ieee80211_crypto_newkey failed\n");
		goto bad;
	}

	memcpy(key->wk_key, t->key, t->key_len);
	key->wk_keylen = t->key_len;
	memset(key->wk_keyrsc, 0, sizeof(key->wk_keyrsc));
	key->wk_keytsc = t->pn - 1;	/* PN-1 since we do encap */
	if (!ieee80211_crypto_setkey(vap, key, mac, NULL)) {
		printk("FAIL: ieee80211_crypto_setkey failed\n");
		goto bad;
	}

	/*
	 * Craft frame from plaintext data.
	 */
	cip = key->wk_cipher;
	skb = ieee80211_dev_alloc_skb(t->plaintext_len +
		cip->ic_header + cip->ic_trailer);
	if (skb == NULL) {
		printk("FAIL: unable to allocate skbuff\n");
		goto bad;
	}
	skb_reserve(skb, cip->ic_header);
	memcpy(skb_put(skb, t->plaintext_len), t->plaintext, t->plaintext_len);

	/*
	 * Encrypt frame w/ MIC.
	 */
	if (!(*cip->ic_encap)(key, skb, t->keyix << 6)) {
		printk("FAIL: ccmp encap failed\n");
		goto bad;
	}
	/*
	 * Verify: frame length, frame contents.
	 */
	if (skb->len != t->encrypted_len) {
		printk("FAIL: encap data length mismatch\n");
		cmpfail(skb->data, skb->len,
			t->encrypted, t->encrypted_len);
		goto bad;
	} else if (memcmp(skb->data, t->encrypted, skb->len)) {
		printk("FAIL: encrypt data does not compare\n");
		cmpfail(skb->data, skb->len,
			t->encrypted, t->encrypted_len);
		dumpdata("Plaintext", t->plaintext, t->plaintext_len);
		goto bad;
	}

	/*
	 * Decrypt frame; strip MIC.
	 */
	hdrlen = ieee80211_hdrspace(vap->iv_ic, skb->data);
	if (!(*cip->ic_decap)(key, skb, hdrlen)) {
		printk("FAIL: ccmp decap failed\n");
		cmpfail(skb->data, skb->len,
			t->plaintext, t->plaintext_len);
		goto bad;
	}
	/*
	 * Verify: frame length, frame contents.
	 */
	if (skb->len != t->plaintext_len) {
		printk("FAIL: decap botch; length mismatch\n");
		cmpfail(skb->data, skb->len,
			t->plaintext, t->plaintext_len);
		goto bad;
	} else if (memcmp(skb->data, t->plaintext, t->plaintext_len)) {
		printk("FAIL: decap botch; data does not compare\n");
		cmpfail(skb->data, skb->len,
			t->plaintext, sizeof(t->plaintext));
		goto bad;
	}
	ieee80211_dev_kfree_skb(&skb);
	ieee80211_crypto_delkey(vap, key, NULL);
	printk("PASS\n");
	return 1;
bad:
	if (skb != NULL)
		ieee80211_dev_kfree_skb(&skb);
	ieee80211_crypto_delkey(vap, key, NULL);
	return 0;
}
Пример #15
0
int
runtest(struct ieee80211com *ic, struct ciphertest *t)
{
	struct ieee80211_key key;
	struct sk_buff *skb = NULL;
	const struct ieee80211_cipher *cip;
	u_int8_t mac[IEEE80211_ADDR_LEN];

	printk("%s: ", t->name);

	/*
	 * Setup key.
	 */
	memset(&key, 0, sizeof(key));
	key.wk_flags = IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV;
	key.wk_cipher = &ieee80211_cipher_none;
	if (!ieee80211_crypto_newkey(ic, t->cipher, &key)) {
		printk("FAIL: ieee80211_crypto_newkey failed\n");
		goto bad;
	}

	memcpy(key.wk_key, t->key, t->key_len);
	key.wk_keylen = t->key_len;
	key.wk_keyrsc = 0;
	key.wk_keytsc = t->pn-1;	/* PN-1 since we do encap */
	if (!ieee80211_crypto_setkey(ic, &key, mac)) {
		printk("FAIL: ieee80211_crypto_setkey failed\n");
		goto bad;
	}

	/*
	 * Craft frame from plaintext data.
	 */
	cip = key.wk_cipher;
	skb = dev_alloc_skb(t->plaintext_len +
			cip->ic_header + cip->ic_trailer);
	if (skb == NULL) {
		printk("FAIL: unable to allocate skbuff\n");
		goto bad;
	}
	skb_reserve(skb, cip->ic_header);
	memcpy(skb_put(skb, t->plaintext_len),
		t->plaintext, t->plaintext_len);

	/*
	 * Encrypt frame w/ MIC.
	 */
	if (!(*cip->ic_encap)(&key, skb, t->keyix<<6)) {
		printk("FAIL: ccmp encap failed\n");
		goto bad;
	}
	/*
	 * Verify: frame length, frame contents.
	 */
	if (skb->len != t->encrypted_len) {
		printk("FAIL: encap data length mismatch\n");
		cmpfail(skb->data, skb->len,
			t->encrypted, t->encrypted_len);
		goto bad;
	} else if (memcmp(skb->data, t->encrypted, skb->len)) {
		printk("FAIL: encrypt data does not compare\n");
		cmpfail(skb->data, skb->len,
			t->encrypted, t->encrypted_len);
		dumpdata("Plaintext", t->plaintext, t->plaintext_len);
		goto bad;
	}

	/*
	 * Decrypt frame; strip MIC.
	 */
	if (!(*cip->ic_decap)(&key, skb)) {
		printk("FAIL: ccmp decap failed\n");
		cmpfail(skb->data, skb->len,
			t->plaintext, t->plaintext_len);
		goto bad;
	}
	/*
	 * Verify: frame length, frame contents.
	 */
	if (skb->len != t->plaintext_len) {
		printk("FAIL: decap botch; length mismatch\n");
		cmpfail(skb->data, skb->len,
			t->plaintext, t->plaintext_len);
		goto bad;
	} else if (memcmp(skb->data, t->plaintext, t->plaintext_len)) {
		printk("FAIL: decap botch; data does not compare\n");
		cmpfail(skb->data, skb->len,
			t->plaintext, sizeof(t->plaintext));
		goto bad;
	}
	dev_kfree_skb(skb);
	ieee80211_crypto_delkey(ic, &key);
	printk("PASS\n");
	return 1;
bad:
	if (skb != NULL)
		dev_kfree_skb(skb);
	ieee80211_crypto_delkey(ic, &key);
	return 0;
}
Пример #16
0
void dumpdataa(void *addr, int len, FILE *f) {
    dumpdata(addr, len, f);

    if((len & 15) != 0)
        dumpzero(16 - (len & 15), f);
}
Пример #17
0
void dumpzero(int len, FILE *f) {
    memset(bigbuf, 0, len);
    dumpdata(bigbuf, len, f);
}
Пример #18
0
void
dumpobj(void)
{
	NodeList *externs, *tmp;
	char arhdr[ArhdrSize];
	vlong startobj, size;
	Sym *zero;

	bout = Bopen(outfile, OWRITE);
	if(bout == nil) {
		flusherrors();
		print("can't create %s: %r\n", outfile);
		errorexit();
	}

	startobj = 0;
	if(writearchive) {
		Bwrite(bout, "!<arch>\n", 8);
		memset(arhdr, 0, sizeof arhdr);
		Bwrite(bout, arhdr, sizeof arhdr);
		startobj = Boffset(bout);
	}
	Bprint(bout, "go object %s %s %s %s\n", getgoos(), getgoarch(), getgoversion(), expstring());
	dumpexport();
	
	if(writearchive) {
		Bflush(bout);
		size = Boffset(bout) - startobj;
		if(size&1)
			Bputc(bout, 0);
		Bseek(bout, startobj - ArhdrSize, 0);
		formathdr(arhdr, "__.PKGDEF", size);
		Bwrite(bout, arhdr, ArhdrSize);
		Bflush(bout);

		Bseek(bout, startobj + size + (size&1), 0);
		memset(arhdr, 0, ArhdrSize);
		Bwrite(bout, arhdr, ArhdrSize);
		startobj = Boffset(bout);
		Bprint(bout, "go object %s %s %s %s\n", getgoos(), getgoarch(), getgoversion(), expstring());
	}

	Bprint(bout, "\n!\n");

	externs = nil;
	if(externdcl != nil)
		externs = externdcl->end;

	dumpglobls();
	dumptypestructs();

	// Dump extra globals.
	tmp = externdcl;
	if(externs != nil)
		externdcl = externs->next;
	dumpglobls();
	externdcl = tmp;

	zero = pkglookup("zerovalue", runtimepkg);
	ggloblsym(zero, zerosize, 1, 1);

	dumpdata();
	writeobj(ctxt, bout);

	if(writearchive) {
		Bflush(bout);
		size = Boffset(bout) - startobj;
		if(size&1)
			Bputc(bout, 0);
		Bseek(bout, startobj - ArhdrSize, 0);
		snprint(namebuf, sizeof namebuf, "_go_.%c", thechar);
		formathdr(arhdr, namebuf, size);
		Bwrite(bout, arhdr, ArhdrSize);
	}
	Bterm(bout);
}
Пример #19
0
int dumpnode(struct filenode *node, FILE *f) {
    struct romfh ri;
    struct filenode *p;

    ri.nextfh = 0;
    ri.spec = 0;
    ri.size = htonl(node->size);
    ri.checksum = htonl(0x55555555);

    if(node->pad)
        dumpzero(node->pad, f);

    if(node->next && node->next->next)
        ri.nextfh = htonl(node->next->offset);

    if((node->modes & 0111) &&
            (S_ISDIR(node->modes) || S_ISREG(node->modes)))
        ri.nextfh |= htonl(ROMFH_EXEC);

    if(node->orig_link) {
        ri.nextfh |= htonl(ROMFH_HRD);
        /* Don't allow hardlinks to convey attributes */
        ri.nextfh &= ~htonl(ROMFH_EXEC);
        ri.spec = htonl(node->orig_link->offset);
        dumpri(&ri, node, f);
    }
    else if(S_ISDIR(node->modes)) {
        ri.nextfh |= htonl(ROMFH_DIR);

        if(listisempty(&node->dirlist)) {
            ri.spec = htonl(node->offset);
        }
        else {
            ri.spec = htonl(node->dirlist.head->offset);
        }

        dumpri(&ri, node, f);
    }
    else if(S_ISLNK(node->modes)) {
        ri.nextfh |= htonl(ROMFH_LNK);
        dumpri(&ri, node, f);
        memset(bigbuf, 0, sizeof(bigbuf));
        if(readlink(node->realname, bigbuf, node->size) < 0) {
            return 1;
        }
        dumpdataa(bigbuf, node->size, f);
    }
    else if(S_ISREG(node->modes)) {
        int offset, len, fd, max, avail;
        ri.nextfh |= htonl(ROMFH_REG);
        dumpri(&ri, node, f);
        offset = 0;
        max = node->size;
        /* XXX warn about size mismatch */
        fd = open(node->realname, O_RDONLY
#ifdef O_BINARY
                  | O_BINARY
#endif
                 );

        if(fd) {
            while(offset < max) {
                avail = max - offset < sizeof(bigbuf) ? max - offset : sizeof(bigbuf);
                len = read(fd, bigbuf, avail);

                if(len <= 0)
                    break;

                dumpdata(bigbuf, len, f);
                offset += len;
            }

            close(fd);
        }

        max = (max + 15)&~15;

        while(offset < max) {
            avail = max - offset < sizeof(bigbuf) ? max - offset : sizeof(bigbuf);
            memset(bigbuf, 0, avail);
            dumpdata(bigbuf, avail, f);
            offset += avail;
        }
    }
    else if(S_ISCHR(node->modes)) {
        ri.nextfh |= htonl(ROMFH_CHR);
        ri.spec = htonl(major(node->devnode) << 16 | minor(node->devnode));
        dumpri(&ri, node, f);
    }
    else if(S_ISBLK(node->modes)) {
        ri.nextfh |= htonl(ROMFH_BLK);
        ri.spec = htonl(major(node->devnode) << 16 | minor(node->devnode));
        dumpri(&ri, node, f);
    }
    else if(S_ISFIFO(node->modes)) {
        ri.nextfh |= htonl(ROMFH_FIF);
        dumpri(&ri, node, f);
    }
    else if(S_ISSOCK(node->modes)) {
        ri.nextfh |= htonl(ROMFH_SCK);
        dumpri(&ri, node, f);
    }

    p = node->dirlist.head;

    while(p->next) {
        if(dumpnode(p, f)) {
            return 1;
        }
        p = p->next;
    }

    return 0;
}
Пример #20
0
static int
runtest(struct ieee80211vap *vap, struct ciphertest *t)
{
	struct ieee80211_key *key;
	struct sk_buff *skb = NULL;
	const struct ieee80211_cipher *cip;
	u_int8_t mac[IEEE80211_ADDR_LEN];
	struct wep_ctx_hw *ctx;
	int hdrlen;

	printk("%s: ", t->name);

	if (!ieee80211_crypto_available(vap, t->cipher)) {
		printk("FAIL: ieee80211_crypto_available failed\n");
		return 0;
	}

	/*
	 * Setup key.
	 */
	key = &vap->iv_nw_keys[t->keyix];
	key->wk_keyix = t->keyix;
	if (!ieee80211_crypto_newkey(vap, t->cipher,
				     IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV,
				     key)) {
		printk("FAIL: ieee80211_crypto_newkey failed\n");
		goto bad;
	}

	memcpy(key->wk_key, t->key, t->key_len);
	key->wk_keylen = t->key_len;
	if (!ieee80211_crypto_setkey(vap, key, mac, NULL)) {
		printk("FAIL: ieee80211_crypto_setkey failed\n");
		goto bad;
	}
	cip = key->wk_cipher;

	/*
	 * Craft encrypted frame from known data.
	 */
	skb = ieee80211_dev_alloc_skb(t->encrypted_len);
	if (skb == NULL) {
		printk("FAIL: unable to allocate skbuff\n");
		goto bad;
	}
	memcpy(skb_put(skb, t->encrypted_len), t->encrypted, t->encrypted_len);

	/*
	 * Decrypt frame.
	 */
	hdrlen = ieee80211_hdrspace(vap->iv_ic, skb->data);
	if (!(*cip->ic_decap)(key, skb, hdrlen)) {
		printk("FAIL: wep decap failed\n");
		cmpfail(skb->data, skb->len,
			t->plaintext, t->plaintext_len);
		goto bad;
	}
	/*
	 * Verify: frame length, frame contents.
	 */
	if (skb->len != t->plaintext_len) {
		printk("FAIL: decap botch; length mismatch\n");
		cmpfail(skb->data, skb->len,
			t->plaintext, t->plaintext_len);
		goto bad;
	} else if (memcmp(skb->data, t->plaintext, t->plaintext_len)) {
		printk("FAIL: decap botch; data does not compare\n");
		cmpfail(skb->data, skb->len,
			t->plaintext, sizeof(t->plaintext));
		goto bad;
	}

	/*
	 * Encrypt frame.
	 */
	ctx = (struct wep_ctx_hw *) key->wk_private;
	memcpy(&ctx->wc_iv, t->iv, sizeof(t->iv));	/* for encap/encrypt */
	if (!(*cip->ic_encap)(key, skb, t->keyix << 6)) {
		printk("FAIL: wep encap failed\n");
		goto bad;
	}
	/*
	 * Verify: frame length, frame contents.
	 */
	if (skb->len != t->encrypted_len) {
		printk("FAIL: encap data length mismatch\n");
		cmpfail(skb->data, skb->len,
			t->encrypted, t->encrypted_len);
		goto bad;
	} else if (memcmp(skb->data, t->encrypted, skb->len)) {
		printk("FAIL: encrypt data does not compare\n");
		cmpfail(skb->data, skb->len,
			t->encrypted, t->encrypted_len);
		dumpdata("Plaintext", t->plaintext, t->plaintext_len);
		goto bad;
	}
	if (skb != NULL)
		ieee80211_dev_kfree_skb(&skb);
	ieee80211_crypto_delkey(vap, key, NULL);
	printk("PASS\n");
	return 1;
bad:
	if (skb != NULL)
		ieee80211_dev_kfree_skb(&skb);
	ieee80211_crypto_delkey(vap, key, NULL);
	return 0;
}
Пример #21
0
void
tkip_test(struct ieee80211com *ic)
{
	struct tkip_ctx *ctx;
	struct ieee80211_key key;
	struct sk_buff *skb = NULL;
	const struct ieee80211_cipher *cip;
	u_int8_t mac[IEEE80211_ADDR_LEN];

	/*
	 * Setup key.
	 */
	memset(&key, 0, sizeof(key));
	key.wk_flags = IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV;
	key.wk_cipher = &ieee80211_cipher_none;
	if (!ieee80211_crypto_newkey(ic, IEEE80211_CIPHER_TKIP, &key)) {
		printk("ieee80211_crypto_newkey failed\n");
		goto bad;
	}

	memcpy(key.wk_key, ref_key, sizeof(ref_key));
	key.wk_keylen = 128 / NBBY;
	key.wk_keyrsc = 0;
	key.wk_keytsc = 0;
	if (!ieee80211_crypto_setkey(ic, &key, mac)) {
		printk("ieee80211_crypto_setkey failed\n");
		goto bad;
	}

	/*
	 * Craft frame from plaintext data.  Note that
	 * we leave the MIC off as we'll add it ourself
	 * and then check it against the reference data.
	 */
	cip = key.wk_cipher;
	skb = dev_alloc_skb(sizeof(ref_plaintext) +
		cip->ic_miclen + cip->ic_header + cip->ic_trailer);
	if (skb == NULL) {
		printk("unable to allocate skbuff\n");
		goto bad;
	}
	skb_reserve(skb, cip->ic_header);
	memcpy(skb_put(skb, sizeof(ref_plaintext) - cip->ic_miclen),
		ref_plaintext, sizeof(ref_plaintext) - cip->ic_miclen);

	/*
	 * Add MIC.
	 */
	if (!ieee80211_crypto_enmic(ic, &key, skb)) {
		printk("tkip enmic failed\n");
		goto bad;
	}
	/*
	 * Verify: frame length, frame contents.
	 */
	if (skb->len != sizeof(ref_plaintext)) {
		printk("enmic botch; length mismatch\n");
		cmpfail(skb->data, skb->len,
			ref_plaintext, sizeof(ref_plaintext));
		goto bad;
	}
	if (memcmp(skb->data, ref_plaintext, sizeof(ref_plaintext))) {
		printk("enmic botch\n");
		cmpfail(skb->data, skb->len,
			ref_plaintext, sizeof(ref_plaintext));
		goto bad;
	}
	/*
	 * Encrypt frame w/ MIC.
	 */
	if (!(*cip->ic_encap)(&key, skb, 0 << 6)) {
		printk("tkip encap failed\n");
		goto bad;
	}
	/*
	 * Verify: phase1, phase2, frame length, frame contents.
	 */
	ctx = key.wk_private;
	if (memcmp(ctx->tx_ttak, ref_phase1, sizeof(ref_phase1))) {
		printk("encrypt phase1 botch\n");
		cmpfail(ctx->tx_ttak, sizeof(ctx->tx_ttak),
			ref_phase1, sizeof(ref_phase1));
		goto bad;
	} else if (memcmp(ctx->tx_rc4key, ref_phase2, sizeof(ref_phase2))) {
		printf("encrypt phase2 botch\n");
		cmpfail(ctx->tx_rc4key, sizeof(ctx->tx_rc4key),
			ref_phase2, sizeof(ref_phase2));
		goto bad;
	} else if (skb->len != sizeof(ref_encrypted)) {
		printk("encrypt data length mismatch\n");
		cmpfail(skb->data, skb->len,
			ref_encrypted, sizeof(ref_encrypted));
		goto bad;
	} else if (memcmp(skb->data, ref_encrypted, skb->len)) {
		printk("encrypt data does not compare\n");
		cmpfail(skb->data, skb->len,
			ref_encrypted, sizeof(ref_encrypted));
		dumpdata("Plaintext", ref_plaintext, sizeof(ref_plaintext));
		goto bad;
	}

	/*
	 * Decrypt frame.
	 */
	if (!(*cip->ic_decap)(&key, skb)) {
		printk("tkip decap failed\n");
		/*
		 * Check reason for failure: phase1, phase2, frame data (ICV).
		 */
		if (memcmp(ctx->rx_ttak, ref_phase1, sizeof(ref_phase1))) {
			printk("decrypt phase1 botch\n");
			cmpfail(ctx->rx_ttak, sizeof(ctx->rx_ttak),
				ref_phase1, sizeof(ref_phase1));
		} else if (memcmp(ctx->rx_rc4key, ref_phase2, sizeof(ref_phase2))) {
			printf("decrypt phase2 botch\n");
			cmpfail(ctx->rx_rc4key, sizeof(ctx->rx_rc4key),
				ref_phase2, sizeof(ref_phase2));
		} else {
			printk("decrypt data does not compare\n");
			cmpfail(skb->data, skb->len,
				ref_plaintext, sizeof(ref_plaintext));
		}
		goto bad;
	}
	/*
	 * Verify: frame length, frame contents.
	 */
	if (skb->len != sizeof(ref_plaintext)) {
		printk("decap botch; length mismatch\n");
		cmpfail(skb->data, skb->len,
			ref_plaintext, sizeof(ref_plaintext));
		goto bad;
	}
	if (memcmp(skb->data, ref_plaintext, sizeof(ref_plaintext))) {
		printk("decap botch; data does not compare\n");
		cmpfail(skb->data, skb->len,
			ref_plaintext, sizeof(ref_plaintext));
		goto bad;
	}
	/*
	 * De-MIC decrypted frame.
	 */
	if (!ieee80211_crypto_demic(ic, &key, skb)) {
		printk("tkip demic failed\n");
		goto bad;
	}
	/* XXX check frame length and contents... */
	printk("802.11i TKIP test vectors passed\n");
bad:
	if (skb != NULL)
		dev_kfree_skb(skb);
	ieee80211_crypto_delkey(ic, &key);
}