88#include <string.h>
99#include <stdio.h>
1010#include <stdlib.h>
11- #include <polarssl /aes.h>
12- #include <polarssl /sha1.h>
11+ #include <mbedtls /aes.h>
12+ #include <mbedtls /sha1.h>
1313
1414#include "types.h"
1515#include "util.h"
@@ -67,14 +67,14 @@ static void XorWithIv(uint8_t* buf, const uint8_t* Iv)
6767
6868static void generateHash (const uint8_t * input , const uint8_t * salt_seed , uint8_t * dest , size_t sz , uint8_t type )
6969{
70- aes_context aes_ctx ;
71- sha1_context sha1_ctx ;
70+ mbedtls_aes_context aes_ctx ;
71+ mbedtls_sha1_context sha1_ctx ;
7272 uint8_t iv [0x10 ];
7373 uint8_t salt [0x40 ];
7474 uint8_t work_buf [0x14 ];
7575
7676 memset (salt , 0 , sizeof (salt ));
77- memset (& aes_ctx , 0 , sizeof ( aes_context ) );
77+ mbedtls_aes_init (& aes_ctx );
7878
7979 LOG ("Type detected: %d" , type );
8080 if (type == PSV_TYPE_PS1 )
@@ -83,10 +83,10 @@ static void generateHash(const uint8_t *input, const uint8_t *salt_seed, uint8_t
8383 //idk why the normal cbc doesn't work.
8484 memcpy (work_buf , salt_seed , 0x10 );
8585
86- aes_setkey_dec (& aes_ctx , psv_ps1key , 128 );
87- aes_crypt_ecb (& aes_ctx , AES_DECRYPT , work_buf , salt );
88- aes_setkey_enc (& aes_ctx , psv_ps1key , 128 );
89- aes_crypt_ecb (& aes_ctx , AES_ENCRYPT , work_buf , salt + 0x10 );
86+ mbedtls_aes_setkey_dec (& aes_ctx , psv_ps1key , 128 );
87+ mbedtls_aes_crypt_ecb (& aes_ctx , MBEDTLS_AES_DECRYPT , work_buf , salt );
88+ mbedtls_aes_setkey_enc (& aes_ctx , psv_ps1key , 128 );
89+ mbedtls_aes_crypt_ecb (& aes_ctx , MBEDTLS_AES_ENCRYPT , work_buf , salt + 0x10 );
9090
9191 XorWithIv (salt , psv_iv );
9292
@@ -101,8 +101,8 @@ static void generateHash(const uint8_t *input, const uint8_t *salt_seed, uint8_t
101101 memcpy (salt , salt_seed , 0x14 );
102102 memcpy (iv , psv_iv , sizeof (iv ));
103103
104- aes_setkey_dec (& aes_ctx , psv_ps2key , 128 );
105- aes_crypt_cbc (& aes_ctx , AES_DECRYPT , sizeof (salt ), iv , salt , salt );
104+ mbedtls_aes_setkey_dec (& aes_ctx , psv_ps2key , 128 );
105+ mbedtls_aes_crypt_cbc (& aes_ctx , MBEDTLS_AES_DECRYPT , sizeof (salt ), iv , salt , salt );
106106 }
107107 else
108108 {
@@ -115,19 +115,19 @@ static void generateHash(const uint8_t *input, const uint8_t *salt_seed, uint8_t
115115
116116 XorWithByte (salt , 0x36 , sizeof (salt ));
117117
118- memset (& sha1_ctx , 0 , sizeof ( sha1_context ) );
119- sha1_starts (& sha1_ctx );
120- sha1_update (& sha1_ctx , salt , sizeof (salt ));
121- sha1_update (& sha1_ctx , input , sz );
122- sha1_finish (& sha1_ctx , work_buf );
118+ mbedtls_sha1_init (& sha1_ctx );
119+ mbedtls_sha1_starts (& sha1_ctx );
120+ mbedtls_sha1_update (& sha1_ctx , salt , sizeof (salt ));
121+ mbedtls_sha1_update (& sha1_ctx , input , sz );
122+ mbedtls_sha1_finish (& sha1_ctx , work_buf );
123123
124124 XorWithByte (salt , 0x6A , sizeof (salt ));
125125
126- memset (& sha1_ctx , 0 , sizeof ( sha1_context ) );
127- sha1_starts (& sha1_ctx );
128- sha1_update (& sha1_ctx , salt , sizeof (salt ));
129- sha1_update (& sha1_ctx , work_buf , 0x14 );
130- sha1_finish (& sha1_ctx , dest );
126+ mbedtls_sha1_init (& sha1_ctx );
127+ mbedtls_sha1_starts (& sha1_ctx );
128+ mbedtls_sha1_update (& sha1_ctx , salt , sizeof (salt ));
129+ mbedtls_sha1_update (& sha1_ctx , work_buf , 0x14 );
130+ mbedtls_sha1_finish (& sha1_ctx , dest );
131131}
132132
133133int psv_resign (const char * src_psv )
0 commit comments