From c03306dde55b9ef0d2073f1376f36b96f84c0679 Mon Sep 17 00:00:00 2001 From: sthen <> Date: Mon, 14 Apr 2014 14:50:09 +0000 Subject: replace PTR_SIZE_INT (only used for VMS) with uintptr_t, tweaks from jca@, makes sense to beck@ --- src/lib/libcrypto/bn/bn.h | 18 ---------- src/lib/libcrypto/bn/bn_mont.c | 2 +- src/lib/libcrypto/bn/bn_nist.c | 66 ++++++++++++++++------------------ src/lib/libcrypto/cryptlib.h | 1 + src/lib/libssl/src/crypto/bn/bn.h | 18 ---------- src/lib/libssl/src/crypto/bn/bn_mont.c | 2 +- src/lib/libssl/src/crypto/bn/bn_nist.c | 66 ++++++++++++++++------------------ src/lib/libssl/src/crypto/cryptlib.h | 1 + 8 files changed, 66 insertions(+), 108 deletions(-) diff --git a/src/lib/libcrypto/bn/bn.h b/src/lib/libcrypto/bn/bn.h index 21a1a3fe35..2e3fab98db 100644 --- a/src/lib/libcrypto/bn/bn.h +++ b/src/lib/libcrypto/bn/bn.h @@ -253,24 +253,6 @@ extern "C" { #define BN_HEX_FMT2 "%08X" #endif -/* 2011-02-22 SMS. - * In various places, a size_t variable or a type cast to size_t was - * used to perform integer-only operations on pointers. This failed on - * VMS with 64-bit pointers (CC /POINTER_SIZE = 64) because size_t is - * still only 32 bits. What's needed in these cases is an integer type - * with the same size as a pointer, which size_t is not certain to be. - * The only fix here is VMS-specific. - */ -#if defined(OPENSSL_SYS_VMS) -# if __INITIAL_POINTER_SIZE == 64 -# define PTR_SIZE_INT long long -# else /* __INITIAL_POINTER_SIZE == 64 */ -# define PTR_SIZE_INT int -# endif /* __INITIAL_POINTER_SIZE == 64 [else] */ -#else /* defined(OPENSSL_SYS_VMS) */ -# define PTR_SIZE_INT size_t -#endif /* defined(OPENSSL_SYS_VMS) [else] */ - #define BN_DEFAULT_BITS 1280 #define BN_FLG_MALLOCED 0x01 diff --git a/src/lib/libcrypto/bn/bn_mont.c b/src/lib/libcrypto/bn/bn_mont.c index 427b5cf4df..a6713ae5b1 100644 --- a/src/lib/libcrypto/bn/bn_mont.c +++ b/src/lib/libcrypto/bn/bn_mont.c @@ -247,7 +247,7 @@ static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont) * trick unconditional memcpy below to perform in-place * "refresh" instead of actual copy. */ m=(0-(size_t)v); - nrp=(BN_ULONG *)(((PTR_SIZE_INT)rp&~m)|((PTR_SIZE_INT)ap&m)); + nrp=(BN_ULONG *)(((uintptr_t)rp&~m)|((uintptr_t)ap&m)); for (i=0,nl-=4; itop = BN_NIST_192_TOP; bn_correct_top(r); @@ -485,8 +485,8 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, } buf; BN_ULONG c_d[BN_NIST_224_TOP], *res; - PTR_SIZE_INT mask; - union { bn_addsub_f f; PTR_SIZE_INT p; } u; + uintptr_t mask; + union { bn_addsub_f f; uintptr_t p; } u; static const BIGNUM _bignum_nist_p_224_sqr = { (BN_ULONG *)_nist_p_224_sqr, sizeof(_nist_p_224_sqr)/sizeof(_nist_p_224_sqr[0]), @@ -599,19 +599,18 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, * to be compared to the modulus and conditionally * adjusted by *subtracting* the latter. */ carry = (int)bn_add_words(r_d,r_d,_nist_p_224[-carry-1],BN_NIST_224_TOP); - mask = 0-(PTR_SIZE_INT)carry; - u.p = ((PTR_SIZE_INT)bn_sub_words&mask) | - ((PTR_SIZE_INT)bn_add_words&~mask); + mask = 0-(uintptr_t)carry; + u.p = ((uintptr_t)bn_sub_words&mask) | + ((uintptr_t)bn_add_words&~mask); } else carry = 1; /* otherwise it's effectively same as in BN_nist_mod_192... */ - mask = 0-(PTR_SIZE_INT)(*u.f)(c_d,r_d,_nist_p_224[0],BN_NIST_224_TOP); - mask &= 0-(PTR_SIZE_INT)carry; + mask = 0-(uintptr_t)(*u.f)(c_d,r_d,_nist_p_224[0],BN_NIST_224_TOP); + mask &= 0-(uintptr_t)carry; res = c_d; - res = (BN_ULONG *)(((PTR_SIZE_INT)res&~mask) | - ((PTR_SIZE_INT)r_d&mask)); + res = (BN_ULONG *)(((uintptr_t)res&~mask) | ((uintptr_t)r_d&mask)); nist_cp_bn(r_d, res, BN_NIST_224_TOP); r->top = BN_NIST_224_TOP; bn_correct_top(r); @@ -643,8 +642,8 @@ int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, } buf; BN_ULONG c_d[BN_NIST_256_TOP], *res; - PTR_SIZE_INT mask; - union { bn_addsub_f f; PTR_SIZE_INT p; } u; + uintptr_t mask; + union { bn_addsub_f f; uintptr_t p; } u; static const BIGNUM _bignum_nist_p_256_sqr = { (BN_ULONG *)_nist_p_256_sqr, sizeof(_nist_p_256_sqr)/sizeof(_nist_p_256_sqr[0]), @@ -800,18 +799,17 @@ int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, else if (carry < 0) { carry = (int)bn_add_words(r_d,r_d,_nist_p_256[-carry-1],BN_NIST_256_TOP); - mask = 0-(PTR_SIZE_INT)carry; - u.p = ((PTR_SIZE_INT)bn_sub_words&mask) | - ((PTR_SIZE_INT)bn_add_words&~mask); + mask = 0-(uintptr_t)carry; + u.p = ((uintptr_t)bn_sub_words&mask) | + ((uintptr_t)bn_add_words&~mask); } else carry = 1; - mask = 0-(PTR_SIZE_INT)(*u.f)(c_d,r_d,_nist_p_256[0],BN_NIST_256_TOP); - mask &= 0-(PTR_SIZE_INT)carry; + mask = 0-(uintptr_t)(*u.f)(c_d,r_d,_nist_p_256[0],BN_NIST_256_TOP); + mask &= 0-(uintptr_t)carry; res = c_d; - res = (BN_ULONG *)(((PTR_SIZE_INT)res&~mask) | - ((PTR_SIZE_INT)r_d&mask)); + res = (BN_ULONG *)(((uintptr_t)res&~mask) | ((uintptr_t)r_d&mask)); nist_cp_bn(r_d, res, BN_NIST_256_TOP); r->top = BN_NIST_256_TOP; bn_correct_top(r); @@ -847,8 +845,8 @@ int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, } buf; BN_ULONG c_d[BN_NIST_384_TOP], *res; - PTR_SIZE_INT mask; - union { bn_addsub_f f; PTR_SIZE_INT p; } u; + uintptr_t mask; + union { bn_addsub_f f; uintptr_t p; } u; static const BIGNUM _bignum_nist_p_384_sqr = { (BN_ULONG *)_nist_p_384_sqr, sizeof(_nist_p_384_sqr)/sizeof(_nist_p_384_sqr[0]), @@ -1022,18 +1020,17 @@ int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, else if (carry < 0) { carry = (int)bn_add_words(r_d,r_d,_nist_p_384[-carry-1],BN_NIST_384_TOP); - mask = 0-(PTR_SIZE_INT)carry; - u.p = ((PTR_SIZE_INT)bn_sub_words&mask) | - ((PTR_SIZE_INT)bn_add_words&~mask); + mask = 0-(uintptr_t)carry; + u.p = ((uintptr_t)bn_sub_words&mask) | + ((uintptr_t)bn_add_words&~mask); } else carry = 1; - mask = 0-(PTR_SIZE_INT)(*u.f)(c_d,r_d,_nist_p_384[0],BN_NIST_384_TOP); - mask &= 0-(PTR_SIZE_INT)carry; + mask = 0-(uintptr_t)(*u.f)(c_d,r_d,_nist_p_384[0],BN_NIST_384_TOP); + mask &= 0-(uintptr_t)carry; res = c_d; - res = (BN_ULONG *)(((PTR_SIZE_INT)res&~mask) | - ((PTR_SIZE_INT)r_d&mask)); + res = (BN_ULONG *)(((uintptr_t)res&~mask) | ((uintptr_t)r_d&mask)); nist_cp_bn(r_d, res, BN_NIST_384_TOP); r->top = BN_NIST_384_TOP; bn_correct_top(r); @@ -1052,7 +1049,7 @@ int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, BN_ULONG *r_d, *a_d = a->d, t_d[BN_NIST_521_TOP], val,tmp,*res; - PTR_SIZE_INT mask; + uintptr_t mask; static const BIGNUM _bignum_nist_p_521_sqr = { (BN_ULONG *)_nist_p_521_sqr, sizeof(_nist_p_521_sqr)/sizeof(_nist_p_521_sqr[0]), @@ -1097,10 +1094,9 @@ int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, r_d[i] &= BN_NIST_521_TOP_MASK; bn_add_words(r_d,r_d,t_d,BN_NIST_521_TOP); - mask = 0-(PTR_SIZE_INT)bn_sub_words(t_d,r_d,_nist_p_521,BN_NIST_521_TOP); + mask = 0-(uintptr_t)bn_sub_words(t_d,r_d,_nist_p_521,BN_NIST_521_TOP); res = t_d; - res = (BN_ULONG *)(((PTR_SIZE_INT)res&~mask) | - ((PTR_SIZE_INT)r_d&mask)); + res = (BN_ULONG *)(((uintptr_t)res&~mask) | ((uintptr_t)r_d&mask)); nist_cp_bn(r_d,res,BN_NIST_521_TOP); r->top = BN_NIST_521_TOP; bn_correct_top(r); diff --git a/src/lib/libcrypto/cryptlib.h b/src/lib/libcrypto/cryptlib.h index a99f3d4614..d1d7cfe80a 100644 --- a/src/lib/libcrypto/cryptlib.h +++ b/src/lib/libcrypto/cryptlib.h @@ -59,6 +59,7 @@ #ifndef HEADER_CRYPTLIB_H #define HEADER_CRYPTLIB_H +#include #include #include diff --git a/src/lib/libssl/src/crypto/bn/bn.h b/src/lib/libssl/src/crypto/bn/bn.h index 21a1a3fe35..2e3fab98db 100644 --- a/src/lib/libssl/src/crypto/bn/bn.h +++ b/src/lib/libssl/src/crypto/bn/bn.h @@ -253,24 +253,6 @@ extern "C" { #define BN_HEX_FMT2 "%08X" #endif -/* 2011-02-22 SMS. - * In various places, a size_t variable or a type cast to size_t was - * used to perform integer-only operations on pointers. This failed on - * VMS with 64-bit pointers (CC /POINTER_SIZE = 64) because size_t is - * still only 32 bits. What's needed in these cases is an integer type - * with the same size as a pointer, which size_t is not certain to be. - * The only fix here is VMS-specific. - */ -#if defined(OPENSSL_SYS_VMS) -# if __INITIAL_POINTER_SIZE == 64 -# define PTR_SIZE_INT long long -# else /* __INITIAL_POINTER_SIZE == 64 */ -# define PTR_SIZE_INT int -# endif /* __INITIAL_POINTER_SIZE == 64 [else] */ -#else /* defined(OPENSSL_SYS_VMS) */ -# define PTR_SIZE_INT size_t -#endif /* defined(OPENSSL_SYS_VMS) [else] */ - #define BN_DEFAULT_BITS 1280 #define BN_FLG_MALLOCED 0x01 diff --git a/src/lib/libssl/src/crypto/bn/bn_mont.c b/src/lib/libssl/src/crypto/bn/bn_mont.c index 427b5cf4df..a6713ae5b1 100644 --- a/src/lib/libssl/src/crypto/bn/bn_mont.c +++ b/src/lib/libssl/src/crypto/bn/bn_mont.c @@ -247,7 +247,7 @@ static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont) * trick unconditional memcpy below to perform in-place * "refresh" instead of actual copy. */ m=(0-(size_t)v); - nrp=(BN_ULONG *)(((PTR_SIZE_INT)rp&~m)|((PTR_SIZE_INT)ap&m)); + nrp=(BN_ULONG *)(((uintptr_t)rp&~m)|((uintptr_t)ap&m)); for (i=0,nl-=4; itop = BN_NIST_192_TOP; bn_correct_top(r); @@ -485,8 +485,8 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, } buf; BN_ULONG c_d[BN_NIST_224_TOP], *res; - PTR_SIZE_INT mask; - union { bn_addsub_f f; PTR_SIZE_INT p; } u; + uintptr_t mask; + union { bn_addsub_f f; uintptr_t p; } u; static const BIGNUM _bignum_nist_p_224_sqr = { (BN_ULONG *)_nist_p_224_sqr, sizeof(_nist_p_224_sqr)/sizeof(_nist_p_224_sqr[0]), @@ -599,19 +599,18 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, * to be compared to the modulus and conditionally * adjusted by *subtracting* the latter. */ carry = (int)bn_add_words(r_d,r_d,_nist_p_224[-carry-1],BN_NIST_224_TOP); - mask = 0-(PTR_SIZE_INT)carry; - u.p = ((PTR_SIZE_INT)bn_sub_words&mask) | - ((PTR_SIZE_INT)bn_add_words&~mask); + mask = 0-(uintptr_t)carry; + u.p = ((uintptr_t)bn_sub_words&mask) | + ((uintptr_t)bn_add_words&~mask); } else carry = 1; /* otherwise it's effectively same as in BN_nist_mod_192... */ - mask = 0-(PTR_SIZE_INT)(*u.f)(c_d,r_d,_nist_p_224[0],BN_NIST_224_TOP); - mask &= 0-(PTR_SIZE_INT)carry; + mask = 0-(uintptr_t)(*u.f)(c_d,r_d,_nist_p_224[0],BN_NIST_224_TOP); + mask &= 0-(uintptr_t)carry; res = c_d; - res = (BN_ULONG *)(((PTR_SIZE_INT)res&~mask) | - ((PTR_SIZE_INT)r_d&mask)); + res = (BN_ULONG *)(((uintptr_t)res&~mask) | ((uintptr_t)r_d&mask)); nist_cp_bn(r_d, res, BN_NIST_224_TOP); r->top = BN_NIST_224_TOP; bn_correct_top(r); @@ -643,8 +642,8 @@ int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, } buf; BN_ULONG c_d[BN_NIST_256_TOP], *res; - PTR_SIZE_INT mask; - union { bn_addsub_f f; PTR_SIZE_INT p; } u; + uintptr_t mask; + union { bn_addsub_f f; uintptr_t p; } u; static const BIGNUM _bignum_nist_p_256_sqr = { (BN_ULONG *)_nist_p_256_sqr, sizeof(_nist_p_256_sqr)/sizeof(_nist_p_256_sqr[0]), @@ -800,18 +799,17 @@ int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, else if (carry < 0) { carry = (int)bn_add_words(r_d,r_d,_nist_p_256[-carry-1],BN_NIST_256_TOP); - mask = 0-(PTR_SIZE_INT)carry; - u.p = ((PTR_SIZE_INT)bn_sub_words&mask) | - ((PTR_SIZE_INT)bn_add_words&~mask); + mask = 0-(uintptr_t)carry; + u.p = ((uintptr_t)bn_sub_words&mask) | + ((uintptr_t)bn_add_words&~mask); } else carry = 1; - mask = 0-(PTR_SIZE_INT)(*u.f)(c_d,r_d,_nist_p_256[0],BN_NIST_256_TOP); - mask &= 0-(PTR_SIZE_INT)carry; + mask = 0-(uintptr_t)(*u.f)(c_d,r_d,_nist_p_256[0],BN_NIST_256_TOP); + mask &= 0-(uintptr_t)carry; res = c_d; - res = (BN_ULONG *)(((PTR_SIZE_INT)res&~mask) | - ((PTR_SIZE_INT)r_d&mask)); + res = (BN_ULONG *)(((uintptr_t)res&~mask) | ((uintptr_t)r_d&mask)); nist_cp_bn(r_d, res, BN_NIST_256_TOP); r->top = BN_NIST_256_TOP; bn_correct_top(r); @@ -847,8 +845,8 @@ int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, } buf; BN_ULONG c_d[BN_NIST_384_TOP], *res; - PTR_SIZE_INT mask; - union { bn_addsub_f f; PTR_SIZE_INT p; } u; + uintptr_t mask; + union { bn_addsub_f f; uintptr_t p; } u; static const BIGNUM _bignum_nist_p_384_sqr = { (BN_ULONG *)_nist_p_384_sqr, sizeof(_nist_p_384_sqr)/sizeof(_nist_p_384_sqr[0]), @@ -1022,18 +1020,17 @@ int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, else if (carry < 0) { carry = (int)bn_add_words(r_d,r_d,_nist_p_384[-carry-1],BN_NIST_384_TOP); - mask = 0-(PTR_SIZE_INT)carry; - u.p = ((PTR_SIZE_INT)bn_sub_words&mask) | - ((PTR_SIZE_INT)bn_add_words&~mask); + mask = 0-(uintptr_t)carry; + u.p = ((uintptr_t)bn_sub_words&mask) | + ((uintptr_t)bn_add_words&~mask); } else carry = 1; - mask = 0-(PTR_SIZE_INT)(*u.f)(c_d,r_d,_nist_p_384[0],BN_NIST_384_TOP); - mask &= 0-(PTR_SIZE_INT)carry; + mask = 0-(uintptr_t)(*u.f)(c_d,r_d,_nist_p_384[0],BN_NIST_384_TOP); + mask &= 0-(uintptr_t)carry; res = c_d; - res = (BN_ULONG *)(((PTR_SIZE_INT)res&~mask) | - ((PTR_SIZE_INT)r_d&mask)); + res = (BN_ULONG *)(((uintptr_t)res&~mask) | ((uintptr_t)r_d&mask)); nist_cp_bn(r_d, res, BN_NIST_384_TOP); r->top = BN_NIST_384_TOP; bn_correct_top(r); @@ -1052,7 +1049,7 @@ int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, BN_ULONG *r_d, *a_d = a->d, t_d[BN_NIST_521_TOP], val,tmp,*res; - PTR_SIZE_INT mask; + uintptr_t mask; static const BIGNUM _bignum_nist_p_521_sqr = { (BN_ULONG *)_nist_p_521_sqr, sizeof(_nist_p_521_sqr)/sizeof(_nist_p_521_sqr[0]), @@ -1097,10 +1094,9 @@ int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, r_d[i] &= BN_NIST_521_TOP_MASK; bn_add_words(r_d,r_d,t_d,BN_NIST_521_TOP); - mask = 0-(PTR_SIZE_INT)bn_sub_words(t_d,r_d,_nist_p_521,BN_NIST_521_TOP); + mask = 0-(uintptr_t)bn_sub_words(t_d,r_d,_nist_p_521,BN_NIST_521_TOP); res = t_d; - res = (BN_ULONG *)(((PTR_SIZE_INT)res&~mask) | - ((PTR_SIZE_INT)r_d&mask)); + res = (BN_ULONG *)(((uintptr_t)res&~mask) | ((uintptr_t)r_d&mask)); nist_cp_bn(r_d,res,BN_NIST_521_TOP); r->top = BN_NIST_521_TOP; bn_correct_top(r); diff --git a/src/lib/libssl/src/crypto/cryptlib.h b/src/lib/libssl/src/crypto/cryptlib.h index a99f3d4614..d1d7cfe80a 100644 --- a/src/lib/libssl/src/crypto/cryptlib.h +++ b/src/lib/libssl/src/crypto/cryptlib.h @@ -59,6 +59,7 @@ #ifndef HEADER_CRYPTLIB_H #define HEADER_CRYPTLIB_H +#include #include #include -- cgit v1.2.3-55-g6feb