// There is no scenario requiring a public key, we support it for completeness. bool create_key_pair(encrypted_private& out_private, encrypted_public& out_public, ec_compressed& out_point, const encrypted_token& token, const ek_seed& seed, uint8_t version, bool compressed) { const parse_encrypted_token parse(token); if (!parse.valid()) return false; const auto point = splice(parse.sign(), parse.data()); auto point_copy = point; const auto factor = bitcoin_hash(seed); if (!ec_multiply(point_copy, factor)) return false; ek_salt salt; if (!address_salt(salt, point_copy, version, compressed)) return false; const auto salt_entropy = splice(salt, parse.entropy()); const auto derived = split(scrypt_pair(point, salt_entropy)); const auto flags = set_flags(compressed, parse.lot_sequence(), true); if (!create_public_key(out_public, flags, salt, parse.entropy(), derived.left, derived.right, factor, version)) return false; create_private_key(out_private, flags, salt, parse.entropy(), derived.left, derived.right, seed, version); out_point = point_copy; return true; }
/*! \brief Input: flag for multiple runs Output: Message. * * This test creates a public and private key. The functions were tested for correctness in testSmall.c * Here we look at the integration of these functions to create the keys to have the properties * required of the GGH algortihm. */ int testGGH(int mruns){ printf("* Executing %i GGH run(s)\n",mruns); gsl_matrix *uniMatrix = gsl_matrix_alloc(SIZE,SIZE); gsl_matrix *privKey = gsl_matrix_alloc(SIZE,SIZE); gsl_matrix *pubKey = gsl_matrix_alloc(SIZE,SIZE); gsl_matrix *message = gsl_matrix_alloc(SIZE,SIZE); gsl_matrix *Cmessage = gsl_matrix_alloc(SIZE,SIZE); gsl_matrix *Dmessage = gsl_matrix_alloc(SIZE,SIZE); int i, match, mismatch =0; if (mruns == 1){ // Choose a good basis (Private key) [V] printf("Choose a good basis (Private key) [V]\n"); privKey = create_private_key(); // Create the unimodular matrix [U] printf("Create the unimodular matrix [U]\n"); uniMatrix = genU(); // Compute a bad basis (Public Key) printf("Compute a bad basis (Public Key)\n"); pubKey = create_public_key(privKey,uniMatrix); // Generate the message printf("Generate the message\n"); message = genM(); // Encrypt printf("Compute cypher text.\n"); Cmessage = encryptor(message,pubKey); // Decrypt printf("Decrypt\n"); Dmessage = decryptor(Cmessage,privKey,uniMatrix); // Compare Messages printf("Compare Messages\n"); if(compare(message,Dmessage)==0){ printf("The messages match.\n"); } else{ printf("Message and decryped message do not match.\n"); } } else{ uniMatrix = genU(); printf("Reusing the generated unimodular matrix [U] on 100 GGH runs.\n"); for(i =0;i < (mruns+1); i++){ // Choose a good basis (Private key) [V] privKey = create_private_key(); // Compute a bad basis (Public Key) pubKey = create_public_key(privKey,uniMatrix); // Generate the message message = genM(); // Encrypt Cmessage = encryptor(message,pubKey); // Decrypt Dmessage = decryptor(Cmessage,privKey,uniMatrix); // Compare Messages if(compare(message,Dmessage)==0){ match++; } else{ mismatch++; } } } printf(" Number of matches: %i",match); return 1; }