|  | 
 
 发表于 2012-4-1 14:44:41
|
显示全部楼层 
| 1.the format of encrypted file > > > can_v1_5/can_tl_bsp.vhd as an example.
 > > > a)the first 8 bytes XlxV38EB is version code
 > > > b)the first 8bytes of line2 is the length of the ciphertext.,it means
 > > > that the next segment of ciphertext is after 3230H
 > > > c)from 18h bytes is ciphertext which is made by the Zlib compress then
 > > > DES encrypted.
 > > >                     ----------------------
 > > > 00000000h: 58 6C 78 56 33 38 45 42 20 20 20 20 66 61 30 30 ;
 > > > XlxV38EB    fa00
 > > > 00000010h: 20 20 20 20 33 32 33 30 39 1E 5F B2 14 42 33 C1 ;
 > > > 32309._?B3?
 > > > 00000020h: 82 40 EA 28 A0 8D 8C E9 8B 75 8B 0E 7C C4 6E BA ;
 > > > ?@??????u?|?n?
 > > > 00000030h: B0 2F 08 7C 51 C0 B0 45 01 D5 BD B8 73 A1 A1 09 ; ?.|Q腊E.战?s
 > > >  .
 > > > 00000040h: 71 2A 81 FA A7 9E 99 CA 9C BE 15 7C 44 D1 E9 C1 ; q*????????.|D
 > > > 验?
 > > > 00000050h: D5 A8 81 9B 1E 3A 19 47 4A 49 AA 87 1C E2 E2 46 ; 炸??.:.GJI??.
 > > > 忖F
 > > > 。。。。。。。。。。。。。。
 > > > 。。。。。。。。。。。。。。。
 > > > 00003220h: 0F DD 81 68 7A B1 C5 92 FD 7C 77 FB 73 96 46 82 ; .??hz迸??|w?s
 > > > ?F?
 > > > 00003230h: A4 63 0B F1 64 17 1D D5 18 19 B2 E8 1D 23 DF 0F ; ?c.?d..?.
 > > > 茶.#?
 > > > 00003240h: 24 11 C2 D4 D0 90 38 7D 58 6C 78 56 33 38 45 42 ; $.略??8}
 > > > XlxV38EB
 > > > 00003250h: 20 20 20 20 36 38 64 37 20 20 20 20 31 34 66 63 ;
 > > > 68d7    14fc
 > > > 00003260h: D5 F9 A3 5C F9 7D D7 4A 72 09 19 86 03 62 C4 2C ; 争?\?}?Jr..?
 > > > b?
 > > > 00003270h: FE DC 28 58 7E 1F 91 2F 0F CD A8 DB 8E A0 FF 37 ; ??(X~.?.通???
 > > > 7
 > > > 00003280h: 01 F4 62 07 CE BA 6E 3C BB 67 4C B0 D9 E8 AE E3 ; .?b.魏n<?gL百
 > > > 璁
 >
 > > > 2.how to decrypt
 > > > 1)With DES, each 8bytes block is encrypted under same DES key。
 > > > if the ciphertext can't be divided evenly,don't process these left
 > > > bytes。
 > > > 2)the DES key of Xilinx IPCOREis same 8f c2 d3 a0 XX XX  XX XX,which
 > > > be recover by below couple dates。
 > > > ciphertext 39 1E 5F B2 14 42 33 C1
 > > > plaintext75 41 73 32 dd 59 ea 0c
 >
 > > > 3)XOR with the initial date 0d 9b 9e 4f b6 2a f1 37
 > > > 4)then we  get 78 73 32 dd xx xx xx xx
 > > > 5)replace the initial XOR date by this 8 bytes39 1E 5F B2 14 42 33 C1,
 > > > 6)go to 2
 > > > 7)combine to a file
 >
 > > > 3.download ZLIB fromhttp://www.zlib.net/
 > > > 1)call the unpress function inf(file1,file2);
 > > > 2)the we got the source code file2 as below:
 >
 > > > -- $Id: can_tl_bsp.vhd,v 1.1.2.2 2007/05/28 13:39:29 snori Exp $
 > > > -------------------------------------------------------------------------------
 > > > -------------------------------------------------------------------------------
 > > > -------------------------------------------------------------------------------
 > > > -- Copyright(C) 2007 by Xilinx, Inc. All rights reserved.
 > > > -- This text/file contains proprietary, confidential
 > > > -- information of Xilinx, Inc., is distributed under
 > > > -- license from Xilinx, Inc., and may be used, copied
 > > > -- and/or disclosed only pursuant to the terms of a valid
 > > > -- license agreement with Xilinx, Inc. Xilinx hereby
 >
 > > > 。。。。。。。。。。。。。。。
 > > > 。。。。。。。。。。。。。。。
 >
 > > > smcomb: process(state, RXE_COUNTER_I, SM_STUFFBIT_PD,SM_STUFFBIT,
 > > >        BSOFF_COUNTER_I,  TEC_INC8_I, EMU_TEC_BOFF_LT1,
 > > >        EMU_REC_ERRACT,BTL_RXBIT,IC_MSR_LBACK,IC_MSR_SLEEP,
 > > >        TX_HPB_EMPTY,TX_FIFO_EMPTY)
 > > >   begin
 >
 > > >     -- Enable Stuff Module when State = ID and after the 3rd bit
 > > >     -- after SOF been received.
 > > >     if (state = ID and RXE_COUNTER_I = C3) then
 > > >       RXE_SM_EN <= '1';
 > > >     else
 > > >       RXE_SM_EN <= '0';
 > > >     end if;
 >
 > > >     -- Reset CRC when State = EOF
 > > >     -- When RXE_CRC_RST = '1', the CRC register is reset.
 > > >     -- Reset when State = EOF and RXE_COUNTER_I = CO
 > > >     -- (After ACK field)
 > > >     -- Reset when in ERRACT and ERRPASS and RXE_COUNTER_I = C0. It is
 > > > possible
 > > >     -- that Reset could be asserted for multiple cycles.
 >
 > > >     if ((state = EOF and RXE_COUNTER_I = C0) or
 > > >        ((state = ERRACT or state = ERRPASS) and RXE_COUNTER_I = C1)
 > > >          or state = BOFF) then
 > > >       RXE_CRC_RST <= '1';
 > > >     else
 > > >       RXE_CRC_RST <= '0';
 > > >     end if;
 >
 > > this is COMMON knowledge for long time already
 > > i wrote a zlib based encoder many many years ago for a study
  >
 > > but thank you for making it public-public!
 >
 > > Antti
 >
 > Hello Antti,
 >
 > can you point me to your encoder please ?
 >
 > Thanks!
 >
 > /HB
 
 Hi HB, it's easy to make a decoder like below
 
 //Initial XOR seeds
 xorseed={0x0d,0x9b,0x9e,0x4f,0xb6,0x2a,0xf1,0x37};
 ....
 do
 {
 //read and process 8 bytes every time
 unRead = fread(crypt, SIZE, 8, encryptfile);
 //Call DES decrypt function
 DES(&crypt[i*SIZE],&decrypt[i*SIZE], 8, deskey, DECRYPT);
 // decrypted results XOR with the initial XOR seeds
 decrypt[i*SIZE]^=xorseed[0];
 decrypt[i*SIZE+1]^=xorseed[1];
 decrypt[i*SIZE+2]^=xorseed[2];
 decrypt[i*SIZE+3]^=xorseed[3];
 decrypt[i*SIZE+4]^=xorseed[4];
 decrypt[i*SIZE+5]^=xorseed[5];
 decrypt[i*SIZE+6]^=xorseed[6];
 decrypt[i*SIZE+7]^=xorseed[7];
 //Update the XOR seeds by last encrypted 8 bytes
 xorseed[0]=crypt[i*SIZE];
 xorseed[1]=crypt[i*SIZE+1];
 xorseed[2]=crypt[i*SIZE+2];
 xorseed[3]=crypt[i*SIZE+3];
 xorseed[4]=crypt[i*SIZE+4];
 xorseed[5]=crypt[i*SIZE+5];
 xorseed[6]=crypt[i*SIZE+6];
 xorseed[7]=crypt[i*SIZE+7];
 //write to a file or keep in memory
 fwrite(decrypt, SIZE, unRead, compressfile);
 } (!feof(cryptfile) && unRead != 0);
 ..........
 //Call ZLIB uncompress
 inf(compressfile,plaintextfile);
 | 
 |