Nicer alpha expansion algorithm

This commit is contained in:
Bottersnike 2023-02-17 21:56:58 +00:00
parent 697eeeb99e
commit f0ee40b08c
1 changed files with 13 additions and 21 deletions

View File

@ -41,9 +41,10 @@
key is always 32768 (8000<sub>h</sub>) bytes, and is unmodified during this process. key is always 32768 (8000<sub>h</sub>) bytes, and is unmodified during this process.
</p> </p>
<p> <p>
Keys are derrived based on a key expansion algorithm that takes as input an unsigned short (16 bit) seed. I'm not Keys are derrived based on a key expansion algorithm that takes as input an unsigned short (16 bit) seed. This
totally sure what expansion algorithm this is, or if it's something totally custom, but for now here's a snippet of algorithm is fundamentally an LSFR-based PRNG, used to generate a stream of bytes, which becomes the key. The
python code that implements the expansion: <code>& 0xffffffff</code> is not strictly necessary but is convenient in python in order to avoid
<code>seed</code> blowing up in size.
</p> </p>
<pre> <pre>
@ -51,26 +52,17 @@
def amAuthDiskInitKey(seed): def amAuthDiskInitKey(seed):
key = bytearray(0x8000) key = bytearray(0x8000)
for i in range(0x8000): seed <<= 1
uVar1 = (seed * 2 >> 4 ^ seed * 2) >> 10 & 2 | seed << 2 for i in range(len(key)):
x = seed
uVar2 = uVar1 * 2 for _ in range(8):
uVar3 = ((seed << 2) >> 4 ^ uVar1) >> 10 & 2 | uVar2 x |= ((((seed >> 4) ^ x) >> 11) & 1)
uVar1 = uVar3 * 2 seed <<= 1
uVar3 = (uVar2 >> 4 ^ uVar3) >> 10 & 2 | uVar1 x <<= 1
key[i] = (x >> 1) & 0xff
uVar2 = uVar3 * 2 seed = x & 0xffffffff
uVar3 = (uVar1 >> 4 ^ uVar3) >> 10 & 2 | uVar2
uVar1 = uVar3 * 2
uVar3 = (uVar2 >> 4 ^ uVar3) >> 10 & 2 | uVar1
uVar2 = uVar3 * 2
uVar3 = (uVar1 >> 4 ^ uVar3) >> 10 & 2 | uVar2
uVar1 = uVar3 * 2
uVar2 = (uVar2 >> 4 ^ uVar3) >> 10 & 2 | uVar1
seed = uVar2 | (uVar1 >> 4 ^ uVar2) >> 11 & 1
key[i] = seed & 0xff
return key return key
{% endhighlight %}</pre {% endhighlight %}</pre