Forums

how to decrypt Xilinx IPCORE source code

Started by Unknown December 29, 2008
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.=A3=ACit 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 ; =82@?=A0=8D=8C=
=E9=8Bu?|=C4n?
00000030h: B0 2F 08 7C 51 C0 B0 45 01 D5 BD B8 73 A1 A1 09 ; ?.|Q=C0=B0E.=
=D5=BD=B8s
=A1=A1.
00000040h: 71 2A 81 FA A7 9E 99 CA 9C BE 15 7C 44 D1 E9 C1 ; q*=81=FA=A7=9E=
=99=CA=9C=BE.|D
=D1=E9?
00000050h: D5 A8 81 9B 1E 3A 19 47 4A 49 AA 87 1C E2 E2 46 ; =D5=A8=81=9B.:=
.GJI=AA=87.
=E2=E2F
=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=
=A3=A1=A3
=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=
=A3=A1=A3=A1=A3
00003220h: 0F DD 81 68 7A B1 C5 92 FD 7C 77 FB 73 96 46 82 ; .=DD=81hz=B1=
=C5=92=FD|w=FBs
=96F?
00003230h: A4 63 0B F1 64 17 1D D5 18 19 B2 E8 1D 23 DF 0F ; =A4c.=F1d..?.
=B2=E8.#?
00003240h: 24 11 C2 D4 D0 90 38 7D 58 6C 78 56 33 38 45 42 ; $.=C2=D4=D0=90=
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 ; =D5=F9=A3\=F9}=
=D7Jr..?
b?
00003270h: FE DC 28 58 7E 1F 91 2F 0F CD A8 DB 8E A0 FF 37 ; =FE=DC(X~.?.=
=CD=A8=DB=8E?
7
00003280h: 01 F4 62 07 CE BA 6E 3C BB 67 4C B0 D9 E8 AE E3 ; .=F4b.=CE=BAn<=
=BBgL=B0=D9
=E8=AE

2.how to decrypt
1)With DES, each 8bytes block is encrypted under same DES key=A1=A3
if the ciphertext can't be divided evenly,don't process these left
bytes=A1=A3
2)the DES key of Xilinx IPCOREis same 8f c2 d3 a0 XX XX  XX XX=A3=ACwhich
be recover by below couple dates=A1=A3
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=A3=AC
6)go to 2
7=A3=A9combine to a file

3.download ZLIB fromhttp://www.zlib.net/
1=A3=A9call the unpress function inf(file1,file2);
2=A3=A9the 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

=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=
=A3=A1=A3=A1=A3
=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=
=A3=A1=A3=A1=A3

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 =3D ID and after the 3rd bit
    -- after SOF been received.
    if (state =3D ID and RXE_COUNTER_I =3D C3) then
      RXE_SM_EN <=3D '1';
    else
      RXE_SM_EN <=3D '0';
    end if;

    -- Reset CRC when State =3D EOF
    -- When RXE_CRC_RST =3D '1', the CRC register is reset.
    -- Reset when State =3D EOF and RXE_COUNTER_I =3D CO
    -- (After ACK field)
    -- Reset when in ERRACT and ERRPASS and RXE_COUNTER_I =3D C0. It is
possible
    -- that Reset could be asserted for multiple cycles.

    if ((state =3D EOF and RXE_COUNTER_I =3D C0) or
       ((state =3D ERRACT or state =3D ERRPASS) and RXE_COUNTER_I =3D C1)
         or state =3D BOFF) then
      RXE_CRC_RST <=3D '1';
    else
      RXE_CRC_RST <=3D '0';
    end if;
On Dec 29, 11:36 am, doom.zh...@gmail.com wrote:
> 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.=A3=ACit mean=
s
> 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 ; =82@?=A0=8D=
=8C=E9=8Bu?|=C4n?
> 00000030h: B0 2F 08 7C 51 C0 B0 45 01 D5 BD B8 73 A1 A1 09 ; ?.|Q=C0=B0E.=
=D5=BD=B8s
> =A1=A1. > 00000040h: 71 2A 81 FA A7 9E 99 CA 9C BE 15 7C 44 D1 E9 C1 ; q*=81=FA=A7=
=9E=99=CA=9C=BE.|D
> =D1=E9? > 00000050h: D5 A8 81 9B 1E 3A 19 47 4A 49 AA 87 1C E2 E2 46 ; =D5=A8=81=9B=
.:.GJI=AA=87.
> =E2=E2F > =A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=
=A1=A3=A1=A3
> =A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=
=A1=A3=A1=A3=A1=A3
> 00003220h: 0F DD 81 68 7A B1 C5 92 FD 7C 77 FB 73 96 46 82 ; .=DD=81hz=B1=
=C5=92=FD|w=FBs
> =96F? > 00003230h: A4 63 0B F1 64 17 1D D5 18 19 B2 E8 1D 23 DF 0F ; =A4c.=F1d..?=
.
> =B2=E8.#? > 00003240h: 24 11 C2 D4 D0 90 38 7D 58 6C 78 56 33 38 45 42 ; $.=C2=D4=D0=
=908}
> 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 ; =D5=F9=A3\=
=F9}=D7Jr..?
> b? > 00003270h: FE DC 28 58 7E 1F 91 2F 0F CD A8 DB 8E A0 FF 37 ; =FE=DC(X~.?.=
=CD=A8=DB=8E?
> 7 > 00003280h: 01 F4 62 07 CE BA 6E 3C BB 67 4C B0 D9 E8 AE E3 ; .=F4b.=CE=BA=
n<=BBgL=B0=D9
> =E8=AE > > 2.how to decrypt > 1)With DES, each 8bytes block is encrypted under same DES key=A1=A3 > if the ciphertext can't be divided evenly,don't process these left > bytes=A1=A3 > 2)the DES key of Xilinx IPCOREis same 8f c2 d3 a0 XX XX XX XX=A3=ACwhich > be recover by below couple dates=A1=A3 > 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=A3=
=AC
> 6)go to 2 > 7=A3=A9combine to a file > > 3.download ZLIB fromhttp://www.zlib.net/ > 1=A3=A9call the unpress function inf(file1,file2); > 2=A3=A9the 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 > > =A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=
=A1=A3=A1=A3=A1=A3
> =A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=
=A1=A3=A1=A3=A1=A3
> > 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 =3D ID and after the 3rd bit > -- after SOF been received. > if (state =3D ID and RXE_COUNTER_I =3D C3) then > RXE_SM_EN <=3D '1'; > else > RXE_SM_EN <=3D '0'; > end if; > > -- Reset CRC when State =3D EOF > -- When RXE_CRC_RST =3D '1', the CRC register is reset. > -- Reset when State =3D EOF and RXE_COUNTER_I =3D CO > -- (After ACK field) > -- Reset when in ERRACT and ERRPASS and RXE_COUNTER_I =3D C0. It is > possible > -- that Reset could be asserted for multiple cycles. > > if ((state =3D EOF and RXE_COUNTER_I =3D C0) or > ((state =3D ERRACT or state =3D ERRPASS) and RXE_COUNTER_I =3D C1) > or state =3D BOFF) then > RXE_CRC_RST <=3D '1'; > else > RXE_CRC_RST <=3D '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
On 29 Dez. 2008, 12:00, Antti <Antti.Luk...@googlemail.com> wrote:
> On Dec 29, 11:36 am, doom.zh...@gmail.com wrote: > > > > > 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.=A3=ACit me=
ans
> > 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 ; =82@?=A0=
=8D=8C=E9=8Bu?|=C4n?
> > 00000030h: B0 2F 08 7C 51 C0 B0 45 01 D5 BD B8 73 A1 A1 09 ; ?.|Q=C0=B0=
E.=D5=BD=B8s
> > =A1=A1. > > 00000040h: 71 2A 81 FA A7 9E 99 CA 9C BE 15 7C 44 D1 E9 C1 ; q*=81=FA=
=A7=9E=99=CA=9C=BE.|D
> > =D1=E9? > > 00000050h: D5 A8 81 9B 1E 3A 19 47 4A 49 AA 87 1C E2 E2 46 ; =D5=A8=81=
=9B.:.GJI=AA=87.
> > =E2=E2F > > =A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=
=A3=A1=A3=A1=A3
> > =A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=
=A3=A1=A3=A1=A3=A1=A3
> > 00003220h: 0F DD 81 68 7A B1 C5 92 FD 7C 77 FB 73 96 46 82 ; .=DD=81hz=
=B1=C5=92=FD|w=FBs
> > =96F? > > 00003230h: A4 63 0B F1 64 17 1D D5 18 19 B2 E8 1D 23 DF 0F ; =A4c.=F1d.=
.?.
> > =B2=E8.#? > > 00003240h: 24 11 C2 D4 D0 90 38 7D 58 6C 78 56 33 38 45 42 ; $.=C2=D4=
=D0=908}
> > 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 ; =D5=F9=A3\=
=F9}=D7Jr..?
> > b? > > 00003270h: FE DC 28 58 7E 1F 91 2F 0F CD A8 DB 8E A0 FF 37 ; =FE=DC(X~.=
?.=CD=A8=DB=8E?
> > 7 > > 00003280h: 01 F4 62 07 CE BA 6E 3C BB 67 4C B0 D9 E8 AE E3 ; .=F4b.=CE=
=BAn<=BBgL=B0=D9
> > =E8=AE > > > 2.how to decrypt > > 1)With DES, each 8bytes block is encrypted under same DES key=A1=A3 > > if the ciphertext can't be divided evenly,don't process these left > > bytes=A1=A3 > > 2)the DES key of Xilinx IPCOREis same 8f c2 d3 a0 XX XX XX XX=A3=ACwhi=
ch
> > be recover by below couple dates=A1=A3 > > 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=
=A3=AC
> > 6)go to 2 > > 7=A3=A9combine to a file > > > 3.download ZLIB fromhttp://www.zlib.net/ > > 1=A3=A9call the unpress function inf(file1,file2); > > 2=A3=A9the 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 > > > =A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=
=A3=A1=A3=A1=A3=A1=A3
> > =A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=
=A3=A1=A3=A1=A3=A1=A3
> > > 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 =3D ID and after the 3rd bit > > -- after SOF been received. > > if (state =3D ID and RXE_COUNTER_I =3D C3) then > > RXE_SM_EN <=3D '1'; > > else > > RXE_SM_EN <=3D '0'; > > end if; > > > -- Reset CRC when State =3D EOF > > -- When RXE_CRC_RST =3D '1', the CRC register is reset. > > -- Reset when State =3D EOF and RXE_COUNTER_I =3D CO > > -- (After ACK field) > > -- Reset when in ERRACT and ERRPASS and RXE_COUNTER_I =3D C0. It is > > possible > > -- that Reset could be asserted for multiple cycles. > > > if ((state =3D EOF and RXE_COUNTER_I =3D C0) or > > ((state =3D ERRACT or state =3D ERRPASS) and RXE_COUNTER_I =3D C=
1)
> > or state =3D BOFF) then > > RXE_CRC_RST <=3D '1'; > > else > > RXE_CRC_RST <=3D '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
On Jan 1, 6:20 pm, hardbreaker <goo...@schwarzers.de> wrote:
> On 29 Dez. 2008, 12:00, Antti <Antti.Luk...@googlemail.com> wrote: > > > > > On Dec 29, 11:36 am, doom.zh...@gmail.com wrote: > > > > 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.=A3=ACit =
means
> > > that the next segment of ciphertext is after 3230H > > > c)from 18h bytes is ciphertext which is made by the Zlib compress the=
n
> > > 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 ; =82@?=A0=
=8D=8C=E9=8Bu?|=C4n?
> > > 00000030h: B0 2F 08 7C 51 C0 B0 45 01 D5 BD B8 73 A1 A1 09 ; ?.|Q=C0=
=B0E.=D5=BD=B8s
> > > =A1=A1. > > > 00000040h: 71 2A 81 FA A7 9E 99 CA 9C BE 15 7C 44 D1 E9 C1 ; q*=81=FA=
=A7=9E=99=CA=9C=BE.|D
> > > =D1=E9? > > > 00000050h: D5 A8 81 9B 1E 3A 19 47 4A 49 AA 87 1C E2 E2 46 ; =D5=A8=
=81=9B.:.GJI=AA=87.
> > > =E2=E2F > > > =A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=
=A3=A1=A3=A1=A3
> > > =A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=
=A3=A1=A3=A1=A3=A1=A3
> > > 00003220h: 0F DD 81 68 7A B1 C5 92 FD 7C 77 FB 73 96 46 82 ; .=DD=81h=
z=B1=C5=92=FD|w=FBs
> > > =96F? > > > 00003230h: A4 63 0B F1 64 17 1D D5 18 19 B2 E8 1D 23 DF 0F ; =A4c.=F1=
d..?.
> > > =B2=E8.#? > > > 00003240h: 24 11 C2 D4 D0 90 38 7D 58 6C 78 56 33 38 45 42 ; $.=C2=D4=
=D0=908}
> > > 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 ; =D5=F9=
=A3\=F9}=D7Jr..?
> > > b? > > > 00003270h: FE DC 28 58 7E 1F 91 2F 0F CD A8 DB 8E A0 FF 37 ; =FE=DC(X=
~.?.=CD=A8=DB=8E?
> > > 7 > > > 00003280h: 01 F4 62 07 CE BA 6E 3C BB 67 4C B0 D9 E8 AE E3 ; .=F4b.=
=CE=BAn<=BBgL=B0=D9
> > > =E8=AE > > > > 2.how to decrypt > > > 1)With DES, each 8bytes block is encrypted under same DES key=A1=A3 > > > if the ciphertext can't be divided evenly,don't process these left > > > bytes=A1=A3 > > > 2)the DES key of Xilinx IPCOREis same 8f c2 d3 a0 XX XX XX XX=A3=ACw=
hich
> > > be recover by below couple dates=A1=A3 > > > 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=
=A3=AC
> > > 6)go to 2 > > > 7=A3=A9combine to a file > > > > 3.download ZLIB fromhttp://www.zlib.net/ > > > 1=A3=A9call the unpress function inf(file1,file2); > > > 2=A3=A9the 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 > > > > =A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=
=A3=A1=A3=A1=A3=A1=A3
> > > =A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=
=A3=A1=A3=A1=A3=A1=A3
> > > > 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 =3D ID and after the 3rd bit > > > -- after SOF been received. > > > if (state =3D ID and RXE_COUNTER_I =3D C3) then > > > RXE_SM_EN <=3D '1'; > > > else > > > RXE_SM_EN <=3D '0'; > > > end if; > > > > -- Reset CRC when State =3D EOF > > > -- When RXE_CRC_RST =3D '1', the CRC register is reset. > > > -- Reset when State =3D EOF and RXE_COUNTER_I =3D CO > > > -- (After ACK field) > > > -- Reset when in ERRACT and ERRPASS and RXE_COUNTER_I =3D C0. It =
is
> > > possible > > > -- that Reset could be asserted for multiple cycles. > > > > if ((state =3D EOF and RXE_COUNTER_I =3D C0) or > > > ((state =3D ERRACT or state =3D ERRPASS) and RXE_COUNTER_I =3D=
C1)
> > > or state =3D BOFF) then > > > RXE_CRC_RST <=3D '1'; > > > else > > > RXE_CRC_RST <=3D '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
LOL, my encoder was done as part of some research. so it was never released. As the information is now pushed to the public, i can say that: any decent programmer, should be able to write Xilinx encoder withing 2 hours of time, after first looking at the binary file <this is for the files from older Xilinx releases 7.x> it is sufficient to see: ok i am writing it from memory in OLDER versions, just look at offset 24 (decimal) in the file, it holds the ZLIB tag for the most the commonly used compression method. so i looked the file, found that value there and in about 1.5 hours later i had decoded the file having written some 2 pages of Delphi source code. just a finger-excercise, nothing more :) Antti
On 1=D4=C22=C8=D5, =C9=CF=CE=E712=CA=B120=B7=D6, hardbreaker <goo...@schwar=
zers.de> wrote:
> On 29 Dez. 2008, 12:00, Antti <Antti.Luk...@googlemail.com> wrote: > > > > > On Dec 29, 11:36 am, doom.zh...@gmail.com wrote: > > > > 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.=A3=ACit =
means
> > > that the next segment of ciphertext is after 3230H > > > c)from 18h bytes is ciphertext which is made by the Zlib compress the=
n
> > > 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 ; =82@?=A0=
=8D=8C=E9=8Bu?|=C4n?
> > > 00000030h: B0 2F 08 7C 51 C0 B0 45 01 D5 BD B8 73 A1 A1 09 ; ?.|Q=C0=
=B0E.=D5=BD=B8s
> > > =A1=A1. > > > 00000040h: 71 2A 81 FA A7 9E 99 CA 9C BE 15 7C 44 D1 E9 C1 ; q*=81=FA=
=A7=9E=99=CA=9C=BE.|D
> > > =D1=E9? > > > 00000050h: D5 A8 81 9B 1E 3A 19 47 4A 49 AA 87 1C E2 E2 46 ; =D5=A8=
=81=9B.:.GJI=AA=87.
> > > =E2=E2F > > > =A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=
=A3=A1=A3=A1=A3
> > > =A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=
=A3=A1=A3=A1=A3=A1=A3
> > > 00003220h: 0F DD 81 68 7A B1 C5 92 FD 7C 77 FB 73 96 46 82 ; .=DD=81h=
z=B1=C5=92=FD|w=FBs
> > > =96F? > > > 00003230h: A4 63 0B F1 64 17 1D D5 18 19 B2 E8 1D 23 DF 0F ; =A4c.=F1=
d..?.
> > > =B2=E8.#? > > > 00003240h: 24 11 C2 D4 D0 90 38 7D 58 6C 78 56 33 38 45 42 ; $.=C2=D4=
=D0=908}
> > > 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 ; =D5=F9=
=A3\=F9}=D7Jr..?
> > > b? > > > 00003270h: FE DC 28 58 7E 1F 91 2F 0F CD A8 DB 8E A0 FF 37 ; =FE=DC(X=
~.?.=CD=A8=DB=8E?
> > > 7 > > > 00003280h: 01 F4 62 07 CE BA 6E 3C BB 67 4C B0 D9 E8 AE E3 ; .=F4b.=
=CE=BAn<=BBgL=B0=D9
> > > =E8=AE > > > > 2.how to decrypt > > > 1)With DES, each 8bytes block is encrypted under same DES key=A1=A3 > > > if the ciphertext can't be divided evenly,don't process these left > > > bytes=A1=A3 > > > 2)the DES key of Xilinx IPCOREis same 8f c2 d3 a0 XX XX XX XX=A3=ACw=
hich
> > > be recover by below couple dates=A1=A3 > > > 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=
=A3=AC
> > > 6)go to 2 > > > 7=A3=A9combine to a file > > > > 3.download ZLIB fromhttp://www.zlib.net/ > > > 1=A3=A9call the unpress function inf(file1,file2); > > > 2=A3=A9the 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 > > > > =A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=
=A3=A1=A3=A1=A3=A1=A3
> > > =A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=A3=A1=
=A3=A1=A3=A1=A3=A1=A3
> > > > 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 =3D ID and after the 3rd bit > > > -- after SOF been received. > > > if (state =3D ID and RXE_COUNTER_I =3D C3) then > > > RXE_SM_EN <=3D '1'; > > > else > > > RXE_SM_EN <=3D '0'; > > > end if; > > > > -- Reset CRC when State =3D EOF > > > -- When RXE_CRC_RST =3D '1', the CRC register is reset. > > > -- Reset when State =3D EOF and RXE_COUNTER_I =3D CO > > > -- (After ACK field) > > > -- Reset when in ERRACT and ERRPASS and RXE_COUNTER_I =3D C0. It =
is
> > > possible > > > -- that Reset could be asserted for multiple cycles. > > > > if ((state =3D EOF and RXE_COUNTER_I =3D C0) or > > > ((state =3D ERRACT or state =3D ERRPASS) and RXE_COUNTER_I =3D=
C1)
> > > or state =3D BOFF) then > > > RXE_CRC_RST <=3D '1'; > > > else > > > RXE_CRC_RST <=3D '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=3D{0x0d,0x9b,0x9e,0x4f,0xb6,0x2a,0xf1,0x37}; .... do { //read and process 8 bytes every time unRead =3D 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]^=3Dxorseed[0]; decrypt[i*SIZE+1]^=3Dxorseed[1]; decrypt[i*SIZE+2]^=3Dxorseed[2]; decrypt[i*SIZE+3]^=3Dxorseed[3]; decrypt[i*SIZE+4]^=3Dxorseed[4]; decrypt[i*SIZE+5]^=3Dxorseed[5]; decrypt[i*SIZE+6]^=3Dxorseed[6]; decrypt[i*SIZE+7]^=3Dxorseed[7]; //Update the XOR seeds by last encrypted 8 bytes xorseed[0]=3Dcrypt[i*SIZE]; xorseed[1]=3Dcrypt[i*SIZE+1]; xorseed[2]=3Dcrypt[i*SIZE+2]; xorseed[3]=3Dcrypt[i*SIZE+3]; xorseed[4]=3Dcrypt[i*SIZE+4]; xorseed[5]=3Dcrypt[i*SIZE+5]; xorseed[6]=3Dcrypt[i*SIZE+6]; xorseed[7]=3Dcrypt[i*SIZE+7]; //write to a file or keep in memory fwrite(decrypt, SIZE, unRead, compressfile); } (!feof(cryptfile) && unRead !=3D 0); .......... //Call ZLIB uncompress inf(compressfile,plaintextfile);
Hi,

> =A0 //Call DES decrypt function > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 DES(&crypt[i*SIZE],&decrypt[i*SIZE], 8, d=
eskey, DECRYPT); What kind of DES you used ? You have a link where I can download the source of DES ? I tried to do the brute with these parameters for recover a DES key: ciphertext (encrypted octect) =3D 39 1E 5F B2 14 42 33 C1 plaintext (decrypted octect) =3D 75 41 73 32 dd 59 ea 0c Initial KEY : 8f c2 d3 a0 XX XX XX XX I have rotate all key with four start byte, but brute force has not found the key :-( ... I need more details about the type of DES used. Thanks. Kappa.
On 1=D4=C27=C8=D5, =CF=C2=CE=E77=CA=B116=B7=D6, secure...@gmail.com wrote:
> Hi, > > > //Call DES decrypt function > > DES(&crypt[i*SIZE],&decrypt[i*SIZE], 8, deskey, DECRYPT=
);
> > What kind of DES you used ? > > You have a link where I can download the source of DES ? > > I tried to do the brute with these parameters for recover a DES key: > > ciphertext (encrypted octect) =3D 39 1E 5F B2 14 42 33 C1 > plaintext (decrypted octect) =3D 75 41 73 32 dd 59 ea 0c > > Initial KEY : 8f c2 d3 a0 XX XX XX XX > > I have rotate all key with four start byte, but brute force has not > found the key :-( ... > > I need more details about the type of DES used. > > Thanks. > > Kappa.
Hi Kappa, Actruly it's a 3DES by Chinese programer,I paste the C code here. enjoy // initial permutation IP const static char IP_Table[64] =3D { 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7 }; /*const static char IP_Table[64] =3D { 64, 56, 48, 40, 32, 24, 16, 8,62, 54, 46, 38, 30, 22, 14, 6, 60, 52, 44, 36, 28, 20, 12, 4,58, 50, 42, 34, 26, 18, 10, 2, 63, 55, 47, 39, 31, 23, 15, 7,61, 53, 45, 37, 29, 21, 13, 5, 59, 51, 43, 35, 27, 19, 11, 3,57, 49, 41, 33, 25, 17, 9, 1 }; */ // final permutation IP^-1 const static char IPR_Table[64] =3D { 40, 8, 48, 16, 56, 24, 64, 32, 39, 7, 47, 15, 55, 23, 63, 31, 38, 6, 46, 14, 54, 22, 62, 30, 37, 5, 45, 13, 53, 21, 61, 29, 36, 4, 44, 12, 52, 20, 60, 28, 35, 3, 43, 11, 51, 19, 59, 27, 34, 2, 42, 10, 50, 18, 58, 26, 33, 1, 41, 9, 49, 17, 57, 25 }; // expansion operation matrix static const char E_Table[48] =3D { 32, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 8, 9, 10, 11, 12, 13, 12, 13, 14, 15, 16, 17, 16, 17, 18, 19, 20, 21, 20, 21, 22, 23, 24, 25, 24, 25, 26, 27, 28, 29, 28, 29, 30, 31, 32, 1 }; /*static const char E_Table[48] =3D { 1, 32, 31, 30, 29, 28, 29, 28, 27, 26, 25, 24, 25, 24, 23, 22, 21, 20, 21, 20, 19, 18, 17, 16, 17, 16, 15, 14, 13, 12, 13, 12, 11, 10, 9, 8, 9, 8, 7, 6, 5, 4, 5, 4, 3, 2, 1, 32 }; */ // 32-bit permutation function P used on the output of the S-boxes const static char P_Table[32] =3D { 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 }; // permuted choice table (key) const static char PC1_Table[56] =3D { 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4 }; // permuted choice key (table) const static char PC2_Table[48] =3D { 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32 }; // number left rotations of pc1 const static char LOOP_Table[16] =3D { 1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1 }; // The (in)famous S-boxes const static char S_Box[8][4][16] =3D { // S1 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13, // S2 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9, // S3 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12, // S4 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14, // S5 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3, // S6 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13, // S7 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12, // S8 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 }; typedef bool (*PSubKey)[16][48]; ////////////////////////////////////////////////////////////////////////// static void DES(char Out[8], char In[8], const PSubKey pSubKey, bool Type);//=B1=EA=D7=BCDES=BC=D3/=BD=E2=C3=DC static void SetKey(const char* Key, int len);// =C9=E8=D6=C3=C3=DC=D4=BF static void SetSubKey(PSubKey pSubKey, const char Key[8]);// =C9=E8=D6=C3= =D7=D3=C3=DC=D4=BF static void F_func(bool In[32], const bool Ki[48]);// f =BA=AF=CA=FD static void S_func(bool Out[32], const bool In[48]);// S =BA=D0=B4=FA=CC=E6 static void Transform(bool *Out, bool *In, const char *Table, int len);// =B1=E4=BB=BB static void Xor(bool *InA, const bool *InB, int len);// =D2=EC=BB=F2 static void RotateL(bool *In, int len, int loop);// =D1=AD=BB=B7=D7=F3=D2= =C6 static void ByteToBit(bool *Out, const char *In, int bits);// =D7=D6=BD=DA= =D7=E9=D7=AA=BB=BB=B3=C9=CE=BB=D7=E9 static void BitToByte(char *Out, const bool *In, int bits);// =CE=BB=D7=E9= =D7=AA=BB=BB=B3=C9=D7=D6=BD=DA=D7=E9 static void ByteToBit_S(bool *Out, const char *In, int bits);// =D7=D6=BD= =DA=D7=E9=D7=AA=BB=BB=B3=C9=CE=BB =D7=E9s-box special static void inv(char *Out, const char *In, int len); //inv int inf(FILE *source, FILE *dest); ////////////////////////////////////////////////////////////////////////// static bool SubKey[2][16][48];// 16=C8=A6=D7=D3=C3=DC=D4=BF static bool Is3DES;// 3=B4=CEDES=B1=EA=D6=BE static char Tmp[256], deskey[16]; ////des code begin here bool Des_Go(char *Out, char *In, long datalen, const char *Key, int keylen, bool Type) { if( !( Out && In && Key && (datalen=3D(datalen+7)&0xfffffff8) ) ) return false; SetKey(Key, keylen); if( !Is3DES ) { // 1=B4=CEDES for(long i=3D0,j=3Ddatalen>>3; i<j; ++i,Out+=3D8,In+=3D8) DES(Out, In, &SubKey[0], Type); } else{ // 3=B4=CEDES =BC=D3=C3=DC:=BC=D3(key0)-=BD=E2(key1)-=BC=D3(key0= ) =BD=E2=C3=DC::=BD=E2(key0)-=BC=D3(key1)-=BD=E2 (key0) for(long i=3D0,j=3Ddatalen>>3; i<j; ++i,Out+=3D8,In+=3D8) { DES(Out, In, &SubKey[0], Type); DES(Out, Out, &SubKey[1], !Type); DES(Out, Out, &SubKey[0], Type); } } return true; } void SetKey(const char* Key, int len) { memset(deskey, 0, 16); memcpy(deskey, Key, len>16?16:len); SetSubKey(&SubKey[0], &deskey[0]); Is3DES =3D len>8 ? (SetSubKey(&SubKey[1], &deskey[8]), true) : false; } void DES(char Out[8], char In[8], const PSubKey pSubKey, bool Type) { char dis[8]; static bool M[64], tmp[32], *Li=3D&M[0], *Ri=3D&M[32]; char inbuf[8], outbuf[8]; inv(inbuf,In, 8); ByteToBit(M, inbuf, 64); Transform(M, M, IP_Table, 64); BitToByte(dis, M, 64); if( Type =3D=3D ENCRYPT ){ for(int i=3D0; i<16; ++i) { memcpy(tmp, Ri, 32); F_func(Ri, (*pSubKey)[i]); Xor(Ri, Li, 32); memcpy(Li, tmp, 32); } }else{ for(int i=3D15; i>=3D0; --i) { //memcpy(tmp, Li, 32); // F_func(Li, (*pSubKey)[i]); memcpy(tmp, Ri, 32); F_func(Ri, (*pSubKey)[i]); //Xor(Li, Ri, 32); Xor(Ri, Li, 32); // memcpy(Ri, tmp, 32); memcpy(Li, tmp, 32); } } memcpy(tmp, Ri, 32); memcpy(Ri, Li, 32); memcpy(Li, tmp, 32); Transform(M, M, IPR_Table, 64); BitToByte(outbuf, M, 64); inv(Out,outbuf, 8); } void SetSubKey(PSubKey pSubKey, const char Key[8]) { static bool K[64], *KL=3D&K[0], *KR=3D&K[28]; // char dis[6]; ByteToBit(K, Key, 64); Transform(K, K, PC1_Table, 56); for(int i=3D0; i<16; ++i) { RotateL(KL, 28, LOOP_Table[i]); RotateL(KR, 28, LOOP_Table[i]); Transform((*pSubKey)[i], K, PC2_Table, 48); // BitToByte(dis, (*pSubKey)[i], 48); } } void F_func(bool In[32], const bool Ki[48]) { static bool MR[48]; // char dis[6]; Transform(MR, In, E_Table, 48); // BitToByte(dis, In, 32); // BitToByte(dis, MR, 48); // BitToByte(dis, Ki, 48); Xor(MR, Ki, 48); // BitToByte(dis, MR, 48); S_func(In, MR); //BitToByte(dis, In, 32); Transform(In, In, P_Table, 32); //BitToByte(dis, In, 32); } void S_func(bool Out[32], const bool In[48]) { for(char i=3D0,j,k; i<8; ++i,In+=3D6,Out+=3D4) { j =3D (In[0]<<1) + In[5]; k =3D (In[1]<<3) + (In[2]<<2) + (In[3]<<1) + In[4]; ByteToBit_S(Out, &S_Box[i][j][k], 4); } } void Transform(bool *Out, bool *In, const char *Table, int len) { // char dis[8]; // BitToByte(dis, In, len); for(int i=3D0; i<len; ++i) Tmp[i] =3D In[ Table[i]-1 ]; memcpy(Out, Tmp, len); // BitToByte(dis, Out, len); } void Xor(bool *InA, const bool *InB, int len) { for(int i=3D0; i<len; ++i) InA[i] ^=3D InB[i]; } void RotateL(bool *In, int len, int loop) { memcpy(Tmp, In, loop); memcpy(In, In+loop, len-loop); memcpy(In+len-loop, Tmp, loop); } void ByteToBit(bool *Out, const char *In, int bits) { for(int i=3D0; i<bits; ++i) Out[i] =3D (In[i>>3]>>(i&7)) & 1; } void ByteToBit_S(bool *Out, const char *In, int bits) { for(int i=3D0; i<bits; ++i) Out[i] =3D (In[i>>3]>>((3-i)&7)) & 1; } void BitToByte(char *Out, const bool *In, int bits) { memset(Out, 0, bits>>3); for(int i=3D0; i<bits; ++i) Out[i>>3] |=3D In[i]<<(i&7); } static void inv(char *Out, const char *In, int len) { memset(Out, 0, len); for(int i=3D0; i<len; ++i) { for(int j=3D0;j<8;j++){ Out[i] |=3D ((In[i]>>j) & 1)<<(7-j); } } }
Hi doom ...

> Actruly it's a 3DES by Chinese programer,I paste the C code here.
This is the problem "3DES" and not DES, Now I have more clear. Thank you very much, even for the code. Kappa.