Subversion Repositories oidplus

Rev

Rev 1116 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
557 daniel-mar 1
#!/usr/bin/env php
211 daniel-mar 2
<?php
3
 
511 daniel-mar 4
/*
5
 * OIDplus 2.0
1072 daniel-mar 6
 * Copyright 2019 - 2022 Daniel Marschall, ViaThinkSoft
511 daniel-mar 7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
 
1116 daniel-mar 21
const TARGET_ID = '6175446'; // ViaThinkSoft RA
211 daniel-mar 22
 
1072 daniel-mar 23
$config = array("digest_alg" => "sha512",
24
                "private_key_bits" => 2048,
211 daniel-mar 25
                "private_key_type" => OPENSSL_KEYTYPE_RSA,
1073 daniel-mar 26
                "config" => __DIR__."/../vendor/phpseclib/phpseclib/phpseclib/openssl.cnf",
211 daniel-mar 27
               );
28
 
29
# ---
30
 
31
$cnt = 0;
32
 
33
echo date('Y-m-d H:i:s')." START\n";
34
 
35
while (true) {
36
	$cnt++;
37
 
38
	$res = openssl_pkey_new($config);
1072 daniel-mar 39
	if (!$res) die("openssl_pkey_new failed\n"); // can happen if private_key_bits is too small
211 daniel-mar 40
 
41
	$details = openssl_pkey_get_details($res);
42
	$pubKey = str_replace(array('BEGIN PUBLIC KEY','END PUBLIC KEY','-',"\n"), '', $details["key"]);
43
	unset($details);
44
 
45
	$system_id = smallhash(base64_decode($pubKey));
46
 
47
	if ($system_id == TARGET_ID) {
1073 daniel-mar 48
		openssl_pkey_export($res, $privKey, null, $config);
211 daniel-mar 49
		echo date('Y-m-d H:i:s')." COLLISSION WITH $system_id AFTER $cnt TRIES: ".$pubKey." / ".$privKey."\n";
50
		unset($privKey);
51
	}
52
 
53
	unset($res);
54
 
55
	if ($cnt%25 == 0) echo "PROCESSING: $cnt       \r";
56
}
57
 
1130 daniel-mar 58
/**
59
 * @param string $data
60
 * @return int
61
 */
62
function smallhash(string $data): int { // get 31 bits from SHA1. Values 0..2147483647
1073 daniel-mar 63
	return (hexdec(substr(sha1($data),-4*2)) & 0x7FFFFFFF);
211 daniel-mar 64
}
65