summaryrefslogtreecommitdiffstats
path: root/include/sha1_hmac.h
blob: 708740695efe1380e9eb2548b1569ed82376b1ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// lol, I didn't know how real HMACs worked when I reversed this
//  released under GPLv3, see http://gplv3.fsf.org/

#include <openssl/sha.h>

void SHA1_ghetto_init(SHA_CTX *c, u8* sha1_hmac) {
  u8 section[0x40];
  int i;
  SHA1_Init(c);
  memset(section, 0x36, 0x40);
  for(i=0;i<0x40;i++) section[i] = sha1_hmac[i] ^ 0x36;
  SHA1_Update(c, section, 0x40);
}

void SHA1_ghetto_final(u8* digest_out, SHA_CTX *c, u8* sha1_hmac) {
  u8 section[0x40];
  int i;
  u8 digest[0x14];
  SHA1_Final(digest, c);
  SHA1_Init(c);
  memset(section, 0x5C, 0x40);
  for(i=0;i<0x40;i++) section[i] = sha1_hmac[i] ^ 0x5C;
  SHA1_Update(c, section, 0x40);
  SHA1_Update(c, digest, 0x14);
  SHA1_Final(digest_out, c);
}