wireguard-vanity-address: more features less bugs
This commit is contained in:
parent
f297f9bac8
commit
f889c26bfd
2 changed files with 127 additions and 6 deletions
|
@ -2,19 +2,17 @@
|
||||||
# Maintainer: psykose <alice@ayaya.dev>
|
# Maintainer: psykose <alice@ayaya.dev>
|
||||||
pkgname=wireguard-vanity-address
|
pkgname=wireguard-vanity-address
|
||||||
pkgver=0.4.0
|
pkgver=0.4.0
|
||||||
pkgrel=0
|
pkgrel=1
|
||||||
pkgdesc="generate Wireguard keypairs with a given prefix string"
|
pkgdesc="generate Wireguard keypairs with a given prefix string"
|
||||||
url="https://github.com/warner/wireguard-vanity-address"
|
url="https://github.com/warner/wireguard-vanity-address"
|
||||||
arch="all"
|
arch="all"
|
||||||
license="MIT"
|
license="MIT"
|
||||||
makedepends="cargo"
|
makedepends="cargo"
|
||||||
source="https://github.com/warner/wireguard-vanity-address/archive/refs/tags/v$pkgver/wireguard-vanity-address-v$pkgver.tar.gz"
|
source="https://github.com/warner/wireguard-vanity-address/archive/refs/tags/v$pkgver/wireguard-vanity-address-v$pkgver.tar.gz
|
||||||
|
more-features.patch
|
||||||
|
"
|
||||||
|
|
||||||
export CARGO_HOME="$srcdir"
|
export CARGO_HOME="$srcdir"
|
||||||
export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1
|
|
||||||
export CARGO_PROFILE_RELEASE_LTO="true"
|
|
||||||
export CARGO_PROFILE_RELEASE_OPT_LEVEL="s"
|
|
||||||
export CARGO_PROFILE_RELEASE_PANIC="abort"
|
|
||||||
|
|
||||||
prepare() {
|
prepare() {
|
||||||
default_prepare
|
default_prepare
|
||||||
|
@ -36,4 +34,5 @@ package() {
|
||||||
|
|
||||||
sha512sums="
|
sha512sums="
|
||||||
7be6823b01dc7741018f6e98a3a91ad84f290d586d4418c9f65f5966141c89bd5e5bd80e856286d6c7ff2f756ca20342169d4b57016ac90882a5c9f74643a11e wireguard-vanity-address-v0.4.0.tar.gz
|
7be6823b01dc7741018f6e98a3a91ad84f290d586d4418c9f65f5966141c89bd5e5bd80e856286d6c7ff2f756ca20342169d4b57016ac90882a5c9f74643a11e wireguard-vanity-address-v0.4.0.tar.gz
|
||||||
|
e5801d0d6ad448fec2a5db7152d9f3fe17324cb79f7d09941106b7a0c9126e1d0ebce5a3157d07f69d3a8879dde6c95232d901ccbdbc054fac1aa3ae70d6f6e8 more-features.patch
|
||||||
"
|
"
|
||||||
|
|
122
wireguard-vanity-address/more-features.patch
Normal file
122
wireguard-vanity-address/more-features.patch
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
From 89b5d55f62bcfdc7c13b43981e0725b6860ebad2 Mon Sep 17 00:00:00 2001
|
||||||
|
From: ThinkChaos <ThinkChaos@users.noreply.github.com>
|
||||||
|
Date: Fri, 24 Apr 2020 22:21:55 +0200
|
||||||
|
Subject: [PATCH] Add `--case-sensitive` and allow `--in 0` meaning actual
|
||||||
|
prefix
|
||||||
|
|
||||||
|
---
|
||||||
|
src/bin.rs | 20 +++++++++++++-------
|
||||||
|
src/lib.rs | 15 +++++++++++----
|
||||||
|
2 files changed, 24 insertions(+), 11 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/src/bin.rs b/src/bin.rs
|
||||||
|
index a5a6f35..c18d430 100644
|
||||||
|
--- a/src/bin.rs
|
||||||
|
+++ b/src/bin.rs
|
||||||
|
@@ -8,12 +8,11 @@ use num_cpus;
|
||||||
|
use rayon::prelude::*;
|
||||||
|
use wireguard_vanity_lib::trial;
|
||||||
|
|
||||||
|
-fn estimate_one_trial() -> Duration {
|
||||||
|
- let prefix = "prefix";
|
||||||
|
+fn estimate_one_trial(prefix: &str, end: usize, case_sensitive: bool) -> Duration {
|
||||||
|
let start = SystemTime::now();
|
||||||
|
const COUNT: u32 = 100;
|
||||||
|
(0..COUNT).for_each(|_| {
|
||||||
|
- trial(&prefix, 0, 10);
|
||||||
|
+ trial(&prefix, end, case_sensitive);
|
||||||
|
});
|
||||||
|
let elapsed = start.elapsed().unwrap();
|
||||||
|
elapsed.checked_div(COUNT).unwrap()
|
||||||
|
@@ -86,11 +85,16 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
.version("0.3.1")
|
||||||
|
.author("Brian Warner <warner@lothar.com>")
|
||||||
|
.about("finds Wireguard keypairs with a given string prefix")
|
||||||
|
+ .arg(
|
||||||
|
+ Arg::with_name("CASE")
|
||||||
|
+ .long("case-sensitive")
|
||||||
|
+ .help("Use case-sensitive matching"),
|
||||||
|
+ )
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("RANGE")
|
||||||
|
.long("in")
|
||||||
|
.takes_value(true)
|
||||||
|
- .help("NAME must be found within first RANGE chars of pubkey (default: 10)"),
|
||||||
|
+ .help("NAME must be found within first RANGE chars of pubkey (default: 10, 0 means actual prefix)"),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("NAME")
|
||||||
|
@@ -98,6 +102,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
.help("string to find near the start of the pubkey"),
|
||||||
|
)
|
||||||
|
.get_matches();
|
||||||
|
+ let case_sensitive = matches.is_present("CASE");
|
||||||
|
let prefix = matches.value_of("NAME").unwrap().to_ascii_lowercase();
|
||||||
|
let len = prefix.len();
|
||||||
|
let end: usize = 44.min(match matches.value_of("RANGE") {
|
||||||
|
@@ -110,6 +115,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
+ let end = if end == 0 { len } else { end };
|
||||||
|
if end < len {
|
||||||
|
return Err(ParseError(format!("range {} is too short for len={}", end, len)).into());
|
||||||
|
}
|
||||||
|
@@ -119,7 +125,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
let mut num = offsets;
|
||||||
|
let mut denom = 1u64;
|
||||||
|
prefix.chars().for_each(|c| {
|
||||||
|
- if c.is_ascii_alphabetic() {
|
||||||
|
+ if !case_sensitive && c.is_ascii_alphabetic() {
|
||||||
|
num *= 2; // letters can match both uppercase and lowercase
|
||||||
|
}
|
||||||
|
denom *= 64; // base64
|
||||||
|
@@ -136,7 +142,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
// run at half the speed that this predicts.
|
||||||
|
|
||||||
|
if trials_per_key < 2u64.pow(32) {
|
||||||
|
- let est = estimate_one_trial();
|
||||||
|
+ let est = estimate_one_trial(&prefix, end, case_sensitive);
|
||||||
|
println!(
|
||||||
|
"one trial takes {}, CPU cores available: {}",
|
||||||
|
format_time(duration_to_f64(est)),
|
||||||
|
@@ -162,7 +168,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
// 1M trials takes about 10s on my laptop, so let it run for 1000s
|
||||||
|
(0..100_000_000)
|
||||||
|
.into_par_iter()
|
||||||
|
- .map(|_| trial(&prefix, 0, end))
|
||||||
|
+ .map(|_| trial(&prefix, end, case_sensitive))
|
||||||
|
.filter_map(|r| r)
|
||||||
|
.try_for_each(print)?;
|
||||||
|
Ok(())
|
||||||
|
diff --git a/src/lib.rs b/src/lib.rs
|
||||||
|
index 31138c5..fb95581 100644
|
||||||
|
--- a/src/lib.rs
|
||||||
|
+++ b/src/lib.rs
|
||||||
|
@@ -1,15 +1,22 @@
|
||||||
|
use base64;
|
||||||
|
use rand::thread_rng;
|
||||||
|
+use std::borrow::Cow;
|
||||||
|
use x25519_dalek::{PublicKey, StaticSecret};
|
||||||
|
|
||||||
|
-pub fn trial(prefix: &str, start: usize, end: usize) -> Option<(String, String)> {
|
||||||
|
+pub fn trial(prefix: &str, end: usize, case_sensitive: bool) -> Option<(String, String)> {
|
||||||
|
let mut rng = thread_rng();
|
||||||
|
let private = StaticSecret::new(&mut rng);
|
||||||
|
let public = PublicKey::from(&private);
|
||||||
|
+
|
||||||
|
let public_b64 = base64::encode(public.as_bytes());
|
||||||
|
- if public_b64[start..end]
|
||||||
|
- .to_ascii_lowercase()
|
||||||
|
- .contains(&prefix)
|
||||||
|
+
|
||||||
|
+ let b64_prefix = if case_sensitive {
|
||||||
|
+ Cow::Borrowed(&public_b64[..end])
|
||||||
|
+ } else {
|
||||||
|
+ Cow::Owned(public_b64[..end].to_ascii_lowercase())
|
||||||
|
+ };
|
||||||
|
+
|
||||||
|
+ if b64_prefix.contains(prefix)
|
||||||
|
{
|
||||||
|
let private_b64 = base64::encode(&private.to_bytes());
|
||||||
|
Some((private_b64, public_b64))
|
Loading…
Reference in a new issue