PS2SDK
PS2 Homebrew Libraries
auth.c
1 /*
2  Copyright 2009-2010, jimmikaelkael
3  Licenced under Academic Free License version 3.0
4 */
5 #include "types.h"
6 #include "defs.h"
7 #include "irx.h"
8 #include "stdio.h"
9 #include "sysclib.h"
10 
11 #include "des.h"
12 #include "md4.h"
13 
14 static u8 passwd_buf[512] __attribute__((aligned(16)));
15 
16 /*
17  * LM_Password_Hash: this function create a LM password hash from a given password
18  */
19 unsigned char *LM_Password_Hash(const unsigned char *password, unsigned char *cipher)
20 {
21  unsigned char tmp_pass[14] = {"\0\0\0\0\0\0\0\0\0\0\0\0\0\0"};
22  unsigned char K1[7];
23  unsigned char K2[7];
24  int i;
25 
26  /* keep only 14 bytes of the password (padded with nul bytes) */
27  strncpy((char *)tmp_pass, (const char *)password, 14);
28 
29  /* turn the password to uppercase */
30  for (i = 0; i < 14; i++) {
31  tmp_pass[i] = toupper(tmp_pass[i]);
32  }
33 
34  /* get 2 7bytes keys from password */
35  memcpy(K1, &tmp_pass[0], 7);
36  memcpy(K2, &tmp_pass[7], 7);
37 
38  /* encrypt the magic string with the keys */
39  DES(K1, (const unsigned char *)"KGS!@#$%", &cipher[0]);
40  DES(K2, (const unsigned char *)"KGS!@#$%", &cipher[8]);
41 
42  return cipher;
43 }
44 
45 /*
46  * NTLM_Password_Hash: this function create a NTLM password hash from a given password
47  */
48 unsigned char *NTLM_Password_Hash(const unsigned char *password, unsigned char *cipher)
49 {
50  int i, j;
51 
52  memset(passwd_buf, 0, sizeof(passwd_buf));
53 
54  /* turn the password to unicode */
55  for (i = 0, j = 0; (unsigned int)i < strlen((const char *)password); i++, j += 2)
56  passwd_buf[j] = password[i];
57 
58  /* get the message digest */
59  MD4(passwd_buf, j, cipher);
60 
61  return (unsigned char *)cipher;
62 }
63 
64 /*
65  * LM_Response: this function create a LM response from a given LM hash & challenge
66  */
67 unsigned char *LM_Response(const unsigned char *LMpasswordhash, unsigned char *chal, unsigned char *cipher)
68 {
69  unsigned char P21[21];
70  unsigned char K[7];
71  int i;
72 
73  /* padd the LM password hash with 5 nul bytes */
74  memcpy(&P21[0], LMpasswordhash, 16);
75  memset(&P21[16], 0, 5);
76 
77  /* encrypt the challenge 3 times, using 7 bytes splitted keys */
78  for (i = 0; i < 3; i++) {
79 
80  /* get the 7bytes key */
81  memcpy(K, &P21[i * 7], 7);
82 
83  /* encrypt each the challenge with the keys */
84  DES(K, chal, &cipher[i * 8]);
85  }
86 
87  return (unsigned char *)cipher;
88 }
sysclib.h
irx.h
__attribute__
typedef __attribute__
Definition: tlbfunc.c:60
stdio.h
__attribute__
Definition: gif_registers.h:38
defs.h