DES算法使用vhdl硬件语言实现

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

libraryieee;useieee.std_logic_1164.all;useieee.std_logic_arith.all;useieee.std_logic_unsigned.all;packagedes_libiscomponentdesport(clk:instd_logic;reset:instd_logic;encrypt:instd_logic;key_in:instd_logic_vector(55downto0);din:instd_logic_vector(63downto0);din_valid:instd_logic;busy:bufferstd_logic;dout:outstd_logic_vector(63downto0);dout_valid:outstd_logic);endcomponent;componentdes_roundport(clk:instd_logic;reset:instd_logic;stall:instd_logic;encrypt_in:instd_logic;encrypt_shift:instd_logic_vector(4downto0);decrypt_shift:instd_logic_vector(4downto0);key_in:instd_logic_vector(55downto0);din:instd_logic_vector(63downto0);din_valid:instd_logic;encrypt_out:outstd_logic;key_out:outstd_logic_vector(55downto0);dout:outstd_logic_vector(63downto0);dout_valid:outstd_logic);endcomponent;--Initalpermutationfunctiondes_ip(din:std_logic_vector(63downto0))returnstd_logic_vector;--Finalpermutationfunctiondes_fp(din:std_logic_vector(63downto0))returnstd_logic_vector;--Keypermutation,convertsa64bitkeyintoa56bitkey,ignoringparityfunctiondes_kp(din:std_logic_vector(63downto0))returnstd_logic_vector;--CompressionPermutation,convertsa56bitkeyintoa48bits.functiondes_cp(din:std_logic_vector(55downto0))returnstd_logic_vector;--Expansionpermutationfunctiondes_ep(din:std_logic_vector(31downto0))returnstd_logic_vector;--S-BoxSubstitution,48bitsin,32bitsout.functiondes_sbox(din:std_logic_vector(47downto0))returnstd_logic_vector;--P-BoxPermutationfunctiondes_pbox(din:std_logic_vector(31downto0))returnstd_logic_vector;--KeyShiftfunctiondes_keyshift(din:std_logic_vector(55downto0);n:std_logic_vector(4downto0))returnstd_logic_vector;enddes_lib;----------------------------------------------------------------------------libraryieee;useieee.std_logic_1164.all;useieee.std_logic_arith.all;useieee.std_logic_unsigned.all;librarywork;usework.des_lib.all;packagebodydes_libis----------------------------------------------------------Initalpermutationfunctiondes_ip(din:std_logic_vector(63downto0))returnstd_logic_vectorisvariableval:std_logic_vector(63downto0);beginval:=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-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-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-7);returnval;enddes_ip;----------------------------------------------------------Finalpermutationfunctiondes_fp(din:std_logic_vector(63downto0))returnstd_logic_vectorisvariableval:std_logic_vector(63downto0);beginval:=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)&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)&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)&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);returnval;enddes_fp;----------------------------------------------------------Keypermutation,convertsa64bitkeyintoa56bitkey,ignoringparityfunctiondes_kp(din:std_logic_vector(63downto0))returnstd_logic_vectorisvariableval:std_logic_vector(55downto0);beginval:=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)&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)&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);returnval;enddes_kp;----------------------------------------------------------CompressionPermutation,convertsa56bitkeyintoa48bits.functiondes_cp(din:std_logic_vector(55downto0))returnstd_logic_vectorisvariableval:std_logic_vector(47downto0);beginval:=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(56-12)&din(56-4)&din(56-26)&din(56-8)&din(56-16)&din(56-7)&di

1 / 15
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功