Example #1
0
auryn_vector_float * SpikingGroup::get_state_vector(string key)
{
	if ( state_vectors.find(key) == state_vectors.end() ) {
		if ( get_vector_size() == 0 ) return NULL;
		auryn_vector_float * vec = auryn_vector_float_alloc (get_vector_size()); 
		state_vectors[key] = vec;
		return vec;
	} else {
		return state_vectors.find(key)->second;
	}
}
 void configure_impl(vcl_size_t /*kernel_id*/, viennacl::ocl::context & /*context*/, statements_container const & statements, viennacl::ocl::kernel & k, unsigned int & n_arg)  const
 {
   k.global_work_size(0,parameters_.local_size_0*parameters_.num_groups);
   k.global_work_size(1,1);
   cl_uint size = static_cast<cl_uint>(get_vector_size(statements.data().front()));
   k.arg(n_arg++, size/parameters_.simd_width);
 }
Example #3
0
gsl_vector_float * SpikingGroup::get_state_vector(string key)
{
	if ( state_vector.find(key) == state_vector.end() ) {
		gsl_vector_float * vec = gsl_vector_float_alloc (get_vector_size()); 
		state_vector[key] = vec;
		return vec;
	} else {
		return state_vector.find(key)->second;
	}
}
Example #4
0
void TIFGroup::init()
{
	e_rest = -60e-3;
	e_rev = -80e-3;
	thr = -50e-3;
	tau_ampa = 5e-3;
	tau_gaba = 10e-3;
	tau_mem = 20e-3;
	refractory_time = (unsigned short) (5.e-3/dt);

	calculate_scale_constants();
	
	ref = gsl_vector_ushort_alloc (get_vector_size()); 
	bg_current = get_state_vector("bg_current");

	t_g_ampa = gsl_vector_float_ptr ( g_ampa , 0 ); 
	t_g_gaba = gsl_vector_float_ptr ( g_gaba , 0 ); 
	t_bg_cur = gsl_vector_float_ptr ( bg_current , 0 ); 
	t_mem = gsl_vector_float_ptr ( mem , 0 ); 
	t_ref = gsl_vector_ushort_ptr ( ref , 0 ); 

	clear();

}
Example #5
0
void TIFGroup::init()
{
	e_rest = -60e-3;
	e_rev = -80e-3;
	thr = -50e-3;
	tau_ampa = 5e-3;
	tau_gaba = 10e-3;
	tau_mem = 20e-3;
	set_refractory_period(5e-3);

	calculate_scale_constants();
	
	ref = auryn_vector_ushort_alloc (get_vector_size()); 
	bg_current = get_state_vector("bg_current");

	t_g_ampa = auryn_vector_float_ptr ( g_ampa , 0 ); 
	t_g_gaba = auryn_vector_float_ptr ( g_gaba , 0 ); 
	t_bg_cur = auryn_vector_float_ptr ( bg_current , 0 ); 
	t_mem = auryn_vector_float_ptr ( mem , 0 ); 
	t_ref = auryn_vector_ushort_ptr ( ref , 0 ); 

	clear();

}
Example #6
0
static void f_longest(int n)
{
    int i;
    int j;
    int k;
    int l;
    int m;

    wcc[pos++] = n;

    /* if we have some edges we run DFS */
    for (i = 0; graph[n][i] >= 0; ++i) {
        f_longest(graph[n][i]);
    }

    /* That's end of our path */
    if (i == 0) {

        int *cand_new_wcc = calloc(pos + 1, sizeof(*cand_new_wcc));;
        memcpy(cand_new_wcc, wcc, pos*sizeof(*wcc));

        int is_new_in_wccs = 1;
        for (j = 0; j < counter; ++j) {  /* by all wccs */
            /* pos is equivalent of get_vector_size(wcc) but
           doesn't need to be -1 terminated */
            int vector_size = get_vector_size(wccs[j]);
            if (vector_size == pos) {
                if (memcmp(wcc, wccs[j], pos*sizeof(*wcc)) == 0) {
                    /* is the same */
                    is_new_in_wccs = 0;

                    break; /* end search */
                }
            }
            else if (vector_size < pos) { /* new greater */
                int delete_others = 0;
                for (m = j; m < counter; ++m) { /* by other wccs */
                    if (get_vector_size(wccs[m]) >= pos) {
                        continue;
                    }

                    int break_m_loop = 0;
                    int is_cand_cont_wcc = 1;
                    for (k = 0; k < vector_size; ++k) { /* by all elements j wcc */
                        int temp_wcc_v = wccs[m][k];

                        int is_new_v_in_wcc = 0;
                        for (l = 0; l  < pos; ++l) { /* by all elements wcc candidat */
                            if(cand_new_wcc[l] == temp_wcc_v) {
                                is_new_v_in_wcc = 1;
                                break; /* go check next element j wcc */
                            }
                        }
                        if (is_new_v_in_wcc == 0) {
                            is_cand_cont_wcc = 0;

                            break_m_loop = 1; /* j wcc candidat not contains wcc */
                            break;
                        }
                    }
                    if (break_m_loop) break;
                    if (is_cand_cont_wcc == 1) {
                        if (delete_others == 1) { /* delete wcc */
                            --counter;
                            memcpy(wccs[m], wccs[counter], get_vector_size(wccs[counter])*sizeof(*wccs[counter]));

                            wccs[counter][0] = -1;
                            wccs[counter] = NULL;
                        }
                        else if (delete_others == 0) { /* swap wcc */
                            is_new_in_wccs = 0;
                            cand_new_wcc[pos++] = -1;
                            wccs[m] = realloc(wccs[m], pos*sizeof(*cand_new_wcc));
                            memcpy(wccs[m], cand_new_wcc, pos*sizeof(*cand_new_wcc));

                            --pos;
                            delete_others = 1;

                        }
                    }
                }
            }

            else if (vector_size > pos) { /* new smaller */
                int is_wcc_cont_cand = 1;
                for (k = 0; k < pos; ++k) { /* by all elements wcc candidat */
                    int temp_wcc_v =  cand_new_wcc[k];

                    int is_new_v_in_wcc = 0;
                    for (l = 0; l < vector_size; ++l) { /* by all elements j wcc */
                        if(wccs[j][l] == temp_wcc_v) {
                            is_new_v_in_wcc = 1;
                            break; /* go check next element wcc candidat */
                        }
                    }

                    if (is_new_v_in_wcc == 0) {
                        is_wcc_cont_cand = 0;
                        break; /* go check next elemnt wcc candidat */
                    }
                }

                if (is_wcc_cont_cand == 1) {
                    is_new_in_wccs = 0;
                    break; /* go out */
                }
            }
        }

        if (is_new_in_wccs) {
            wcc[pos++] = -1;
            wccs[counter] = calloc(pos, sizeof(*wcc));
            assert(wccs[counter]);

            memcpy(wccs[counter], wcc, pos*sizeof(*wcc));
            ++counter;
            --pos;
        }
	free(cand_new_wcc);
    }

    --pos;

    return;
}
Example #7
0
/* Load plugin */
hash_stat load_plugin(void)
{
    char soname[1024];

    snprintf(soname,1024,"%s/hashkill/plugins/%s.so", DATADIR, get_current_plugin());
    dlhandle=dlopen(soname,RTLD_LAZY);
    if (dlhandle)
    {
        *(hash_stat **) (&hash_plugin_parse_hash) = dlsym(dlhandle, "hash_plugin_parse_hash");
        *(hash_stat **) (&hash_plugin_check_hash) = dlsym(dlhandle, "hash_plugin_check_hash");
        *(hash_stat **) (&hash_plugin_check_hash_dictionary) = dlsym(dlhandle, "hash_plugin_check_hash_dictionary");
        /* no special dictionary function? */
        if (hash_plugin_check_hash_dictionary==NULL)
        {
    	    *(hash_stat **) (&hash_plugin_check_hash_dictionary) = dlsym(dlhandle, "hash_plugin_check_hash");
        }

        *(int **) (&hash_plugin_hash_length) = dlsym(dlhandle, "hash_plugin_hash_length");
        *(int **) (&hash_plugin_is_raw) = dlsym(dlhandle, "hash_plugin_is_raw");
        *(int **) (&hash_plugin_is_special) = dlsym(dlhandle, "hash_plugin_is_special");
        *(void **) (&get_vector_size) = dlsym(dlhandle, "get_vector_size");
        *(int **) (&get_salt_size) = dlsym(dlhandle, "get_salt_size");
	
	if ( (!hash_plugin_parse_hash) || (!hash_plugin_check_hash) || (!hash_plugin_hash_length) || (!get_vector_size) || (!get_salt_size))
	{
	    if (!detecting) elog("Plugin %s does not export all the necessary functions!\n", get_current_plugin());
	    return hash_err;
	}
	salt_size = get_salt_size();

	/* import register functions */
	void(*register_add_username)(void (*add_username)(const char *username)) = dlsym(dlhandle, "register_add_username");
	void(*register_add_hash)(void (*add_hash)(const char *hash, int len)) = dlsym(dlhandle, "register_add_hash");
	void(*register_add_salt)(void (*add_salt)(const char *salt)) = dlsym(dlhandle, "register_add_salt");
	void(*register_add_salt2)(void (*add_salt2)(const char *salt2)) = dlsym(dlhandle, "register_add_salt2");
	void(*register_md5)(hash_stat  (*md5)(char *plaintext[VECTORSIZE], char *hash[VECTORSIZE], int len, int threadid)) = dlsym(dlhandle, "register_md5");
	void(*register_md5_unicode)(void (*md5_unicode)(char *plaintext[VECTORSIZE], char *hash[VECTORSIZE], int len[VECTORSIZE])) = dlsym(dlhandle, "register_md5_unicode");
	void(*register_md5_unicode_slow)(void (*md5_unicode_slow)(char *plaintext[VECTORSIZE], char *hash[VECTORSIZE], int len[VECTORSIZE])) = dlsym(dlhandle, "register_md5_unicode_slow");
	void(*register_md5_slow)(void (*md5_slow)(char *plaintext[VECTORSIZE], char *hash[VECTORSIZE], int len, int threadid)) = dlsym(dlhandle, "register_md5_slow");
	void(*register_md4)(hash_stat (*md4)(char *plaintext[VECTORSIZE], char *hash[VECTORSIZE], int len[VECTORSIZE],int threadid)) = dlsym(dlhandle, "register_md4");
	void(*register_md4_unicode)(hash_stat (*md4)(char *plaintext[VECTORSIZE], char *hash[VECTORSIZE], int len,int threadid)) = dlsym(dlhandle, "register_md4_unicode");
	void(*register_md4_slow)(void (*md4_slow)(char *plaintext[VECTORSIZE], char *hash[VECTORSIZE], int len[VECTORSIZE],int threadid)) = dlsym(dlhandle, "register_md4_slow");
	void(*register_md5_hex)(void (*md5_hex)(const char *hash[VECTORSIZE], char *hashhex[VECTORSIZE])) = dlsym(dlhandle, "register_md5_hex");
	void(*register_sha1)(hash_stat (*md5)(char *plaintext[VECTORSIZE], char *hash[VECTORSIZE], int len, int threadid)) = dlsym(dlhandle, "register_sha1");
	void(*register_sha1_unicode)(void (*sha1_unicode)(char *plaintext[VECTORSIZE], char *hash[VECTORSIZE], int len[VECTORSIZE])) = dlsym(dlhandle, "register_sha1_unicode");
	void(*register_sha1_slow)(void (*sha1_slow)(char *plaintext[VECTORSIZE], char *hash[VECTORSIZE], int len[VECTORSIZE])) = dlsym(dlhandle, "register_sha1_slow");
	void(*register_sha1_hex)(void (*md5_hex)(const char *hash[VECTORSIZE], char *hashhex[VECTORSIZE])) = dlsym(dlhandle, "register_sha1_hex");
	void(*register_sha256_unicode)(void (*sha256_unicode)(const char *plaintext[VECTORSIZE], char *hash[VECTORSIZE], int len[VECTORSIZE])) = dlsym(dlhandle, "register_sha256_unicode");
	void(*register_sha256_hex)(void (*sha256_hex)(const char *hash[VECTORSIZE], char *hashhex[VECTORSIZE])) = dlsym(dlhandle, "register_sha256_hex");
	void(*register_sha512_unicode)(void (*sha512_unicode)(const char *plaintext[VECTORSIZE], char *hash[VECTORSIZE], int len[VECTORSIZE])) = dlsym(dlhandle, "register_sha512_unicode");
	void(*register_sha384_unicode)(void (*sha384_unicode)(const char *plaintext[VECTORSIZE], char *hash[VECTORSIZE], int len[VECTORSIZE])) = dlsym(dlhandle, "register_sha384_unicode");
	void(*register_sha512_hex)(void (*sha512_hex)(const char *hash[VECTORSIZE], char *hashhex[VECTORSIZE])) = dlsym(dlhandle, "register_sha512_hex");
	void(*register_fcrypt)(hash_stat (*fcrypt)(const char *password[VECTORSIZE], const char *salt, char *ret[VECTORSIZE])) = dlsym(dlhandle, "register_fcrypt");
	void(*register_fcrypt_slow)(hash_stat (*fcrypt_slow)(const char *password[VECTORSIZE], const char *salt, char *ret[VECTORSIZE])) = dlsym(dlhandle, "register_fcrypt_slow");
	void(*register_PEM_readfile)(void (*PEM_readfile)(const char *passphrase, int *RSAret)) = dlsym(dlhandle, "register_PEM_readfile");
	void(*register_new_biomem)(void (*new_biomem)(FILE *file)) = dlsym(dlhandle, "register_new_biomem");
	void(*register_pbkdf2)(void (*pbkdf2)(const char *pass, unsigned char *salt, int saltlen, int iter, int keylen, unsigned char *out)) = dlsym(dlhandle, "register_pbkdf2");
	void(*register_pbkdf2_len)(void (*pbkdf2_len)(const char *pass, int passlen, unsigned char *salt, int saltlen, int iter, int keylen, unsigned char *out)) = dlsym(dlhandle, "register_pbkdf2_len");
	void(*register_pbkdf2_256_len)(void (*pbkdf2_256_len)(const char *pass, int passlen, unsigned char *salt, int saltlen, int iter, int keylen, unsigned char *out)) = dlsym(dlhandle, "register_pbkdf2_256_len");
	void(*register_hmac_sha1_file)(void (*hmac_sha1_file)(void *key, int keylen, char *filename, long offset, long size, unsigned char *output, int outputlen)) = dlsym(dlhandle, "register_hmac_sha1_file");
	void(*register_hmac_sha1)(void (*hmac_sha1)(void *key, int keylen, unsigned char *data, int datalen,unsigned char *output, int outputlen)) = dlsym(dlhandle, "register_hmac_sha1");
	void(*register_hmac_md5)(void (*hmac_md5)(void *key, int keylen, unsigned char *data, int datalen, unsigned char *output, int outputlen)) = dlsym(dlhandle, "register_hmac_md5");
	void(*register_ripemd160)(void (*ripemd160)(const char *plaintext[VECTORSIZE], char *hash[VECTORSIZE], int len[VECTORSIZE])) = dlsym(dlhandle, "register_ripemd160");
	void(*register_whirlpool)(void (*whirlpool)(const char *plaintext[VECTORSIZE], char *hash[VECTORSIZE], int len[VECTORSIZE])) = dlsym(dlhandle, "register_whirlpool");
	void(*register_pbkdf512)(void (*pbkdf512)(const char *pass, int len, unsigned char *salt, int saltlen, int iter, int keylen, unsigned char *out)) = dlsym(dlhandle, "register_pbkdf512");
	void(*register_pbkdfrmd160)(void (*pbkdfrmd160)(const char *pass, int len, unsigned char *salt, int saltlen, int iter, int keylen, unsigned char *out)) = dlsym(dlhandle, "register_pbkdfrmd160");
	void(*register_pbkdfwhirlpool)(void (*pbkdfwhirlpool)(const char *pass, int len, unsigned char *salt, int saltlen, int iter, int keylen, unsigned char *out)) = dlsym(dlhandle, "register_pbkdfwhirlpool");
	void(*register_aes_encrypt)(void (*aes_encrypt)(const unsigned char *key, int keysize, const unsigned char *in, int len, unsigned char *vec, unsigned char *out, int mode)) = dlsym(dlhandle, "register_aes_encrypt");
	void(*register_aes_decrypt)(void (*aes_decrypt)(const unsigned char *key, int keysize, const unsigned char *in, int len, unsigned char *vec, unsigned char *out, int mode)) = dlsym(dlhandle, "register_aes_decrypt");
	void(*register_des_ecb_encrypt)(void (*des_ecb_encrypt)(const unsigned char *key, int keysize, const unsigned char *in[VECTORSIZE], int len, unsigned char *out[VECTORSIZE], int mode)) = dlsym(dlhandle, "register_des_ecb_encrypt");
	void(*register_des_ecb_decrypt)(void (*des_ecbdecrypt)(const unsigned char *key, int keysize, const unsigned char *in, int len, unsigned char *out, int mode)) = dlsym(dlhandle, "register_des_ecb_decrypt");
	void(*register_des_cbc_encrypt)(void (*des_ecb_encrypt)(const unsigned char *key[VECTORSIZE], int keysize, const unsigned char *in[VECTORSIZE], int len[VECTORSIZE], unsigned char *out[VECTORSIZE], unsigned char *iv[VECTORSIZE], int mode)) = dlsym(dlhandle, "register_des_cbc_encrypt");
	void(*register_rc4_encrypt)(void (*des_rc4_encrypt)(const unsigned char *key, int keysize, const unsigned char *in, int len, unsigned char *out)) = dlsym(dlhandle, "register_rc4_encrypt");
	void(*register_lm)(void (*lm)(const unsigned char *in[VECTORSIZE], unsigned char *out[VECTORSIZE])) = dlsym(dlhandle, "register_lm");
	void(*register_lm_slow)(void (*lm_slow)(const unsigned char *in[VECTORSIZE], unsigned char *out[VECTORSIZE])) = dlsym(dlhandle, "register_lm_slow");
	void(*register_aes_cbc_encrypt)(void (*aes_cbc_encrypt)(const unsigned char *in,unsigned char *out,unsigned long length,AES_KEY *key,unsigned char ivec[16],int oper)) = dlsym(dlhandle, "register_aes_cbc_encrypt");
	void(*register_aes_set_encrypt_key)(int (*aes_set_encrypt_key)(const unsigned char *userKey,const int bits,AES_KEY *key)) = dlsym(dlhandle, "register_aes_set_encrypt_key");
	void(*register_aes_set_decrypt_key)(int (*aes_set_decrypt_key)(const unsigned char *userKey,const int bits,AES_KEY *key)) = dlsym(dlhandle, "register_aes_set_decrypt_key");
	void(*register_decrypt_aes_xts)(void (*decrypt_aes_xts)(char *key1, char *key2, char *in, char *out, int len, int sector, int cur_block)) = dlsym(dlhandle, "register_decrypt_aes_xts");
	void(*register_decrypt_twofish_xts)(void (*decrypt_twofish_xts)(char *key1, char *key2, char *in, char *out, int len, int sector, int cur_block)) = dlsym(dlhandle, "register_decrypt_twofish_xts");
	void(*register_decrypt_serpent_xts)(void (*decrypt_serpent_xts)(char *key1, char *key2, char *in, char *out, int len, int sector, int cur_block)) = dlsym(dlhandle, "register_decrypt_serpent_xts");



        if ((hash_plugin_parse_hash != NULL) && (hash_plugin_check_hash != NULL) && (hash_plugin_is_raw != NULL) && (hash_plugin_is_special != NULL))
        {
// register our callbacks
	    register_add_username(hash_proto_add_username);
	    register_add_hash(hash_proto_add_hash);
	    register_add_salt(hash_proto_add_salt);
	    register_add_salt2(hash_proto_add_salt2);
	    register_md5(hash_proto_md5);
	    register_md5_unicode(hash_proto_md5_unicode);
	    register_md5_unicode_slow(hash_proto_md5_unicode_slow);
	    register_md5_slow(hash_proto_md5_slow);
	    register_md4(hash_proto_md4);
	    register_md4_unicode(hash_proto_md4_unicode);
	    register_md4_slow(hash_proto_md4_slow);
	    register_md5_hex(hash_proto_md5_hex);
	    register_sha1(hash_proto_sha1);
	    register_sha1_unicode(hash_proto_sha1_unicode);
	    register_sha1_slow(hash_proto_sha1_slow);
	    register_sha1_hex(hash_proto_sha1_hex);
	    register_sha256_unicode(hash_proto_sha256_unicode);
	    register_sha256_hex(hash_proto_sha256_hex);
	    register_sha512_unicode(hash_proto_sha512_unicode);
	    register_sha384_unicode(hash_proto_sha384_unicode);
	    register_sha512_hex(hash_proto_sha512_hex);
	    register_fcrypt(hash_proto_fcrypt);
	    register_fcrypt_slow(hash_proto_fcrypt_slow);
	    register_new_biomem(hash_proto_new_biomem);
	    register_PEM_readfile(hash_proto_PEM_readfile);
	    register_pbkdf2(hash_proto_pbkdf2);
	    register_pbkdf2_len(hash_proto_pbkdf2_len);
	    register_pbkdf2_256_len(hash_proto_pbkdf2_256_len);
	    register_hmac_sha1_file(hash_proto_hmac_sha1_file);
	    register_hmac_sha1(hash_proto_hmac_sha1);
	    register_hmac_md5(hash_proto_hmac_md5);
	    register_ripemd160(hash_proto_ripemd160);
	    register_whirlpool(hash_proto_whirlpool);
	    register_pbkdf512(hash_proto_pbkdf512);
	    register_pbkdfrmd160(hash_proto_pbkdfrmd160);
	    register_pbkdfwhirlpool(hash_proto_pbkdfwhirlpool);
	    register_aes_encrypt(hash_proto_aes_encrypt);
	    register_aes_decrypt(hash_proto_aes_decrypt);
	    register_des_ecb_encrypt(hash_proto_des_ecb_encrypt);
	    register_des_ecb_decrypt(hash_proto_des_ecb_decrypt);
	    register_des_cbc_encrypt(hash_proto_des_cbc_encrypt);
	    register_rc4_encrypt(hash_proto_rc4_encrypt);
	    register_lm(hash_proto_lm);
	    register_lm_slow(hash_proto_lm_slow);
	    register_aes_cbc_encrypt(hash_proto_aes_cbc_encrypt);
	    register_aes_set_encrypt_key(hash_proto_aes_set_encrypt_key);
	    register_aes_set_decrypt_key(hash_proto_aes_set_decrypt_key);
	    register_decrypt_aes_xts(hash_proto_decrypt_aes_xts);
	    register_decrypt_twofish_xts(hash_proto_decrypt_twofish_xts);
	    register_decrypt_serpent_xts(hash_proto_decrypt_serpent_xts);

	    /* set vector size hackery */
	    if ( (strcmp(get_current_plugin(),"desunix")==0) || (strcmp(get_current_plugin(),"lm")==0) || (strcmp(get_current_plugin(),"oracle-old")==0)) 
	    {
		vectorsize = 128; 
		get_vector_size(128);
	    }
	    else if ( (strcmp(get_current_plugin(),"privkey")==0) || (strcmp(get_current_plugin(),"zip")==0) || (strcmp(get_current_plugin(),"wpa")==0) || (strcmp(get_current_plugin(),"rar")==0) || (strcmp(get_current_plugin(),"dmg")==0))
	    {
		vectorsize = 8;
		get_vector_size(8);
	    }
	    else if (strcmp(get_current_plugin(),"privkey")==0)
	    {
		vectorsize = 24;
		get_vector_size(24);
	    }
	    else 
	    {
		vectorsize = 12;
		get_vector_size(12);
	    }
	    
	    /* single-hash optimization for certain plugins */
	    cpu_optimize_single=0;
	    if ((strcmp(get_current_plugin(),"md5")==0) || (strcmp(get_current_plugin(),"sha1")==0) || (strcmp(get_current_plugin(),"md4")==0) || (strcmp(get_current_plugin(),"ntlm")==0) || (strcmp(get_current_plugin(),"desunix")==0) || (strcmp(get_current_plugin(),"md4")==0)) cpu_optimize_single=1;

	    /* is raw? */
	    hash_is_raw = hash_plugin_is_raw();
	    if (!detecting) hlog("Plugin \'%s\' loaded successfully\n",get_current_plugin());
	}
	else 
	{
	    if (!detecting) elog("Plugin \'%s\' could not be loaded\n",get_current_plugin());
	    dlclose(dlhandle);
	    return hash_err;
	}
    }
    else 
    {
	if (!detecting) elog("Cannot open plugin library: %s\n",soname);
	return hash_err;
    }
    return hash_ok;
}