Пример #1
0
int main(int argc, char** argv) {
	int n, fd;
        long dec, enc; 
        struct Arguments args;
	pthread_t readThread, writeThread;
        long a, b; // two prime numbers
	if(argc < 5) {
	   printf("file portNum hostName prime1 prime2\n");
	   exit(0);
	}
        a = atoi(argv[3]) + 6;
        b = atoi(argv[4]) + 6; 
        generatePrimeNumbers(&a, &b);
        generateKeys(a, b, &args.my_e, &args.my_d, &args.my_c);
        args.run = 1;  
	
        fd = connectTo(argv[2], atoi(argv[1]));
        args.connfd = fd;
        sendKeys(&args);
        receiveKeys(&args);
        
        pthread_create(&readThread, NULL, readData, &args);
        pthread_create(&writeThread, NULL, writeData, &args);
        pthread_join(readThread, NULL);
        pthread_cancel(writeThread);
	close(fd);
}
Пример #2
0
	void Plugin::initPlugin (QObject *obj)
	{
		AzothProxy_ = qobject_cast<IProxyObject*> (obj);

		OtrHandler_ = new OtrHandler (CoreProxy_, AzothProxy_);

		FPManager_ = new FPManager (OtrHandler_->GetUserState (), AzothProxy_);
		connect (FPManager_,
				SIGNAL (fingerprintsChanged ()),
				OtrHandler_,
				SLOT (writeFingerprints ()));
		XSD_->SetDataSource ("KnownFPs", FPManager_->GetModel ());

		PKManager_ = new PrivKeyManager (OtrHandler_->GetUserState (), AzothProxy_);
		connect (PKManager_,
				SIGNAL (keysChanged ()),
				OtrHandler_,
				SLOT (writeKeys ()));
		connect (PKManager_,
				SIGNAL (keysGenerationRequested (QString, QString)),
				OtrHandler_,
				SLOT (generateKeys (QString, QString)));
		connect (OtrHandler_,
				SIGNAL (privKeysChanged ()),
				PKManager_,
				SLOT (reloadAll ()));
		XSD_->SetDataSource ("PrivKeys", PKManager_->GetModel ());
	}
void ConfigurationDialog::prepareKeysGeneration()
{
    UserLoginDialog *d = new UserLoginDialog(this);
    d->show();
    d->setWindowTitle("Passphrase generation");
    connect(d, SIGNAL(dataChecked(QString,QString)),
            this, SLOT(generateKeys(QString,QString)));
    connect(d, SIGNAL(dataChecked(QString,QString)),
            d, SLOT(close()));
}
Пример #4
0
void setupLoad(struct config* config) {

    if(config->input_file==NULL) {
        printf("Option '-a' is mandatory and requires an argument\n");
        exit(-1);
    }

    if(config->server_file==NULL) {
        printf("Option '-s' is mandatory and requires a server configuration file as an argument\n");
        exit(-1);
    }
    loadServerFile(config);

    if(config->n_workers % config->n_servers != 0) {
        printf("Number of client (worker) threads must be divisible by the number of servers\n");
        exit(-1);
    }

    if((config->output_file == NULL) && (config->scaling_factor>1)) {
        printf("Preloading requires an output file\n");
        exit(-1);
    }

    if(!config->pre_load || (config->scaling_factor==1)) config->dep_dist = loadDepFile(config);
    else config->dep_dist = loadAndScaleDepFile(config);


    if(config->value_size_dist == NULL) {
        config->value_size_dist = createUniformDistribution(1, 1024);
    }
    if(config->key_pop_dist == NULL) {
        config->key_pop_dist = createUniformDistribution(0, config->n_keys -1);
        printf("created uniform distribution %d\n", config->n_keys);
    } else {
        config->n_keys = CDF_VALUES;
    }
    config->key_list = generateKeys(config);

    if(config->multiget_dist == NULL) {
        config->multiget_dist = createUniformDistribution(2, 10);
    }

    printf("rps %d cpus %d\n", config->rps, config->n_workers);
    if (config->rps == -1 || config->rps == 0)
        return;

    int meanInterarrival = 1.0/(((float)config->rps)/(float)config->n_workers)*1e6;
    printf("meanInterarrival %d\n", meanInterarrival);
    if(config->arrival_distribution_type == ARRIVAL_CONSTANT) {
        config->interarrival_dist = createConstantDistribution(meanInterarrival);
    } else {
        config->interarrival_dist = createExponentialDistribution(meanInterarrival);
    }

}//End setupLoad()
Пример #5
0
TestKeyList::TestKeyList(int listSize, uint32_t seed)
    : size_(listSize), rand_(seed) {
  assert(size_ > 0);

  // Make the results actually random if requested to do so.
  if (seed == 0) {
    folly::Random::seed(rand_);
  }

  generateKeys();
}
Пример #6
0
SshKeyCreationDialog::SshKeyCreationDialog(QWidget *parent)
    : QDialog(parent), m_keyGenerator(0), m_ui(new Ui::SshKeyCreationDialog)
{
    m_ui->setupUi(this);
    const QString defaultPath = QDesktopServices::storageLocation(QDesktopServices::HomeLocation)
        + QLatin1String("/.ssh/qtc_id");
    setPrivateKeyFile(defaultPath);

    connect(m_ui->rsa, SIGNAL(toggled(bool)), this, SLOT(keyTypeChanged()));
    connect(m_ui->dsa, SIGNAL(toggled(bool)), this, SLOT(keyTypeChanged()));
    connect(m_ui->privateKeyFileButton, SIGNAL(clicked()), SLOT(handleBrowseButtonClicked()));
    connect(m_ui->generateButton, SIGNAL(clicked()), this, SLOT(generateKeys()));
}
Пример #7
0
void runBench(HASH_FUNCTION hash_fn, int numReplicas, int numNodes, int numKeys, int keySize) {
    char *hash = NULL;
    if(hash_fn == HASH_FUNCTION_MD5) hash = "MD5";
    else if(hash_fn == HASH_FUNCTION_SHA1) hash = "SHA1";
    
    printf("----------------------------------------------------\n");
    printf("bench (%s): replicas = %d, nodes = %d, keys: %d, ring size: %d\n", hash, numReplicas, numNodes, numKeys, numReplicas * numNodes);
    printf("----------------------------------------------------\n");
    hash_ring_t *ring = hash_ring_create(numReplicas, hash_fn);
    
    addNodes(ring, numNodes);
    
    uint8_t *keys = (uint8_t*)malloc(keySize * numKeys);
    generateKeys(keys, numKeys, keySize);
    
    printf("running...\r");
    
    uint64_t min = 0;
    uint64_t max = 0;
    uint64_t total = 0;
    int times = 100;
    
    int x, y;
    for(y = 0; y < times; y++) {
        startTiming();
        for(x = 0; x < numKeys; x++) {
            assert(hash_ring_find_node(ring, keys + (keySize * x), keySize) != NULL);
        }
        uint64_t result = endTiming();
        if(result > max) max = result;
        if(min == 0 || result < min) min = result;
        total += result;
    }
    
    printf("stats: total = %.5fs, avg/lookup: %.5fus, min: %.5fus, max: %.5fus, ops/sec: %.0f\n", 
        (double)total / 1000000000,
        (((double)(total / numKeys)) / 1000) / times,
        (double)min / numKeys / 1000,
        (double)max / numKeys / 1000,
        1000000000 / ((double)(total / (numKeys * times))));
    
    free(keys);
    hash_ring_free(ring);
}
Пример #8
0
void sendInitMsg (int clientSocket, struct sockaddr_in serverAddr, socklen_t addr_size) {
	struct signInfo sig;
	char buffer1[BUFF_SIZE - sizeof(struct signInfo)];
	char buffer2[BUFF_SIZE];

	generateKeys(lightChain, saltChain);
	time(&senderTime);
	time(&epochStart);
	senderTimeSecond = timeSecons(senderTime);

	cpInitValues(buffer1);
	sig = RSASignBuff(buffer1, BUFF_SIZE - sizeof(struct signInfo));
	memcpy(buffer2, buffer1, BUFF_SIZE - sizeof(struct signInfo));
	memcpy(buffer2 + BUFF_SIZE - sizeof(struct signInfo), &sig, sizeof(struct signInfo));

	if (sendto(clientSocket, buffer2, BUFF_SIZE, 0, (struct sockaddr *) &serverAddr,
			addr_size) < 0 )
		error("ERROR writing to socket");
}
SshKeyCreationDialog::SshKeyCreationDialog(QWidget *parent)
    : QDialog(parent), m_keyGenerator(0), m_ui(new Ui::SshKeyCreationDialog)
{
    m_ui->setupUi(this);
    // Not using Utils::PathChooser::browseButtonLabel to avoid dependency
#ifdef Q_OS_MAC
    m_ui->privateKeyFileButton->setText(tr("Choose..."));
#else
    m_ui->privateKeyFileButton->setText(tr("Browse..."));
#endif
    const QString defaultPath = QDesktopServices::storageLocation(QDesktopServices::HomeLocation)
        + QLatin1String("/.ssh/qtc_id");
    setPrivateKeyFile(defaultPath);

    connect(m_ui->rsa, SIGNAL(toggled(bool)), this, SLOT(keyTypeChanged()));
    connect(m_ui->dsa, SIGNAL(toggled(bool)), this, SLOT(keyTypeChanged()));
    connect(m_ui->privateKeyFileButton, SIGNAL(clicked()), SLOT(handleBrowseButtonClicked()));
    connect(m_ui->generateButton, SIGNAL(clicked()), this, SLOT(generateKeys()));
}
Пример #10
0
/* Main function that also spawns the thread */
int main(int argc, char** argv) {
    srand(time(NULL));
    pthread_t readThread, writeThread;
    struct Parameters args;
    int connfd;
    long first_prime, sec_prime, e, c, d;

    if(argc < 3) {
        printf("Run client with 'client [host name] [port number]'\n");
        exit(0);
    }

    char host[20];
    strcpy(host, argv[1]);
    connfd = connectTo(host, atoi(argv[2]));

    printf("\nEnter two numbers (m n) to generate keys based on the mth and nth primes: ");
    scanf("%ld %ld", &first_prime, &sec_prime);
    printf("\nGenerating keys...\n");
    generatePrimeNumbers(&first_prime, &sec_prime);
    generateKeys(first_prime, sec_prime, &e, &d, &c);
    printf("Your public key (will be sent to server): %ld %ld\n", e, c);
    printf("Your private key (will not be sent): %ld %ld\n", d, c);

    args.connfd = connfd;
    args.clientE = e;
    args.clientN = c;
    args.clientD = d;
    receive_key(&args);
    send_key(&args);

    pthread_create(&writeThread, NULL, write_data, &args);
    pthread_create(&readThread, NULL, read_data, &args);

    pthread_join(writeThread, NULL);
    pthread_join(readThread, NULL);

    close(connfd);
    exit(0);
}
Пример #11
0
 Rsa::Rsa() {
     x = X509_new();
     evp_pkey = EVP_PKEY_new();
     keypair = ssl_generateKeys(2048);
     generateKeys(256);
 }
Пример #12
0
Файл: rsa.c Проект: jasongi/rsa
/*  this program does three different things depending on the
    flags given. -g will generate a public key e, private key d
    and a modulo n. -e will take in/out filenames, a key and n
    and it will encrypt the in file and save it to the out file.
    -d will take an in/out filename, a key and a n and it will
    decrypt the in file and save it to the out file. The reason
    I didn't have key generation and encryption happen at the same
    time is because with RSA, the person you're encrypting the message
    for is the person who generates the key to encrypt it with*/
int main(int argc, char** argv)
{
    /*  the usage will print if the arguments are wrong*/
    char usage[] = "rsa by Jason Giancono\nUSAGE: rsa <FLAG>\nFLAGS:\t\t-g: generate keys\n\t\t-d <input filename> <output filename> <key> <n modulo>: decrypt file using key and modulo and output to <output filename>\n\t\t-e <input filename> <output filename> <key> <n modulo>: encrypt file using key and modulo and output to <output filename>\n";
    /*  seed the PRNG when the program starts*/
    srand(time(NULL));
    /*  variable for i/o errors*/
    int error = 0;
    /*  test to see if the -g flag and make sure there is any arguments at all
        (it will segfault otherwise*/
    if ( (argc != 1) && !strcmp(argv[1],"-g") )
    {
        uint64_t pub, priv,n;
        /*generates the keys*/
        generateKeys(&pub, &priv, &n);
        /*print the keys to the terminal*/
        printf("\nKeys:\t\t\tPublic: \t%llu\n\t\t\tPrivate: \t%llu\n\t\t\tN: \t\t%llu\n", pub, priv, n);
    }
    else if (argc ==6)
    {
        uint64_t key,n;
        /*open files for reading/writing*/
        FILE *input,*output;
        input = fopen(argv[2], "r");
        output = fopen(argv[3], "w");
        /*convert arguments to integers*/
        key = strtoll(argv[4], NULL,10);
        n = strtoll(argv[5], NULL,10);
        /*calculate the amount of chars I can fit in one encryption block*/
        int arraySize = (msb(n)-1)/8;
        /*make sure the files opened OK*/
        if(output != NULL)
        {
            if(input !=NULL)
            {
                /*check the flag for encrypt*/
                if(!strcmp(argv[1], "-e"))
                {
                    /*continue reading and encrypting until an error or end of file*/
                    while((!feof(input)) && !ferror(input) && !ferror(output) )
                    {
                        /*make the array size 8 because then it is sizeof(uint64_t)*/
                        char block[8];
                        memset(block,0,8);
                        int ii;
                        /*read characters into the array*/
                        for(ii=0; ii<arraySize; ii++)
                        {
                            block[ii] = getc(input);
                        }
                        /*dirty pointer manipulation so you can do FMEA on the array*/
                        uint64_t *m = (uint64_t*)block;
                        /*do the RSA encryption*/
                        *m = fmea(*m,key,n);
                        /*  write characters into encrypted file, one extra character is copied
                            copies the arraySize+1 because the FMEA may have made the block
                            larger than it's original size*/
                        for(ii=0; ii<arraySize+1; ii++)
                        {
                            putc(block[ii],output);
                        }
                    }
                }
                /*check the flag for decrypt*/
                else if(!strcmp(argv[1], "-d"))
                {
                    /*continue reading and encrypting until an error or end of file*/
                    while((!feof(input)) && !ferror(input) && !ferror(output) )
                    {
                        /*make the array size 8 because then it is sizeof(uint64_t)*/
                        char block[8];
                        memset(block,0,8);
                        int ii;
                        /*read characters into the array*/
                        for(ii=0; ii<arraySize+1; ii++)
                        {
                            block[ii] = getc(input);
                        }
                        /*dirty pointer manipulation so you can do FMEA on the array*/
                        uint64_t *m = (uint64_t*)block;
                        /*do the RSA decryption*/
                        *m = fmea(*m,key,n);
                        /*  write characters into decrypted file, check for EOF so that
                        you don't copy in extra junk.*/
                        for(ii=0; ii<(arraySize); ii++)
                        {
                            if(!feof(input) && (block[ii] != EOF))
                                putc(block[ii],output);
                        }
                    }
                }
                else error = 1;
            }
            else error = 1;
        }
        else error = 1;
        /*error handling*/
        if (error || ferror(output) || ferror(input))
        {
            error = 1;
            perror("An Error Occurred");
            if (output !=NULL)
                fclose(output);
            if (input != NULL)
                fclose(input);
        }
        else
        {
            /*close the files*/
            fclose(output);
            fclose(input);
        }
    }
    /*print the usage because the muffin obviously doesn't know the arguments*/
    else printf("Wrong number of args \n\n%s", usage);
    return error;
}