希望在ns3仿真中使用一些密碼學(xué)算法。以下為整理的安裝過(guò)程,來(lái)源見(jiàn)參考文獻(xiàn)。在ubuntu18.04可行。
安裝crypto++
ubuntu使用的包管理系統(tǒng)apt中的crypto++版本比較舊了翎碑。不介意用舊版,或者是使用的是基于debian的發(fā)行版(yum)的話可以使用:
sudo apt-get install libcrypto++-dev libcrypto++-doc libcrypto++-utils
或者相應(yīng)的
yum install cryptopp cryptopp-devel
最新版可以下載源碼編譯安裝:
首先下載cryptopp的源碼:https://www.cryptopp.com/#download之斯,并解壓到一個(gè)工作文件夾中日杈。
比如:
mkdir cryptopp
cd cryptopp/
wget https://www.cryptopp.com/cryptopp820.zip
unzip -a cryptopp820.zip
其中cryptopp820.zip可以相應(yīng)換成你希望的版本。
然后是build。如果想定制makefile flag可以參考crypto++的官方文檔莉擒。執(zhí)行:
make static dynamic cryptest.exe
build完可以執(zhí)行
./cryptest.exe v
./cryptest.exe tv all
來(lái)測(cè)試build得到的庫(kù)酿炸。
最后是安裝庫(kù):
sudo make install PREFIX=/usr/local
sudo mkdir -p /usr/local/include/cryptopp
sudo cp *.h /usr/local/include/cryptopp
sudo chmod 755 /usr/local/include/cryptopp
sudo chmod 644 /usr/local/include/cryptopp/*.h
sudo mkdir -p /usr/local/lib
sudo cp libcryptopp.a /usr/local/lib
sudo chmod 644 /usr/local/lib/libcryptopp.a
sudo mkdir -p /usr/local/bin
sudo cp cryptest.exe /usr/local/bin
sudo chmod 755 /usr/local/bin/cryptest.exe
sudo mkdir -p /usr/local/share/cryptopp
sudo cp -r TestData /usr/local/share/cryptopp
sudo cp -r TestVectors /usr/local/share/cryptopp
sudo chmod 755 /usr/local/share/cryptopp
sudo chmod 755 /usr/local/share/cryptopp/TestData
sudo chmod 755 /usr/local/share/cryptopp/TestVectors
sudo chmod 644 /usr/local/share/cryptopp/TestData/*.dat
sudo chmod 644 /usr/local/share/cryptopp/TestVectors/*.txt
并配置shared library鏈接:
sudo ldconfig
修改wscript
打開(kāi)ns3根目錄(waf所在目錄)下的wscript文件。
搜索
env = conf.env
并在下面添加:
conf.env['lpp']
crypto= conf.check(mandatory=True, lib='cryptopp', uselib_store='cryptopp')
conf.env.append_value('CXXDEFINES', 'ENABLE_CRYPTOPP')
conf.env.append_value('CCDEFINES', 'ENABLE_CRYPTOPP')
搜索
if program.env[‘ENABLE_STATIC_NS3’]:
找到代碼
if program.env['ENABLE_STATIC_NS3']:
if sys.platform == 'darwin':
program.env.STLIB_MARKER = '-Wl,-all_load'
else:
program.env.STLIB_MARKER = '-Wl,-Bstatic,--whole-archive'
program.env.SHLIB_MARKER = '-Wl,-Bdynamic,--no-whole-archive'
else:
if program.env.DEST_BINFMT == 'elf':
# All ELF platforms are impacted but only the gcc compiler has a flag to fix it.
if 'gcc' in (program.env.CXX_NAME, program.env.CC_NAME):
program.env.append_value ('SHLIB_MARKER', '-Wl,--no-as-needed')
return program
并修改為:
if program.env['ENABLE_STATIC_NS3']:
if sys.platform == 'darwin':
program.env.STLIB_MARKER = '-Wl,-all_load,-lcryptopp'
else:
program.env.STLIB_MARKER = '-Wl,-Bstatic,--whole-archive,-lcryptopp'
program.env.SHLIB_MARKER = '-Wl,-Bdynamic,--no-whole-archive,-lcryptopp'
else:
if program.env.DEST_BINFMT == 'elf':
# All ELF platforms are impacted but only the gcc compiler has a flag to fix it.
if 'gcc' in (program.env.CXX_NAME, program.env.CC_NAME):
program.env.append_value ('SHLIB_MARKER', '-Wl,--no-as-needed,-lcryptopp')
return program
搜索
obj.install_path = None
應(yīng)有兩個(gè)結(jié)果涨冀,在每一個(gè)后面都加上
obj.uselib = ‘CRYPTOPP'
修改完之后這段代碼應(yīng)形如:
if os.path.isdir(os.path.join("scratch", filename)):
obj = bld.create_ns3_program(filename, all_modules)
obj.path = obj.path.find_dir('scratch').find_dir(filename)
obj.source = obj.path.ant_glob('*.cc')
obj.target = filename
obj.name = obj.target
obj.install_path = None
obj.uselib = 'CRYPTOPP'
elif filename.endswith(".cc"):
name = filename[:-len(".cc")]
obj = bld.create_ns3_program(name, all_modules)
obj.path = obj.path.find_dir('scratch')
obj.source = filename
obj.target = name
obj.name = obj.target
obj.install_path = None
obj.uselib = 'CRYPTOPP'
重新配置編譯ns3
sudo ./waf distclean
sudo ./waf configure (你通常使用的配置參數(shù))
sudo ./waf
此時(shí)你已成功的在ns3中安裝了crypto++填硕。比如如果需要SM3庫(kù),可以在你的ns3腳本中
#include <crypto++/sm3.h>; //如果你通過(guò)apt-get安裝crypto++鹿鳖,使用這個(gè)
#include <cryptopp/sm3.h>; //如果你按本文方法從源碼安裝crypto++扁眯,使用這個(gè)
來(lái)使用。
參考文獻(xiàn)
https://www.mehic.info/2016/04/installing-and-crypto-libcryptopp-with-ns3/