|
看OpenQ的代码,在qq_crypt.c中发现这样的一个函数,严重不明白。其中似乎套嵌定义了一个函数
- void qq_encrypt (
- unsigned char* instr,
- int instrlen,
- unsigned char* key,
- unsigned char* outstr,
- int* outstrlen_prt)
- {
- unsigned char
- plain[8], // plain text buffer
- plain_pre_8[8], // plain text buffer, previous 8 bytes
- * crypted, // crypted text
- * crypted_pre_8, // crypted test, previous 8 bytes
- * inp; // current position in instr
- int
- pos_in_byte = 1, // loop in the byte
- is_header=1, // header is one byte
- count=0, // number of bytes being crypted
- padding = 0; // number of padding stuff
- int rand(void) { // it can be the real random seed function
- return 0xdead; } // override with number, convenient for debug
- /*** we encrypt every eight byte ***/
- [color=crimson]void encrypt_every_8_byte (void) {[/color]
- for(pos_in_byte=0; pos_in_byte<8; pos_in_byte++) {
- if(is_header) { plain[pos_in_byte] ^= plain_pre_8[pos_in_byte]; }
- else { plain[pos_in_byte] ^= crypted_pre_8[pos_in_byte]; }
- } // prepare plain text
- qq_encipher( (unsigned long *) plain,
- (unsigned long *) key,
- (unsigned long *) crypted); // encrypt it
- for(pos_in_byte=0; pos_in_byte<8; pos_in_byte++) {
- crypted[pos_in_byte] ^= plain_pre_8[pos_in_byte];
- }
- memcpy(plain_pre_8, plain, 8); // prepare next
- crypted_pre_8 = crypted; // store position of previous 8 byte
- crypted += 8; // prepare next output
- count += 8; // outstrlen increase by 8
- pos_in_byte = 0; // back to start
- is_header = 0; // and exit header
- }// encrypt_every_8_byte
- pos_in_byte = (instrlen + 0x0a) % 8; // header padding decided by instrlen
- if (pos_in_byte) {
- pos_in_byte = 8 - pos_in_byte;
- }
- plain[0] = (rand() & 0xf8) | pos_in_byte;
- memset(plain+1, rand()&0xff, pos_in_byte++);
- memset(plain_pre_8, 0x00, sizeof(plain_pre_8));
- crypted = crypted_pre_8 = outstr;
- padding = 1; // pad some stuff in header
- while (padding <= 2) { // at most two byte
- if(pos_in_byte < 8) { plain[pos_in_byte++] = rand() & 0xff; padding ++; }
- if(pos_in_byte == 8){ encrypt_every_8_byte(); }
- }
- inp = instr;
- while (instrlen > 0) {
- if (pos_in_byte < 8) { plain[pos_in_byte++] = *(inp++); instrlen --; }
- if (pos_in_byte == 8){ encrypt_every_8_byte(); }
- }
- padding = 1; // pad some stuff in tailer
- while (padding <= 7) { // at most sever byte
- if (pos_in_byte < 8) { plain[pos_in_byte++] = 0x00; padding ++; }
- if (pos_in_byte == 8){ encrypt_every_8_byte(); }
- }
- *outstrlen_prt = count;
- }// qq_encrypt
复制代码 |
|