we know a secret!

This commit is contained in:
rusefillc 2023-06-03 01:30:48 -04:00
parent 442ce2939d
commit 412d214a99
2 changed files with 23 additions and 5 deletions

View File

@ -1,10 +1,18 @@
package com.rusefi.uds;
public class KeyCalculator {
//private static final int SECRET = 0x57649392;
private static final int MAIN_APP_SECRET = 0x57649392;
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) {
rnd += 35;
} else {
@ -13,7 +21,7 @@ public class KeyCalculator {
for (int i = 0; i < rnd; i++) {
if (seed < 0) {
seed = BOOTLOADER_SECRET ^ seed << 1;
seed = secret ^ seed << 1;
} else {
seed <<= 1;
}

View File

@ -7,7 +7,17 @@ import static org.junit.Assert.assertEquals;
public class SecurityTest {
@Test
public void testCalcKey() {
int key = KeyCalculator.udsSecurityCalcKey(0x5D8A2010, 0xF0);
assertEquals("Got " + String.format("%x", key), 0xc42f15ae, key);
{
int key = KeyCalculator.udsBootloaderSecurityCalcKey(0x5D8A2010, 0xF0);
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);
}
}
}