about summary refs log tree commit diff stats
path: root/gba/source/serialize.c
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2017-09-26 16:52:33 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2017-09-26 16:52:33 -0400
commit566d5fe1e012c0001396810bc56395597eb79c2c (patch)
tree464262d2772299b3c7b39d153395461983d17c83 /gba/source/serialize.c
parent8d9df7cc26ef86c7af1d4aa6fd4633667bb3a743 (diff)
downloadgen3uploader-566d5fe1e012c0001396810bc56395597eb79c2c.tar.gz
gen3uploader-566d5fe1e012c0001396810bc56395597eb79c2c.tar.bz2
gen3uploader-566d5fe1e012c0001396810bc56395597eb79c2c.zip
Replaced SHA-224 with BLAKE2s
Also changed the hash determiner format such that each IV, as well as
the Shedinja flag, has its own byte. This increases the size of the
determiner to 16 bytes, 33 bits of which are always unset. While this is
somewhat wasteful, it is useful for debugging purposes because it is
hard to predict the behavior of bitfields.

For testing purposes, the amount of time that the Wii waits for the GBA
to compute hashes has been increased. Given that BLAKE2s is a generally
faster algorithm than SHA-224, it will likely be safe to decrease this
delay in a future commit.

Because the hash algorithm has changed, all old hashes are now invalid.

refs #2
Diffstat (limited to 'gba/source/serialize.c')
-rw-r--r--gba/source/serialize.c51
1 files changed, 20 insertions, 31 deletions
diff --git a/gba/source/serialize.c b/gba/source/serialize.c index ddb156c..5c4ff8d 100644 --- a/gba/source/serialize.c +++ b/gba/source/serialize.c
@@ -10,21 +10,7 @@
10#include "basestats.h" 10#include "basestats.h"
11#include "exptables.h" 11#include "exptables.h"
12#include "dexorder.h" 12#include "dexorder.h"
13#include "sha2.h" 13#include "blake2.h"
14
15// See pokemon.h for more information about this.
16struct HashDeterminer {
17 u32 otId;
18 u32 personality;
19 u32 hpIV:5;
20 u32 attackIV:5;
21 u32 defenseIV:5;
22 u32 speedIV:5;
23 u32 spAttackIV:5;
24 u32 spDefenseIV:5;
25 u32 isShedinja:1;
26 u32 zero:1;
27};
28 14
29u32 CalculateStat( 15u32 CalculateStat(
30 u8 base, 16 u8 base,
@@ -64,22 +50,25 @@ void PokemonIntermediateInit(
64 struct PokemonSubstruct2* sub2 = GetBoxPokemonSubstruct2(bpkm); 50 struct PokemonSubstruct2* sub2 = GetBoxPokemonSubstruct2(bpkm);
65 struct PokemonSubstruct3* sub3 = GetBoxPokemonSubstruct3(bpkm); 51 struct PokemonSubstruct3* sub3 = GetBoxPokemonSubstruct3(bpkm);
66 52
67 struct HashDeterminer identifier; 53 u8 identifier[16];
68 identifier.otId = bpkm->otId; 54 identifier[0] = bpkm->otId & 0x000000FF;
69 identifier.personality = bpkm->personality; 55 identifier[1] = (bpkm->otId >> 8) & 0x000000FF;
70 identifier.hpIV = sub3->hpIV; 56 identifier[2] = (bpkm->otId >> 16) & 0x000000FF;
71 identifier.attackIV = sub3->attackIV; 57 identifier[3] = (bpkm->otId >> 24) & 0x000000FF;
72 identifier.defenseIV = sub3->defenseIV; 58 identifier[4] = bpkm->personality & 0x000000FF;
73 identifier.speedIV = sub3->speedIV; 59 identifier[5] = (bpkm->personality >> 8) & 0x000000FF;
74 identifier.spAttackIV = sub3->spAttackIV; 60 identifier[6] = (bpkm->personality >> 16) & 0x000000FF;
75 identifier.spDefenseIV = sub3->spDefenseIV; 61 identifier[7] = (bpkm->personality >> 24) & 0x000000FF;
76 identifier.isShedinja = (sub0->species == SHEDINJA_SPECIES_INDEX) ? 1 : 0; 62 identifier[8] = sub3->hpIV;
77 identifier.zero = 0; 63 identifier[9] = sub3->attackIV;
78 64 identifier[10] = sub3->defenseIV;
79 sha224( 65 identifier[11] = sub3->speedIV;
80 (const unsigned char*)&identifier, 66 identifier[12] = sub3->spAttackIV;
81 12, 67 identifier[13] = sub3->spDefenseIV;
82 (unsigned char*)pki->key); 68 identifier[14] = (sub0->species == SHEDINJA_SPECIES_INDEX) ? 1 : 0;
69 identifier[15] = 0;
70
71 blake2s((u8*)pki->key, 28, identifier, 16, 0, 0);
83 72
84 const struct SmallBaseStats* baseStats = BaseStatsForSpecies(sub0->species); 73 const struct SmallBaseStats* baseStats = BaseStatsForSpecies(sub0->species);
85 74