From d35ad000c51d317da2f222cb8c1adf91c2276bf8 Mon Sep 17 00:00:00 2001 From: niklas Date: Fri, 7 Apr 2000 22:03:51 +0000 Subject: [PATCH] gmp_util.c: Merge with EOM 1.4 gmp_util.h: Merge with EOM 1.2 author: niklas Ugly multi-implementation MP support, will get better later --- sbin/isakmpd/gmp_util.c | 49 +++++++++++++++++++++++++++++++---------- sbin/isakmpd/gmp_util.h | 12 +++++----- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/sbin/isakmpd/gmp_util.c b/sbin/isakmpd/gmp_util.c index 9ecb0fb425e..22e9c724592 100644 --- a/sbin/isakmpd/gmp_util.c +++ b/sbin/isakmpd/gmp_util.c @@ -1,5 +1,5 @@ -/* $OpenBSD: gmp_util.c,v 1.5 1999/04/19 19:54:53 niklas Exp $ */ -/* $EOM: gmp_util.c,v 1.3 1999/04/02 00:57:39 niklas Exp $ */ +/* $OpenBSD: gmp_util.c,v 1.6 2000/04/07 22:03:51 niklas Exp $ */ +/* $EOM: gmp_util.c,v 1.4 2000/04/07 19:40:15 niklas Exp $ */ /* * Copyright (c) 1998 Niels Provos. All rights reserved. @@ -36,45 +36,70 @@ */ #include -#include #include "sysdep.h" #include "gmp_util.h" +#include "math_mp.h" /* Various utility functions for gmp, used in more than one module */ u_int32_t -mpz_sizeinoctets (mpz_ptr a) +mpz_sizeinoctets (math_mp_t a) { +#if MP_FLAVOUR == MP_FLAVOUR_GMP return (7 + mpz_sizeinbase (a, 2)) >> 3; +#elif MP_FLAVOUR == MP_FLAVOUR_OPENSSL + return BN_num_bytes (a); +#endif } void -mpz_getraw (u_int8_t *raw, mpz_ptr v, u_int32_t len) +mpz_getraw (u_int8_t *raw, math_mp_t v, u_int32_t len) { - mpz_t a, tmp; + math_mp_t a; - mpz_init_set (a, v); - mpz_init (tmp); +#if MP_FLAVOUR == MP_FLAVOUR_GMP +#error "XXX not implemented yet" +#elif MP_FLAVOUR == MP_FLAVOUR_OPENSSL + /* XXX bn2bin? */ + a = BN_dup (v); +#endif while (len-- > 0) +#if MP_FLAVOUR == MP_FLAVOUR_GMP raw[len] = mpz_fdiv_qr_ui (a, tmp, a, 256); +#elif MP_FLAVOUR == MP_FLAVOUR_OPENSSL + raw[len] = BN_div_word (a, 256); +#endif - mpz_clear (a); - mpz_clear (tmp); +#if MP_FLAVOUR == MP_FLAVOUR_GMP +#error "XXX not implemented yet" +#elif MP_FLAVOUR == MP_FLAVOUR_OPENSSL + BN_clear_free (a); +#endif } void -mpz_setraw (mpz_ptr d, u_int8_t *s, u_int32_t l) +mpz_setraw (math_mp_t d, u_int8_t *s, u_int32_t l) { u_int32_t i; - mpz_set_ui (d, 0); +#if MP_FLAVOUR == MP_FLAVOUR_GMP +#error "XXX not implemented yet" +#elif MP_FLAVOUR == MP_FLAVOUR_OPENSSL + /* XXX bin2bn? */ + BN_set_word (d, 0); +#endif for (i = 0; i < l; i++) { +#if MP_FLAVOUR == MP_FLAVOUR_GMP mpz_mul_ui (d, d, 256); mpz_add_ui (d, d, s[i]); +#elif MP_FLAVOUR == MP_FLAVOUR_OPENSSL + BN_mul_word (d, 256); + BN_add_word (d, s[i]); +#endif } } diff --git a/sbin/isakmpd/gmp_util.h b/sbin/isakmpd/gmp_util.h index d0d4c54940a..7d064694984 100644 --- a/sbin/isakmpd/gmp_util.h +++ b/sbin/isakmpd/gmp_util.h @@ -1,5 +1,5 @@ -/* $OpenBSD: gmp_util.h,v 1.3 1998/11/17 11:10:11 niklas Exp $ */ -/* $EOM: gmp_util.h,v 1.1 1998/08/03 19:32:36 provos Exp $ */ +/* $OpenBSD: gmp_util.h,v 1.4 2000/04/07 22:03:51 niklas Exp $ */ +/* $EOM: gmp_util.h,v 1.2 2000/04/07 19:40:15 niklas Exp $ */ /* * Copyright (c) 1998 Niels Provos. All rights reserved. @@ -37,8 +37,10 @@ #ifndef _GMP_UTIL_H_ #define _GMP_UTIL_H_ -u_int32_t mpz_sizeinoctets (mpz_ptr); -void mpz_getraw (u_int8_t *, mpz_ptr, u_int32_t); -void mpz_setraw (mpz_ptr, u_int8_t *, u_int32_t); +#include "math_mp.h" + +u_int32_t mpz_sizeinoctets (math_mp_t); +void mpz_getraw (u_int8_t *, BIGNUM *, u_int32_t); +void mpz_setraw (math_mp_t, u_int8_t *, u_int32_t); #endif /* _GMP_UTIL_H_ */ -- 2.20.1