summaryrefslogtreecommitdiffstats
path: root/crypto/bn
AgeCommit message (Collapse)Author
2004-03-17Variety of belt-tightenings in the bignum code. (Please help test this!)Geoff Thorpe
- Remove some unnecessary "+1"-like fudges. Sizes should be handled exactly, as enlarging size parameters causes needless bloat and may just make bugs less likely rather than fixing them: bn_expand() macro, bn_expand_internal(), and BN_sqr(). - Deprecate bn_dup_expand() - it's new since 0.9.7, unused, and not that useful. - Remove unnecessary zeroing of unused bytes in bn_expand2(). - Rewrite BN_set_word() - it should be much simpler, the previous complexities probably date from old mismatched type issues. - Add missing bn_check_top() macros in bn_word.c - Improve some degenerate case handling in BN_[add|sub]_word(), add comments, and avoid a bignum expansion if an overflow isn't possible.
2004-03-13Convert openssl code not to assume the deprecated form of BN_zero().Geoff Thorpe
Remove certain redundant BN_zero() initialisations, because BN_CTX_get(), BN_init(), [etc] already initialise to zero. Correct error checking in bn_sqr.c, and be less wishy-wash about how/why the result's 'top' value is set (note also, 'max' is always > 0 at this point).
2004-03-13The efforts to eliminate the dual-representation of zero and to ensureGeoff Thorpe
bignums are passed in and out of functions and APIs in a consistent form has highlighted that zero-valued bignums don't need any allocated word data. The use of BN_set_word() to initialise a bignum to zero causes needless allocation and gives it a return value that must be checked. This change converts BN_zero() to a self-contained macro that has no return/expression value and does not cause any expansion of bignum data. Note, it would be tempting to rewrite the deprecated version as a success-valued comma expression, such as; #define BN_zero(a) ((a)->top = (a)->neg = 0, 1) However, this evaluates 'a' twice and would confuse initialisation loops (eg. while(..) { BN_zero(bn++) } ). As such, the deprecated version continues to use BN_set_word().
2004-03-13Document a change I'd already made, and at the same time, correct theGeoff Thorpe
change to work properly; BN_zero() should set 'neg' to zero as well as 'top' to match the behaviour of BN_new().
2004-03-09Minimise the amount of code dependent on BN_DEBUG_RAND. In particular,Geoff Thorpe
redefine bn_clear_top2max() to be a NOP in the non-debugging case, and remove some unnecessary usages in bn_nist.c. Submitted by: Nils Larsch Reviewed by: Geoff Thorpe, Ulf Möller
2004-03-09More changes coming out of the bignum auditing. BN_CTX_get() should ideallyGeoff Thorpe
return a "zero" bignum as BN_new() does - so reset 'top'. During BN_CTX_end(), released bignums should be consistent so enforce this in debug builds. Also, reduce the number of wasted BN_clear_free() calls from BN_CTX_end() (typically by 75% or so). Submitted by: Nils Larsch Reviewed by: Geoff Thorpe, Ulf Möller
2004-02-22When adding positive elements, we can use BN_uadd() instead of BN_add().Geoff Thorpe
Submitted by: Nils Larsch Reviewed by: Geoff Thorpe
2004-02-07Typo in crypto/bn/asm/x86_64.c, bn_div_words().Andy Polyakov
PR: 821
2004-01-30Typo in PA-RISC 2 rules in crypto/bn/Makefile.sslAndy Polyakov
2004-01-29HP/UX PA-RISC 2 targets update.Andy Polyakov
2004-01-28make updateRichard Levitte
2004-01-25Even though C specification explicitly says that constant type "stretches"Andy Polyakov
automatically to accomodate the value, some compilers fail to do so. Most notably 0x0123456789ABCDEF should come out as long long in 32-bit context, but HP compiler truncates it to 32-bit value. Which in turn breaks GF(2^m) arithmetics in hpux-parisc2-cc build. Therefore this fix...
2003-12-27Use sh explicitely to run point.shRichard Levitte
This is part of a large change submitted by Markus Friedl <markus@openbsd.org>
2003-12-27Use BUF_strlcpy() instead of strcpy().Richard Levitte
Use BUF_strlcat() instead of strcat(). Use BIO_snprintf() instead of sprintf(). In some cases, keep better track of buffer lengths. This is part of a large change submitted by Markus Friedl <markus@openbsd.org>
2003-12-06Add "dif" variable to clean up the loop implementations.Ulf Möller
Submitted by: Nils Larsch
2003-12-06Avoid segfault if ret==0.Ulf Möller
Submitted by: Nils Larsch
2003-12-02Incremental cleanups to bn_lib.c.Geoff Thorpe
- Add missing bn_check_top() calls and relocate some others - Use BN_is_zero() where appropriate - Remove assert()s that bn_check_top() is already covering - Simplify the code in places (esp. bn_expand2()) - Only keep ambiguous zero handling if BN_STRICT isn't defined - Remove some white-space and make some other aesthetic tweaks
2003-12-02Use the BN_is_odd() macro in place of code that (inconsistently) does muchGeoff Thorpe
the same thing. Also, I have some stuff on the back-burner related to some BN_CTX notes from Peter Gutmann about his cryptlib hacks to the bignum code. The BN_CTX comments are there to remind me of some relevant points in the code.
2003-12-02BN_FLG_FREE is of extremely dubious usefulness, and is only referred toGeoff Thorpe
once in the source (where it is set for the benefit of no other code whatsoever). I've deprecated the declaration in the header and likewise made the use of the flag conditional in bn_lib.c. Note, this change also NULLs the 'd' pointer in a BIGNUM when it is reset but not deallocated.
2003-12-01Declare the static BIGNUM "BN_value_one()" more carefully.Geoff Thorpe
2003-12-01Add missing bn_check_top()s to bn_kron.c, remove some miscellaneousGeoff Thorpe
white-space, and include extra headers to satisfy debugging builds.
2003-12-01Add missing bn_check_top()s to bn_gf2m.c and remove some miscellaneousGeoff Thorpe
white-space.
2003-12-01The bn_set_max() macro is only "used" by the bn_set_[low|high]() macrosGeoff Thorpe
which, in turn, are used nowhere at all. This is a good thing because bn_set_max() would currently generate code that wouldn't compile (BIGNUM has no 'max' element). The only apparent use for bn_set_[low|high] would be for implementing windowing algorithms, and all of openssl's seem to use bn_***_words() helpers instead (including the BN_div() that Nils fixed recently, which had been using independently-coded versions of what these unused macros are intended for). I'm therefore consigning these macros to cvs oblivion in the name of readability.
2003-12-01bn_fix_top() exists for compatibility's sake and is mapped toGeoff Thorpe
bn_correct_top() or bn_check_top() depending on debug settings. For internal source, all bn_fix_top()s should be converted one way or the other depending on whether the use of bn_correct_top() is justified. For BN_div_recp(), these cases should not require correction if the other bignum functions are doing their jobs properly, so convert to bn_check_top().
2003-11-30If BN_STRICT is defined, don't accept an ambiguous representation of zeroGeoff Thorpe
(ie. where top may be zero, or it may be one if the corresponding word is set to zero). Note, this only affects the macros in bn.h, there are probably similar corrections required in some c files. Also, clarify the audit-related macros at the top of the header. Mental note: I must not forget to clean all this out before 0.9.8 is released ...
2003-11-30Improve a couple of the bignum macros. Note, this doesn't eliminateGeoff Thorpe
tolerance of ambiguous zero-representation, it just improves BN_abs_is_word() and simplifies other macros that depend on it.
2003-11-30Make BN_DEBUG_RAND less painfully slow by only consuming one byte ofGeoff Thorpe
pseudo-random data for each bn_pollute().
2003-11-29This improves the placement of check_top() macros in a couple of bn_libGeoff Thorpe
functions.
2003-11-28Get rid of some signed/unsigned comparison warnings.Geoff Thorpe
2003-11-28Netware-specific changes,Richard Levitte
PR: 780 Submitted by: Verdon Walker <VWalker@novell.com> Reviewed by: Richard Levitte
2003-11-25Due to recent debugging bursts, openssl should be more or less solidGeoff Thorpe
against inconsistent BIGNUMs coming out of any of its API functions. So this change no longer "fixes" the bn_print.c functions, but it makes for cleaner code. This patch was a part of ticket 697. PR: 697 Submitted by: Otto Moerbeek Reviewed by: Geoff Thorpe
2003-11-25Fix some handling in bn_word. This also resolves the issues observed inGeoff Thorpe
ticket 697 (though uses a different solution than the proposed one). This problem was initially raised by Otto Moerbeek. PR: 697 Submitted by: Nils Larsch Reviewed by: Geoff Thorpe
2003-11-25Some changes for bn_gf2m.c: better error checking plus some minorGeoff Thorpe
optimizations. Submitted by: Nils Larsch
2003-11-22BN_div() cleanup: replace the use of BN_sub and BN_add with bn_sub_wordsGeoff Thorpe
and bn_add_words to avoid using fake bignums to window other bignums that can lead to corruption. This change allows all bignum tests to pass with BN_DEBUG and BN_DEBUG_RAND debugging and valgrind. NB: This should be tested on a few different architectures and configuration targets, as the bignum code this deals with is quite preprocessor (and assembly) sensitive. Submitted by: Nils Narsch Reviewed by: Geoff Thorpe, Ulf Moeller
2003-11-15BN_set_bit() etc should use "unsigned int".Ulf Möller
Keep it as is to avoid an API change, but check for negativ values. Submitted by: Nils Larsch
2003-11-13This rewrites two "for" loops in BN_rshift() - equality with zero isGeoff Thorpe
generally a more efficient comparison than comparing two integers, and the first of these two loops was off-by-one (copying one too many values). This change also removes a superfluous assignment that would set an unused word to zero (and potentially allow an overrun in some cases). Submitted by: Nils Larsch Reviewed by: Geoff Thorpe
2003-11-06This extends the debugging macros to use "pollution" duringGeoff Thorpe
bn_correct_top(), previously only bn_check_top() did this.
2003-11-06Add debug-screening of input parameters to some functions I'd missedGeoff Thorpe
before.
2003-11-06Put more debug screening in BN_div() and correct a comment.Geoff Thorpe
2003-11-05This is a revert of my previous commit to "improve" the declaration ofGeoff Thorpe
constant BIGNUMs. It turns out that this trips up different but equally useful compiler warnings to -Wcast-qual, and so wasn't worth the ugliness it created. (Thanks to Ulf for the forehead-slap.)
2003-11-05typo in commentUlf Möller
2003-11-05cleanup as discussed with GeoffUlf Möller
2003-11-04Put the first stage of my bignum debugging adventures into CVS. This codeGeoff Thorpe
is itself experimental, and in addition may cause execution to break on existing openssl "bugs" that previously were harmless or at least invisible.
2003-11-04This is the least unacceptable way I've found for declaring the bignum dataGeoff Thorpe
and structures as constant without having to cast away const at any point. There is still plenty of other code that makes gcc's "-Wcast-qual" unhappy, but crypto/bn/ is now ok. Purists are welcome to suggest alternatives.
2003-10-31bn_div() does some pretty nasty things with temporary variables,Geoff Thorpe
constructing BIGNUM structures with pointers offset into other bignums (among other things). This corrects some of it that is too plainly insane, and tries to ensure that bignums are normalised when passed to other functions.
2003-10-30When a BN_CTX is used for temporary workspace, the variables are sometimesGeoff Thorpe
left in an inconsistent state when they are released for later reuse. This change resets the BIGNUMs when they are released back to the context.
2003-10-30This fixes a couple of cases where an inconsistent BIGNUM could be passed asGeoff Thorpe
input to a function.
2003-10-29Some provisional bignum debugging has begun to detect inconsistent BIGNUMGeoff Thorpe
structures being passed in to or out of API functions, and this corrects a couple of cases found so far. Also, lop off a couple of bytes of white-space.
2003-10-29A general spring-cleaning (in autumn) to fix up signed/unsigned warnings.Geoff Thorpe
I have tried to convert 'len' type variable declarations to unsigned as a means to address these warnings when appropriate, but when in doubt I have used casts in the comparisons instead. The better solution (that would get us all lynched by API users) would be to go through and convert all the function prototypes and structure definitions to use unsigned variables except when signed is necessary. The proliferation of (signed) "int" for strictly non-negative uses is unfortunate.
2003-10-29BN_CTX is opaque and the static initialiser BN_CTX_init() is not usedGeoff Thorpe
except internally to the allocator BN_CTX_new(), as such this deprecates the use of BN_CTX_init() in the API. Moreover, the structure definition of BN_CTX is taken out of bn_lcl.h and moved into bn_ctx.c itself. NDEBUG should probably only be "forced" in the top-level configuration, but until it is I will avoid removing it from bn_ctx.c which might surprise people with massive slow-downs in their keygens. So I've left it in bn_ctx.c but tidied up the preprocessor logic a touch and made it more tolerant of debugging efforts.