PBC Library - Pairing-Based Cryptography (2024)

This guide is aimed at developers who are familiar with using Linuxbut are less acquainted with typical Linux development tools,and who do not have root access to the box they are working on.It is written with PBC in mind, but should work for most libraries.

This Program LibraryHOWTO contains a thorough explanation of why libraries are setupthe way they are in Linux.

For information on how to use the PBC library, pleaseconsult the manual.One of the chapters is a tutorial.

You can skim most of the text and just type in what you see in theexamples.

Compiling and Installing Libraries

For most libraries,once you have decompressed the source package, type the followingto install it to the .local subdirectory of your home directory.

 $ ./configure --prefix=$HOME/.local $ make $ make install

Occasionally a library does not conform to this standard, in which caseyou may have to edit a Makefile or similar to tell it where to install.In this case, there ought to be documentation specifying how to do this.

We call the destination directory .local becauseit functions as the system-wide /usr/local directory (exceptthat it’s for your user account only), and the preceding period prevents it fromcluttering directory listings. (Of course, if you prefer to see everythingin your directory listings you don’t need the period, and in this caseyou may even wish to use --prefix=$HOME.)

If everything worked, you should see new files in assortedsubdirectories of $HOME/.local with names such asinclude, lib and bin.

Compiling Your Code

A PBC program foo.c might look like the following.

#include "pbc.h"int main(void){ /* call PBC functions */ return 0;}

Simply typing gcc -o foo foo.c will fail for two reasons.

Firstly,gcc does not know where to find the include file pbc.h.You must explicitly tell gcc where to do this, using the-I option, because gcc normally only searchesthe standardsystem-wide include directories.

However, even if this is done correctly, the compilation still fails,this time because the library file (which contains the compiled libraryroutines) has not been mentioned in any way. Not only do you have to mentionwhich library you want to link with using the -l option,you must also tell gcc where to find itbecause the library is somewhere in your home directory andnot in a standard location.This can be done with the -L option.

But even if you did all this, although your program would compile, it wouldnot run. This is because it is dynamically linked (that is, the libraryroutines are not placed in the binary so when run, the program needs toknow where to find the library).

There are two ways around this. One is to use the -staticoption which will put all the required library routines in your binary.Your binary will be a lot bigger, and every time you upgrade your library youhave to recompile the binary. On the other hand, it may be faster.

The other way is to embed the location of the library in the binary.This can only be done by the linker, not the compiler, so we use the-Wl option to pass another option on to the linker.The linker option we want is the -rpath option (which is sometimescalled the -R option).

Thus to compile foo.c type:

 $ gcc -o foo foo.c -I ~/.local/include/pbc -L ~/.local/lib -Wl,-rpath ~/.local/lib -l pbc

LD_LIBRARY_PATH

Actually, there is another way, but it isconsidered harmful.

If you add $HOME/.local/lib tothe environment variable named LD_LIBRARY_PATHall binaries will now look in that directory for any libraries they need.

I recommend only doing this in special situations. For example,if you moved the library to a different location and want to testa binary without recompiling, or if you forgot to usethe rpath option and you want to test the binary without recompiling.

Makefiles

Typing in all these options is an annoyance. You can eliminate the needfor the -L and -rpath options with environmentvariables LDFLAGS or LD_RUN_PATH,but you still have to type the other ones.

One solution to this is to usethe make program.You should eventually follow a proper make tutorial,but for now, createa file named Makefile with the following contents.

target: gcc -o foo foo.c -I ~/.local/include/pbc -L ~/.local/lib -Wl,-rpath ~/.local/lib -l pbc

The second line must begin with a tab and not spaces,otherwise it will not work.

Now running make will compile your program.

But Why…

You may be wondering why there’s a pbc on the end of the -Ioption but not the -L option. This is PBC’s fault: instead ofhaving a single header file named "pbc.h", there are many otherheader files that the developer never needs to know about, and to stopthem messing up the include directory, all the PBC header files areplaced in a separate subdirectory of their own. Other libraries alsofollow this convention.

It might seem pointless to have an rpath option. Why nothave the binary automaticallysearch for the library in the directory specified by the-L option? While this may suit you now, situationswhere this behaviour is undesirable can easily occur.For example, say you don’t have root access on the system you developon and the "Foo" library is not installed (so you need the L option),but on the target systemsthat your binaries end up on, the "Foo" library is always foundin a standard location (so you don’t want the rpath option). Or maybe"Foo" is located somewhere special on the target machine, soyou want rpath to point to a different directory altogether.

PBC Library - Pairing-Based Cryptography (2024)

References

Top Articles
Latest Posts
Article information

Author: Fredrick Kertzmann

Last Updated:

Views: 6194

Rating: 4.6 / 5 (66 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Fredrick Kertzmann

Birthday: 2000-04-29

Address: Apt. 203 613 Huels Gateway, Ralphtown, LA 40204

Phone: +2135150832870

Job: Regional Design Producer

Hobby: Nordic skating, Lacemaking, Mountain biking, Rowing, Gardening, Water sports, role-playing games

Introduction: My name is Fredrick Kertzmann, I am a gleaming, encouraging, inexpensive, thankful, tender, quaint, precious person who loves writing and wants to share my knowledge and understanding with you.