summaryrefslogtreecommitdiff
path: root/src/misc.c
Commit message (Collapse)AuthorAgeFilesLines
* Prevent link-time optimization from inlining __gcry_burn_stackJussi Kivilinna2020-12-031-1/+1
| | | | | | | | | | | | | | * src/g10lib.h (NOINLINE_FUNC): New attribute macro. * src/misc.c (__gcry_burn_stack): Add NOINLINE_FUNC attribute. -- LTO can cause inline of __gcry_burn_stack and result tail-call to _gcry_fast_wipememory and defeat tail-call prevention in _gcry_burn_stack macro. Mark __gcry_burn_stack with 'noinline' attribute to prevent unwanted inlining of this function in LTO builds. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* Add support for explicit_memsetJussi Kivilinna2019-04-271-1/+9
| | | | | | | | | | | * configure.ac: Add function check for 'explicit_memset'. * src/misc.c (_gcry_fast_wipememory, _gcry_fast_wipememory2): Use explicit_memset if available. -- GnuPG-bug-id: D476 Reported-by: <devnexen@gmail.com> Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* Use explicit_bzero for wipememoryJussi Kivilinna2018-11-201-3/+34
| | | | | | | | | | | | | | | | | | * configure.ac (AC_CHECK_FUNCS): Check for 'explicit_bzero'. * src/g10lib.h (wipememory2): Use _gcry_fast_wipememory if _SET is zero. (_gcry_fast_wipememory): New. (_gcry_wipememory2): Rename to... (_gcry_fast_wipememory2): ...this. * src/misc.c (_gcry_wipememory): New. (_gcry_wipememory2): Rename to... (_gcry_fast_wipememory2): ...this. (_gcry_fast_wipememory2) [HAVE_EXPLICIT_BZERO]: Use explicit_bzero if SET is zero. (_gcry_burn_stack): Use _gcry_fast_wipememory. -- Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* wipememory: use memset for non-constant length or large buffer wipesJussi Kivilinna2018-11-051-9/+17
| | | | | | | | | | | | | | | * src/g10lib.h (CONSTANT_P): New. (_gcry_wipememory2): New prototype. (wipememory2): Use _gcry_wipememory2 if _len not constant expression or lenght is larger than 64 bytes. (FASTWIPE_T, FASTWIPE_MULT, fast_wipememory2_unaligned_head): Remove. (fast_wipememory2): Always handle buffer as unaligned. * src/misc.c (__gcry_burn_stack): Move memset_ptr variable to... (memset_ptr): ... here. New. (_gcry_wipememory2): New. -- Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* _gcry_burn_stack: use memset for clearing memoryJussi Kivilinna2018-03-221-2/+3
| | | | | | | | | | | | * src/misc.c (__gcry_burn_stack) [HAVE_VLA]: Use 'memset' for clearing stack. -- Patch switches stacking burning to use faster memset instead of wipememory. Memset is accessed through volatile function pointer, so that compiler will not optimize away the call. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* api: New function gcry_get_config.Werner Koch2017-06-211-12/+0
| | | | | | | | | | | | | | | | | | * src/misc.c (_gcry_log_info_with_dummy_fp): Remove. * src/global.c (print_config): New arg WHAT. Remove arg FNC and use gpgrt_fprintf directly. (_gcry_get_config): New. (_gcry_vcontrol) <GCRYCTL_PRINT_CONFIG>: Use _gcry_get_config instead of print_config. * src/gcrypt.h.in (gcry_get_config): New. * src/libgcrypt.def, src/libgcrypt.vers: Add new function. * src/visibility.c (gcry_get_config): New. * src/visibility.h: Mark new function. * tests/version.c (test_get_config): New. (main): Call new test. Signed-off-by: Werner Koch <wk@gnupg.org>
* Fix possible NULL-deref in gcry_log_debugsxpWerner Koch2016-12-061-1/+1
| | | | | | * src/misc.c (_gcry_log_printsxp): Prevent passing NULL to strlen. Signed-off-by: Werner Koch <wk@gnupg.org>
* Improve robustness and help lint.Werner Koch2016-06-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | * cipher/rsa.c (rsa_encrypt): Check for !DATA. * cipher/md.c (search_oid): Check early for !OID. (md_copy): Use gpg_err_code_from_syserror. Replace chains of if(!err) tests. * cipher/cipher.c (search_oid): Check early for !OID. * src/misc.c (do_printhex): Allow for BUFFER==NULL even with LENGTH>0. * mpi/mpicoder.c (onecompl): Allow for A==NULL to help static analyzers. -- The change for md_copy is to help static analyzers which have no idea that gpg_err_code_from_syserror will never return 0. A gcc attribute returns_nonzero would be a nice to have. Some changes are due to the fact the macros like mpi_is_immutable gracefully handle a NULL arg but a static analyzer the considers that the function allows for a NULL arg. Signed-off-by: Werner Koch <wk@gnupg.org>
* Add helper function _gcry_strtokenize.Werner Koch2016-02-191-0/+73
| | | | | | | | | | * src/misc.c (_gcry_strtokenize): New. -- The code has been taken from GnuPG and re-licensed to LPGLv2+ by me as its original author. Minor changes for use in Libgcrypt. Signed-off-by: Werner Koch <wk@gnupg.org>
* Remove macro hacks for internal vs. external functions. Part 2 and last.Werner Koch2013-12-121-3/+3
| | | | | | | | | | | | | | | | | | | * src/visibility.h: Remove remaining define/undef hacks for symbol visibility. Add macros to detect the use of the public functions. Change all affected functions by replacing them by the x-macros. * src/g10lib.h: Add internal prototypes. (xtrymalloc, xtrycalloc, xtrymalloc_secure, xtrycalloc_secure) (xtryrealloc, xtrystrdup, xmalloc, xcalloc, xmalloc_secure) (xcalloc_secure, xrealloc, xstrdup, xfree): New macros. -- The use of xmalloc/xtrymalloc/xfree is a more common pattern than the gcry_free etc. functions. Those functions behave like those defined by C and thus for better readability we use these macros and not the underscore prefixed functions. Signed-off-by: Werner Koch <wk@gnupg.org>
* Remove macro hacks for internal vs. external functions. Part 1.Werner Koch2013-12-051-7/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * src/visibility.h: Remove almost all define/undef hacks for symbol visibility. Add macros to detect the use of the public functions. Change all affected functions by prefixing them explicitly with an underscore and change all internal callers to call the underscore prefixed versions. Provide convenience macros from sexp and mpi functions. * src/visibility.c: Change all functions to use only gpg_err_code_t and translate to gpg_error_t only in visibility.c. -- The use of the macro magic made if hard to follow the function calls in the source. It was not easy to see if an internal or external function (as defined by visibility.c) was called. The change is quite large but hopefully makes Libgcrypt easier to maintain. Some function have not yet been fixed; this will be done soon. Because Libgcrypt does no make use of any other libgpg-error using libraries it is useless to always translate between gpg_error_t and gpg_err_code_t (i.e with and w/o error source identifier). This translation has no mostly be moved to the function wrappers in visibility.c. An additional advantage of using gpg_err_code_t is that comparison can be done without using gpg_err_code(). I am sorry for that large patch, but a series of patches would actually be more work to audit. Signed-off-by: Werner Koch <wk@gnupg.org>
* Prevent tail call optimization with _gcry_burn_stackJussi Kivilinna2013-10-101-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | * configure.ac: New check, HAVE_GCC_ASM_VOLATILE_MEMORY. * src/g10lib.h (_gcry_burn_stack): Rename to __gcry_burn_stack. (__gcry_burn_stack_dummy): New. (_gcry_burn_stack): New macro. * src/misc.c (_gcry_burn_stack): Rename to __gcry_burn_stack. (__gcry_burn_stack_dummy): New. -- Tail call optimization can turn _gcry_burn_stack call in to tail jump. When this happens, stack pointer is restored to initial state of current function. This causes problem for _gcry_burn_stack because its callers do not count in current function stack depth. One solution is to prevent gcry_burn_stack being tail optimized by inserting dummy function call behind it. Another would be to add memory barrier 'asm volatile("":::"memory")' behind every _gcry_burn_stack call. This however requires GCC asm support from compiler. Patch adds detection for memory barrier support and when available uses memory barrier to prevent when tail call optimization. If not available dummy function call is used instead. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* ecc: Prepare for future Ed25519 optimization.Werner Koch2013-09-301-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | * mpi/ec-ed25519.c: New but empty file. * mpi/ec-internal.h: New. * mpi/ec.c: Include ec-internal.h. (ec_mod): New. (ec_addm): Use ec_mod. (ec_mulm): Remove commented code. Use ec_mod. (ec_subm): Call simple sub. (ec_pow2): Use ec_mulm. (ec_mul2): New. (dup_point_weierstrass): Use ec_mul2. (dup_point_twistededwards): Add special case for a == -1. Use ec_mul2. (add_points_weierstrass): Use ec_mul2. (add_points_twistededwards): Add special case for a == -1. (_gcry_mpi_ec_curve_point): Ditto. (ec_p_init): Add hack to test Barrett functions. * src/ec-context.h (mpi_ec_ctx_s): Add P_BARRETT. * mpi/mpi-mod.c (_gcry_mpi_mod_barrett): Fix sign problem. Signed-off-by: Werner Koch <wk@gnupg.org>
* log: Try to print s-expressions in a more compact format.Werner Koch2013-09-301-4/+29
| | | | | | | | * src/misc.c (count_closing_parens): New. (_gcry_log_printsxp): Use new function. * mpi/ec.c (_gcry_mpi_point_log): Take care of a NULL point. Signed-off-by: Werner Koch <wk@gnupg.org>
* Add logging functions to the API.Werner Koch2013-09-301-1/+50
| | | | | | | | | | | | | | | | | | | | | * src/gcrypt.h.in (_GCRY_GCC_ATTR_PRINTF): New. (gcry_log_debug, gcry_log_debughex, gcry_log_debugmpi): New. (gcry_log_debugpnt, gcry_log_debugsxp): New. * src/visibility.c (gcry_log_debug): New. (gcry_log_debughex, gcry_log_debugmpi, gcry_log_debugpnt): New. (gcry_log_debugsxp): New. * src/libgcrypt.def, src/libgcrypt.vers: Add new functions. * src/misc.c (_gcry_logv): Make public. (_gcry_log_printsxp): New. * src/g10lib.h (log_printsxp): New macro. -- For debugging applications it is often required to dump certain data structures. Libgcrypt uses several internal functions for this. To avoid re-implementing everything in the caller, we now provide access to some of those functions. Signed-off-by: Werner Koch <wk@gnupg.org>
* ecc: Implement Curve Ed25519 signing and verification.Werner Koch2013-09-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * cipher/ecc-curves.c (domain_parms): Add curve "Ed25519". * cipher/ecc.c (reverse_buffer): New. (eddsa_encodempi): New. (eddsa_encodepoint): New. (eddsa_decodepoint): New. (sign_eddsa): Implement. (verify_eddsa): Implement. (ecc_sign): Init unused Q. Pass public key to sign_eddsa. (ecc_verify): Init pk.Q if not used. Pass public key verbatim to verify_eddsa. * cipher/pubkey.c (sexp_elements_extract): Add arg OPAQUE. Change all callers to pass 0. (sexp_to_sig): Add arg OPAQUE and pass it to sexp_elements_extract. (sexp_data_to_mpi): Allow for a zero length "value". (gcry_pk_verify): Reorder parameter processing. Pass OPAQUE flag as required. * mpi/ec.c (ec_invm): Print a warning if the inverse does not exist. (_gcry_mpi_ec_get_affine): Implement for our Twisted Edwards curve model. (dup_point_twistededwards): Implement. (add_points_twistededwards): Implement. (_gcry_mpi_ec_mul_point): Support Twisted Edwards. * mpi/mpicoder.c (do_get_buffer): Add arg FILL_LE. (_gcry_mpi_get_buffer): Ditto. Change all callers. (_gcry_mpi_get_secure_buffer): Ditto. * src/sexp.c (_gcry_sexp_nth_opaque_mpi): New. * tests/t-ed25519.c: New. * tests/t-ed25519.inp: New. * tests/t-mpi-point.c (basic_ec_math_simplified): Print some output only in debug mode. (twistededwards_math): New test. (main): Call new test. -- This is a non optimized version which takes far too long. On my X220 Thinkpad the 1024 test cases take 14 seconds (12 with --sign-with-pk). There should be a lot of room for improvements. Signed-off-by: Werner Koch <wk@gnupg.org>
* Fix _gcry_log_printmpi to print 00 instead of a sole sign.Werner Koch2013-09-121-1/+4
| | | | * src/misc.c: Special case an mpi length of 0.
* Streamline the use of the internal mpi and hex debug functions.Werner Koch2013-09-111-9/+81
| | | | | | | | | | | | | | | | | | | | | | | | | | * mpi/mpicoder.c (gcry_mpi_dump): Remove. (_gcry_log_mpidump): Remove. * src/misc.c (_gcry_log_printhex): Factor all code out to ... (do_printhex): new. Add line wrapping a and compact printing. (_gcry_log_printmpi): New. * src/mpi.h (log_mpidump): Remove macro. * src/g10lib.h (log_mpidump): Add compatibility macro. (log_printmpi): New macro * src/visibility.c (gcry_mpi_dump): Call _gcry_log_printmpi. * cipher/primegen.c (prime_generate_internal): Replace gcry_mpi_dump by log_printmpi. (gcry_prime_group_generator): Ditto. * cipher/pubkey.c: Remove extra colons from log_mpidump call. * cipher/rsa.c (stronger_key_check): Use log_printmpi. -- The values to debug get longer and longer and the different debug functions made it hard to check them out. Now MPIs and hex buffers are printed very similar. Lines may now wrap with an backslash as indicator. MPIs are distinguished from plain buffers in the output by always using a sign. Signed-off-by: Werner Koch <wk@gnupg.org>
* Change _gcry_burn_stack take burn depth as unsigned integerJussi Kivilinna2013-09-051-5/+5
| | | | | | | | | | * src/misc.c (_gcry_burn_stack): Change to handle 'unsigned int' bytes. -- Unsigned integer is better here for code generation because we can now avoid possible branching caused by (bytes <= 0) check. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* Make _gcry_burn_stack use variable length arrayJussi Kivilinna2013-09-041-1/+8
| | | | | | | | | | | | | | | | | | | * configure.ac (HAVE_VLA): Add check. * src/misc.c (_gcry_burn_stack) [HAVE_VLA]: Add VLA code. -- Some gcc versions convert _gcry_burn_stack into loop that overwrites the same 64-byte stack buffer instead of burn stack deeper. It's argued at GCC bugzilla that _gcry_burn_stack is doing wrong thing here [1] and that this kind of optimization is allowed. So lets fix _gcry_burn_stack by using variable length array when VLAs are supported by compiler. This should ensure proper stack burning to the requested depth and avoid GCC loop optimizations. [1] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52285 Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* Remove burn_stack optimizationJussi Kivilinna2013-08-171-26/+1
| | | | | | | | | | | | | | | | | * src/misc.c (_gcry_burn_stack): Remove SIZEOF_UNSIGNED_LONG == 4 or 8 optimization. -- At least GCC 4.6 on Debian Wheezy (armhf) generates wrong code for burn_stack, causing recursive structure to be transformed in to iterative without updating stack pointer between iterations. Therefore only first 64 bytes of stack get zeroed. This appears to be fixed in GCC 4.7, but lets play this safe and remove this optimization. Better approach would probably be to add architecture specific assembly routine(s) that replace this generic function. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* Optimize _gcry_burn_stack for 32-bit and 64-bit architecturesJussi Kivilinna2013-06-091-0/+26
| | | | | | | | | | | | | | | * src/misc.c (_gcry_burn_stack): Add optimization for 32-bit and 64-bit architectures. -- Busy looping 'tests/benchmark --cipher-repetitions 10 cipher blowfish' on ARM Cortex-A8 shows that _gcry_burn_stack takes 21% of CPU time. With this patch, that number drops to 3.4%. On AMD64 (Intel i5-4570) CPU usage for _gcry_burn_stack in the same test drops from 3.5% to 1.1%. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* Replace deliberate division by zero with _gcry_divide_by_zero.Xi Wang2012-08-161-0/+8
| | | | | | | | | | | | | | | * mpi/mpi-pow.c: Replace 1 / msize. * mpi/mpih-div.c: Replace 1 / dsize. * src/misc.c: Add _gcry_divide_by_zero. -- 1) Division by zero doesn't "provoke a signal" on architectures like PowerPC. 2) C compilers like clang will optimize away these divisions, even though the code tries "to make the compiler not remove" them. This patch redirects these cases to _gcry_divide_by_zero.
* Nuked almost all trailing whitespace.post-nuke-of-trailing-wsWerner Koch2011-02-041-7/+7
| | | | Check and install the standard git pre-commit hook.
* 2010-04-19 Marcus Brinkmann <marcus@g10code.de>Marcus Brinkmann2010-04-191-1/+3
| | | | | * misc.c (write2stderr): Dummy variable to silence gcc warning.
* Finished the X9.31 RNG implementations.Werner Koch2008-08-211-0/+21
|
* Replace assert calls by a new gcry_assert at most places.Werner Koch2008-08-201-2/+18
|
* A whole bunch of changes to eventually support Werner Koch2008-08-191-1/+3
| | | | | | | FIPS restricted mode. Also some documentation improvements and other minor enhancements. See the ChangeLogs. Stay tuned.
* Preparing a releaselibgcrypt-1.3.2Werner Koch2007-12-031-22/+27
|
* Dropped GCRYCTL_DUMP_CONFIG in favor of GCRYCTL_PRINT_CONFIG.Werner Koch2007-04-301-0/+12
|
* 2004-08-23 Moritz Schulte <moritz@g10code.com>Moritz Schulte2004-08-231-1/+0
| | | | | | | | * global.c: Do not include <assert.h>. * sexp.c: Likewise. * module.c: Likewise. * misc.c: Likewise.
* About to release 1.2Werner Koch2004-04-151-4/+4
|
* * acinclude.m4 (AC_CHECK_PTH): Added.Werner Koch2003-10-311-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * configure.ac: Use it here instead of the generic lib test. Bumbed LT vesion to C9/A2/R0. * dsa.c (verify): s/exp/ex/ due to shadowing of a builtin. * elgamal.c (verify): Ditto. * ac.c (gcry_ac_data_get_index): s/index/idx/ (gcry_ac_data_copy_internal): Remove the cast in _gcry_malloc. (gcry_ac_data_add): Must use gcry_realloc instead of realloc. * pubkey.c (sexp_elements_extract): s/index/idx/ as tribute to the forehackers. (gcry_pk_encrypt): Removed shadowed definition of I. Reordered arguments to malloc for clarity. (gcry_pk_sign, gcry_pk_genkey): Ditto. * primegen.c (prime_generate_internal): s/random/randomlevel/. * i386/mpih-rshift.S, i386/mpih-lshift.S: Use %dl and not %edx for testb; this avoids an assembler warning. * mpi-pow.c (gcry_mpi_powm): s/exp/expo/ to avoid shadowing warning. * autogen.sh: Allow to override the tool name. Do not run libtoolize. Update required version numbers. * libgcrypt.vers (_gcry_generate_elg_prime): Removed this symbol; gnutls does not need it anymore. * secmem.c (mb_get_new): s/pool/block/ due to global pool. * misc.c (gcry_set_log_handler): s/logf/f/ to avoid shadowing warning against a builtin. * ath-pth-compat.c: cast pth_connect to get rid of the const prototype. * basic.c (check_aes128_cbc_cts_cipher): Make it a prototype * ac.c (check_run): Comment unused variable.
* 2003-06-15 Moritz Schulte <moritz@g10code.com>Moritz Schulte2003-06-151-10/+9
| | | | | | | | | | * global.c (gcry_control): Fixed typo. * misc.c (_gcry_fatal_error): Use gpg_strerror instead of gcry_strerror. * types.h (STRLIST): Removed type since it is not used.
* 2003-03-06 Moritz Schulte <mo@g10code.com>Moritz Schulte2003-03-061-2/+2
| | | | | | | | | | | | * secmem.h (GCRY_SECMEM_FLAG_NO_WARNING, GCRY_SECMEM_FLAG_SUSPEND_WARNING): New symbols. * global.c (gcry_control): Use GCRY_SECMEM_FLAG_{NO,SUSPEND}_WARNING, instead of hard-coded values. * secmem.c (_gcry_secmem_set_flags): Likewise. * secmem.c (_gcry_secmem_get_flags): Likewise.
* 2003-03-03 Moritz Schulte <moritz@g10code.com>Moritz Schulte2003-03-041-1/+1
| | | | | | | | | | | | | | * misc.c: Removed old FIXME, since there is already a function to set the value of `verbosity_level'. * gcrypt.h: Removed enumeration list: gcry_ctl_cmds. New enumeration lists: gcry_global_control_cmds, gcry_control_cmds, gcry_info_cmds, gcry_algo_info_cmds. 2003-03-02 Moritz Schulte <moritz@g10code.com> * gcrypt.h (gcry_cipher_reset): New macro for resetting a handle.
* 2003-02-28 Moritz Schulte <moritz@g10code.com>Moritz Schulte2003-03-011-1/+12
| | | | | | | | | | | | | | | | | | | * secmem.c (DEFAULT_PAGESIZE): New symbol. (init_pool): Use DEFAULT_PAGESIZE. 2003-02-23 Moritz Schulte <moritz@g10code.com> * secmem.h: Fix typo in declaration of _gcry_secmem_term. * sexp.c: Move macro definitions of `digitp', `octdigit', `alphap' and `hexdigit' ... * g10lib.h: ... here. * misc.c (_gcry_burn_stack): New function (former name: burn_stack). * g10lib.h (burn_stack): Declare _gcry_burn_stack().
* * misc.c (_gcry_log_printf): Don't initialize a va_list. Noted byWerner Koch2002-05-211-1/+1
| | | | | Jeff Johnson.
* Change the license to the LGPL.now-less-freedom-protectedWerner Koch2002-05-141-7/+7
|
* * misc.c (_gcry_log_printf): New.Werner Koch2001-12-061-0/+12
| | | | | | * sexp.c (dump_string,gcry_sexp_dump): Use logging functions instead of stderr.
* The first libgcrypt only release.V1-1-3Werner Koch2001-05-311-22/+22
|
* Changed program name in all filesWerner Koch2000-12-211-3/+3
|
* See ChangeLog: Wed Dec 8 21:58:32 CET 1999 Werner KochWerner Koch1999-12-081-4/+17
|
* See ChangeLog: Fri Nov 19 17:15:20 CET 1999 Werner KochWerner Koch1999-11-191-0/+123
|
* See ChangeLog: Mon Nov 15 21:36:02 CET 1999 Werner KochWerner Koch1999-11-151-7/+40
|
* See ChangeLog: Fri Feb 19 15:49:15 CET 1999 Werner KochWerner Koch1999-02-191-3/+3
|
* See ChangeLog: Wed Feb 10 17:15:39 CET 1999 Werner KochWerner Koch1999-02-101-0/+12
|
* See ChangeLog: Tue Dec 29 14:41:47 CET 1998 Werner KochWerner Koch1998-12-291-0/+38