]> git.xonotic.org Git - xonotic/d0_blind_id.git/commitdiff
make auto* hackery work, fix errors
authorRudolf Polzer <divverent@alientrap.org>
Thu, 2 Sep 2010 05:45:51 +0000 (07:45 +0200)
committerRudolf Polzer <divverent@alientrap.org>
Thu, 2 Sep 2010 05:45:51 +0000 (07:45 +0200)
configure.ac
d0_bignum-openssl.c
main.c

index ce36408ad6e63eb17f31ff3ce881df9751bd7def..63d299262b64983bed03017632f43f235ad48117 100644 (file)
@@ -4,15 +4,12 @@ AM_INIT_AUTOMAKE([-Wall foreign])
 AC_PROG_CC
 AC_PROG_LIBTOOL
 
-AC_ARG_WITH(openssl, AS_HELP_STRING([--with-openssl], [Use OpenSSL instead of GMP (beware of the OpenSSL license)]), [enable_openssl=$enableval], [enable_openssl=no])
-AM_CONDITIONAL(ENABLE_OPENSSL, [test x$enable_openssl = xyes])
+AC_ARG_WITH(openssl, AS_HELP_STRING([--with-openssl], [Use OpenSSL instead of GMP (beware of the OpenSSL license)]), [with_openssl=$enableval], [with_openssl=no])
+AM_CONDITIONAL(WITH_OPENSSL, [test x"$with_openssl" != xno])
 
-if test x$enable_openssl = xyes
-then
-       AC_SEARCH_LIBS(BN_init, ssl, , [AC_MSG_ERROR([OpenSSL not found, see http://www.openssl.org/, or try --without-openssl])])
-else
-       AC_SEARCH_LIBS(__gmpz_init, gmp, , [AC_MSG_ERROR([GNU MP not found, see http://gmplib.org/, or try --with-openssl])])
-fi
+AS_IF([test x"$with_openssl" != xno],
+       [AC_SEARCH_LIBS(BN_init, ssl, , [AC_MSG_ERROR([OpenSSL not found, see http://www.openssl.org/, or try --without-openssl])])],
+       [AC_SEARCH_LIBS(__gmpz_init, gmp, , [AC_MSG_ERROR([GNU MP not found, see http://gmplib.org/, or try --with-openssl])])])
 
 AC_ARG_ENABLE(rijndael, AS_HELP_STRING([--disable-rijndael], [Disable build of the d0_rijndael library]), [enable_aes=$enableval], [enable_aes=yes])
 AM_CONDITIONAL(ENABLE_RIJNDAEL, [test x$enable_aes = xyes])
index ad04a1fbd46c7f0ca428662968d868e754be32c2..60bba7370a4871b13b46ffd9121bfb985e32508f 100644 (file)
@@ -19,6 +19,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include "d0_bignum.h"
 
+#include <assert.h>
+#include <string.h>
 #include <openssl/bn.h>
 
 struct d0_bignum_s
@@ -27,14 +29,14 @@ struct d0_bignum_s
 };
 
 static d0_bignum_t temp;
-static BN_CTX ctx;
+static BN_CTX *ctx;
 
 #include <time.h>
 #include <stdio.h>
 
 WARN_UNUSED_RESULT BOOL d0_bignum_INITIALIZE(void)
 {
-       BN_CTX_init(&ctx);
+       ctx = BN_CTX_new();
        d0_bignum_init(&temp);
        return 1;
 }
@@ -42,7 +44,8 @@ WARN_UNUSED_RESULT BOOL d0_bignum_INITIALIZE(void)
 void d0_bignum_SHUTDOWN(void)
 {
        d0_bignum_clear(&temp);
-       BN_CTX_free(&ctx);
+       BN_CTX_free(ctx);
+       ctx = NULL;
 }
 
 BOOL d0_iobuf_write_bignum(d0_iobuf_t *buf, const d0_bignum_t *bignum)
@@ -55,7 +58,7 @@ BOOL d0_iobuf_write_bignum(d0_iobuf_t *buf, const d0_bignum_t *bignum)
                count = BN_num_bytes(&bignum->z);
                if(count > sizeof(numbuf) - 1)
                        return 0;
-               BN_bn2bin(numbuf+1, &bignum->z);
+               BN_bn2bin(&bignum->z, numbuf+1);
        }
        return d0_iobuf_write_packet(buf, numbuf, count + 1);
 }
@@ -230,7 +233,7 @@ d0_bignum_t *d0_bignum_sub(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum
 d0_bignum_t *d0_bignum_mul(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *b)
 {
        if(!r) r = d0_bignum_new(); if(!r) return NULL;
-       BN_mul(&r->z, &a->z, &b->z);
+       BN_mul(&r->z, &a->z, &b->z, ctx);
        return r;
 }
 
@@ -241,13 +244,13 @@ d0_bignum_t *d0_bignum_divmod(d0_bignum_t *q, d0_bignum_t *m, const d0_bignum_t
        if(q)
        {
                if(m)
-                       BN_div(&q->z, &m->z, &a->z, &b->z, &ctx);
+                       BN_div(&q->z, &m->z, &a->z, &b->z, ctx);
                else
-                       BN_div(&q->z, NULL, &a->z, &b->z, &ctx);
+                       BN_div(&q->z, NULL, &a->z, &b->z, ctx);
                assert(!"I know this code is broken (rounds towards zero), need handle negative correctly");
        }
        else
-               BN_nnmod(&q->z, NULL, &a->z, &b->z, &ctx);
+               BN_nnmod(&q->z, &a->z, &b->z, ctx);
        if(m)
                return m;
        else
@@ -257,33 +260,33 @@ d0_bignum_t *d0_bignum_divmod(d0_bignum_t *q, d0_bignum_t *m, const d0_bignum_t
 d0_bignum_t *d0_bignum_mod_add(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *b, const d0_bignum_t *m)
 {
        if(!r) r = d0_bignum_new(); if(!r) return NULL;
-       BN_mod_add(&r->z, &a->z, &b->z, &m->z, &ctx);
+       BN_mod_add(&r->z, &a->z, &b->z, &m->z, ctx);
        return r;
 }
 
 d0_bignum_t *d0_bignum_mod_mul(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *b, const d0_bignum_t *m)
 {
        if(!r) r = d0_bignum_new(); if(!r) return NULL;
-       BN_mod_mul(&r->z, &a->z, &b->z, &m->z, &ctx);
+       BN_mod_mul(&r->z, &a->z, &b->z, &m->z, ctx);
        return r;
 }
 
 d0_bignum_t *d0_bignum_mod_pow(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *b, const d0_bignum_t *m)
 {
        if(!r) r = d0_bignum_new(); if(!r) return NULL;
-       BN_mod_exp(&r->z, &a->z, &b->z, &m->z, &ctx);
+       BN_mod_exp(&r->z, &a->z, &b->z, &m->z, ctx);
        return r;
 }
 
 BOOL d0_bignum_mod_inv(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *m)
 {
        // here, r MUST be set, as otherwise we cannot return error state!
-       return !!BN_mod_inverse(&r->z, &a->z, &m->z, &ctx);
+       return !!BN_mod_inverse(&r->z, &a->z, &m->z, ctx);
 }
 
 int d0_bignum_isprime(d0_bignum_t *r, int param)
 {
-       return BN_is_prime(&r->z, param, NULL, &ctx, NULL);
+       return BN_is_prime(&r->z, param, NULL, ctx, NULL);
 }
 
 d0_bignum_t *d0_bignum_gcd(d0_bignum_t *r, d0_bignum_t *s, d0_bignum_t *t, const d0_bignum_t *a, const d0_bignum_t *b)
@@ -294,7 +297,7 @@ d0_bignum_t *d0_bignum_gcd(d0_bignum_t *r, d0_bignum_t *s, d0_bignum_t *t, const
        else if(t)
                assert(!"Extended gcd not implemented");
        else
-               BN_gcd(&r->z, &a->z, &b->z, &ctx);
+               BN_gcd(&r->z, &a->z, &b->z, ctx);
        return r;
 }
 
diff --git a/main.c b/main.c
index 2e8e24e1ef344508a0e3b5d56345dacb937d7ce8..d52a8bf6ce6a1bbabf11a6ef5faf81f0283ddb87 100644 (file)
--- a/main.c
+++ b/main.c
@@ -67,7 +67,7 @@ int main(int argc, char **argv)
        ctx_other = d0_blind_id_new();
 
        printf("keygen RSA...\n");
-       if(!d0_blind_id_generate_private_key(ctx_self, 1024))
+       if(!d0_blind_id_generate_private_key(ctx_self, 256))
                errx(1, "keygen fail");
        buf2size = sizeof(buf2) - 1;
        if(!d0_blind_id_fingerprint64_public_key(ctx_self, buf2, &buf2size))