You are on page 1of 13

B GIO DC V O TO TRNG I HC M - A CHT

----- -----

BI TP LN AN TON V BO MT THNG TIN


TI:

H M HA KHI DES

GV hng dn: ng Vn Nam SV thc hin: Phm Th Ngn Lp: CNPMK54 MSSV: 0921050275

H Ni, 4/2013

LI NI U T trc cng nguyn con ngi phi quan tm ti vic lm th no m bo an ton b mt cho cc ti liu, vn bn quan trng, c bit l trong lnh vc qun s, ngoi giao. Ngy nay, vi s xut hin ca my tnh, cc ti liu vn bn giy t v cc thng tin quan trng u c s ha v x l trn my tnh, c truyn i trong mi trng m mc nh l khng an ton. Do yu cu v vic c mt c ch, gii php bo v s an ton v b mt ca cc thng tin nhy cm, quan trng ngy cng tr nn cp thit. Mt m hc chnh l ngnh khoa hc m bo cho mc ch ny. N da trn nn tng cc thut ton ton hc, s hc, xc sut v cc mn khoa hc khc to ra cc h m ha. V c bit phi k n l h m ha khi m in hnh l h m ha khi DES (Data Encryption Standard), mt trong s cc h m ha khi c s dng rng ri nht v l nn tng cho rt nhiu h m ha khi khc.

I. Tng quan v h m ha khi


Trong mt m hc, m ha khi l nhng thut ton m ha i xng hot ng trn nhng khi thng tin c di xc nh (block) vi nhng chuyn i xc nh. Chng hn mt thut ton m ha khi c th x l khi 128 bits u vo v bin n thnh khi 128 bits u ra. Qu trnh chuyn i cn s dng thm mt tham s na: kha b mt c bit ha qu trnh. Vic gii m cng din ra tng t: x l khi m ha 128 bits cng vi kha tr v khi 128 bits bn r ban u. m ha nhng vn bn c di vt qu di ca khi, ngi ta s dng thut ton theo mt c ch m ha khi no . Phn bit vi m ha khi l m ha dng. M ha dng lm vic trn tng bits ca dng d liu v qu trnh bin i thay i theo qu trnh m ha. Tuy nhin, s phn bit gia hai phng php nhiu khi khng r rng v m ha khi khi hot ng theo mt c ch no th c tc dng nh mt phng php m ha dng. Qu trnh m ha khi bao gm 2 thut ton: m ha - k hiu E v gii m - k hiu E-1. C 2 thut ton u tc ng ln mt khi u vo n bt s dng mt kha k bt cho ra mt khi u ra n bt. i vi bt k kha no, gii m l hm ngc ca m ha, ngha l: trong M l khi thng tin v K l kha bt k. Vi mi kha K, EK l mt hon v (song nh) ca khi u vo. Mi kha s xc nh mt hon v trong tng s kh nng. di ca khi thng tin, k hiu l n, thng thng l c nh 64 hoc 128 bt. Mt s thut ton c di khi thay i nhng khng ph bin. Tnh n trc nhng nm gia ca thp k 1990 th di 64 bt thng c s dng. T tr v sau th khi 128 bt c s dng rng ri hn. Trong cc ch m ha khi th ngi ta thng phi b sung thm mt s bt cho vn bn (ting Anh: padding) vn bn cha s nguyn ln cc khi. Mi ch m ha c c tnh khc nhau v lan truyn li (li m ha trong khi ny nh hng ti khi khc), kh nng truy xut ngu nhin v kh nng chng li cc kiu tn cng khc nhau. di thng thng ca kha k l 40, 56, 64, 80, 128, 192 v 256 bt. Cho n nm 2006 th 80 bt l di ti thiu ca kha c th chng li tn cng kiu duyt ton b. Hu ht cc thut ton m ha khi s dng lp i lp li cc hm n gin. Phng php ny cn c gi l m ha khi lp. Mi chu k lp c gi l mt vng (round) v thng thng cc thut ton c t 4 ti 32 vng. Rt nhiu thut ton m ha khi c tnh cht ca mng Feistel, hay tng qut hn l h thng th v hon v. Cc thnh phn s dng trong thut ton l cc hm ton hc, cc hm logic (c bit l hm XOR), hp th (S-box) v cc phng php hon v.

iu kin m ha khi an ton: Kch thc khi phi ln chng li phng n tn cng bng phng php thng k. Tuy nhin iu ny s dn n thi gian m ha tng ln. Khng gian kha, tc chiu di kha phi ln chng li phng n tn cng bng vt cn. Tuy nhin kha phi ngn vic to kha, phn phi v lu tr kha c d dng. Khi thit k mt h m ha khi, phi m bo hai yu cu sau: S hn lon (confusion): S ph thuc gia bn r v bn m phi thc s phc tp gy kh khn vi vic tm quy lut thm m. Mi quan h ny tt nht l phi tuyn. S khuch tn (diffusion): Mi bit ca bn r v kha pahri nh hng ln cng nhiu bit ca bn m cng tt.
II.

Chun m ha d liu khi DES


1. M t s m ha khi DES

DES l thut ton m ha vi input l khi 64 bit, output cng l khi 64 bit. Kha m ha c di 56 bit, thc ra chnh xc hn phi l 64 bit vi cc bit v tr chia ht cho 8 c th s dng cho cc bit kim tra tnh chn l. S kha ca khng gian kha K l 256.

Hnh 1: Chun m ha d liu DES Thut ton thc hin 16 vng. T kha input K, 16 kha con 48 bit K i s c sinh ra, mi kha thay th 6 bit thnh 4 bit Si (cn gi l hp Si) c chn la k cng v c nh, k hiu chung l S s c s dng. Bn r 64 bit s c s dng chia thnh hai na L0 v R0. Cc vng c chc nng ging nhau, nhn input l Li-1 v Ri-1 t vng trc v sinh ra output l cc xu 32 bit Li v Ri nh sau: Li = Ri-1; (1) Ri = Li-1 f(Ri-1, Ki) trong f(Ri-1, Ki) = P(S(E(Ri-1) Ki)); (2) Trong : l k hiu ca php tuyn loi tr (XOR) ca hai xu bit theo modulo 2. - Hm f l mt hm phi tuyn. - E l hon v m rng nh x Ri-1 t 32 bit thnh 48 bit (i khi tt c cc bit s c s dng hoc mt bit s c s dng 2 ln). - P l hon v c nh khc ca 32 bit. Mt hon v bit khi u (IP) c s dng cho vng u tin; sau vng cui cng na tri v phi s c i ngc cho nhau v cui cng xu kt qu s c hon v bit ln cui bi hon v ngc ca IP (IP-1).

Qu trnh gii m din ra tng t nhng vi cc kha con ng dng vo cc vng trong theo th t ngc li. C th hnh dung n gin l phn bn phi trong mi vng (sau khi m rng input 32 bit thnh 8 k t 6 bit xu 48 bit) s c thc hin mt tnh ton thay th ph thuc kha trn mi mt k t trong xu 48 bit, v sau s dng mt php chuyn bit c nh phn b li cc bit ca cc k t kt qu hnh thnh nn output 32 bit. Cc kha con Ki ( cha 48 bit ca K) c tnh bng cch s dng cc bng PC1 v PC2 (Permutation Choice 1 v 2). Trc tin 8 bit (k8, k16,, k64) ca K b b i (p dng PC1). 56 bit cn li c hon v v gn cho hai bin 28 bit C v D, sau trong 16 vng lp c C v D s c quay 1 hoc 2 bit, v cc kha con 48 bit Ki c chn t kt qu ca vic ghp hai xu vi nhau. Nh vy ta c th m t ton b thut ton sinh m DES di dng cng thc nh sau: Trong : - T m t php hon v ca cc khi LiRi (1 i 15). - fi m t vic dng hm f vi kha Ki (1 i 16). Thut ton chi tit: Input: Bn r M = m1m2m64, kha 64 bit K = k1k2k64 (bao gm c 8 bit chn l, vic thm bit chn l sao cho cc on kha 8 bit c s bit 1 l l). Output: bn m 64 bit C = c1c2c64 i. Sinh kha con. Tnh cc kha con theo thut ton sinh kha con bn di ii. (L0,R0) IP(m1m2m64) (S dng bng hon v IP hon v cc bit, kt qu nhn c chia thnh hai na l L0 = m58m50m8, R0 = m57m49m7.) iii. (16 vng) for i = 1 to 16 Tnh cc Li v Ri theo cc cng thc (1) v (2), vic tnh f(Ri-1,Ki) = P(S(E(Ri-1) Ki)) c thc hin nh sau: a) M rng Ri-1 = r1r2r32 t 32 bit thnh 48 bit bng cch s dng hon v m rng E. TE(Ri-1). (V th T = r32r1r2r32r1) b) TT Ki. Biu din T nh l cc xu gm 8 k t 6 bit T = (B1,,B8) c) T(S1(B1), S2(B2),, S8(B8)). Trong Si(Bi) nh x b1b2b8 thnh cc xu 4 bit ca phn t thuc hng r v ct ca cc bng Si(Sbox) trong r=2*b1 + b6 v c = b2b3b4b5 l mt s nh phn t 0 ti 15. Chng hn S1(011011) s cho r = 1 v c = 13 v kt qu l 5 biu din di dng nh phn l 0101. d) TP(T) trong P l hon v c nh hon v 32 bit ca T = t1t2t32 sinh ra t16t7t25. iv. b1b2b64(R16,L16) (i v tr ca cc khi cui cng L16, R16 v. CIP-1(b1b2b64) (bin i s dng IP-1, C = b40b8b25)

S 16 vng lp ca DES:

Hnh 2: S m ha DES

2. Ha v IP v hon v ngc IP-1

Bng hon v IP c a ra trong bng di y: 5 50 42 34 26 18 10 2 60 52 44 36 8 6 54 46 38 30 22 14 6 64 56 48 40 2 5 49 41 33 25 17 9 1 59 51 43 35 7 6 53 45 37 29 21 13 5 63 55 47 39 1 Bng 1: Bng hon v IP 4 8 48 16 56 24 64 3 39 7 47 15 0 2 3 6 46 14 54 22 62 3 37 5 45 13 8 0 3 4 44 12 52 20 60 2 35 3 43 11 6 8 3 2 42 10 50 18 58 2 33 1 41 9 4 6 Bng 2: Bng hon v ngc IP-1 Hai hon v IP v IP-1 khng c ngha g v mt mt nhm to iu kin cho vic chip ha thut ton DES. S cu trc mt vng DES:

28 20 12 4 32 24 16 8 27 19 11 3 31 23 15 7 55 23 63 31 53 21 61 29 51 19 59 27 49 17 57 25 m m hon ton

Hnh 3: S mt vng DES

3. Thut ton sinh kha con Mi su vng lp ca DES chy cng thut ton nh nhau nhng vi 16 kha con khc nhau. Cc kha con u c sinh ra t kha chnh ca DES bng mt thut ton sinh kha con. Kha chnh K (64bit) i qua 16 bc bin i, ti mi bc bin i ny mt kha con c sinh ra vi di 48 bit. C th m t thut ton sinh cc kha con chi tit nh sau: Input: kha 64 bit K = k1k2k64 (bao gm c 8 bit kim tra tnh chn l) Output: 16 kha con 48 bit Ki, 1 i 16. i. nh ngha vi, 1 i 16 nh sau: vi = 1 i vi i { 1, 2, 9, 16}; v i = 2 cho cc trng hp khc (y l cc gi tr dch tri cho cc vng 28 bit bn di). ii. T PC1(K); biu din T thnh cc na 28 bit (C0, D0) (S dng bng PC1 chn cc bit t K: C0 = k57k49k36, D0 = k63k55k4.) iii. For i from 1 to 16, tnh cc Ki nh sau: Ci (Ci-1 vi), Di (Di-1 vi), Ki PC2(Ci, Di). (S dng PC2 chn 48 bit t xu ghp b1b2 b56 ca Ci v Di. Ki = b14b17b32. l k hiu dch vng tri). S sinh cc kha con ca DES:

Hnh 4: S to kha con ca DES 64 bit u vo s gim xung cn 56 bit bng cch b i 8 bit ( cc v tr chia ht cho 8), cc bit ny dng kim tra bit chn l. Sau 56 bit ny li c trch ly 48 bit sinh ra cho 16 vng kha ca DES. Bng trt t kha (PC-1):
57 10 63 14 49 2 55 6 41 59 47 61 33 51 39 53 25 43 31 45 17 35 23 37 9 27 15 29 1 19 7 21 58 11 62 13 50 3 54 5 42 60 46 28 34 52 38 20 26 44 30 12 18 36 22 4

Bng 4: Bng PC-1 u tin 56 bit kha c chia ra thnh hai na 28 bit. Sau , hai na 28 bit ny c dch vng tri hoc 1 hoc 2 bit ph thuc vo s bit dch tng ng vi vng . S bit dch ca cc vng (LS):
Vng lp 1 2 1 3 2 4 2 5 2 6 2 7 2 8 2 9 1 10 11 2 2 12 2 13 2 14 15 16 2 2 1 S bit dch 1

Bng 5: Bng dch bit ti cc vng lp ca DES

Sau khi dch vng, mt bng chn 48 bit c s dng. V cch hon v ny ca cc bit c chn nh mt t hp con ca cc bit nn c gi l hon v nn hay trt t nn. Bng trt t nn (PC-2):
14 23 41 44 17 19 52 49 11 12 31 39 24 4 37 56 1 26 47 34 5 8 55 53 3 16 30 46 28 7 40 42 15 27 51 50 6 20 45 36 21 13 33 29 10 2 48 32

Bng 6: Bng PC-2 V d nh chng ta c th nhn thy bit v tr 33 ca kha s dch sang v tr 35 ra ngoi, cn bit v tr 18 ca kha s b b qua. Chnh vic dch vng ny to nn mt tp hp con ca kha c s dng trong mi t hp kha, d khng phi tt c cc bit c s dng mt cch chnh xc cng mt lc trong mi ln s dng. 4. M t hm f Hm f(Ri-1, Ki) l mt hm c hai bin vo: bin th nht Ri-1 l mt xu bit c di 32 bit. Hm f c th l hm bt k tuy nhin v ngun gc sc mnh ca DES nm trong hm f nn vic chn hm f phi cn thn trnh b ph m mt cch d dng. Thng thng hm f c chn thng l hm c tnh cht f = f-1, tc f(f(x)) = x. Trong s m t m ha ca DES c cng b bi y ban Tiu chun Quc gia Hoa K (The Untied Nation Bureau of Standard), hm f thc hin cc vic sau: Bin th nht Ri-1 c m rng thnh mt xu bit c di 48 bit theo mt hm m rng c nh E. Thc cht hm m rng E(R i-1) l mt hon v c lp trong lp li 16 bit ca Ri-1 a 8 khi Bi vo 8 bng S1, S2, , S8 (c gi l cc hp SBox). Mi hp S-Box l mt bng 4*16 c nh c cc ct t 0 n 15 v cc hng t 0 n 3. Vi mi xu 6 bit Bi = b1b2b3b4b5b6, ta tnh c Si(Bi) nh sau: hai bit b1b6 xc nh hng r trong hp Si, bn bit b2b3b4b5 xc nh ct c trong hp Si. Khi , Si(Bi) s xc nh phn t Ci = Si(r,c), phn t ny vit di dng nh phn 4 bit. Nh vy, 8 khi 6 bit Bi (1 i 8) s cho ra 8 khi 4 bit Ci vi (1 i 8). Xu bit C = C1C2C3C4C5C6C7C8 c di 32 bit c hon v theo php hon v P (hp P-Box). Kt qu P(C) s l kt qu ca hm f(Ri-1, Ki), v cng chnh l Ri cho vng sau. Hm f cng c th m t bng hnh v sau:

Hnh 5: S hm f 5. Hm (nh x) m rng (E) Hm m rng s tng di ca Ri t 32 bit ln 48 bit bng cch thay i cc th t ca cc bit cng nh lp li cc bit. Vic thc hin ny nhm hai mc ch: Lm di ca Ri cng c vi kha K thc hin vic cng modulo XOR. Cho kt qu di hn c th c nn trong sut qu trnh thay th. Tuy nhin, c hai mc ch ny u nhm mt mc tiu chnh l bo mt d liu. Bng cch cho php 1 bit c th chn vo hai v tr thay th, s ph thuc ca cc bit u ra vi cc bit u vo s tri rng ra. DES c thit k vi iu kin l mi bit ca bn m ph thuc vo mi bit cu bn r v kha. S hm m rng:

Hnh 6: S hm m rng (E) i khi n c gi l hm E-Box, mi 4 bit ca khi vo, bit th nht v bit th t tng ng vi 2 bit ca u ra, trong khi bit th 2 v bit th 3 tng ng vi 1 bit u ra. Bng sau y miu t v tr ca bit ra so vi bit vo. Bng m t hm m rng (E):
32 8 16 24 1 9 17 25 2 10 18 26 3 11 19 27 4 12 20 28 5 13 21 29 4 12 20 28 5 13 21 29 6 14 22 30 7 15 23 31 8 16 24 32 9 17 25 1

Bng 7: Bng m t hm m rng E V d nh bit v tr s 3 ca khi vo s di chuyn n v tr s 4 ca khi ra v bit v tr 21 u vo s di chuyn n v tr 30 v 32 u ra. 6. M t hp S-box 7. Hp P-box
III. V

IV.
1. 2. 3. 4.

d v m ha khi DES Hn ch ca m ha khi DES


Tnh b Kha yu DES c cu trc i s Khng gian kha k