//====================================================================
// interface APIs
//====================================================================
static int get_secu_ra_key(fp_int *n, fp_int *e, fp_int *d)
{
	int nRet = 1;
	if(!n || !e || !d)
		return nRet;
	if(psecu_ra->status != 0)
		return nRet;
	
	fp_init(n);
	fp_init(e);
	fp_init(d);
	/*memcpy(n->dp,szTxtN,128);
	memcpy(e->dp,szTxtE,128);
	memcpy(d->dp,szTxtD,128);*/
	memcpy(n->dp, psecu_ra->n, 128);
	memcpy(e->dp,psecu_ra->e,5);
	memcpy(d->dp, psecu_ra->d, 128);
	
	n->used=FP_SIZE;
	fp_clamp(n);			
	e->used=FP_SIZE;
	fp_clamp(e);			
	d->used=FP_SIZE;
	fp_clamp(d);
	
	nRet = 0;		
	
	return nRet;	
}
//-------------------------------------------------------------------------------------
static int get_auth_ra_key(fp_int *n, fp_int *e, fp_int *d)
{
	int nRet = 1;
	if(!n || !e || !d)
		return nRet;
	if(pauth_ra->status != 0)
		return nRet;
	
//	unsigned char szTxtN[] = {0xB9,0x14,0xF5,0x2B,0x27,0x16,0x97,0x8A,0x19,0x54,0x8C,0x38,0xB9,0xA5,0xA9,0xA1,0x6C,0x8A,0x3A,0x2A,0x8D,0x1D,0x10,0x44,0x8B,0x53,0x8A,0xA4,0xE4,0x49,0x82,0xA1,0xD5,0x1D,0x3B,0x0A,0x2B,0xA0,0x48,0x0A,0x9D,0xBA,0xF7,0x79,0xC9,0xF2,0x17,0xE2,0x6B,0x32,0x8F,0xC9,0xED,0x13,0xA8,0x38,0xD1,0x27,0x2A,0xBD,0xE1,0xE8,0x8C,0xAF,0x0A,0x15,0x58,0xF7,0xF5,0x8D,0xAA,0x85,0xBB,0xEB,0x51,0x74,0x66,0x8C,0x00,0xB4,0x1E,0x97,0x14,0xD6,0x1B,0x3A,0x3E,0x54,0xED,0x8C,0x82,0xDA,0x3E,0x06,0x68,0xFB,0x51,0x0C,0x72,0xF6,0xE3,0x0F,0x09,0xF2,0xB3,0xFF,0xD7,0xF2,0xF5,0x5D,0x06,0x58,0xFC,0x9D,0xB3,0x53,0x5F,0x45,0x2F,0x22,0x17,0x1E,0x4A,0x4F,0x0A,0xBF,0x04,0x73};
//	unsigned char szTxtE[] = {0x4B,0x37,0x01};
//	unsigned char szTxtD[] = {0xCF,0x8D,0xF9,0xC9,0x57,0x53,0x4D,0xD7,0x36,0xFD,0x27,0x3E,0xA9,0x3A,0x76,0xE8,0xC1,0x50,0x7F,0x95,0x65,0xF8,0x99,0x14,0xD7,0x6C,0x3F,0x1A,0x9D,0x50,0xD3,0x95,0x7C,0xC8,0xFE,0xE3,0x04,0x85,0xF9,0x5A,0xCF,0x48,0x42,0x15,0x83,0x0E,0xE2,0xB6,0xC6,0xC8,0x4F,0xB8,0xA3,0x9B,0xF2,0xAB,0x95,0x20,0xE0,0x0D,0x10,0x16,0x6D,0xFB,0x95,0x38,0x15,0x24,0x82,0x15,0xEC,0x4F,0xF1,0xCF,0xFA,0x76,0x83,0x74,0x8F,0x0B,0xA4,0x79,0x45,0xEB,0x61,0xA8,0xD5,0x26,0x60,0x3D,0x6C,0x8D,0x46,0x9A,0xDE,0xFB,0x5C,0x26,0x77,0x5F,0x2A,0xCD,0x97,0xD6,0x13,0x90,0x72,0xAF,0x4E,0x6F,0x54,0x63,0xFE,0xCB,0xF6,0x69,0x97,0xB1,0x5C,0xA3,0xD6,0x7A,0xDA,0xDF,0x74,0xC9,0x35,0x4F};
	
	fp_init(n);
	fp_init(e);
	fp_init(d);
	/*memcpy(n->dp,szTxtN,sizeof(szTxtN));
	memcpy(e->dp,szTxtE,sizeof(szTxtE));
	memcpy(d->dp,szTxtD,sizeof(szTxtD));*/
	memcpy(n->dp, pauth_ra->n, 128);
	memcpy(e->dp,pauth_ra->e,5);
	memcpy(d->dp, pauth_ra->d, 128);
	
	n->used=FP_SIZE;
	fp_clamp(n);			
	e->used=FP_SIZE;
	fp_clamp(e);			
	d->used=FP_SIZE;
	fp_clamp(d);
	
	nRet = 0;		
	
	return nRet;	
}
Пример #3
0
//RSA key : psudo code for demo
//0 is success, 1 for fail
static int get_rsa_key(fp_int *n,fp_int *e,fp_int*d)
{
	//here the long number is little
	//to replace N,E,D...
	unsigned char szTxtN[] = {0xB9,0x14,0xF5,0x2B,0x27,0x16,0x97,0x8A,0x19,0x54,0x8C,0x38,0xB9,0xA5,0xA9,0xA1,0x6C,0x8A,0x3A,0x2A,0x8D,0x1D,0x10,0x44,0x8B,0x53,0x8A,0xA4,0xE4,0x49,0x82,0xA1,0xD5,0x1D,0x3B,0x0A,0x2B,0xA0,0x48,0x0A,0x9D,0xBA,0xF7,0x79,0xC9,0xF2,0x17,0xE2,0x6B,0x32,0x8F,0xC9,0xED,0x13,0xA8,0x38,0xD1,0x27,0x2A,0xBD,0xE1,0xE8,0x8C,0xAF,0x0A,0x15,0x58,0xF7,0xF5,0x8D,0xAA,0x85,0xBB,0xEB,0x51,0x74,0x66,0x8C,0x00,0xB4,0x1E,0x97,0x14,0xD6,0x1B,0x3A,0x3E,0x54,0xED,0x8C,0x82,0xDA,0x3E,0x06,0x68,0xFB,0x51,0x0C,0x72,0xF6,0xE3,0x0F,0x09,0xF2,0xB3,0xFF,0xD7,0xF2,0xF5,0x5D,0x06,0x58,0xFC,0x9D,0xB3,0x53,0x5F,0x45,0x2F,0x22,0x17,0x1E,0x4A,0x4F,0x0A,0xBF,0x04,0x73};
	unsigned char szTxtE[] = {0x4B,0x37,0x01};
	unsigned char szTxtD[] = {0xCF,0x8D,0xF9,0xC9,0x57,0x53,0x4D,0xD7,0x36,0xFD,0x27,0x3E,0xA9,0x3A,0x76,0xE8,0xC1,0x50,0x7F,0x95,0x65,0xF8,0x99,0x14,0xD7,0x6C,0x3F,0x1A,0x9D,0x50,0xD3,0x95,0x7C,0xC8,0xFE,0xE3,0x04,0x85,0xF9,0x5A,0xCF,0x48,0x42,0x15,0x83,0x0E,0xE2,0xB6,0xC6,0xC8,0x4F,0xB8,0xA3,0x9B,0xF2,0xAB,0x95,0x20,0xE0,0x0D,0x10,0x16,0x6D,0xFB,0x95,0x38,0x15,0x24,0x82,0x15,0xEC,0x4F,0xF1,0xCF,0xFA,0x76,0x83,0x74,0x8F,0x0B,0xA4,0x79,0x45,0xEB,0x61,0xA8,0xD5,0x26,0x60,0x3D,0x6C,0x8D,0x46,0x9A,0xDE,0xFB,0x5C,0x26,0x77,0x5F,0x2A,0xCD,0x97,0xD6,0x13,0x90,0x72,0xAF,0x4E,0x6F,0x54,0x63,0xFE,0xCB,0xF6,0x69,0x97,0xB1,0x5C,0xA3,0xD6,0x7A,0xDA,0xDF,0x74,0xC9,0x35,0x4F};

        void* n_address = (void*)(0x49000000 + 16 * 1024 + 384 + 256);
        void* e_address = n_address + 128;

        memcpy((void*)szTxtN, n_address, 128);
        memcpy((void*)szTxtE, e_address, 3);
	
	int nRet = 1;
	if(!n || !e || !d)
		return nRet;
		
	fp_init(n);
	fp_init(e);
	fp_init(d);
	memcpy(n->dp,szTxtN,sizeof(szTxtN));
	memcpy(e->dp,szTxtE,sizeof(szTxtE));
	memcpy(d->dp,szTxtD,sizeof(szTxtD));
	n->used=FP_SIZE;
	fp_clamp(n);			
	e->used=FP_SIZE;
	fp_clamp(e);			
	d->used=FP_SIZE;
	fp_clamp(d);
	
	nRet = 0;		
	
	return nRet;	
}
Пример #4
0
/* c = [a, b] */
void fp_lcm(fp_int *a, fp_int *b, fp_int *c)
{
   fp_int  t1, t2;

   fp_init(&t1);
   fp_init(&t2);
   fp_gcd(a, b, &t1);
   if (fp_cmp_mag(a, b) == FP_GT) {
      fp_div(a, &t1, &t2, NULL);
      fp_mul(b, &t2, c);
   } else {
      fp_div(b, &t1, &t2, NULL);
      fp_mul(a, &t2, c);
   }   
}
Пример #5
0
int fp_isprime(fp_int *a)
{
   fp_int   b;
   fp_digit d;
   int      r, res;

   /* do trial division */
   for (r = 0; r < 256; r++) {
       fp_mod_d(a, primes[r], &d);
       if (d == 0) {
          return FP_NO;
       }
   }

   /* now do 8 miller rabins */
   fp_init(&b);
   for (r = 0; r < 8; r++) {
       fp_set(&b, primes[r]);
       fp_prime_miller_rabin(a, &b, &res);
       if (res == FP_NO) {
          return FP_NO;
       }
   }
   return FP_YES;
}
Пример #6
0
int main(int argc, char **argv)
{
	int r;

	r = fp_init();
	if (r < 0)
		return r;

	gtk_init(&argc, &argv);
	gtk_window_set_default_icon_name("fprint_demo");

	r = setup_pollfds();
	if (r < 0)
		return r;

	mwin_create();
	mwin_populate_devs();
	mwin_select_first_dev();

	gtk_main();

	if (fpdev)
		fp_dev_close(fpdev);
	fp_exit();
	return 0;
}
Пример #7
0
static int
tfm_dh_compute_key(unsigned char *shared, const BIGNUM * pub, DH *dh)
{
    fp_int s, priv_key, p, peer_pub;
    size_t size = 0;
    int ret;

    if (dh->pub_key == NULL || dh->g == NULL || dh->priv_key == NULL)
	return -1;

    fp_init(&p);
    BN2mpz(&p, dh->p);

    fp_init(&peer_pub);
    BN2mpz(&peer_pub, pub);

    /* check if peers pubkey is reasonable */
    if (fp_isneg(&peer_pub)
	|| fp_cmp(&peer_pub, &p) >= 0
	|| fp_cmp_d(&peer_pub, 1) <= 0)
    {
	fp_zero(&p);
	fp_zero(&peer_pub);
	return -1;
    }

    fp_init(&priv_key);
    BN2mpz(&priv_key, dh->priv_key);

    fp_init(&s);

    ret = fp_exptmod(&peer_pub, &priv_key, &p, &s);

    fp_zero(&p);
    fp_zero(&peer_pub);
    fp_zero(&priv_key);

    if (ret != 0)
	return -1;

    size = fp_unsigned_bin_size(&s);
    fp_to_unsigned_bin(&s, shared);
    fp_zero(&s);

    return size;
}
Пример #8
0
void main(void) 
{
	imme_init();

	fp_init();
	
	fp_run(); // blocking

}
Пример #9
0
static int init(void **a) {
    LTC_ARGCHK(a != NULL);

    *a = XCALLOC(1, sizeof(fp_int));
    if (*a == NULL) {
        return CRYPT_MEM;
    }
    fp_init(*a);
    return CRYPT_OK;
}
Пример #10
0
void machine_init(uint32_t hart_id)
{
  hls_init(hart_id);
  mstatus_init();
  fp_init();

  if (hart_id == 0)
    init_first_hart();
  else
    init_other_hart();
}
Пример #11
0
/**
 * Enrolls a finger and returns the associated fp-data.
 * 
 * @param env the Java Environment pointer. 
 * @param obj the jobject of the type jlibfprint/JlibFprint.
 * @return the jlibfprint/JlibFprint$fp_print_data with the data just given by the scanner.
 * @throws an enroll_exception is raised is something gone wrong.
 */
JNIEXPORT jobject JNICALL Java_jlibfprint_JlibFprint_enroll_1finger(JNIEnv* env, jobject ref)
{
    const jclass fpClass = env->FindClass("jlibfprint/JlibFprint$fp_print_data");
    const jclass eeClass = env->FindClass("jlibfprint/JlibFprint$EnrollException");
    
    /* Starts the library */
    if (fp_init())  // Se differente da 0 => Exception
    {
        jobject enrollException = env->AllocObject(eeClass);
        jfieldID eeExcp_id = env->GetFieldID(eeClass, "enroll_exception", "I");
        env->SetIntField(enrollException, eeExcp_id, UNABLE_TO_LOAD_LIBFPRINT);
        env->Throw((jthrowable)enrollException);
        return NULL;
    }
    fp_dev *device;
    fp_print_data* pdp;    
    
    /* Gets the pointer to the device */
    if (!get_device_id(env, ref, &device))
    {
        jobject enrollException = env->AllocObject(eeClass);
        jfieldID eeExcp_id = env->GetFieldID(eeClass, "enroll_exception", "I");
        env->SetIntField(enrollException, eeExcp_id, DEVICE_NOT_FOUND);
        env->Throw((jthrowable)enrollException);
        return NULL;
    }    
    
    /* Enrolls the finger */
    int ef = fp_enroll_finger(device, &pdp);
    /* Create a new obj to store the data */
    jobject obj = env->AllocObject(fpClass); 
    
    /* Raises an exception if the enrollment was not completed */
    if (ef != FP_ENROLL_COMPLETE)
    {
        jobject enrollException = env->AllocObject(eeClass);
        jfieldID eeExcp_id = env->GetFieldID(eeClass, "enroll_exception", "I");
        env->SetIntField(enrollException, eeExcp_id, ef);
        env->Throw((jthrowable)enrollException);
    }
    else
    {
        /* Fills the object with the enrollment data */
        cfp2jfp(env, obj, pdp);
        memset(pdp, 0, sizeof(fp_print_data));
        fp_print_data_free(pdp); 
    }
    fp_dev_close(device);
    fp_exit();
    
    return obj;
}
Пример #12
0
static void
BN2mpz(fp_int *s, const BIGNUM *bn)
{
    size_t len;
    void *p;

    fp_init(s);

    len = BN_num_bytes(bn);
    p = malloc(len);
    BN_bn2bin(bn, p);
    fp_read_unsigned_bin(s, p, len);
    free(p);
}
Пример #13
0
/*
 * Responsible for reading from the serial port, assembling packets and
 * sending them via a Redis PUBLISH command.
 */
void
redis_transmitter(char *hostname, int port)
{
	int i, n;
	unsigned char rdbuffer[32];
	char wrbuffer[32];
	struct fonz *fp;
	redisContext *ctxt;

	/*
	 * Initialize the Fonz packet receiver, and the Redis connection.
	 */
	fp_init(4, 0);
	ctxt = redisConnect(hostname, port);
	if (ctxt->err) {
		fprintf(stderr, "?redis (tx) error: %s\n", ctxt->errstr);
		exit(1);
	}
	/*
	 * Loop forever, pulling packets from the serial wire and sending
	 * them out via Redis PUB/SUB.
	 */
	while (1) {
		/*
		 * Read a pile of data from the serial device, and stuff
		 * it into the packet receiver.
		 */
		if ((n = read(filedes, rdbuffer, sizeof(rdbuffer))) < 0) {
			perror("redis_tx: read");
			exit(1);
		}
		for (i = 0; i < n; i++)
			fp_indata(rdbuffer[i]);
		/*
		 * Process any packets on the receive queue.
		 */
		while ((fp = fp_receive()) != NULL) {
			if (fp->cmd & FONZ_RESPONSE)
				sprintf(wrbuffer, "[%u,%u,%u]", fp->cmd & 0xff, fp->arg1 & 0xff, fp->arg2 & 0xff);
			else
				sprintf(wrbuffer, "%u", fp->cmd & 0xff);
			if (txlfp != NULL)
				fprintf(txlfp, "< {%s}\n", wrbuffer);
			redisCommand(ctxt, "PUBLISH fonz-in %s", wrbuffer);
			fp_free(fp);
		}
	}
}
int main(void) {
	// Vars
	struct fp_dev *device;
	struct fp_driver *driver;
	struct fp_print_data *print_data;
	struct fp_img *img;
	int err;

	// Init the LCD
	lcdinit(0x00, 0x12, 0x20);
	lcd_reset();

	// Init libfprint
	fp_init();

	// Init the keypad
	matrix_init(4, 17, 27, 22, 10, 9, 11, handle_key_press);

	// Signal handler - does an fp_exit() on SIGINT
	init_signals();

	// Get the first fingerprint device
	if ((err = get_fingerprint_device(&device)) < 0 || !device) { // Errorz
		if (err == -1) {
			error("No devices found");
		}
		else if (err == -2) {
			error("Couldn't open the device");
		}

		return 1;
	}

	// Get driver
	driver = fp_dev_get_driver(device);

	// Init message
	printf("Programme started! Device is %s\n\n", fp_driver_get_full_name(driver));

	// Scan the print
	fp_enroll_finger_img(device, &print_data, &img);

	// Deinit libfprint
	fp_exit();

	return 0;
}
Пример #15
0
/* ================================================================== */
int main(int argc, char *argv[])
{
	fpstate	fpvar;

	if (argc <= 1) { fp_usage (); fp_hint (); exit (-1); }

	fp_init (&fpvar);
	fp_get_param (argc, argv, &fpvar);

	if (fpvar.listonly) {
	    fp_list (argc, argv, fpvar);

	} else {
	    fp_preflight (argc, argv, FPACK, &fpvar);
	    fp_loop (argc, argv, FPACK, fpvar);
	}

	exit (0);
}
Пример #16
0
int main(){

    //initialize
    if (fp_init()){
        printf("libfprint patladi!\n");
        exit(1); //failure
    }

    //dev discovery
    struct fp_dscv_dev** ddevicelist;
    struct fp_dscv_dev* ddevice;

    if (!(ddevicelist = fp_discover_devs())){ //listeyi al
        printf("Device discovery calismadi!\n");
        exit(1); //failure
    }

    if(!(ddevice = ddevicelist[0])){ //bos? TODO: 2 alet varsa nolacak?
        printf("Alet nerde?\n");
        exit(1); //failure
    }

    print_driver_info(ddevice);

    //open dev
    struct fp_dev* device;

    if(!(device = fp_dev_open(ddevice))){
        printf("Okuyucu baslamadi!\n");
        exit(1); //failure
    }

    //get image
    fp_img_save_to_file(get_image(device), "./parmak.pgm"); //TODO: nasi freelenir lan bu?

    //cleanup
    fp_dev_close(device);
    fp_exit();

    return 0;
}
Пример #17
0
int main(int argc, char **argv)
{
	struct filepirate *fp;
	bool interactive = true;

	if (argc == 3)
		interactive = false;
	else
		assert(argc == 2);

	if ((fp = fp_init(argv[1])) == NULL) {
		ERROR("pool init main");
		return 1;
	}

	if (interactive) {
		term_modified = false;
		atexit(term_reset);
		term_init();
	}

	//fp_filter(fp, positive_filter, negative_filter);
  fp_add_ignore_rule(fp, "bower_components");

	if (fp_init_dir(fp, argv[1]) == false) {
		fp_deinit(fp);
    ERROR("init dir failed");
		return 1;
	}

	if (argc == 2)
		filepirate_interactive_test(fp);
	else
		filepirate_search_once(fp, argv[2]);
	fp_deinit(fp);
}
Пример #18
0
/*
 * Responsible for subscribing to the Redis "fonz-out" channel, receiving
 * PUB messages, assembling packets and forwarding them to the serial port.
 */
void
redis_receiver(char *hostname, int port)
{
	redisAsyncContext *ctxt;
	struct event_base *base;

	/*
	 * Initialize the Fonz packet transmitter, and the Redis connection.
	 */
	fp_init(0, 4);
	ctxt = redisAsyncConnect(hostname, port);
	if (ctxt->err) {
		fprintf(stderr, "?redis (rx) error: %s\n", ctxt->errstr);
		exit(1);
	}
	base = event_base_new();
	redisLibeventAttach(ctxt, base);
	/*
	 * Subscribe to the fonz-out channel, and use the libevent
	 * dispatcher to do the work.
	 */
	redisAsyncCommand(ctxt, pkt_recv, NULL, "SUBSCRIBE fonz-out");
	event_base_dispatch(base);
}
Пример #19
0
Файл: main.c Проект: dsd/fprintd
int main(int argc, char **argv)
{
	GOptionContext *context;
	GMainLoop *loop;
	GError *error = NULL;
	FprintManager *manager;
	DBusGProxy *driver_proxy;
	guint32 request_name_ret;
	int r = 0;

	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	context = g_option_context_new ("Fingerprint handler daemon");
	g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
	g_type_init();

	if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) {
		g_print ("couldn't parse command-line options: %s\n", error->message);
		g_error_free (error);
		return 1;
	}

	if (g_fatal_warnings) {
		GLogLevelFlags fatal_mask;

		fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
		fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
		g_log_set_always_fatal (fatal_mask);
	}

	/* Load the configuration file,
	 * and the default storage plugin */
	if (!load_conf())
		set_storage_file ();
	store.init ();

	r = fp_init();
	if (r < 0) {
		g_error("fprint init failed with error %d\n", r);
		return r;
	}

	loop = g_main_loop_new(NULL, FALSE);

	r = setup_pollfds();
	if (r < 0) {
		g_print("pollfd setup failed\n");
		goto err;
	}

	g_print("Launching FprintObject\n");

	/* Obtain a connection to the session bus */
	fprintd_dbus_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
	if (fprintd_dbus_conn == NULL)
		g_error("Failed to open connection to bus: %s", error->message);

	/* create the one instance of the Manager object to be shared between
	 * all fprintd users */
	manager = fprint_manager_new(no_timeout);

	driver_proxy = dbus_g_proxy_new_for_name(fprintd_dbus_conn,
		DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);

	if (!org_freedesktop_DBus_request_name(driver_proxy, FPRINT_SERVICE_NAME,
			0, &request_name_ret, &error))
		g_error("Failed to get name: %s", error->message);

	if (request_name_ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
		g_error ("Got result code %u from requesting name", request_name_ret);
		exit(1);
	}

	g_message("D-Bus service launched with name: %s", FPRINT_SERVICE_NAME);

	g_message("entering main loop");
	g_main_loop_run(loop);
	g_message("main loop completed");

err:
	fp_exit();
	return 0;
}
Пример #20
0
int main(int argc, char *argv[])
{
	int r = 1, i;
	int next_option;
	enum fp_finger finger = RIGHT_INDEX;

	struct fp_dscv_dev *ddev;
	struct fp_dscv_dev **discovered_devs;
	struct fp_dev *dev;
	struct fp_print_data *data;
	
	const char * const short_options = "hf:";
	const struct option long_options[] = {
		{ "help", 0, NULL, 'h'},
		{ "enroll-finger", 1, NULL, 'f'},
		{ NULL, 0, NULL, 0}
	};
	
	do {
		next_option = getopt_long(argc, argv, short_options, long_options,
			NULL);
		switch (next_option) {
		case 'h':
			/* Printing usage */
			printf("Usage: %s options\n", argv[0]);
			printf("	-h	--help			Display this usage information.\n"
			   "	-f	--enroll-finger index	Enroll finger with index.\n\n");
			printf("	Valid indexes are:\n");
			for (i = LEFT_THUMB; i <= RIGHT_LITTLE; i++) {
				printf("	%d - %s\n", i, finger_names[i]);
			}
			exit(1);
			   
			break;
		case 'f':
			sscanf(optarg, "%d", &finger);
			if (finger < LEFT_THUMB || finger > RIGHT_LITTLE) {
				printf("%s: Invalid finger index.\n", argv[0]);
				printf("%s: Valid indexes are:\n", argv[0]);
				for (i = LEFT_THUMB; i <= RIGHT_LITTLE; i++) {
					printf("%s: %d - %s\n", argv[0], i, finger_names[i]);
				}
				exit(1);
			}
			break;
		case -1:	/* Done with options. */
			break;
		default:	/* Unexpected option */
			exit(1);
		}
	} while (next_option != -1);

	printf("This program will enroll your finger, "
		"unconditionally overwriting any selected print that was enrolled "
		"previously. If you want to continue, press enter, otherwise hit "
		"Ctrl+C\n");
	getchar();

	r = fp_init();
	if (r < 0) {
		fprintf(stderr, "Failed to initialize libfprint\n");
		exit(1);
	}

	discovered_devs = fp_discover_devs();
	if (!discovered_devs) {
		fprintf(stderr, "Could not discover devices\n");
		goto out;
	}

	ddev = discover_device(discovered_devs);
	if (!ddev) {
		fprintf(stderr, "No devices detected.\n");
		goto out;
	}

	dev = fp_dev_open(ddev);
	fp_dscv_devs_free(discovered_devs);
	if (!dev) {
		fprintf(stderr, "Could not open device.\n");
		goto out;
	}

	printf("Opened device. It's now time to enroll your finger.\n\n");
	data = enroll(dev, finger);
	if (!data)
		goto out_close;

	r = fp_print_data_save(data, finger);
	if (r < 0)
		fprintf(stderr, "Data save failed, code %d\n", r);

	fp_print_data_free(data);
out_close:
	fp_dev_close(dev);
out:
	fp_exit();
	return r;
}
Пример #21
0
int main(){

    //initialize
    if (fp_init()){
        printf("libfprint patladi!\n");
        exit(1); //failure
    }

    //dev discovery
    struct fp_dscv_dev** ddevicelist;
    struct fp_dscv_dev* ddevice;

    if (!(ddevicelist = fp_discover_devs())){ //listeyi al
        printf("Device discovery calismadi!\n");
        exit(1); //failure
    }

    if(!(ddevice = ddevicelist[0])){ //bos? TODO: 2 alet varsa nolacak?
        printf("Alet nerde?\n");
        exit(1); //failure
    }

    print_driver_info(ddevice);

    //open device
    struct fp_dev* device;

    if(!(device = fp_dev_open(ddevice))){
        printf("Okuyucu baslamadi!\n");
        exit(1); //failure
    }

    //enroll
    //printf("%d", fp_dev_get_nr_enroll_stages(device)); //tek olmali, cunku laptop.

    int done = 0;
	struct fp_print_data* guvenliparmak = NULL;
    while(!done){

	switch(fp_enroll_finger_img(device, &guvenliparmak, NULL)){
		case FP_ENROLL_FAIL:
			printf("Parmakizi alimi tamamlanamadi!\n");
			exit(1); //fail
		case FP_ENROLL_COMPLETE:
			done = 1;
			printf("Parmakizi alimi basariyla tamamlandi.\n");
			break;
		case FP_ENROLL_PASS:
			printf("Tanima asamasi basarili..\n");
			break;
		default:
			printf("Yeniden deneyin!\n");
			break;
	}

    }

    fp_print_data_free(guvenliparmak);

    //cleanup
    fp_dev_close(device);
    fp_exit();

    return 0;
}
Пример #22
0
/**
   Add two ECC points
   @param P        The point to add
   @param Q        The point to add
   @param R        [out] The destination of the double
   @param modulus  The modulus of the field the ECC curve is in
   @param mp       The "b" value from montgomery_setup()
   @return CRYPT_OK on success
*/
static int tfm_ecc_projective_add_point(ecc_point *P, ecc_point *Q, ecc_point *R, void *modulus, void *Mp)
{
   fp_int  t1, t2, x, y, z;
   fp_digit mp;  
   
   LTC_ARGCHK(P       != NULL);
   LTC_ARGCHK(Q       != NULL);
   LTC_ARGCHK(R       != NULL);
   LTC_ARGCHK(modulus != NULL);
   LTC_ARGCHK(Mp      != NULL);

   mp = *((fp_digit*)Mp);

   fp_init(&t1);
   fp_init(&t2);
   fp_init(&x);
   fp_init(&y);
   fp_init(&z);

   /* should we dbl instead? */
   fp_sub(modulus, Q->y, &t1);
   if ( (fp_cmp(P->x, Q->x) == FP_EQ) && 
        (Q->z != NULL && fp_cmp(P->z, Q->z) == FP_EQ) &&
        (fp_cmp(P->y, Q->y) == FP_EQ || fp_cmp(P->y, &t1) == FP_EQ)) {
        return tfm_ecc_projective_dbl_point(P, R, modulus, Mp);
   }

   fp_copy(P->x, &x);
   fp_copy(P->y, &y);
   fp_copy(P->z, &z);

   /* if Z is one then these are no-operations */
   if (Q->z != NULL) {
      /* T1 = Z' * Z' */
      fp_sqr(Q->z, &t1);
      fp_montgomery_reduce(&t1, modulus, mp);
      /* X = X * T1 */
      fp_mul(&t1, &x, &x);
      fp_montgomery_reduce(&x, modulus, mp);
      /* T1 = Z' * T1 */
      fp_mul(Q->z, &t1, &t1);
      fp_montgomery_reduce(&t1, modulus, mp);
      /* Y = Y * T1 */
      fp_mul(&t1, &y, &y);
      fp_montgomery_reduce(&y, modulus, mp);
   }

   /* T1 = Z*Z */
   fp_sqr(&z, &t1);
   fp_montgomery_reduce(&t1, modulus, mp);
   /* T2 = X' * T1 */
   fp_mul(Q->x, &t1, &t2);
   fp_montgomery_reduce(&t2, modulus, mp);
   /* T1 = Z * T1 */
   fp_mul(&z, &t1, &t1);
   fp_montgomery_reduce(&t1, modulus, mp);
   /* T1 = Y' * T1 */
   fp_mul(Q->y, &t1, &t1);
   fp_montgomery_reduce(&t1, modulus, mp);

   /* Y = Y - T1 */
   fp_sub(&y, &t1, &y);
   if (fp_cmp_d(&y, 0) == FP_LT) {
      fp_add(&y, modulus, &y);
   }
   /* T1 = 2T1 */
   fp_add(&t1, &t1, &t1);
   if (fp_cmp(&t1, modulus) != FP_LT) {
      fp_sub(&t1, modulus, &t1);
   }
   /* T1 = Y + T1 */
   fp_add(&t1, &y, &t1);
   if (fp_cmp(&t1, modulus) != FP_LT) {
      fp_sub(&t1, modulus, &t1);
   }
   /* X = X - T2 */
   fp_sub(&x, &t2, &x);
   if (fp_cmp_d(&x, 0) == FP_LT) {
      fp_add(&x, modulus, &x);
   }
   /* T2 = 2T2 */
   fp_add(&t2, &t2, &t2);
   if (fp_cmp(&t2, modulus) != FP_LT) {
      fp_sub(&t2, modulus, &t2);
   }
   /* T2 = X + T2 */
   fp_add(&t2, &x, &t2);
   if (fp_cmp(&t2, modulus) != FP_LT) {
      fp_sub(&t2, modulus, &t2);
   }

   /* if Z' != 1 */
   if (Q->z != NULL) {
      /* Z = Z * Z' */
      fp_mul(&z, Q->z, &z);
      fp_montgomery_reduce(&z, modulus, mp);
   }

   /* Z = Z * X */
   fp_mul(&z, &x, &z);
   fp_montgomery_reduce(&z, modulus, mp);

   /* T1 = T1 * X  */
   fp_mul(&t1, &x, &t1);
   fp_montgomery_reduce(&t1, modulus, mp);
   /* X = X * X */
   fp_sqr(&x, &x);
   fp_montgomery_reduce(&x, modulus, mp);
   /* T2 = T2 * x */
   fp_mul(&t2, &x, &t2);
   fp_montgomery_reduce(&t2, modulus, mp);
   /* T1 = T1 * X  */
   fp_mul(&t1, &x, &t1);
   fp_montgomery_reduce(&t1, modulus, mp);
 
   /* X = Y*Y */
   fp_sqr(&y, &x);
   fp_montgomery_reduce(&x, modulus, mp);
   /* X = X - T2 */
   fp_sub(&x, &t2, &x);
   if (fp_cmp_d(&x, 0) == FP_LT) {
      fp_add(&x, modulus, &x);
   }

   /* T2 = T2 - X */
   fp_sub(&t2, &x, &t2);
   if (fp_cmp_d(&t2, 0) == FP_LT) {
      fp_add(&t2, modulus, &t2);
   } 
   /* T2 = T2 - X */
   fp_sub(&t2, &x, &t2);
   if (fp_cmp_d(&t2, 0) == FP_LT) {
      fp_add(&t2, modulus, &t2);
   }
   /* T2 = T2 * Y */
   fp_mul(&t2, &y, &t2);
   fp_montgomery_reduce(&t2, modulus, mp);
   /* Y = T2 - T1 */
   fp_sub(&t2, &t1, &y);
   if (fp_cmp_d(&y, 0) == FP_LT) {
      fp_add(&y, modulus, &y);
   }
   /* Y = Y/2 */
   if (fp_isodd(&y)) {
      fp_add(&y, modulus, &y);
   }
   fp_div_2(&y, &y);

   fp_copy(&x, R->x);
   fp_copy(&y, R->y);
   fp_copy(&z, R->z);
   
   return CRYPT_OK;
}
Пример #23
0
static int tfm_ecc_projective_dbl_point(ecc_point *P, ecc_point *R, void *modulus, void *Mp)
{
   fp_int t1, t2;
   fp_digit mp;

   LTC_ARGCHK(P       != NULL);
   LTC_ARGCHK(R       != NULL);
   LTC_ARGCHK(modulus != NULL);
   LTC_ARGCHK(Mp      != NULL);

   mp = *((fp_digit*)Mp);

   fp_init(&t1);
   fp_init(&t2);

   if (P != R) {
      fp_copy(P->x, R->x);
      fp_copy(P->y, R->y);
      fp_copy(P->z, R->z);
   }

   /* t1 = Z * Z */
   fp_sqr(R->z, &t1);
   fp_montgomery_reduce(&t1, modulus, mp);
   /* Z = Y * Z */
   fp_mul(R->z, R->y, R->z);
   fp_montgomery_reduce(R->z, modulus, mp);
   /* Z = 2Z */
   fp_add(R->z, R->z, R->z);
   if (fp_cmp(R->z, modulus) != FP_LT) {
      fp_sub(R->z, modulus, R->z);
   }
   
   /* &t2 = X - T1 */
   fp_sub(R->x, &t1, &t2);
   if (fp_cmp_d(&t2, 0) == FP_LT) {
      fp_add(&t2, modulus, &t2);
   }
   /* T1 = X + T1 */
   fp_add(&t1, R->x, &t1);
   if (fp_cmp(&t1, modulus) != FP_LT) {
      fp_sub(&t1, modulus, &t1);
   }
   /* T2 = T1 * T2 */
   fp_mul(&t1, &t2, &t2);
   fp_montgomery_reduce(&t2, modulus, mp);
   /* T1 = 2T2 */
   fp_add(&t2, &t2, &t1);
   if (fp_cmp(&t1, modulus) != FP_LT) {
      fp_sub(&t1, modulus, &t1);
   }
   /* T1 = T1 + T2 */
   fp_add(&t1, &t2, &t1);
   if (fp_cmp(&t1, modulus) != FP_LT) {
      fp_sub(&t1, modulus, &t1);
   }

   /* Y = 2Y */
   fp_add(R->y, R->y, R->y);
   if (fp_cmp(R->y, modulus) != FP_LT) {
      fp_sub(R->y, modulus, R->y);
   }
   /* Y = Y * Y */
   fp_sqr(R->y, R->y);
   fp_montgomery_reduce(R->y, modulus, mp);
   /* T2 = Y * Y */
   fp_sqr(R->y, &t2);
   fp_montgomery_reduce(&t2, modulus, mp);
   /* T2 = T2/2 */
   if (fp_isodd(&t2)) {
      fp_add(&t2, modulus, &t2);
   }
   fp_div_2(&t2, &t2);
   /* Y = Y * X */
   fp_mul(R->y, R->x, R->y);
   fp_montgomery_reduce(R->y, modulus, mp);

   /* X  = T1 * T1 */
   fp_sqr(&t1, R->x);
   fp_montgomery_reduce(R->x, modulus, mp);
   /* X = X - Y */
   fp_sub(R->x, R->y, R->x);
   if (fp_cmp_d(R->x, 0) == FP_LT) {
      fp_add(R->x, modulus, R->x);
   }
   /* X = X - Y */
   fp_sub(R->x, R->y, R->x);
   if (fp_cmp_d(R->x, 0) == FP_LT) {
      fp_add(R->x, modulus, R->x);
   }

   /* Y = Y - X */     
   fp_sub(R->y, R->x, R->y);
   if (fp_cmp_d(R->y, 0) == FP_LT) {
      fp_add(R->y, modulus, R->y);
   }
   /* Y = Y * T1 */
   fp_mul(R->y, &t1, R->y);
   fp_montgomery_reduce(R->y, modulus, mp);
   /* Y = Y - T2 */
   fp_sub(R->y, &t2, R->y);
   if (fp_cmp_d(R->y, 0) == FP_LT) {
      fp_add(R->y, modulus, R->y);
   }
 
   return CRYPT_OK;
}
Пример #24
0
int
main (int argc, char **argv)
{
  int r = 1;
  struct fp_dscv_dev *ddev;
  struct fp_dscv_dev **discovered_devs;
  struct fp_dev *dev;
  struct fp_print_data *data;

  int finger;

  finger = atoi(argv[3]);



  printf ("This program will enroll your right index finger, "
	  "unconditionally overwriting any right-index print that was enrolled "
	  "previously. If you want to continue, press enter, otherwise hit "
	  "Ctrl+C\n");
  getchar ();

  r = fp_init ();
  if (r < 0)
    {
      fprintf (stderr, "Failed to initialize libfprint\n");
      exit (1);
    }
  fp_set_debug (3);

  discovered_devs = fp_discover_devs ();
  if (!discovered_devs)
    {
      fprintf (stderr, "Could not discover devices\n");
      goto out;
    }

  ddev = discover_device (discovered_devs);
  if (!ddev)
    {
      fprintf (stderr, "No devices detected.\n");
      goto out;
    }

  dev = fp_dev_open (ddev);
  fp_dscv_devs_free (discovered_devs);
  if (!dev)
    {
      fprintf (stderr, "Could not open device.\n");
      goto out;
    }

  printf ("Opened device. It's now time to enroll your finger.\n\n");
  data = enroll (dev);
  if (!data)
    goto out_close;

  r = fp_print_data_save (data, finger, argv[1], argv[2]);
  if (r < 0)
    fprintf (stderr, "Data save failed, code %d\n", r);

  fp_print_data_free (data);
out_close:
  fp_dev_close (dev);
out:
  fp_exit ();
  return r;
}
Пример #25
0
// Initialize machine and add it to list of machines 
static void machine_add(const char *p_code,void(*fp_init)(machine_t*,uint8_t*,uint8_t*)) {
	strcpy(p_mach->code,p_code);
	fp_init(p_mach++,data,sids);
}
Пример #26
0
int main(void)
{
	int r = 1;
	struct fp_dscv_dev *ddev;
	struct fp_dscv_dev **discovered_devs;
	struct fp_dev *dev;
	struct fp_print_data *data;

	r = fp_init();
	if (r < 0) {
		printf("Failed to initialize fprint\n");
		exit(1);
	}
	fp_set_debug(3);

	discovered_devs = fp_discover_devs();
	if (!discovered_devs) {
		printf("Could not discover devices\n");
		goto out;
	}

	ddev = discover_device(discovered_devs);
	if (!ddev) {
		printf("No devices detected.\n");
		goto out;
	}

	dev = fp_dev_open(ddev);
	fp_dscv_devs_free(discovered_devs);
	if (!dev) {
		printf("Could not open device.\n");
		goto out;
	}

	printf("Opened device.  "
		"enrolling...\n");

	r = fp_print_data_load(dev, RIGHT_INDEX, &data);
	if (r != 0) {
		printf("Failed to load fingerprint,\n");
		goto out_close;
	}

	printf("Print loaded. Try to verify!\n");
	do {
		char buffer[20];

		verify(dev, data);
		printf("Verify again? [Y/n]? ");
		fgets(buffer, sizeof(buffer), stdin);
		if (buffer[0] != '\n' && buffer[0] != 'y' && buffer[0] != 'Y')
			break;
	} while (1);

	fp_print_data_free(data);
out_close:
	fp_dev_close(dev);
out:
	fp_exit();
	return r;
}
Пример #27
0
int main(void)
{
	
	struct fp_dscv_dev *ddev;
	struct fp_dscv_dev **discovered_devs;
	struct fp_dev *dev;
	struct fp_print_data *data;
	int r = fp_init();

	if (r < 0) {
		fprintf(stderr, "Failed to initialize libfprint\n");
		exit(1);
	}
	fp_set_debug(3);

	discovered_devs = fp_discover_devs();
	if (!discovered_devs) {
		fprintf(stderr, "Could not discover devices\n");
		goto out;
	}

	ddev = discover_device(discovered_devs);
	if (!ddev) {
		fprintf(stderr, "No devices detected.\n");
		goto out;
	}

	dev = fp_dev_open(ddev);
	fp_dscv_devs_free(discovered_devs);
	if (!dev) {
		fprintf(stderr, "Could not open device.\n");
		goto out;
	}

	printf("Opened device. Loading previously enrolled right index finger "
		"data...\n");

	r = fp_print_data_load(dev, RIGHT_INDEX, &data);
	if (r != 0) {
		fprintf(stderr, "Failed to load fingerprint, error %d\n", r);
		fprintf(stderr, "Did you remember to enroll your right index finger "
			"first?\n");
		goto out_close;
	}

	printf("Print loaded. Time to verify!\n");
	do {
		char buffer[20];

		verify(dev, data);
		printf("Verify again? [Y/n]? ");
		fgets(buffer, sizeof(buffer), stdin);
		if (buffer[0] != '\n' && buffer[0] != 'y' && buffer[0] != 'Y')
			break;
	} while (1);

	fp_print_data_free(data);
out_close:
	fp_dev_close(dev);
out:
	fp_exit();
	return r;
}
Пример #28
0
int do_rsa_proc(char *pSRC, int nDataLen,char *pOUT,int *pOUTLen,fp_int *key, int procedure)
{
	// fp_int *key--> key[0], key[1], key[2]	
	int in_size = nDataLen;
	int nret=-1;
	int nlen;		
	fp_int c,m;
	fp_int* k,* t;	
	
	unsigned char *pSRCBuff = (unsigned char *)pSRC;
	unsigned char *pOUTBuff = (unsigned char *)pOUT;	
	memset(pOUTBuff,0,*pOUTLen);
	*pOUTLen = 0;
	
	//get key length
	//for RSA1024 : 1028bit -> 128 bytes
	//dec-i_len : 128 dec-o_len:127
	//enc-i_len : 127 dec-o_len:128
	uint32_t bits=fp_count_bits(&key[0]);
	uint32_t o_len,i_len;

	//dec
	i_len=(bits+7)>>3;
	o_len=i_len-1;
	
	//pub key
	k=&key[1];

	switch(procedure & RSA_ENC_DEC_MASK)
	{
	case ENC_WITH_PRIV:o_len=i_len;--i_len;;k=&key[2];break;
	case DEC_WITH_PUB:break;
	case ENC_WITH_PUB:o_len=i_len;--i_len;break;
	case DEC_WITH_PRIV:k=&key[2];break;
	default: 
		//printf("Internal error! Not support this enc-dec mode %d\n",procedure);
		//dbg_print("Internal error! Not support this enc-dec mode ", procedure);
		return nret; break;
	}
		
	//buffer process
	if((procedure & RSA_BUF_IN_TYPE_MASK) != RSA_BUF_IN_TYPE_IGNORE)
		aml_buffer_proc_before(pSRCBuff,nDataLen,i_len,procedure);
	
	for(nlen=0;nlen<in_size;nlen+=i_len)
	{		
		fp_init(&c);
		fp_init(&m);		
		memcpy(c.dp,pSRCBuff,i_len);
		pSRCBuff += i_len;
		c.used=FP_SIZE;
		fp_clamp(&c);		
		fp_exptmod(&c,k,&key[0],&m);			
		memcpy(pOUTBuff+*pOUTLen,m.dp,o_len);
		*pOUTLen += o_len;		
	}	
	
	//buffer process	
	if((procedure & RSA_BUF_OUT_TYPE_MASK) != RSA_BUF_OUT_TYPE_IGNORE)
		aml_buffer_proc_after(pOUTBuff,pOUTLen,o_len,procedure);	
	
	nret = 0;	
	return nret;		
}
Пример #29
0
/* a/b => cb + d == a */
int fp_div_d(fp_int *a, fp_digit b, fp_int *c, fp_digit *d)
{
  fp_int   q;
  fp_word  w;
  fp_digit t;
  int      ix;

  /* cannot divide by zero */
  if (b == 0) {
     return FP_VAL;
  }

  /* quick outs */
  if (b == 1 || fp_iszero(a) == 1) {
     if (d != NULL) {
        *d = 0;
     }
     if (c != NULL) {
        fp_copy(a, c);
     }
     return FP_OKAY;
  }

  /* power of two ? */
  if (s_is_power_of_two(b, &ix) == 1) {
     if (d != NULL) {
        *d = a->dp[0] & ((((fp_digit)1)<<ix) - 1);
     }
     if (c != NULL) {
        fp_div_2d(a, ix, c, NULL);
     }
     return FP_OKAY;
  }

  /* no easy answer [c'est la vie].  Just division */
  fp_init(&q);
  
  q.used = a->used;
  q.sign = a->sign;
  w = 0;
  for (ix = a->used - 1; ix >= 0; ix--) {
     w = (w << ((fp_word)DIGIT_BIT)) | ((fp_word)a->dp[ix]);
     
     if (w >= b) {
        t = (fp_digit)(w / b);
        w -= ((fp_word)t) * ((fp_word)b);
      } else {
        t = 0;
      }
      q.dp[ix] = (fp_digit)t;
  }
  
  if (d != NULL) {
     *d = (fp_digit)w;
  }
  
  if (c != NULL) {
     fp_clamp(&q);
     fp_copy(&q, c);
  }
 
  return FP_OKAY;
}
Пример #30
0
int main(void)
{
	struct fp_dscv_dev *ddev;
	struct fp_dscv_dev **discovered_devs;
	struct fp_dev *dev;
	struct fp_print_data *data;
	int r = fp_init();

	if (r < 0) {
		fprintf(stderr, "Failed to initialize libfprint\n");
		exit(1);
	}
	fp_set_debug(3);

	discovered_devs = fp_discover_devs();
	if (!discovered_devs) {
		fprintf(stderr, "Could not discover devices\n");
		goto out;
	}

	ddev = discover_device(discovered_devs);
	if (!ddev) {
		fprintf(stderr, "No devices detected.\n");
		goto out;
	}

	dev = fp_dev_open(ddev);
	fp_dscv_devs_free(discovered_devs);
	if (!dev) {
		fprintf(stderr, "Could not open device.\n");
		goto out;
	}

	printf("Opened device. It's now time to enroll your finger.\n\n");
	data = enroll(dev);
	if (!data)
		goto out_close;


	printf("Normally we'd save that print to disk, and recall it at some "
		"point later when we want to authenticate the user who just "
		"enrolled. In the interests of demonstration, we'll authenticate "
		"that user immediately.\n");

	do {
		char buffer[20];

		verify(dev, data);
		printf("Verify again? [Y/n]? ");
		fgets(buffer, sizeof(buffer), stdin);
		if (buffer[0] != '\n' && buffer[0] != 'y' && buffer[0] != 'Y')
			break;
	} while (1);

	fp_print_data_free(data);
out_close:
	fp_dev_close(dev);
out:
	fp_exit();
	return r;
}