最新DES算法使用vhdl硬件语言实现.doc

上传人:1595****071 文档编号:33837051 上传时间:2022-08-12 格式:DOC 页数:49 大小:247KB
返回 下载 相关 举报
最新DES算法使用vhdl硬件语言实现.doc_第1页
第1页 / 共49页
最新DES算法使用vhdl硬件语言实现.doc_第2页
第2页 / 共49页
点击查看更多>>
资源描述

《最新DES算法使用vhdl硬件语言实现.doc》由会员分享,可在线阅读,更多相关《最新DES算法使用vhdl硬件语言实现.doc(49页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、精品资料DES算法使用vhdl硬件语言实现.library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;package des_lib is component des port (clk:in std_logic; reset:in std_logic; encrypt:in std_logic; key_in:in std_logic_vector (55 downto 0); din:in std_logic_vector (63 downto

2、0); din_valid:in std_logic; busy:buffer std_logic; dout:out std_logic_vector (63 downto 0); dout_valid:out std_logic ); end component; component des_round port (clk:in std_logic; reset:in std_logic; stall:in std_logic; encrypt_in:in std_logic; encrypt_shift:in std_logic_vector (4 downto 0); decrypt_

3、shift:in std_logic_vector (4 downto 0); key_in:in std_logic_vector (55 downto 0); din:in std_logic_vector (63 downto 0); din_valid :in std_logic; encrypt_out:out std_logic; key_out:out std_logic_vector (55 downto 0); dout:out std_logic_vector (63 downto 0); dout_valid:out std_logic ); end component;

4、 - Inital permutation function des_ip(din:std_logic_vector(63 downto 0) return std_logic_vector; - Final permutation function des_fp(din:std_logic_vector(63 downto 0) return std_logic_vector; - Key permutation, converts a 64 bit key into a 56 bit key, ignoring parity function des_kp(din :std_logic_v

5、ector (63 downto 0) return std_logic_vector; - Compression Permutation, converts a 56 bit key into a 48 bits. function des_cp(din :std_logic_vector (55 downto 0) return std_logic_vector; - Expansion permutation function des_ep(din :std_logic_vector (31 downto 0) return std_logic_vector; - S-Box Subs

6、titution, 48 bits in, 32 bits out. function des_sbox(din :std_logic_vector (47 downto 0) return std_logic_vector; - P-Box Permutation function des_pbox(din :std_logic_vector (31 downto 0) return std_logic_vector; - Key Shift function des_keyshift (din:std_logic_vector (55 downto 0); n :std_logic_vec

7、tor (4 downto 0) return std_logic_vector;end des_lib;-library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;library work;use work.des_lib.all;package body des_lib is - - Inital permutation function des_ip(din:std_logic_vector(63 downto 0) return std_lo

8、gic_vector is variable val :std_logic_vector (63 downto 0); begin val := din(64-58) & din(64-50) & din(64-42) & din(64-34) & din(64-26) & din(64-18) & din(64-10) & din(64- 2) & din(64-60) & din(64-52) & din(64-44) & din(64-36) & din(64-28) & din(64-20) & din(64-12) & din(64- 4) & din(64-62) & din(64

9、-54) & din(64-46) & din(64-38) & din(64-30) & din(64-22) & din(64-14) & din(64- 6) & din(64-64) & din(64-56) & din(64-48) & din(64-40) & din(64-32) & din(64-24) & din(64-16) & din(64- 8) & din(64-57) & din(64-49) & din(64-41) & din(64-33) & din(64-25) & din(64-17) & din(64- 9) & din(64- 1) & din(64-

10、59) & din(64-51) & din(64-43) & din(64-35) & din(64-27) & din(64-19) & din(64-11) & din(64- 3) & din(64-61) & din(64-53) & din(64-45) & din(64-37) & din(64-29) & din(64-21) & din(64-13) & din(64- 5) & din(64-63) & din(64-55) & din(64-47) & din(64-39) & din(64-31) & din(64-23) & din(64-15) & din(64-

11、7); return val; end des_ip; - - Final permutation function des_fp(din:std_logic_vector(63 downto 0) return std_logic_vector is variable val :std_logic_vector (63 downto 0); begin val := din(64-40) & din(64- 8) & din(64-48) & din(64-16) & din(64-56) & din(64-24) & din(64-64) & din(64-32) & din(64-39)

12、 & din(64- 7) & din(64-47) & din(64-15) & din(64-55) & din(64-23) & din(64-63) & din(64-31) & din(64-38) & din(64- 6) & din(64-46) & din(64-14) & din(64-54) & din(64-22) & din(64-62) & din(64-30) & din(64-37) & din(64- 5) & din(64-45) & din(64-13) & din(64-53) & din(64-21) & din(64-61) & din(64-29)

13、& din(64-36) & din(64- 4) & din(64-44) & din(64-12) & din(64-52) & din(64-20) & din(64-60) & din(64-28) & din(64-35) & din(64- 3) & din(64-43) & din(64-11) & din(64-51) & din(64-19) & din(64-59) & din(64-27) & din(64-34) & din(64- 2) & din(64-42) & din(64-10) & din(64-50) & din(64-18) & din(64-58) &

14、 din(64-26) & din(64-33) & din(64- 1) & din(64-41) & din(64- 9) & din(64-49) & din(64-17) & din(64-57) & din(64-25); return val; end des_fp; - - Key permutation, converts a 64 bit key into a 56 bit key, ignoring parity function des_kp(din :std_logic_vector (63 downto 0) return std_logic_vector is va

15、riable val :std_logic_vector (55 downto 0); begin val := din(64-57) & din(64-49) & din(64-41) & din(64-33) & din(64-25) & din(64-17) & din(64- 9) & din(64- 1) & din(64-58) & din(64-50) & din(64-42) & din(64-34) & din(64-26) & din(64-18) & din(64-10) & din(64- 2) & din(64-59) & din(64-51) & din(64-43

16、) & din(64-35) & din(64-27) & din(64-19) & din(64-11) & din(64- 3) & din(64-60) & din(64-52) & din(64-44) & din(64-36) & din(64-63) & din(64-55) & din(64-47) & din(64-39) & din(64-31) & din(64-23) & din(64-15) & din(64- 7) & din(64-62) & din(64-54) & din(64-46) & din(64-38) & din(64-30) & din(64-22)

17、 & din(64-14) & din(64- 6) & din(64-61) & din(64-53) & din(64-45) & din(64-37) & din(64-29) & din(64-21) & din(64-13) & din(64- 5) & din(64-28) & din(64-20) & din(64-12) & din(64- 4); return val; end des_kp; - - Compression Permutation, converts a 56 bit key into a 48 bits. function des_cp(din :std_

18、logic_vector (55 downto 0) return std_logic_vector is variable val :std_logic_vector (47 downto 0); begin val := din(56-14) & din(56-17) & din(56-11) & din(56-24) & din(56- 1) & din(56- 5) & din(56- 3) & din(56-28) & din(56-15) & din(56- 6) & din(56-21) & din(56-10) & din(56-23) & din(56-19) & din(5

19、6-12) & din(56- 4) & din(56-26) & din(56- 8) & din(56-16) & din(56- 7) & din(56-27) & din(56-20) & din(56-13) & din(56- 2) & din(56-41) & din(56-52) & din(56-31) & din(56-37) & din(56-47) & din(56-55) & din(56-30) & din(56-40) & din(56-51) & din(56-45) & din(56-33) & din(56-48) & din(56-44) & din(56

20、-49) & din(56-39) & din(56-56) & din(56-34) & din(56-53) & din(56-46) & din(56-42) & din(56-50) & din(56-36) & din(56-29) & din(56-32); return val; end des_cp; - - Expansion permutation function des_ep(din :std_logic_vector (31 downto 0) return std_logic_vector is variable val :std_logic_vector (47

21、downto 0); begin val := din(32-32) & din(32- 1) & din(32- 2) & din(32- 3) & din(32- 4) & din(32- 5) & din(32- 4) & din(32- 5) & din(32- 6) & din(32- 7) & din(32- 8) & din(32- 9) & din(32- 8) & din(32- 9) & din(32-10) & din(32-11) & din(32-12) & din(32-13) & din(32-12) & din(32-13) & din(32-14) & din

22、(32-15) & din(32-16) & din(32-17) & din(32-16) & din(32-17) & din(32-18) & din(32-19) & din(32-20) & din(32-21) & din(32-20) & din(32-21) & din(32-22) & din(32-23) & din(32-24) & din(32-25) & din(32-24) & din(32-25) & din(32-26) & din(32-27) & din(32-28) & din(32-29) & din(32-28) & din(32-29) & din(

23、32-30) & din(32-31) & din(32-32) & din(32- 1); return val; end des_ep; - - S-Box Substitution, 48 bits in, 32 bits out. function des_sbox(din :std_logic_vector (47 downto 0) return std_logic_vector is variable val :std_logic_vector (31 downto 0); begin - SBOX 8 case din( 5 downto 0) is when 000000 =

24、 val(3 downto 0) := 1101; when 000001 = val(3 downto 0) := 0001; when 000010 = val(3 downto 0) := 0010; when 000011 = val(3 downto 0) := 1111; when 000100 = val(3 downto 0) := 1000; when 000101 = val(3 downto 0) := 1101; when 000110 = val(3 downto 0) := 0100; when 000111 = val(3 downto 0) := 1000; w

25、hen 001000 = val(3 downto 0) := 0110; when 001001 = val(3 downto 0) := 1010; when 001010 = val(3 downto 0) := 1111; when 001011 = val(3 downto 0) := 0011; when 001100 = val(3 downto 0) := 1011; when 001101 = val(3 downto 0) := 0111; when 001110 = val(3 downto 0) := 0001; when 001111 = val(3 downto 0

26、) := 0100; when 010000 = val(3 downto 0) := 1010; when 010001 = val(3 downto 0) := 1100; when 010010 = val(3 downto 0) := 1001; when 010011 = val(3 downto 0) := 0101; when 010100 = val(3 downto 0) := 0011; when 010101 = val(3 downto 0) := 0110; when 010110 = val(3 downto 0) := 1110; when 010111 = va

27、l(3 downto 0) := 1011; when 011000 = val(3 downto 0) := 0101; when 011001 = val(3 downto 0) := 0000; when 011010 = val(3 downto 0) := 0000; when 011011 = val(3 downto 0) := 1110; when 011100 = val(3 downto 0) := 1100; when 011101 = val(3 downto 0) := 1001; when 011110 = val(3 downto 0) := 0111; when

28、 011111 = val(3 downto 0) := 0010; when 100000 = val(3 downto 0) := 0111; when 100001 = val(3 downto 0) := 0010; when 100010 = val(3 downto 0) := 1011; when 100011 = val(3 downto 0) := 0001; when 100100 = val(3 downto 0) := 0100; when 100101 = val(3 downto 0) := 1110; when 100110 = val(3 downto 0) :

29、= 0001; when 100111 = val(3 downto 0) := 0111; when 101000 = val(3 downto 0) := 1001; when 101001 = val(3 downto 0) := 0100; when 101010 = val(3 downto 0) := 1100; when 101011 = val(3 downto 0) := 1010; when 101100 = val(3 downto 0) := 1110; when 101101 = val(3 downto 0) := 1000; when 101110 = val(3

30、 downto 0) := 0010; when 101111 = val(3 downto 0) := 1101; when 110000 = val(3 downto 0) := 0000; when 110001 = val(3 downto 0) := 1111; when 110010 = val(3 downto 0) := 0110; when 110011 = val(3 downto 0) := 1100; when 110100 = val(3 downto 0) := 1010; when 110101 = val(3 downto 0) := 1001; when 11

31、0110 = val(3 downto 0) := 1101; when 110111 = val(3 downto 0) := 0000; when 111000 = val(3 downto 0) := 1111; when 111001 = val(3 downto 0) := 0011; when 111010 = val(3 downto 0) := 0011; when 111011 = val(3 downto 0) := 0101; when 111100 = val(3 downto 0) := 0101; when 111101 = val(3 downto 0) := 0

32、110; when 111110 = val(3 downto 0) := 1000; when 111111 = val(3 downto 0) := 1011; when others = val(3 downto 0) := 1011; end case; - SBOX 7 case din(11 downto 6) is when 000000 = val(7 downto 4) := 0100; when 000001 = val(7 downto 4) := 1101; when 000010 = val(7 downto 4) := 1011; when 000011 = val

33、(7 downto 4) := 0000; when 000100 = val(7 downto 4) := 0010; when 000101 = val(7 downto 4) := 1011; when 000110 = val(7 downto 4) := 1110; when 000111 = val(7 downto 4) := 0111; when 001000 = val(7 downto 4) := 1111; when 001001 = val(7 downto 4) := 0100; when 001010 = val(7 downto 4) := 0000; when

34、001011 = val(7 downto 4) := 1001; when 001100 = val(7 downto 4) := 1000; when 001101 = val(7 downto 4) := 0001; when 001110 = val(7 downto 4) := 1101; when 001111 = val(7 downto 4) := 1010; when 010000 = val(7 downto 4) := 0011; when 010001 = val(7 downto 4) := 1110; when 010010 = val(7 downto 4) :=

35、 1100; when 010011 = val(7 downto 4) := 0011; when 010100 = val(7 downto 4) := 1001; when 010101 = val(7 downto 4) := 0101; when 010110 = val(7 downto 4) := 0111; when 010111 = val(7 downto 4) := 1100; when 011000 = val(7 downto 4) := 0101; when 011001 = val(7 downto 4) := 0010; when 011010 = val(7

36、downto 4) := 1010; when 011011 = val(7 downto 4) := 1111; when 011100 = val(7 downto 4) := 0110; when 011101 = val(7 downto 4) := 1000; when 011110 = val(7 downto 4) := 0001; when 011111 = val(7 downto 4) := 0110; when 100000 = val(7 downto 4) := 0001; when 100001 = val(7 downto 4) := 0110; when 100

37、010 = val(7 downto 4) := 0100; when 100011 = val(7 downto 4) := 1011; when 100100 = val(7 downto 4) := 1011; when 100101 = val(7 downto 4) := 1101; when 100110 = val(7 downto 4) := 1101; when 100111 = val(7 downto 4) := 1000; when 101000 = val(7 downto 4) := 1100; when 101001 = val(7 downto 4) := 00

38、01; when 101010 = val(7 downto 4) := 0011; when 101011 = val(7 downto 4) := 0100; when 101100 = val(7 downto 4) := 0111; when 101101 = val(7 downto 4) := 1010; when 101110 = val(7 downto 4) := 1110; when 101111 = val(7 downto 4) := 0111; when 110000 = val(7 downto 4) := 1010; when 110001 = val(7 dow

39、nto 4) := 1001; when 110010 = val(7 downto 4) := 1111; when 110011 = val(7 downto 4) := 0101; when 110100 = val(7 downto 4) := 0110; when 110101 = val(7 downto 4) := 0000; when 110110 = val(7 downto 4) := 1000; when 110111 = val(7 downto 4) := 1111; when 111000 = val(7 downto 4) := 0000; when 111001 =

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 小学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁