示例#1
0
bool	aes_ctr_encrypter::set_key(const aes_256_key_t& key)
{
	if (set_key(EVP_aes_256_ctr(), key.key, key.iv) == false)
	{
		return false;
	}

	return true;
}
示例#2
0
文件: AES.cpp 项目: Yveaux/MySensors
void AES::do_aes_encrypt(byte *plain,int size_p,byte *cipher,byte *key, int bits)
{
	calc_size_n_pad(size_p);
	byte plain_p[get_size()];
	padPlaintext(plain,plain_p);
	int blocks = get_size() / N_BLOCK;
	set_key (key, bits) ;
	cbc_encrypt (plain_p, cipher, blocks);
}
示例#3
0
void LanguageData_Language::MergeFrom(const LanguageData_Language& from) {
  GOOGLE_CHECK_NE(&from, this);
  statement_.MergeFrom(from.statement_);
  if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
    if (from.has_key()) {
      set_key(from.key());
    }
  }
}
示例#4
0
u8 set_802_11_add_wep(_adapter* padapter, NDIS_802_11_WEP *wep)
{
	u8	bdefaultkey;
	u8	btransmitkey;
	sint	keyid;
	struct security_priv *psecuritypriv = &padapter->securitypriv;
	u8	ret = _SUCCESS;

_func_enter_;

	bdefaultkey = (wep->KeyIndex & 0x40000000) > 0 ? _FALSE : _TRUE;	//for ???
	btransmitkey = (wep->KeyIndex & 0x80000000) > 0 ? _TRUE : _FALSE;	//for ???
	keyid = wep->KeyIndex & 0x3fffffff;

	if (keyid >= WEP_KEYS) {
		RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_, ("MgntActSet_802_11_ADD_WEP: keyid>4 FAIL!\n"));
		ret = _FALSE;
		goto exit;
	}

	switch (wep->KeyLength)
	{
		case 5:
			psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
			RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("MgntActSet_802_11_ADD_WEP:wep->KeyLength=5\n"));
			break;
		case 13:
			psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
			RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("MgntActSet_802_11_ADD_WEP:wep->KeyLength=13\n"));
			break;
		default:
			psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
			RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("MgntActSet_802_11_ADD_WEP:wep->KeyLength!=5 or 13\n"));
			break;
	}

	RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("MgntActSet_802_11_ADD_WEP:befor memcpy, wep->KeyLength=0x%x wep->KeyIndex=0x%x  keyid =%x\n",wep->KeyLength,wep->KeyIndex,keyid));

	_memcpy(psecuritypriv->dot11DefKey[keyid].skey, &wep->KeyMaterial, wep->KeyLength);
	psecuritypriv->dot11DefKeylen[keyid] = wep->KeyLength;
	psecuritypriv->dot11PrivacyKeyIndex = keyid;

	RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("MgntActSet_802_11_ADD_WEP:security key material: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
		psecuritypriv->dot11DefKey[keyid].skey[0],psecuritypriv->dot11DefKey[keyid].skey[1],psecuritypriv->dot11DefKey[keyid].skey[2],
		psecuritypriv->dot11DefKey[keyid].skey[3],psecuritypriv->dot11DefKey[keyid].skey[4],psecuritypriv->dot11DefKey[keyid].skey[5],
		psecuritypriv->dot11DefKey[keyid].skey[6],psecuritypriv->dot11DefKey[keyid].skey[7],psecuritypriv->dot11DefKey[keyid].skey[8],
		psecuritypriv->dot11DefKey[keyid].skey[9],psecuritypriv->dot11DefKey[keyid].skey[10],psecuritypriv->dot11DefKey[keyid].skey[11],
		psecuritypriv->dot11DefKey[keyid].skey[12]));

	if (set_key(padapter, psecuritypriv, keyid) == _FAIL)
		ret = _FALSE;
exit:

_func_exit_;

	return ret;
}
示例#5
0
void LoadConfig()
{
	FILE *f;
	char str[256];
	bool have_user_setting = false;

	if (!conf)
		conf = new PADconf;

	conf->init();

	const std::string iniFile(s_strIniPath + "OnePAD.ini");
	f = fopen(iniFile.c_str(), "r");
	if (f == NULL)
	{
		printf("OnePAD: failed to load ini %s\n", iniFile.c_str());
		SaveConfig(); //save and return
		return;
	}

	u32 value;
	if (fscanf(f, "log = %d\n", &value) == 0) return;
	conf->log = value;
	if (fscanf(f, "options = %d\n", &value) == 0) return;
	conf->options = value;
	if (fscanf(f, "mouse_sensibility = %d\n", &value) == 0) return;
	conf->sensibility = value;
	if (fscanf(f, "joy_pad_map = %d\n", &value) == 0) return;
	conf->joyid_map = value;
	if (fscanf(f, "ff_intensity = %d\n", &value) == 0) return;
	conf->ff_intensity = value;

	for (int pad = 0; pad < 2; pad++)
	{
		for (int key = 0; key < MAX_KEYS; key++)
		{
			sprintf(str, "[%d][%d] = 0x%%x\n", pad, key);
			u32 temp = 0;

			if (fscanf(f, str, &temp) == 0) temp = 0;
			set_key(pad, key, temp);
			if (temp && pad == 0) have_user_setting = true;
		}
	}

	u32 pad;
	u32 keysym;
	u32 index;
	while( fscanf(f, "PAD %d:KEYSYM 0x%x = %d\n", &pad, &keysym, &index) != EOF ) {
		set_keyboad_key(pad, keysym, index);
		if(pad == 0) have_user_setting = true;
	}

	fclose(f);

	if (!have_user_setting) DefaultKeyboardValues();
}
示例#6
0
void Client::on_input_event(const InputData& input) {
    if (!are_options_visible()) {
        switch (input.data_type) {
            case InputData::InputDataTypeKeyDown:
                set_key(MappedKey::DeviceKeyboard, input.keycode);
                /* escape fallback */
                if (input.key_type == InputData::InputKeyTypeEscape) {
                    if (!input.key_repeat) {
                        show_options_menu();
                    }
                }
                break;

            case InputData::InputDataTypeKeyUp:
                reset_key(MappedKey::DeviceKeyboard, input.keycode);
                break;

            case InputData::InputDataTypeJoyButtonDown:
                set_key(MappedKey::DeviceJoyButton, input.param1);
                break;

            case InputData::InputDataTypeJoyButtonUp:
                reset_key(MappedKey::DeviceJoyButton, input.param1);
                break;

            case InputData::InputDataTypeJoyMotion:
            {
                joyaxis_t axis = static_cast<joyaxis_t>(input.param1);
                if (me) {
                    if (!get_stack_count()) {
                        me->state.client_server_state.jaxis = axis;
                    } else {
                        me->state.client_server_state.jaxis = 0;
                    }
                }
                break;
            }

            default:
                break;
        }
    }
}
void draw_ring(struct razer_keys *keys,struct razer_pos *pos,struct razer_rgb *color)
{
	set_key(keys,pos->x+1, pos->y,color);
	set_key(keys,pos->x-1, pos->y,color);
	if(pos->y==4 || pos->y==1)
	{
		set_key(keys,pos->x-1, pos->y-1,color);
		set_key(keys,pos->x, pos->y-1,color);
		set_key(keys,pos->x-1, pos->y+1,color);
		set_key(keys,pos->x, pos->y+1,color);
	}
	else
	{
		set_key(keys,pos->x, pos->y-1,color);
		set_key(keys,pos->x+1, pos->y-1,color);
		set_key(keys,pos->x, pos->y+1,color);
		set_key(keys,pos->x+1, pos->y+1,color);
	}
}
示例#8
0
static void find_best_workgroup()
{
	cl_event myEvent;
	cl_ulong startTime, endTime, kernelExecTimeNs = CL_ULONG_MAX;
	size_t my_work_group = 1;
	cl_int ret_code;
	int i;
	size_t max_group_size;

	clGetDeviceInfo(devices[gpu_id], CL_DEVICE_MAX_WORK_GROUP_SIZE,
	    sizeof(max_group_size), &max_group_size, NULL);
	cl_command_queue queue_prof =
	    clCreateCommandQueue(context[gpu_id], devices[gpu_id],
	    CL_QUEUE_PROFILING_ENABLE,
	    &ret_code);
	//printf("Max Group Work Size %d\n",(int)max_group_size);
	local_work_size = 1;

	/// Set keys
	char *pass = "******";
	for (i = 0; i < KEYS_PER_CRYPT; i++) {
		set_key(pass, i);
	}
	/// Copy data to GPU
	HANDLE_CLERROR(clEnqueueWriteBuffer
	    (queue_prof, mem_in, CL_FALSE, 0, insize, inbuffer, 0, NULL, NULL),
	    "Copy memin");
	HANDLE_CLERROR(clEnqueueWriteBuffer(queue_prof, mem_salt, CL_FALSE, 0,
		saltsize, &host_salt, 0, NULL, NULL), "Copy memsalt");

	/// Find minimum time
	for (my_work_group = 1; (int) my_work_group <= (int) max_group_size;
	    my_work_group *= 2) {

		size_t localworksize = my_work_group;
		HANDLE_CLERROR(clEnqueueNDRangeKernel
		    (queue_prof, crypt_kernel, 1, NULL, &global_work_size,
			&localworksize, 0, NULL, &myEvent), "Set ND range");


		HANDLE_CLERROR(clFinish(queue_prof), "clFinish error");
		clGetEventProfilingInfo(myEvent, CL_PROFILING_COMMAND_SUBMIT,
		    sizeof(cl_ulong), &startTime, NULL);
		clGetEventProfilingInfo(myEvent, CL_PROFILING_COMMAND_END,
		    sizeof(cl_ulong), &endTime, NULL);

		if ((endTime - startTime) < kernelExecTimeNs) {
			kernelExecTimeNs = endTime - startTime;
			local_work_size = my_work_group;
		}
		//printf("%d time=%lld\n",(int) my_work_group, endTime-startTime);
	}
	//printf("Optimal Group work Size = %d\n",(int)local_work_size);
	clReleaseCommandQueue(queue_prof);
}
示例#9
0
void testDES()
{
    char t[100]="11111111";
	int i;
	set_key(t);
	scanf("%s",t);
    des_encrypt(t,t);
    printf("密文长度为%d %s\n",strlen(t),t);
    des_decrypt(t,t);
    printf("明文长度为%d %s\n",strlen(t),t);
}
示例#10
0
result_t Stats::set_key(int n, v8::Local<v8::Value> key)
{
    v8::String::Utf8Value str(key);
    const char *p = *str;
    if (p == NULL)
        return CHECK_ERROR(CALL_E_INVALIDARG);

    set_key(n, p);

    return 0;
}
示例#11
0
void Preferences::copy(const Preferences& preferences) {
    for (size_t i = 0; i < KEY_COUNT; ++i) {
        set_key(i, preferences.key(i));
    }
    set_play_idle_music(preferences.play_idle_music());
    set_play_music_in_game(preferences.play_music_in_game());
    set_speech_on(preferences.speech_on());
    set_volume(preferences.volume());
    set_screen_size(preferences.screen_size());
    set_scenario_identifier(preferences.scenario_identifier());
}
示例#12
0
/*
* EAX_Decryption Constructor
*/
EAX_Decryption::EAX_Decryption(BlockCipher* ciph,
                               const SymmetricKey& key,
                               const InitializationVector& iv,
                               size_t tag_size) :
   EAX_Base(ciph, tag_size)
   {
   set_key(key);
   set_iv(iv);
   queue.resize(2*TAG_SIZE + DEFAULT_BUFFERSIZE);
   queue_start = queue_end = 0;
   }
示例#13
0
文件: dialog.cpp 项目: adi6190/pcsx2
		void remove_selected()
		{
			int key, pad, keysym;
			if (get_selected(pad, key, keysym))
			{
				if (keysym)
					conf->keysym_map[pad].erase(keysym);
				else
					set_key(pad, key, 0);
				update();
			}
		}
示例#14
0
void Client::set_key(MappedKey::Device dev, int param) {
    set_key(dev, param, binding.left, PlayerKeyStateLeft);
    set_key(dev, param, binding.right, PlayerKeyStateRight);
    set_key(dev, param, binding.up, PlayerKeyStateUp);
    set_key(dev, param, binding.down, PlayerKeyStateDown);
    set_key(dev, param, binding.jump, PlayerKeyStateJump);
    set_key(dev, param, binding.fire, PlayerKeyStateFire);
    set_key(dev, param, binding.drop1, PlayerKeyStateDrop1);
    set_key(dev, param, binding.drop2, PlayerKeyStateDrop2);
    set_key(dev, param, binding.drop3, PlayerKeyStateDrop3);

    if (binding.chat.device == dev && binding.chat.param == param) {
        if (!get_stack_count()) {
            subsystem.clear_input_buffer();
            int vw = subsystem.get_view_width();
            int vh = subsystem.get_view_height();
            int ww = 350;
            int wh = 30;
            GuiWindow *window = push_window(1, 1, ww, wh, "Enter Message");
            window->set_on_keydown(static_window_keydown, this);
            window->set_on_joybuttondown(static_window_joybutton_down, this);
            ww = window->get_client_width();
            chat_textbox = create_textbox(window, Spc, Spc, ww - 2 * Spc, "");
            window->set_height(window->get_height() - window->get_client_height() + 2 * Spc + chat_textbox->get_height());
            window->set_x(vw / 2 - window->get_client_width() / 2);
            window->set_y(vh / 2 - window->get_client_height() / 2);
            chat_textbox->set_focus();
            if (me) {
                me->state.client_server_state.key_states = 0;
            }
        }
    }

    if (binding.stats.device == dev && binding.stats.param == param) {
        if (!get_stack_count()) {
            if (tournament) {
                tournament->show_stats(true);
            }
        }
    }

    if (binding.escape.device == dev && binding.escape.param == param) {
        show_options_menu();
    }
}
示例#15
0
/*
* XTS_Decryption constructor
*/
XTS_Decryption::XTS_Decryption(BlockCipher* ciph,
                               const SymmetricKey& key,
                               const InitializationVector& iv)
   {
   cipher = ciph;
   cipher2 = ciph->clone();
   tweak.create(cipher->BLOCK_SIZE);
   buffer.create(2 * cipher->BLOCK_SIZE);
   position = 0;

   set_key(key);
   set_iv(iv);
   }
示例#16
0
inline void set_bprint( container *C, buffer *B, char *delim, value a )
{
    int		i=0;
    iterator	it = set_begin(a.C);

    for (; it.valid; it=set_next(it))
	{
	    if (i==0) i++;
	    else bprintf(B, "%s", delim);

	    bprintv(((set_container_priv*)C->priv)->Key, B, delim, set_key(it));
	}
}
示例#17
0
/*
 * Scroll up/down by figuring out the pred/succ key in the model
 */
static void
screen_scroll_up(Screen *s)
{
	RowIterator iter = RowMapLowerBound(rowmap(s), key(s));

	if (iter != RowMapBegin(rowmap(s))) {
		iter--;

		set_key(s, RowGetKey(iter));
	} else {
		clear_key(s);
	}
}
示例#18
0
static void
screen_scroll_down(Screen *s)
{
	RowIterator iter = RowMapLowerBound(rowmap(s), key(s));

	if (iter != RowMapEnd(rowmap(s)))
	{
		iter++;

		if (iter != RowMapEnd(rowmap(s)))
			set_key(s, RowGetKey(iter));
	}
}
示例#19
0
文件: crypt.cpp 项目: pierz/vic
int Crypt::command(int argc, const char*const* argv)
{
	if (argc == 3) {
		Tcl& tcl = Tcl::instance();
		if (strcmp(argv[1], "key") == 0) {
			if (set_key(argv[2]) != 0)
				tcl.result("0");
			else
				tcl.result("1");
			return (TCL_OK);
		}
	}
	return (TclObject::command(argc, argv));
}
示例#20
0
inline void set_print( container *C, value a )
{
    int		i=0;
    iterator	it = set_begin(a.C);

    printf("(");
    for (; it.valid; it=set_next(it))
	{
	    if (i==0) i++;
	    else printf(" ");

	    printv(((set_container_priv*)C->priv)->Key, set_key(it));
	}
    printf(")");
}
示例#21
0
void	Joystick::save_default_config( void ) {
	FILE *stream;

	if ((stream = fopen(CONFIG_FILE, "w")) == NULL)
		return ;

	fputs("1,1,0,0,0", stream);
	fclose(stream);
	this->config[0] = 1;
	this->config[1] = 1;
	this->config[2] = 0;
	this->config[3] = 0;
	this->config[4] = 0;
	set_key();
}
示例#22
0
文件: bstree.c 项目: gidj/cStructures
Node tree_create(int key, void* value, int elementSize, Node left, Node right)
{
  assert(value);
  assert(elementSize > 0);
  
  Node node = malloc(sizeof(*node));
  assert(node);

  set_key(node, key);
  set_value(node, value, elementSize);
  set_elementSize(node, elementSize);
  set_left(node, left);
  set_right(node, right);

  return node;
}
示例#23
0
    void register_service(std::string const &name,
			  int port,
			  std::map<std::string, std::string> const &txt)
    {
	directoryd::ServiceRequest request;
	request.set_type(directoryd::REGISTER);
	auto *r = request.mutable_register_();
	auto l = r->add_location();
	l->set_port(port);
	l->set_type("_hotdec._tcp");
	r->set_name(name);
	for (auto &t : txt) {
	    auto txtfield = r->add_txt();
	    txtfield->set_key(t.first);
	    txtfield->set_value(t.second);
	}
	zframe_t *sf = zframe_new(NULL, request.ByteSize());
	assert (sf != NULL);
	request.SerializeToArray(zframe_data(sf),zframe_size(sf));

	string buffer;
	if (debug && TextFormat::PrintToString(request, &buffer)) {
	    fprintf(stderr, "request: %s\n", buffer.c_str());
	}

	int retval = zframe_send(&sf, DDClient::instance().register_socket(), 0);
	assert(retval == 0);

	zframe_t *rf = zframe_recv (DDClient::instance().register_socket());
	directoryd::ServiceReply reply;
	reply.ParseFromArray(zframe_data(rf),zframe_size(rf));

	if (debug && TextFormat::PrintToString(reply, &buffer)) {
	    fprintf(stderr, "reply: %s\n", buffer.c_str());
	}

	zframe_destroy(&rf);

	if (reply.type() != directoryd::REGISTER) {
	    throw RegistrationError("Got back incorrect message type when trying to register.");
	}
	if (reply.success() != true) {
	    throw RegistrationError(reply.result());
	}

	RegistrationManager::instance().add(name);
    }
示例#24
0
文件: udpif.c 项目: sTeeLM/shadowfax
static void
low_level_init(struct netif *netif)
{
  struct udpif *udpif;
  struct sockaddr_in addr;

  udpif = (struct udpif *)netif->state;

  /* Obtain MAC address from network interface. */

  /* (We just fake an address...), need make random */
  /*
  udpif->ethaddr->addr[0] = 0x1;
  udpif->ethaddr->addr[1] = 0x2;
  udpif->ethaddr->addr[2] = 0x3;
  udpif->ethaddr->addr[3] = 0x4;
  udpif->ethaddr->addr[4] = 0x5;
  udpif->ethaddr->addr[5] = 0x6;
  */
  rand_hw_addr(udpif->ethaddr->addr);
  /* Do whatever else is needed to initialize interface. */

  set_key(udpif->enc_handle, udpif->ethaddr->addr, 6);

  udpif->fd = socket(PF_INET, SOCK_DGRAM, 0);
  LWIP_DEBUGF(UDPIF_DEBUG, ("udpif_init: fd %d\n", udpif->fd));
  if(udpif->fd == -1) {
    perror("udpif_init: cannot open socket");
    exit(1);
  }

  bzero(&addr, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = udpif->local_ip.addr;
  addr.sin_port = udpif->local_port;
  
  if(bind(udpif->fd, (struct sockaddr *)&addr, sizeof(addr)) == -1)
  {
    perror("udpif_init: bind error");
    exit(1);
  }

  sys_thread_new("udpif_thread", udpif_thread, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);

}
示例#25
0
void Joystick::load_config( void ) {
	FILE *stream;
	char buff[128] = {0};

	if ((stream = fopen(CONFIG_FILE, "r")) == NULL) {
		save_default_config();
		return ;
	}
	if ( fgets (buff , 128 , stream) == NULL ) {
		fclose(stream);
		save_default_config();
		return ;
	}

	if (strlen(buff) < 9)
		return ;
	if ((buff[0] - '0' != 1 && buff[0] - '0' != 0)
		|| (buff[2] - '0' != 1 && buff[2] - '0' != 0)
		|| (buff[4] - '0' != 1 && buff[4] - '0' != 0)
		|| (buff[6] - '0' != 1 && buff[6] - '0' != 0)
		|| (buff[8] - '0' != 1 && buff[8] - '0' != 0))
			return ;

	this->config[0] = buff[0] - '0';
	this->config[1] = buff[2] - '0';
	this->config[2] = buff[4] - '0';
	this->config[3] = buff[6] - '0';
	this->config[4] = buff[8] - '0';
	fclose(stream);

	int i = 0, tmp = 0;

	while (i < 5) {
		if (this->config[i] == 1)
			tmp++;
		if (tmp > 2) {
			save_default_config();
			return ;
		}
		i++;
	}

	set_key();
}
示例#26
0
文件: xif_key.cpp 项目: ChangerR/xcc
void Cxif_key::load_old(const byte*& data)
{
	{
		// keys
		int count = read_int(data);
		while (count--)
		{
			Cxif_key& i = set_key(read_int(data));
			i.load_old(data);
		}
	}

	{
		// values
		int count = read_int(data);
		while (count--)
		{
			Cxif_value& i = set_value(read_int(data));
			i.load_old(data);
		}
	}
}
示例#27
0
//##############################################################################
//##############################################################################
void
BerkeleyDB::add_new_range_version()
{
    RANGE_LOG_FUNCTION();
    this->init_info();
    auto lock = info_->write_lock(record_type::GRAPH_META, "graph_list");

    std::string buf = info_->get_record(record_type::GRAPH_META,
            "range_changelist");
    ChangeList changes;
    if(!buf.empty()) {
        changes.ParseFromString(buf);
    }

    std::unordered_map<std::string, uint64_t> vermap;
    for (auto &gname : listGraphInstances()) {
        auto ginst = getGraphInstance(gname);
        vermap[gname] = ginst->version();
    }

    ChangeList_Change *c = changes.add_change();

    for(auto &verinfo : vermap) {
        auto item = c->add_items();
        item->set_key(verinfo.first);
        item->set_version(verinfo.second);
    }

    struct timeval cur_time;
    gettimeofday(&cur_time, NULL);

    auto ts = c->mutable_timestamp();
    ts->set_seconds(cur_time.tv_sec);
    ts->set_msec(cur_time.tv_usec / 1000);

    changes.set_current_version(changes.current_version() + 1);
    info_->commit_record(std::make_tuple(record_type::GRAPH_META, "range_changelist", 0, changes.SerializeAsString()));
}
示例#28
0
cl_ulong gws_test(int gws)
{
	cl_ulong startTime, endTime, run_time;
	cl_command_queue queue_prof;
	cl_event myEvent;
	cl_int ret_code;
	int i;
	int num = VF * gws;

	create_clobj(gws);
	queue_prof = clCreateCommandQueue(context[ocl_gpu_id], devices[ocl_gpu_id], CL_QUEUE_PROFILING_ENABLE, &ret_code);
	for (i = 0; i < num; i++)
		set_key(rar_fmt.params.tests[0].plaintext, i);
	HANDLE_CLERROR(clEnqueueWriteBuffer(queue_prof, cl_salt, BLOCK_IF_DEBUG, 0, 8, saved_salt, 0, NULL, NULL), "Failed transferring salt");
	HANDLE_CLERROR(clEnqueueWriteBuffer(queue_prof, cl_saved_key, BLOCK_IF_DEBUG, 0, UNICODE_LENGTH * num, saved_key, 0, NULL, NULL), "Failed transferring keys");
	HANDLE_CLERROR(clEnqueueWriteBuffer(queue_prof, cl_saved_len, BLOCK_IF_DEBUG, 0, sizeof(int) * num, saved_len, 0, NULL, NULL), "Failed transferring lengths");
	ret_code = clEnqueueNDRangeKernel(queue_prof, crypt_kernel, 1, NULL, &global_work_size, &local_work_size, 0, NULL, &myEvent);
	if (ret_code != CL_SUCCESS) {
		fprintf(stderr, "Error: %s\n", get_error_name(ret_code));
		clReleaseCommandQueue(queue_prof);
		release_clobj();
		return 0;
	}
	HANDLE_CLERROR(clFinish(queue_prof), "Failed running kernel");
	clGetEventProfilingInfo(myEvent, CL_PROFILING_COMMAND_SUBMIT, sizeof(cl_ulong), &startTime, NULL);
	clGetEventProfilingInfo(myEvent, CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &endTime, NULL);
	run_time = endTime - startTime;
	HANDLE_CLERROR(clEnqueueReadBuffer(queue_prof, cl_aes_iv, BLOCK_IF_DEBUG, 0, 16 * num, aes_iv, 0, NULL, &myEvent), "Failed reading iv back");
	HANDLE_CLERROR(clEnqueueReadBuffer(queue_prof, cl_aes_key, BLOCK_IF_DEBUG, 0, 16 * num, aes_key, 0, NULL, &myEvent), "Failed reading key back");
	HANDLE_CLERROR(clFinish(queue_prof), "Failed reading results back");
	clGetEventProfilingInfo(myEvent, CL_PROFILING_COMMAND_SUBMIT, sizeof(cl_ulong), &startTime, NULL);
	clGetEventProfilingInfo(myEvent, CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &endTime, NULL);
	clReleaseCommandQueue(queue_prof);
	release_clobj();

	return (run_time + endTime - startTime);
}
示例#29
0
文件: arc.c 项目: mdrone/TR15Badge
void loop_clone_rfid(uint8_t *menu, uint8_t *opmode)
{
    uint8_t data[80];
    uint8_t keyindex = 0;
    uint8_t block = 0;
    uint8_t tries = 0;
    int res, oid;

	get_firmware_version();

    while (block < BLOCKS) {
        if ( READ != *menu) { break; }
        res = mifare_reader_init(data, sizeof(data));

        if (tries >= KEYS) {
            tries = 0;
            block += 1;
        }

        if (res >= 0) {
            res = initiator_init(data, sizeof(data));

            if (res >= 11) {
                if (0x00 == data[3] && data[6] >= 0x04) {
                    memcpy(&oid, &data[7], sizeof(oid));
                    if (0x00 == block) {
                        debug_printf("MIFARE_CARD_ID:");
                        rfid_hexdump(&oid, sizeof(oid));
                    }

                    set_uid(data, oid);
                    set_key(data, keyindex);

                    res = mifare_authenticate_block(data, sizeof(data), block);

/*
                    debug_printf("res:");
                    rfid_hexdump(&res, sizeof(res));

                    debug_printf("data:");
                    rfid_hexdump(&data[0], sizeof(data));
*/

                    if (0x41 == data[0] && 0x00 == data[1]) {
                        debug_printf("Auth Succeeded.\n");
                        tries = 0;

                        switch (*opmode) {
                            case READ:
                                res = mifare_read_block(data, sizeof(data), block);

                                if (res == 18) {
                                    debug_printf("Block:");
                                    rfid_hexdump(&block, sizeof(block));
                                    debug_printf("Data:");
                                    rfid_hexdump(&data[2], BLOCK_SIZE);
                                    debug_printf("Key:");
                                    rfid_hexdump(&default_keys[keyindex], MIFARE_KEY_SIZE);

                                    memcpy(&mifare_card[block*BLOCK_SIZE], &data[2], BLOCK_SIZE);
                                    if (0x00 == (block+1) % 4) {
                                        memcpy(&mifare_card[block*BLOCK_SIZE], &default_keys[keyindex], MIFARE_KEY_SIZE);
                                        memcpy(&mifare_card[block*BLOCK_SIZE+6], &access_bytes[0], ACCESS_BYTES);
                                        memcpy(&mifare_card[block*BLOCK_SIZE+10], &key_b[0], MIFARE_KEY_SIZE);
                                    }
                                }
                            break;
                            case WRITE:
                                memcpy(&data[4], &mifare_card[block*BLOCK_SIZE], BLOCK_SIZE);
                                res = mifare_write_block(data, sizeof(data), block);
                                debug_printf("res:");
                                rfid_hexdump(&res, sizeof(res));
                            break;
                        }
                        block += 1;
                    } else if (0x41 == data[0] && 0x14 == data[1]) {
                        debug_printf("Auth Failed.\n");
                        keyindex = (keyindex + 1) % KEYS;
                        tries += 1;
                    }
                }
            }
        } else {
            turn_rf_off(data, sizeof(data));
        }
    }
    *menu = LIBNFC;
}
示例#30
0
int rt2x00mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
		      struct ieee80211_vif *vif, struct ieee80211_sta *sta,
		      struct ieee80211_key_conf *key)
{
	struct rt2x00_dev *rt2x00dev = hw->priv;
	int (*set_key) (struct rt2x00_dev *rt2x00dev,
			struct rt2x00lib_crypto *crypto,
			struct ieee80211_key_conf *key);
	struct rt2x00lib_crypto crypto;
	static const u8 bcast_addr[ETH_ALEN] =
		{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, };
	struct rt2x00_sta *sta_priv = NULL;

	if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
		return 0;

	if (!rt2x00_has_cap_hw_crypto(rt2x00dev))
		return -EOPNOTSUPP;

	/*
	 * To support IBSS RSN, don't program group keys in IBSS, the
	 * hardware will then not attempt to decrypt the frames.
	 */
	if (vif->type == NL80211_IFTYPE_ADHOC &&
	    !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
		return -EOPNOTSUPP;

	if (key->keylen > 32)
		return -ENOSPC;

	memset(&crypto, 0, sizeof(crypto));

	crypto.bssidx = rt2x00lib_get_bssidx(rt2x00dev, vif);
	crypto.cipher = rt2x00crypto_key_to_cipher(key);
	if (crypto.cipher == CIPHER_NONE)
		return -EOPNOTSUPP;
	if (crypto.cipher == CIPHER_TKIP && rt2x00_is_usb(rt2x00dev))
		return -EOPNOTSUPP;

	crypto.cmd = cmd;

	if (sta) {
		crypto.address = sta->addr;
		sta_priv = sta_to_rt2x00_sta(sta);
		crypto.wcid = sta_priv->wcid;
	} else
		crypto.address = bcast_addr;

	if (crypto.cipher == CIPHER_TKIP)
		memcpy_tkip(&crypto, &key->key[0], key->keylen);
	else
		memcpy(crypto.key, &key->key[0], key->keylen);
	/*
	 * Each BSS has a maximum of 4 shared keys.
	 * Shared key index values:
	 *	0) BSS0 key0
	 *	1) BSS0 key1
	 *	...
	 *	4) BSS1 key0
	 *	...
	 *	8) BSS2 key0
	 *	...
	 * Both pairwise as shared key indeces are determined by
	 * driver. This is required because the hardware requires
	 * keys to be assigned in correct order (When key 1 is
	 * provided but key 0 is not, then the key is not found
	 * by the hardware during RX).
	 */
	if (cmd == SET_KEY)
		key->hw_key_idx = 0;

	if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
		set_key = rt2x00dev->ops->lib->config_pairwise_key;
	else
		set_key = rt2x00dev->ops->lib->config_shared_key;

	if (!set_key)
		return -EOPNOTSUPP;

	return set_key(rt2x00dev, &crypto, key);
}