gui: Allow --use-time with an offset

Prior to this patch, --use-time only worked on the CLI as it was a
"one-shot" computation.  But it may be useful to specify a time offset
when using the GUI to compensate for time skew on other copies of the
same token (either hard or soft).

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
sdtid: Add leading S/N zeroes when parsing hard token XML files

There are a couple of assumptions built into the code that token serial
numbers are 12 digits long:

 - The tokencode calculation (key_from_time()) uses 8 digits from the
   serial number.  If we pick the wrong 8 digits, then the wrong result
   will be generated.

 - Generation of V2 ctf strings assumes that the serial number is 12
   digits long, because the serial number is copied verbatim into a fixed
   12-character-long field of the output string.

In some places like decrypt_seed() we'll still need to use the short
number (struct sdtid->sn) but in other places we need the padded number
(struct securid_token->serial).

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
securid: v3: Add sanity check on serial number length

Short serial numbers can cause various other modules to malfunction and
may lead to bad memory accesses.  Ban them.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
added tests

Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
tests: Add a few more cases for --sdtid and --v3 tokens

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
autoconf: Add configure option --enable-valgrind

Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
autoconf: Fix up --enable-debug handling

Respect $enableval, add [default=no] to help text, and add -fno-inline.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
travis: Run "make check" under valgrind on each new commit

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Start moving crypto wrappers into a separate module

Since we want to be able to use nettle/tomcrypt/... interchangeably,
we will want to call generic wrapper functions instead of directly
invoking the crypto library.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
stc: Move AES wrappers into stc-tomcrypt.c

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
securid: Make securid_rand() crypto-library-agnostic

rng_get_bytes() typically just reads /dev/urandom anyway.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
stc: Move sha1 and sha256 wrappers into stc-tomcrypt.c

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
stc: Add base64 wrappers to stc-tomcrypt.c

securid.c is now <tomcrypt.h>-free.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
stc: Move RSA signature wrapper into stc-tomcrypt.c

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
autoconf: Probe libtomcrypt for RSA support

As seen in Bug #13, not all tomcrypt packages link against libtommath.
Catch this at ./configure time so that we can substitute another crypto
library if available.  Or maybe link with TomsFastMath if that is
available instead.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
autoconf: Use generic CRYPTO_* names in Makefile.am

This will make it easier to substitute a different crypto library.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Initial commit of nettle support

Add stc-nettle.c wrappers and autoconf magic.  This passes "make check".
Tested on nettle/hogweed 2.4 (Ubuntu 12.04) and 2.7 (Ubuntu 14.04).

Fixes #12.

Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
travis: Add test build using nettle

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
README: mention nettle as dependency