mirror of https://github.com/rusefi/uds-tool.git
we know a secret!
This commit is contained in:
parent
442ce2939d
commit
412d214a99
|
@ -1,10 +1,18 @@
|
||||||
package com.rusefi.uds;
|
package com.rusefi.uds;
|
||||||
|
|
||||||
public class KeyCalculator {
|
public class KeyCalculator {
|
||||||
//private static final int SECRET = 0x57649392;
|
private static final int MAIN_APP_SECRET = 0x57649392;
|
||||||
private static final int BOOTLOADER_SECRET = 0xB24F5249;
|
private static final int BOOTLOADER_SECRET = 0xB24F5249;
|
||||||
|
|
||||||
public static int udsSecurityCalcKey(int seed, int rnd) {
|
public static int udsBootloaderSecurityCalcKey(int seed, int rnd) {
|
||||||
|
return udsSecurityCalcKey(BOOTLOADER_SECRET, seed, rnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int udsMainAppSecurityCalcKey(int seed, int rnd) {
|
||||||
|
return udsSecurityCalcKey(MAIN_APP_SECRET, seed, rnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int udsSecurityCalcKey(int secret, int seed, int rnd) {
|
||||||
if (rnd < 220) {
|
if (rnd < 220) {
|
||||||
rnd += 35;
|
rnd += 35;
|
||||||
} else {
|
} else {
|
||||||
|
@ -13,7 +21,7 @@ public class KeyCalculator {
|
||||||
|
|
||||||
for (int i = 0; i < rnd; i++) {
|
for (int i = 0; i < rnd; i++) {
|
||||||
if (seed < 0) {
|
if (seed < 0) {
|
||||||
seed = BOOTLOADER_SECRET ^ seed << 1;
|
seed = secret ^ seed << 1;
|
||||||
} else {
|
} else {
|
||||||
seed <<= 1;
|
seed <<= 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,17 @@ import static org.junit.Assert.assertEquals;
|
||||||
public class SecurityTest {
|
public class SecurityTest {
|
||||||
@Test
|
@Test
|
||||||
public void testCalcKey() {
|
public void testCalcKey() {
|
||||||
int key = KeyCalculator.udsSecurityCalcKey(0x5D8A2010, 0xF0);
|
{
|
||||||
|
int key = KeyCalculator.udsBootloaderSecurityCalcKey(0x5D8A2010, 0xF0);
|
||||||
assertEquals("Got " + String.format("%x", key), 0xc42f15ae, key);
|
assertEquals("Got " + String.format("%x", key), 0xc42f15ae, key);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
int key = KeyCalculator.udsBootloaderSecurityCalcKey(0x5D8A202C, 0xF0);
|
||||||
|
assertEquals("Got " + String.format("%x", key), 0xAEE52AA2, key);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
int key = KeyCalculator.udsMainAppSecurityCalcKey(0x5DA0B808, 0xA4);
|
||||||
|
assertEquals("Got " + String.format("%x", key), 0x001B6F78, key);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue