]>
git.zerfleddert.de Git - rsbs2/blob - src/rsb-crc.c
3 #define POLY 0x04c11db7
5 unsigned int rsb_crc(unsigned int r11_crc
, unsigned char *r10_buf
, unsigned int r14_len
) {
6 unsigned int r6_pos
= 0;
10 while (r6_pos
< r14_len
) {
11 r3_data
= (*(r6_pos
+r10_buf
)) << 24;
12 r11_crc
= r11_crc
^ r3_data
;
17 r3_data
= r11_crc
& 0x80000000;
20 r3_data
= r11_crc
<< 1;
21 r11_crc
= r3_data
^ POLY
;
23 r11_crc
= r11_crc
<< 1;
34 unsigned int rsb_crc2(unsigned char *r0_buf
, unsigned int r1_buflen
, unsigned int r2_magic
, unsigned int *crc_out
) {
36 unsigned int file_crc
;
38 r4_len
= *(unsigned int*)(r0_buf
+ 0x20);
40 if (*((unsigned int*)(r0_buf
+ 0x24)) != r2_magic
)
41 return 2; /* MAGIC does not match */
43 if (r1_buflen
< r4_len
)
44 return 3; /* image to small */
46 *crc_out
= ~rsb_crc(~0x0, r0_buf
, r4_len
);
48 file_crc
= *((unsigned int*)(r0_buf
+ r4_len
));
50 if (file_crc
!= *crc_out
)