summaryrefslogtreecommitdiff
path: root/mpi/mpicoder.c
AgeCommit message (Collapse)AuthorFilesLines
2014-07-25mpi: Extend the internal mpi_get_buffer.Werner Koch1-12/+37
* mpi/mpicoder.c (do_get_buffer): Add arg EXTRAALLOC. (_gcry_mpi_get_buffer_extra): New.
2013-12-12Remove macro hacks for internal vs. external functions. Part 2 and last.Werner Koch1-15/+15
* 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>
2013-12-05Remove macro hacks for internal vs. external functions. Part 1.Werner Koch1-37/+35
* 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>
2013-10-29Typo fix.Werner Koch1-1/+1
--
2013-10-23mpi: Fix scanning of negative SSH formats and add more tests.Werner Koch1-1/+1
* mpi/mpicoder.c (gcry_mpi_scan): Fix sign setting for SSH format. * tests/t-convert.c (negative_zero): Test all formats. (check_formats): Add tests for PGP and scan tests for SSH and USG. * src/gcrypt.h.in (mpi_is_neg): Fix macro. * mpi/mpi-scan.c (_gcry_mpi_getbyte, _gcry_mpi_putbyte): Comment out these unused functions. Signed-off-by: Werner Koch <wk@gnupg.org>
2013-09-19pk: Move s-expr creation for sign and encrypt to the modules.Werner Koch1-0/+58
* cipher/pubkey.c (pubkey_encrypt): Fold into gcry_pk_encrypt. (pubkey_decrypt): Fold into gcry_pk_decrypt. (pubkey_sign): Fold into gcry_pk_sign. (pubkey_verify): Fold into gcry_pk_verify. (octet_string_from_mpi): Make it a wrapper and factor code out to ... * mpi/mpicoder.c (_gcry_mpi_to_octet_string): New function. * src/cipher.h (PUBKEY_FLAG_FIXEDLEN): New. * cipher/pubkey.c (sexp_data_to_mpi): Set flag for some encodings. (gcry_pk_encrypt): Simply by moving the s-expr generation to the modules. (gcry_pk_sign): Ditto. * cipher/dsa.c (dsa_sign): Create s-expr. * cipher/elgamal.c (elg_encrypt, elg_sign): Ditto. * cipher/rsa.c (rsa_encrypt, rsa_sign): Ditto. * cipher/ecc.c (ecc_sign, ecc_encrypt_raw): Ditto. (ecdsa_names): Add "eddsa". * tests/t-ed25519.c (one_test): Expect "eddsa" token. Signed-off-by: Werner Koch <wk@gnupg.org>
2013-09-17mpi: Support printing of negative numbers.Werner Koch1-26/+111
* mpi/mpicoder.c (twocompl, onecompl): New. (gcry_mpi_print): Use it for STD and SSH. (gcry_mpi_scan): Use it for STD and SSH. Always set NSCANNED. (gcry_mpi_aprint): Clear the extra allocated byte. * tests/t-convert.c (showhex, showmpi): New. (mpi2bitstr_nlz): New. (check_formats): New. (main): Call new test. Signed-off-by: Werner Koch <wk@gnupg.org>
2013-09-16ecc: Implement Curve Ed25519 signing and verification.Werner Koch1-15/+42
* 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>
2013-09-11Streamline the use of the internal mpi and hex debug functions.Werner Koch1-59/+0
* 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>
2013-08-30mpi: Make gcry_mpi_print work with negative zeroes.Werner Koch1-9/+27
* mpi/mpicoder.c (gcry_mpi_print): Take care of negative zero. (gcry_mpi_aprint): Allocate at least 1 byte. * tests/t-convert.c: New. * tests/Makefile.am (TESTS): Add t-convert. -- Reported-by: Christian Fuchs Signed-off-by: Werner Koch <wk@gnupg.org>
2013-07-17Allow gcry_mpi_dump to print opaque MPIs.Werner Koch1-0/+11
* mpi/mpicoder.c (gcry_mpi_dump): Detect abd print opaque MPIs. * tests/mpitests.c (test_opaque): New. (main): Call new test. Signed-off-by: Werner Koch <wk@gnupg.org>
2013-03-13Add GCRYMPI_FLAG_IMMUTABLE to help debugging.Werner Koch1-0/+6
* src/gcrypt.h.in (GCRYMPI_FLAG_IMMUTABLE): New. * src/mpi.h (mpi_is_immutable): New macro. * mpi/mpiutil.c (gcry_mpi_set_flag, gcry_mpi_clear_flag) (gcry_mpi_get_flag): Implement new flag (_gcry_mpi_immutable_failed): New. * mpi/mpiutil.c (_gcry_mpi_clear, _gcry_mpi_free, gcry_mpi_snatch) (gcry_mpi_set, gcry_mpi_randomize): Act upon the immutable flag. * mpi/mpi-bit.c (gcry_mpi_set_bit, gcry_mpi_set_highbit) (gcry_mpi_clear_highbit, gcry_mpi_clear_bit) (_gcry_mpi_rshift_limbs, gcry_mpi_lshift): Ditto. * mpi/mpicoder.c (_gcry_mpi_set_buffer): Ditto. -- Note that this flag is currently only checked by a few MPI functions. The reason why we eventually need such a flag is to help implementing a generic way to retrieve and set ECC parameters without accidentally changing a curve parameter taken from a list of predefined curves.
2012-11-05Avoid dereferencing pointer right after the endWerner Koch1-1/+1
* mpi/mpicoder.c (do_get_buffer): Check the length before derefing P. -- Christian Grothoff found this bug using Valgrind.
2011-02-04Nuked almost all trailing whitespace.Werner Koch1-34/+33
Check and install the standard git pre-commit hook.
2009-05-26Fix reading of a zero MPIs.Werner Koch1-5/+0
2009-02-16Portability fixes.Werner Koch1-0/+4
2008-12-05Fixed error cases in mpicoder.Werner Koch1-27/+61
Documentation cleanups.
2008-12-04Re-indent source4.Werner Koch1-404/+472
2008-08-29Overhauled the keygrip computation.Werner Koch1-2/+2
2008-08-20Replace assert calls by a new gcry_assert at most places.Werner Koch1-4/+3
2007-02-21A lot of cleanups as well as minor API changes.Werner Koch1-1/+3
Ported some changes from 1.2 to here.
2006-07-26Collected changes - see ChangeLogsWerner Koch1-51/+57
2003-07-28Minor char * to unsigned char* changes. The general rule is to useWerner Koch1-4/+6
unsigned char * for memory buffers which are not Nul-terminated
2003-07-27* gcrypt.h (gcry_mpi_scan, gcry_mpi_print): API change.Werner Koch1-86/+92
(gcry_mpi_dump): New. * mpicoder.c (gcry_mpi_scan): New argument BUFLEN to replace the use of the intial value of NBYTES. (gcry_mpi_print): Likewise. (gcry_mpi_dump): New. (_gcry_log_mpidump): Make use of gcry_mpi_dump. (mpi_print): Removed. (gcry_mpi_scan): Allocated mpi in secure memory when required. * gcrypt.texi: Adjusted description of gcry_mpi_scan and gcry_mpi_dump. Add gcry_mpi_dump.
2003-07-142003-07-14 Moritz Schulte <moritz@g10code.com>Moritz Schulte1-31/+31
* mpicoder.c: Used gcry_err* wrappers for libgpg-error symbols.
2003-06-172003-06-16 Moritz Schulte <moritz@g10code.com>Moritz Schulte1-9/+9
* mpi-add.c: Replace last occurences of old type names with newer names (i.e. replace MPI with gcry_mpi_t). * mpi-bit.c: Likewise. * mpi-cmp.c: Likewise. * mpi-div.c: Likewise. * mpi-gcd.c: Likewise. * mpi-internal.h: Likewise. * mpi-inv.c: Likewise. * mpi-mpow.c: Likewise. * mpi-mul.c: Likewise. * mpi-pow.c: Likewise. * mpi-scan.c: Likewise. * mpicoder.c: Likewise. * mpiutil.c: Likewise.
2003-06-092003-06-09 Moritz Schulte <moritz@g10code.com>Moritz Schulte1-52/+50
* mpicoder.c (gcry_mpi_scan): Adjust for libgpg-error. (gcry_mpi_print): Likewise. (gcry_mpi_aprint): Likewise. 2003-06-07 Moritz Schulte <moritz@g10code.com> * longlong.h, mpi-add.c, mpi-bit.c, mpi-cmp.c, mpi-div.c, mpi-gcd.c, mpi-inline.c, mpi-inline.h, mpi-internal.h, mpi-inv.c, mpi-mpow.c, mpi-mul.c, mpi-pow.c, mpi-scan.c, mpicoder.c, mpih-div.c, mpih-mul.c, mpiutil.c, generic/mpi-asm-defs.h, generic/mpih-add1.c, generic/mpih-lshift.c, generic/mpih-mul1.c, generic/mpih-mul2.c, generic/mpih-mul3.c, generic/mpih-rshift.c, generic/mpih-sub1.c, generic/udiv-w-sdiv.c, i386/syntax.h, m68k/syntax.h, mips3/mpi-asm-defs.h, powerpc32/syntax.h: Edited all preprocessor instructions to remove whitespace before the '#'. This is not required by C89, but there are some compilers out there that don't like it. Replaced any occurence of the now deprecated type names with the new ones.
2003-04-02* mpicoder.c (gcry_mpi_print): Fixed testing against possibleWerner Koch1-5/+5
uninitialized LEN. Valgrinded by Nikos Mavroyanopoulos.
2002-06-25* mpiutil.c (gcry_mpi_swap): New.Werner Koch1-2/+4
* mpi-div.c (gcry_mpi_div): New. (gcry_mpi_mod): New. * mpi-inv.c (gcry_mpi_invm): New. * mpicoder.c (do_get_buffer): Make sure that we allocate at least one byte.
2002-05-14Change the license to the LGPL.Werner Koch1-7/+7
2002-05-02* mpicoder.c (gcry_mpi_scan): Don't use normalize on a NULL MPI.Werner Koch1-1/+1
2002-03-20* mpicoder.c (mpi_read_from_buffer): Bail out on a zero lengthWerner Koch1-1/+5
buffer because we can't eventually do an malloc of this size. Reported by Timo.
2002-02-07issue #warning only for gcc.Werner Koch1-1/+5
Ready to release 1.1.6
2001-11-15Changes mainly to fix automake problemsWerner Koch1-6/+9
2001-05-31The first libgcrypt only release.Werner Koch1-26/+26
2001-05-28Merged back some changes fron gnupg. Fixed doc building.Werner Koch1-8/+8
2000-12-21Changed program name in all filesWerner Koch1-3/+3
2000-11-14Some configuration changesWerner Koch1-2/+0
2000-07-28See ChangeLog: Fri Jul 28 18:19:11 CEST 2000 Werner KochWerner Koch1-5/+15
2000-01-24See ChangeLog: Mon Jan 24 22:24:38 CET 2000 Werner KochWerner Koch1-0/+2
2000-01-24See ChangeLog: Mon Jan 24 13:04:28 CET 2000 Werner KochWerner Koch1-17/+56
1999-12-31See ChangeLog: Fri Dec 31 12:48:31 CET 1999 Werner KochWerner Koch1-65/+60
1999-12-08See ChangeLog: Wed Dec 8 21:58:32 CET 1999 Werner KochWerner Koch1-107/+231
1999-11-19See ChangeLog: Fri Nov 19 17:15:20 CET 1999 Werner KochWerner Koch1-2/+12
1999-07-07See ChangeLog: Wed Jul 7 13:23:40 CEST 1999 Werner KochWerner Koch1-0/+10
1998-12-23See ChangeLog: Wed Dec 23 13:34:22 CET 1998 Werner KochWerner Koch1-3/+3
1998-08-07chnages done at the trainWerner Koch1-1/+0
1998-08-05intermediate check inWerner Koch1-0/+44
1998-06-16some more internall structure changesWerner Koch1-4/+11
1998-04-14applied Mathews typo and grammar fixesWerner Koch1-6/+6