@@ -34,6 +34,33 @@ int ocl_brute_console_id(const cl_uchar *console_id, const cl_uchar *emmc_cid,
3434 cl_uint offset1 , const cl_uchar * src1 , const cl_uchar * ver1 ,
3535 ocl_brute_mode mode )
3636{
37+ // preparing args
38+ cl_ulong console_id_template = u64be (console_id );
39+ cl_ulong xor0 [2 ] = { 0 }, xor1 [2 ] = { 0 };
40+ dsi_make_xor ((u8 * )xor0 , src0 , ver0 );
41+ if (src1 != 0 ) {
42+ dsi_make_xor ((u8 * )xor1 , src1 , ver1 );
43+ }
44+ cl_uint ctr [4 ] = { 0 };
45+ if (emmc_cid != 0 ) {
46+ dsi_make_ctr ((u8 * )ctr , emmc_cid , offset0 );
47+ }
48+ cl_ulong out = 0 ;
49+ #if DEBUG
50+ {
51+ printf ("XOR : %s\n" , hexdump (xor0 , 16 , 0 ));
52+ u8 aes_key [16 ];
53+ dsi_make_key (aes_key , u64be (console_id ));
54+ printf ("AES KEY : %s\n" , hexdump (aes_key , 16 , 0 ));
55+ aes_init ();
56+ aes_set_key_enc_128 (aes_key );
57+ printf ("CTR : %s\n" , hexdump (ctr , 16 , 0 ));
58+ aes_encrypt_128 ((u8 * )ctr , (u8 * )xor0 );
59+ printf ("XOR TRY : %s\n" , hexdump (xor0 , 16 , 0 ));
60+ // exit(1);
61+ }
62+ #endif
63+
3764 TimeHP t0 , t1 ; long long td = 0 ;
3865
3966 cl_int err ;
@@ -73,35 +100,6 @@ int ocl_brute_console_id(const cl_uchar *console_id, const cl_uchar *emmc_cid,
73100 OCL_ASSERT (clGetKernelWorkGroupInfo (kernel , device_id , CL_KERNEL_WORK_GROUP_SIZE , sizeof (local ), & local , NULL ));
74101 printf ("local work size: %u\n" , (unsigned )local );
75102
76- // preparing args
77- cl_ulong console_id_template = u64be (console_id );
78- cl_ulong xor0 [2 ] = { 0 }, xor1 [2 ] = { 0 };
79- dsi_make_xor ((u8 * )xor0 , src0 , ver0 );
80- if (src1 != 0 ) {
81- dsi_make_xor ((u8 * )xor1 , src1 , ver1 );
82- }
83- cl_uint ctr [4 ] = { 0 };
84- if (emmc_cid != 0 ) {
85- dsi_make_ctr ((u8 * )ctr , emmc_cid , offset0 );
86- }
87- cl_ulong out = 0 ;
88- #if DEBUG
89- {
90- printf ("XOR : %s\n" , hexdump (xor , 16 , 0 ));
91- u8 aes_key [16 ];
92- dsi_make_key (aes_key , u64be (console_id ));
93- printf ("AES KEY : %s\n" , hexdump (aes_key , 16 , 0 ));
94- cl_uint aes_rk [RK_LEN ];
95- aes_gen_tables ();
96- aes_set_key_enc_128 (aes_rk , aes_key );
97- printf ("AES RK : %s\n" , hexdump (aes_rk , 48 , 0 ));
98- printf ("CTR : %s\n" , hexdump (ctr , 16 , 0 ));
99- aes_encrypt_128 (aes_rk , (u8 * )ctr , (u8 * )xor );
100- printf ("XOR TRY : %s\n" , hexdump (xor , 16 , 0 ));
101- // exit(1);
102- }
103- #endif
104-
105103 // there's no option to create it zero initialized
106104 cl_mem mem_out = OCL_ASSERT2 (clCreateBuffer (context , CL_MEM_READ_WRITE , sizeof (cl_ulong ), NULL , & err ));
107105 OCL_ASSERT (clEnqueueWriteBuffer (command_queue , mem_out , CL_TRUE , 0 , sizeof (cl_ulong ), & out , 0 , NULL , NULL ));
@@ -208,6 +206,28 @@ int ocl_brute_console_id(const cl_uchar *console_id, const cl_uchar *emmc_cid,
208206int ocl_brute_emmc_cid (const cl_uchar * console_id , cl_uchar * emmc_cid ,
209207 cl_uint offset , const cl_uchar * src , const cl_uchar * ver )
210208{
209+ // preparing args
210+ u8 aes_key [16 ];
211+ dsi_make_key (aes_key , u64be (console_id ));
212+ aes_init ();
213+ aes_set_key_dec_128 (aes_key );
214+ cl_ulong xor [2 ];
215+ dsi_make_xor ((u8 * )xor , src , ver );
216+ cl_ulong ctr [2 ];
217+ aes_decrypt_128 ((u8 * )xor , (u8 * )ctr );
218+ cl_ulong emmc_cid_sha1_16 [2 ];
219+ byte_reverse_16 ((u8 * )emmc_cid_sha1_16 , (u8 * )ctr );
220+ sub_128_64 (emmc_cid_sha1_16 , offset );
221+ cl_ulong out = 0 ;
222+ #ifdef DEBUG
223+ {
224+ printf ("SHA1 A: %s\n" , hexdump (emmc_cid_sha1_16 , 16 , 0 ));
225+ u8 sha1_verify [16 ];
226+ sha1_16 (emmc_cid , sha1_verify );
227+ printf ("SHA1 B: %s\n" , hexdump (sha1_verify , 16 , 0 ));
228+ }
229+ #endif
230+
211231 TimeHP t0 , t1 ; long long td = 0 ;
212232
213233 cl_int err ;
@@ -234,33 +254,6 @@ int ocl_brute_emmc_cid(const cl_uchar *console_id, cl_uchar *emmc_cid,
234254 OCL_ASSERT (clGetKernelWorkGroupInfo (kernel , device_id , CL_KERNEL_WORK_GROUP_SIZE , sizeof (local ), & local , NULL ));
235255 printf ("local work size: %u\n" , (unsigned )local );
236256
237- // preparing args
238- u8 aes_key [16 ];
239- dsi_make_key (aes_key , u64be (console_id ));
240- aes_init ();
241- aes_set_key_dec_128 (aes_key );
242- cl_ulong xor [2 ];
243- dsi_make_xor ((u8 * )xor , src , ver );
244- cl_ulong ctr [2 ];
245- aes_decrypt_128 ((u8 * )xor , (u8 * )ctr );
246- cl_ulong emmc_cid_sha1_16 [2 ];
247- byte_reverse_16 ((u8 * )emmc_cid_sha1_16 , (u8 * )ctr );
248- sub_128_64 (emmc_cid_sha1_16 , offset );
249- cl_ulong out = 0 ;
250- #ifdef DEBUG
251- {
252- printf ("XOR : %s\n" , hexdump (xor , 16 , 0 ));
253- printf ("AES KEY : %s\n" , hexdump (aes_key , 16 , 0 ));
254- printf ("AES RK : %s\n" , hexdump (aes_rk , 48 , 0 ));
255- u8 ctr [16 ];
256- dsi_make_ctr (ctr , emmc_cid , u_offset );
257- printf ("CTR : %s\n" , hexdump (ctr , 16 , 0 ));
258- aes_encrypt_128 (aes_rk , ctr , (u8 * )xor );
259- printf ("XOR TRY : %s\n" , hexdump (xor , 16 , 0 ));
260- // exit(1);
261- }
262- #endif
263-
264257 // there's no option to create it zero initialized
265258 cl_mem mem_out = OCL_ASSERT2 (clCreateBuffer (context , CL_MEM_READ_WRITE , sizeof (cl_ulong ), NULL , & err ));
266259 OCL_ASSERT (clEnqueueWriteBuffer (command_queue , mem_out , CL_TRUE , 0 , sizeof (cl_ulong ), & out , 0 , NULL , NULL ));
@@ -280,8 +273,8 @@ int ocl_brute_emmc_cid(const cl_uchar *console_id, cl_uchar *emmc_cid,
280273 puts (hexdump (emmc_cid , 16 , 0 ));
281274 OCL_ASSERT (clSetKernelArg (kernel , 0 , sizeof (cl_ulong ), emmc_cid ));
282275 OCL_ASSERT (clSetKernelArg (kernel , 1 , sizeof (cl_ulong ), emmc_cid + 8 ));
283- OCL_ASSERT (clSetKernelArg (kernel , 2 , sizeof (cl_ulong ), & emmc_cid_sha1_16 [ 0 ] ));
284- OCL_ASSERT (clSetKernelArg (kernel , 3 , sizeof (cl_ulong ), & emmc_cid_sha1_16 [ 1 ] ));
276+ OCL_ASSERT (clSetKernelArg (kernel , 2 , sizeof (cl_ulong ), emmc_cid_sha1_16 ));
277+ OCL_ASSERT (clSetKernelArg (kernel , 3 , sizeof (cl_ulong ), emmc_cid_sha1_16 + 1 ));
285278 OCL_ASSERT (clSetKernelArg (kernel , 4 , sizeof (cl_mem ), & mem_out ));
286279
287280 OCL_ASSERT (clEnqueueNDRangeKernel (command_queue , kernel , 1 , NULL , & num_items , & local , 0 , NULL , NULL ));
@@ -308,7 +301,6 @@ int ocl_brute_emmc_cid(const cl_uchar *console_id, cl_uchar *emmc_cid,
308301 printf ("%.2f seconds, %.2f M/s\n" , td / 1000000.0 , tested * 1.0 / td );
309302
310303 clReleaseKernel (kernel );
311- clReleaseMemObject (mem_rk );
312304 clReleaseMemObject (mem_out );
313305 clReleaseProgram (program );
314306 clReleaseCommandQueue (command_queue );
0 commit comments