Sebilj, Sarajevo, Bosnia and Herzegovina

Installing crypto++ with ns3

Installing crypto++ (libcryptopp) on Ubuntu

sudo apt-get install libcrypto++-dev libcrypto++-doc libcrypto++-utils

On distributions which use yum (such as Fedora):

yum install cryptopp cryptopp-devel

More details on: http://stackoverflow.com/questions/19187990/installing-crypto-libcryptopp-on-ubuntu and https://www.cryptopp.com/wiki/Linux

Then compile and run some test.cc source file
Make testcode.cc which contains following:

/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
#include <iostream>
int main (int argc, char **argv)
{
    std::cout << "Hello\n";
    return 0;
}

Execute in the same folder:

g++ -Wall testcode.cc -o testcode
./test 

More details on : http://pages.cs.wisc.edu/~beechung/ref/gcc-intro.html

To integrate qcrypto in ns3 open the scriptfile wscript in your ns3 root directory and find “env = conf.env” code. In next line add following code:

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')

Then find the code “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

and replace it with following:

    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

Then find lines with code “obj.install_path = None”, there should be two such lines and after both of them add “obj.uselib = ‘CRYPTOPP'”. It should look like this:

            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' 

Finally reconfigure your ns3

sudo ./waf distclean
sudo ./waf configure (with any other options that you normally would add)
sudo ./waf

In your scripts simple include required library such as:

#include <crypto++/aes.h>;
#include <crypto++/modes.h>;
#include <crypto++/filters.h>;

Enjoy!

Update on 10.10.2016: Please find my wscript connected with crypto++ for ns3.26 here: wscript3.26