diff options
author | Martin Willi <martin@strongswan.org> | 2009-08-26 14:08:20 +0200 |
---|---|---|
committer | Martin Willi <martin@strongswan.org> | 2009-08-26 14:08:20 +0200 |
commit | d16fd64d395ed4467c69c9c67aa26777132ec757 (patch) | |
tree | cf96e007a15283f3301f5183222004eaec96fc35 | |
parent | 500f515a64311d3c07d163d24da9730aefc967bd (diff) | |
download | strongswan-d16fd64d395ed4467c69c9c67aa26777132ec757.tar.bz2 strongswan-d16fd64d395ed4467c69c9c67aa26777132ec757.tar.xz |
openac (and tools) do not depend on gmp anymore
-rw-r--r-- | configure.in | 4 | ||||
-rw-r--r-- | src/openac/Makefile.am | 2 | ||||
-rwxr-xr-x | src/openac/openac.c | 74 |
3 files changed, 20 insertions, 60 deletions
diff --git a/configure.in b/configure.in index 002af39b7..061cb1177 100644 --- a/configure.in +++ b/configure.in @@ -862,10 +862,6 @@ if test x$fips_prf = xtrue; then sha1=true; fi -if test x$tools = xtrue; then - gmp=true; -fi - if test x$smp = xtrue; then xml=true fi diff --git a/src/openac/Makefile.am b/src/openac/Makefile.am index 005486779..b9b864838 100644 --- a/src/openac/Makefile.am +++ b/src/openac/Makefile.am @@ -8,5 +8,5 @@ AM_CFLAGS = \ -DSTRONGSWAN_CONF=\"${strongswan_conf}\" \ -DIPSEC_PLUGINDIR=\"${plugindir}\" \ -DPLUGINS=\""${libstrongswan_plugins}\"" -openac_LDADD = $(top_builddir)/src/libstrongswan/libstrongswan.la -lgmp +openac_LDADD = $(top_builddir)/src/libstrongswan/libstrongswan.la diff --git a/src/openac/openac.c b/src/openac/openac.c index 49b376fe4..db9959803 100755 --- a/src/openac/openac.c +++ b/src/openac/openac.c @@ -29,7 +29,6 @@ #include <getopt.h> #include <ctype.h> #include <time.h> -#include <gmp.h> #include <library.h> #include <debug.h> @@ -78,55 +77,24 @@ static void usage(const char *message) ); } - -/** - * convert a chunk into a multi-precision integer - */ -static void chunk_to_mpz(chunk_t chunk, mpz_t number) -{ - mpz_import(number, chunk.len, 1, 1, 1, 0, chunk.ptr); -} - -/** - * convert a multi-precision integer into a chunk - */ -static chunk_t mpz_to_chunk(mpz_t number) -{ - chunk_t chunk; - - chunk.len = 1 + mpz_sizeinbase(number, 2)/BITS_PER_BYTE; - chunk.ptr = mpz_export(NULL, NULL, 1, chunk.len, 1, 0, number); - if (chunk.ptr == NULL) - { - chunk.len = 0; - } - return chunk; -} - /** * read the last serial number from file */ static chunk_t read_serial(void) { - mpz_t number; - - char buf[BUF_LEN], buf1[BUF_LEN]; - chunk_t hex_serial = { buf, BUF_LEN }; - chunk_t last_serial = { buf1, BUF_LEN }; - chunk_t serial; - - FILE *fd = fopen(OPENAC_SERIAL, "r"); - - /* last serial number defaults to 0 */ - *last_serial.ptr = 0x00; - last_serial.len = 1; - + chunk_t hex, serial = chunk_empty; + char one[] = {0x01}; + FILE *fd; + + fd = fopen(OPENAC_SERIAL, "r"); if (fd) { - if (fscanf(fd, "%s", hex_serial.ptr)) + hex = chunk_alloca(64); + hex.len = fread(hex.ptr, 1, hex.len, fd); + if (hex.len) { - hex_serial.len = strlen(hex_serial.ptr); - last_serial = chunk_from_hex(hex_serial, last_serial.ptr); + serial = chunk_alloca((hex.len / 2) + (hex.len % 2)); + serial = chunk_from_hex(hex, serial.ptr); } fclose(fd); } @@ -134,19 +102,15 @@ static chunk_t read_serial(void) { DBG1(" file '%s' does not exist yet - serial number set to 01", OPENAC_SERIAL); } - - /** - * conversion of read serial number to a multiprecision integer - * and incrementing it by one - * and representing it as a two's complement octet string - */ - mpz_init(number); - chunk_to_mpz(last_serial, number); - mpz_add_ui(number, number, 0x01); - serial = mpz_to_chunk(number); - mpz_clear(number); - - return serial; + if (!serial.len) + { + return chunk_clone(chunk_create(one, 1)); + } + if (chunk_increment(serial)) + { /* overflow, prepend 0x01 */ + return chunk_cat("cc", chunk_create(one, 1), serial); + } + return chunk_clone(serial); } /** |