mirror of
https://github.com/PurpleI2P/i2pd-tools.git
synced 2025-06-07 14:46:51 +02:00
generate
This commit is contained in:
parent
dfdf64c3cf
commit
262bc466c7
2 changed files with 72 additions and 9 deletions
2
Makefile
2
Makefile
|
@ -2,7 +2,7 @@ I2PD_PATH = i2pd
|
||||||
LIBI2PD_PATH = $(I2PD_PATH)/libi2pd
|
LIBI2PD_PATH = $(I2PD_PATH)/libi2pd
|
||||||
LIBI2PD_CLIENT_PATH = $(I2PD_PATH)/libi2pd_client
|
LIBI2PD_CLIENT_PATH = $(I2PD_PATH)/libi2pd_client
|
||||||
CXX = g++
|
CXX = g++
|
||||||
FLAGS = -g -Wall -std=c++11
|
FLAGS = -g -Wall -std=c++11 -fpermissive
|
||||||
INCFLAGS = -I$(LIBI2PD_PATH) -I$(LIBI2PD_CLIENT_PATH) -I$(I2PD_PATH)
|
INCFLAGS = -I$(LIBI2PD_PATH) -I$(LIBI2PD_CLIENT_PATH) -I$(I2PD_PATH)
|
||||||
CXXFLAGS = $(FLAGS) $(INCFLAGS)
|
CXXFLAGS = $(FLAGS) $(INCFLAGS)
|
||||||
LDFLAGS = -Wl,-rpath,/usr/local/lib
|
LDFLAGS = -Wl,-rpath,/usr/local/lib
|
||||||
|
|
75
keygen.cpp
75
keygen.cpp
|
@ -1,24 +1,87 @@
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <sched.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <stdlib.h>
|
|
||||||
#include "Crypto.h"
|
#include "Crypto.h"
|
||||||
#include "Identity.h"
|
#include "Identity.h"
|
||||||
#include "common/key.hpp"
|
#include "common/key.hpp"
|
||||||
|
|
||||||
|
#define error(msg) \
|
||||||
|
std::cout << "Error: " << msg << std::endl;\
|
||||||
|
i2p::crypto::TerminateCrypto ();\
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
#define SET_CPUS(cpus,num_proc)\
|
||||||
|
CPU_ZERO(&cpus);\
|
||||||
|
for(unsigned int i = num_proc;i--;)\
|
||||||
|
CPU_SET(i, &cpus);
|
||||||
|
|
||||||
|
|
||||||
|
static i2p::data::PrivateKeys keys;
|
||||||
|
static i2p::data::SigningKeyType type;
|
||||||
|
|
||||||
|
static cpu_set_t cpus;
|
||||||
|
static unsigned num_proc;
|
||||||
|
static volatile bool all=false;
|
||||||
|
void generate_dest(const char * whatFind)
|
||||||
|
{
|
||||||
|
std::cout << "Start a thread" << std::endl;
|
||||||
|
i2p::data::PrivateKeys tmp_key = i2p::data::PrivateKeys::CreateRandomKeys (type);
|
||||||
|
|
||||||
|
while( tmp_key.GetPublic ()->GetIdentHash ().ToBase32 ().find( whatFind ) == -1 )
|
||||||
|
|
||||||
|
{
|
||||||
|
if(all) break;
|
||||||
|
tmp_key = i2p::data::PrivateKeys::CreateRandomKeys (type);
|
||||||
|
}
|
||||||
|
|
||||||
|
keys = tmp_key;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
int main (int argc, char * argv[])
|
int main (int argc, char * argv[])
|
||||||
{
|
{
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
{
|
{
|
||||||
std::cout << "Usage: keygen filename <signature type>" << std::endl;
|
std::cout << "Usage: keygen filename <signature type> <string>" << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
i2p::crypto::InitCrypto (false);
|
i2p::crypto::InitCrypto (false);
|
||||||
i2p::data::SigningKeyType type = i2p::data::SIGNING_KEY_TYPE_DSA_SHA1;
|
i2p::data::SigningKeyType type = i2p::data::SIGNING_KEY_TYPE_DSA_SHA1;
|
||||||
if (argc > 2) {
|
if (argc >= 3) {
|
||||||
std::string str(argv[2]);
|
std::string str(argv[2]);
|
||||||
type = NameToSigType(str);
|
type = NameToSigType(str);
|
||||||
}
|
}
|
||||||
auto keys = i2p::data::PrivateKeys::CreateRandomKeys (type);
|
std::cout << "Start generate\n";
|
||||||
|
|
||||||
|
if(argc == 4)
|
||||||
|
{
|
||||||
|
|
||||||
|
num_proc = std::thread::hardware_concurrency();
|
||||||
|
pthread_t thr[num_proc];
|
||||||
|
|
||||||
|
SET_CPUS(cpus,num_proc);
|
||||||
|
|
||||||
|
for( unsigned int i = num_proc;i--;)
|
||||||
|
{
|
||||||
|
pthread_create(&thr[i],NULL,generate_dest,argv[3]);
|
||||||
|
pthread_setaffinity_np(thr[i], sizeof(cpu_set_t), &cpus);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(unsigned int i = num_proc;i--;)
|
||||||
|
pthread_join(thr[i],NULL);
|
||||||
|
|
||||||
|
CPU_ZERO(&cpus);
|
||||||
|
} // if(argc==4)
|
||||||
|
else
|
||||||
|
keys = i2p::data::PrivateKeys::CreateRandomKeys (type);
|
||||||
|
|
||||||
|
std::cout << "Write to file\n";
|
||||||
|
|
||||||
std::ofstream f (argv[1], std::ofstream::binary | std::ofstream::out);
|
std::ofstream f (argv[1], std::ofstream::binary | std::ofstream::out);
|
||||||
if (f)
|
if (f)
|
||||||
{
|
{
|
||||||
|
@ -26,11 +89,11 @@ int main (int argc, char * argv[])
|
||||||
uint8_t * buf = new uint8_t[len];
|
uint8_t * buf = new uint8_t[len];
|
||||||
len = keys.ToBuffer (buf, len);
|
len = keys.ToBuffer (buf, len);
|
||||||
f.write ((char *)buf, len);
|
f.write ((char *)buf, len);
|
||||||
delete[] buf;
|
|
||||||
std::cout << "Destination " << keys.GetPublic ()->GetIdentHash ().ToBase32 () << " created" << std::endl;
|
std::cout << "Destination " << keys.GetPublic ()->GetIdentHash ().ToBase32 () << " created" << std::endl;
|
||||||
|
delete[] buf;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
std::cout << "Can't create file " << argv[1] << std::endl;
|
error("Can't create file");
|
||||||
|
|
||||||
i2p::crypto::TerminateCrypto ();
|
i2p::crypto::TerminateCrypto ();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue