diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..8788cd8 --- /dev/null +++ b/AUTHORS @@ -0,0 +1 @@ +Mikaël Ates diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..bf50f20 --- /dev/null +++ b/COPYING @@ -0,0 +1,482 @@ + GNU LIBRARY GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the library GPL. It is + numbered 2 because it goes with version 2 of the ordinary GPL.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Library General Public License, applies to some +specially designated Free Software Foundation software, and to any +other libraries whose authors decide to use it. You can use it for +your libraries, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if +you distribute copies of the library, or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link a program with the library, you must provide +complete object files to the recipients so that they can relink them +with the library, after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + Our method of protecting your rights has two steps: (1) copyright +the library, and (2) offer you this license which gives you legal +permission to copy, distribute and/or modify the library. + + Also, for each distributor's protection, we want to make certain +that everyone understands that there is no warranty for this free +library. If the library is modified by someone else and passed on, we +want its recipients to know that what they have is not the original +version, so that any problems introduced by others will not reflect on +the original authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that companies distributing free +software will individually obtain patent licenses, thus in effect +transforming the program into proprietary software. To prevent this, +we have made it clear that any patent must be licensed for everyone's +free use or not licensed at all. + + Most GNU software, including some libraries, is covered by the ordinary +GNU General Public License, which was designed for utility programs. This +license, the GNU Library General Public License, applies to certain +designated libraries. This license is quite different from the ordinary +one; be sure to read it in full, and don't assume that anything in it is +the same as in the ordinary license. + + The reason we have a separate public license for some libraries is that +they blur the distinction we usually make between modifying or adding to a +program and simply using it. Linking a program with a library, without +changing the library, is in some sense simply using the library, and is +analogous to running a utility program or application program. However, in +a textual and legal sense, the linked executable is a combined work, a +derivative of the original library, and the ordinary General Public License +treats it as such. + + Because of this blurred distinction, using the ordinary General +Public License for libraries did not effectively promote software +sharing, because most developers did not use the libraries. We +concluded that weaker conditions might promote sharing better. + + However, unrestricted linking of non-free programs would deprive the +users of those programs of all benefit from the free status of the +libraries themselves. This Library General Public License is intended to +permit developers of non-free programs to use free libraries, while +preserving your freedom as a user of such programs to change the free +libraries that are incorporated in them. (We have not seen how to achieve +this as regards changes in header files, but we have achieved it as regards +changes in the actual functions of the Library.) The hope is that this +will lead to faster development of free libraries. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, while the latter only +works together with the library. + + Note that it is possible for a library to be covered by the ordinary +General Public License rather than by this special one. + + GNU LIBRARY GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library which +contains a notice placed by the copyright holder or other authorized +party saying it may be distributed under the terms of this Library +General Public License (also called "this License"). Each licensee is +addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also compile or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + c) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + d) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the source code distributed need not include anything that is normally +distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Library General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307 USA. + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..a4c6e39 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,20 @@ +ACLOCAL_AMFLAGS = -I m4 + +#pour afficher les deps de cryptic +pkgconfig_DATA = cryptic.pc +pkgconfigdir = $(libdir)/pkgconfig + +SUBDIRS = cryptic tests bindings +#SUBDIRS = cryptic tests + +#Ajout de fichier au .tgz +EXTRA_DIST = COPYING cryptic.pc.in autogen.sh + +# clean nromal + rm -f cryptic.pc +#-rm si rm échoue pas de blocage... +clean-local: + -rm -f cryptic.pc + +dist-hook: + -rm -rf `find $(distdir) -name .svn` + diff --git a/README b/README index 8b13789..ce029ca 100644 --- a/README +++ b/README @@ -1 +1,20 @@ +General Information +=================== + +Cryptographic tools and protocols + +Installation +============ + +Please check the Makefile before trying to compile. +Then, + + autogen.sh + make + make install + +Author +====== + +Mikaël Ates diff --git a/TODO b/TODO new file mode 100644 index 0000000..820e442 --- /dev/null +++ b/TODO @@ -0,0 +1,21 @@ +GROUPS +====== +- Reallocation to add base. +- Pedersen zkpk. + +PROOFS +====== +- Non interactive proof (Fiat Shamir Heuristic) for Shnorr. +- Pedersen. + +CLSIG +===== +- Non interactive proof of good public parameters generation. + +BINDINGS +====== +- Java. + +OTHERS +====== +- Tests. diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..5ba580c --- /dev/null +++ b/autogen.sh @@ -0,0 +1,96 @@ +#!/bin/sh +# Run this to generate all the initial makefiles, etc. + +PROJECT=cryptic +TEST_TYPE=-f +FILE=cryptic.pc.in + +# a silly hack that generates autoregen.sh but it's handy +echo "#!/bin/sh" > autoregen.sh +echo "./autogen.sh $@ \$@" >> autoregen.sh +chmod +x autoregen.sh + +DIE=0 + +srcdir=`dirname $0` +test -z "$srcdir" && srcdir=. + +THEDIR="`pwd`" + +cd "$srcdir" + +(autoconf --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have autoconf installed to compile $PROJECT." + echo "Download the appropriate package for your distribution," + echo "or get the source tarball at ftp://ftp.gnu.org/gnu/autoconf/" + DIE=1 +} + +if automake-1.11 --version < /dev/null > /dev/null 2>&1; then + AUTOMAKE=automake-1.11 + ACLOCAL=aclocal-1.11 +elif automake-1.10 --version < /dev/null > /dev/null 2>&1; then + AUTOMAKE=automake-1.10 + ACLOCAL=aclocal-1.10 +elif automake-1.9 --version < /dev/null > /dev/null 2>&1; then + AUTOMAKE=automake-1.9 + ACLOCAL=aclocal-1.9 +elif automake-1.8 --version < /dev/null > /dev/null 2>&1; then + AUTOMAKE=automake-1.8 + ACLOCAL=aclocal-1.8 +elif automake-1.7 --version < /dev/null > /dev/null 2>&1; then + AUTOMAKE=automake-1.7 + ACLOCAL=aclocal-1.7 +elif automake-1.6 --version < /dev/null > /dev/null 2>&1; then + AUTOMAKE=automake-1.6 + ACLOCAL=aclocal-1.6 +else + echo + echo "You must have automake installed to compile $PROJECT." + echo "Download the appropriate package for your distribution," + echo "or get the source tarball at ftp://ftp.gnu.org/gnu/automake/" + DIE=1 +fi + +if test "$DIE" -eq 1; then + exit 1 +fi + +test $TEST_TYPE $FILE || { + echo "You must run this script in the top-level $PROJECT directory" + exit 1 +} + +if test "$#" = 0; then + echo "I am going to run ./configure with no arguments - if you wish " + echo "to pass any to it, please specify them on the $0 command line." +fi + +# to support timj aclocal setup we are shipping gnome-doc-utils.m4 +# and making sure automake picks it up ;) +# this is bad as -I prepends to the search path +echo "* Running libtoolize" +libtoolize --copy --force + +echo "* Running gtkdocize" +gtkdocize --flavour no-tmpl || exit $? + +echo "* Running $ACLOCAL" +$ACLOCAL $ACLOCAL_FLAGS -I m4 || exit $? + +echo "* Running autoconf" +autoconf || exit $? +(autoheader --version) < /dev/null > /dev/null 2>&1 && autoheader + +echo "* Running $AUTOMAKE" +$AUTOMAKE --add-missing -Wno-portability $am_opt || exit $? + +cd "$THEDIR" + +if [ "$1" != "noconfig" ]; then + $srcdir/configure --enable-gtk-doc --enable-maintainer-mode "$@" || exit $? +fi + +echo +echo "Now type 'make install' to install $PROJECT." diff --git a/autoregen.sh b/autoregen.sh new file mode 100755 index 0000000..c67a299 --- /dev/null +++ b/autoregen.sh @@ -0,0 +1,2 @@ +#!/bin/sh +./autogen.sh $@ diff --git a/bindings/Makefile.am b/bindings/Makefile.am new file mode 100644 index 0000000..9276412 --- /dev/null +++ b/bindings/Makefile.am @@ -0,0 +1,25 @@ +MAINTAINERCLEANFILES = Makefile.in +SUBDIRS = +if PYTHON_ENABLED +SUBDIRS += python +endif +#if PHP5_ENABLED +#SUBDIRS += php5 +#endif +if JAVA_ENABLED +SUBDIRS += java +endif +#if PERL_ENABLED +#SUBDIRS += perl +#endif + +CLEANFILES = bindings.pyc lang_java.pyc lang_python.pyc lang_php5.pyc \ + utils.pyc lang_php5_helpers/__init__.pyc lang_php5_helpers/php_code.pyc \ + lang_php5_helpers/wrapper_header.pyc lang_php5_helpers/wrapper_source.pyc + +EXTRA_DIST = bindings.py \ + overrides.xml \ + utils.py \ + utility-scripts/error-analyzer.pl \ + ghashtable.h + diff --git a/bindings/Makefile.in b/bindings/Makefile.in new file mode 100644 index 0000000..3f1ab88 --- /dev/null +++ b/bindings/Makefile.in @@ -0,0 +1,683 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +@PYTHON_ENABLED_TRUE@am__append_1 = python +#if PHP5_ENABLED +#SUBDIRS += php5 +#endif +@JAVA_ENABLED_TRUE@am__append_2 = java +subdir = bindings +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/ac_check_class.m4 \ + $(top_srcdir)/m4/ac_check_classpath.m4 \ + $(top_srcdir)/m4/ac_check_junit.m4 \ + $(top_srcdir)/m4/ac_prog_jar.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/ac_prog_javah.m4 \ + $(top_srcdir)/m4/ac_try_compile_java.m4 \ + $(top_srcdir)/m4/as-compiler-flag.m4 \ + $(top_srcdir)/m4/dps_java_check_class.m4 \ + $(top_srcdir)/m4/dps_xtra_classpath.m4 \ + $(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/libtool.m4 \ + $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ + $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +SOURCES = +DIST_SOURCES = +RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \ + html-recursive info-recursive install-data-recursive \ + install-dvi-recursive install-exec-recursive \ + install-html-recursive install-info-recursive \ + install-pdf-recursive install-ps-recursive install-recursive \ + installcheck-recursive installdirs-recursive pdf-recursive \ + ps-recursive uninstall-recursive +RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ + distclean-recursive maintainer-clean-recursive +AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \ + $(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \ + distdir +ETAGS = etags +CTAGS = ctags +DIST_SUBDIRS = python java +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +am__relativize = \ + dir0=`pwd`; \ + sed_first='s,^\([^/]*\)/.*$$,\1,'; \ + sed_rest='s,^[^/]*/*,,'; \ + sed_last='s,^.*/\([^/]*\)$$,\1,'; \ + sed_butlast='s,/*[^/]*$$,,'; \ + while test -n "$$dir1"; do \ + first=`echo "$$dir1" | sed -e "$$sed_first"`; \ + if test "$$first" != "."; then \ + if test "$$first" = ".."; then \ + dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ + dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ + else \ + first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ + if test "$$first2" = "$$first"; then \ + dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ + else \ + dir2="../$$dir2"; \ + fi; \ + dir0="$$dir0"/"$$first"; \ + fi; \ + fi; \ + dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ + done; \ + reldir="$$dir2" +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_CFLAGS = @AM_CFLAGS@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AS = @AS@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CHECK_CFLAGS = @CHECK_CFLAGS@ +CHECK_LIBS = @CHECK_LIBS@ +CLASSPATH_JUNIT = @CLASSPATH_JUNIT@ +CLASSPATH_OPT = @CLASSPATH_OPT@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CRYPTIC_APP_DEFINES = @CRYPTIC_APP_DEFINES@ +CRYPTIC_CFLAGS = @CRYPTIC_CFLAGS@ +CRYPTIC_CORE_CFLAGS = @CRYPTIC_CORE_CFLAGS@ +CRYPTIC_CORE_LIBS = @CRYPTIC_CORE_LIBS@ +CRYPTIC_DEFINES = @CRYPTIC_DEFINES@ +CRYPTIC_DOCDIR = @CRYPTIC_DOCDIR@ +CRYPTIC_LIBS = @CRYPTIC_LIBS@ +CRYPTIC_PUB_CFLAGS = @CRYPTIC_PUB_CFLAGS@ +CRYPTIC_STATIC_BINARIES = @CRYPTIC_STATIC_BINARIES@ +CRYPTIC_VERSION_INFO = @CRYPTIC_VERSION_INFO@ +CSHARPCILINTERPRETER = @CSHARPCILINTERPRETER@ +CSHARPCOMPILER = @CSHARPCOMPILER@ +CSHARPCYGPATH_W = @CSHARPCYGPATH_W@ +CSHARPDYNAMICLINKING = @CSHARPDYNAMICLINKING@ +CSHARPLIBRARYPREFIX = @CSHARPLIBRARYPREFIX@ +CYGPATH_W = @CYGPATH_W@ +DEBUGGING = @DEBUGGING@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DLL_FILENAME = @DLL_FILENAME@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GACUTIL = @GACUTIL@ +GREP = @GREP@ +GTKDOC_CHECK = @GTKDOC_CHECK@ +GTKDOC_MKPDF = @GTKDOC_MKPDF@ +GTKDOC_REBASE = @GTKDOC_REBASE@ +HTML_DIR = @HTML_DIR@ +INKSCAPE = @INKSCAPE@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_FLAGS = @JAVAC_FLAGS@ +JAVAH = @JAVAH@ +JAVAH_FLAGS = @JAVAH_FLAGS@ +JAVA_INCLUDE = @JAVA_INCLUDE@ +JAVA_JUNIT = @JAVA_JUNIT@ +JAVA_VERSION = @JAVA_VERSION@ +JDK_INCLUDE = @JDK_INCLUDE@ +JUNIT = @JUNIT@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBTOOL_DEPS = @LIBTOOL_DEPS@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ +PERLINSTALLSITEARCH = @PERLINSTALLSITEARCH@ +PERLMAN3DIR = @PERLMAN3DIR@ +PERL_VERSION = @PERL_VERSION@ +PHP5 = @PHP5@ +PHP5_CONFIG = @PHP5_CONFIG@ +PHP5_CONFIG_DIR = @PHP5_CONFIG_DIR@ +PHP5_EXTENSION_DIR = @PHP5_EXTENSION_DIR@ +PHP5_INCLUDES = @PHP5_INCLUDES@ +PHP5_INCLUDE_DIR = @PHP5_INCLUDE_DIR@ +PHP5_LDFLAGS = @PHP5_LDFLAGS@ +PHP5_LIBS = @PHP5_LIBS@ +PHP5_PREFIX = @PHP5_PREFIX@ +PHP5_UNPREFIXED_EXTENSION_DIR = @PHP5_UNPREFIXED_EXTENSION_DIR@ +PHP5_VERSION = @PHP5_VERSION@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +PYTHON = @PYTHON@ +PYTHON_VERSION = @PYTHON_VERSION@ +PY_CFLAGS = @PY_CFLAGS@ +PY_DYNLOAD = @PY_DYNLOAD@ +PY_EXTRA_LIBS = @PY_EXTRA_LIBS@ +PY_LIB_A = @PY_LIB_A@ +PY_LIB_LOC = @PY_LIB_LOC@ +PY_SITE_PACKAGES = @PY_SITE_PACKAGES@ +RANLIB = @RANLIB@ +RC = @RC@ +REST2HTML = @REST2HTML@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +SWIG = @SWIG@ +SWIG_PYTHON_ARGS = @SWIG_PYTHON_ARGS@ +SWIG_VERSION = @SWIG_VERSION@ +TAR = @TAR@ +TESTS_JUNIT = @TESTS_JUNIT@ +U = @U@ +UPCASED_DLL_FILENAME = @UPCASED_DLL_FILENAME@ +VERSION = @VERSION@ +VERSION_UNDERSCORED = @VERSION_UNDERSCORED@ +WINDOWS_VERSION = @WINDOWS_VERSION@ +XSLTPROC = @XSLTPROC@ +Z_CFLAGS = @Z_CFLAGS@ +Z_LIBS = @Z_LIBS@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +lt_ECHO = @lt_ECHO@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +MAINTAINERCLEANFILES = Makefile.in +SUBDIRS = $(am__append_1) $(am__append_2) +#if PERL_ENABLED +#SUBDIRS += perl +#endif +CLEANFILES = bindings.pyc lang_java.pyc lang_python.pyc lang_php5.pyc \ + utils.pyc lang_php5_helpers/__init__.pyc lang_php5_helpers/php_code.pyc \ + lang_php5_helpers/wrapper_header.pyc lang_php5_helpers/wrapper_source.pyc + +EXTRA_DIST = bindings.py \ + overrides.xml \ + utils.py \ + utility-scripts/error-analyzer.pl \ + ghashtable.h + +all: all-recursive + +.SUFFIXES: +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign bindings/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign bindings/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +# This directory's subdirectories are mostly independent; you can cd +# into them and run `make' without going through this Makefile. +# To change the values of `make' variables: instead of editing Makefiles, +# (1) if the variable is set in `config.status', edit `config.status' +# (which will cause the Makefiles to be regenerated when you run `make'); +# (2) otherwise, pass the desired values on the `make' command line. +$(RECURSIVE_TARGETS): + @fail= failcom='exit 1'; \ + for f in x $$MAKEFLAGS; do \ + case $$f in \ + *=* | --[!k]*);; \ + *k*) failcom='fail=yes';; \ + esac; \ + done; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + +$(RECURSIVE_CLEAN_TARGETS): + @fail= failcom='exit 1'; \ + for f in x $$MAKEFLAGS; do \ + case $$f in \ + *=* | --[!k]*);; \ + *k*) failcom='fail=yes';; \ + esac; \ + done; \ + dot_seen=no; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + rev=''; for subdir in $$list; do \ + if test "$$subdir" = "."; then :; else \ + rev="$$subdir $$rev"; \ + fi; \ + done; \ + rev="$$rev ."; \ + target=`echo $@ | sed s/-recursive//`; \ + for subdir in $$rev; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done && test -z "$$fail" +tags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ + done +ctags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + empty_fix=.; \ + else \ + include_option=--include; \ + empty_fix=; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test ! -f $$subdir/TAGS || \ + set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done + @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test -d "$(distdir)/$$subdir" \ + || $(MKDIR_P) "$(distdir)/$$subdir" \ + || exit 1; \ + fi; \ + done + @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ + $(am__relativize); \ + new_distdir=$$reldir; \ + dir1=$$subdir; dir2="$(top_distdir)"; \ + $(am__relativize); \ + new_top_distdir=$$reldir; \ + echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ + echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ + ($(am__cd) $$subdir && \ + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="$$new_top_distdir" \ + distdir="$$new_distdir" \ + am__remove_distdir=: \ + am__skip_length_check=: \ + am__skip_mode_fix=: \ + distdir) \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-recursive +all-am: Makefile +installdirs: installdirs-recursive +installdirs-am: +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-recursive +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." + -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) +clean: clean-recursive + +clean-am: clean-generic clean-libtool mostlyclean-am + +distclean: distclean-recursive + -rm -f Makefile +distclean-am: clean-am distclean-generic distclean-tags + +dvi: dvi-recursive + +dvi-am: + +html: html-recursive + +html-am: + +info: info-recursive + +info-am: + +install-data-am: + +install-dvi: install-dvi-recursive + +install-dvi-am: + +install-exec-am: + +install-html: install-html-recursive + +install-html-am: + +install-info: install-info-recursive + +install-info-am: + +install-man: + +install-pdf: install-pdf-recursive + +install-pdf-am: + +install-ps: install-ps-recursive + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-recursive + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-recursive + +mostlyclean-am: mostlyclean-generic mostlyclean-libtool + +pdf: pdf-recursive + +pdf-am: + +ps: ps-recursive + +ps-am: + +uninstall-am: + +.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) ctags-recursive \ + install-am install-strip tags-recursive + +.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \ + all all-am check check-am clean clean-generic clean-libtool \ + ctags ctags-recursive distclean distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs installdirs-am maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am tags tags-recursive \ + uninstall uninstall-am + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/bindings/bindings.py b/bindings/bindings.py new file mode 100644 index 0000000..12a2b12 --- /dev/null +++ b/bindings/bindings.py @@ -0,0 +1,632 @@ +#! /usr/bin/env python +# +# Lasso - A free implementation of the Liberty Alliance specifications. +# +# Copyright (C) 2004-2007 Entr'ouvert +# http://lasso.entrouvert.org +# +# Authors: See AUTHORS file in top-level directory. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +import os +import re +import sys +from utils import * + +from optparse import OptionParser + +try: + from lxml import etree as ET +except ImportError: + try: + import cElementTree as ET + except ImportError: + try: + import elementtree.ElementTree as ET + except ImportError: + import xml.etree.ElementTree as ET + +sys.path.append(os.path.dirname(__file__)) + +# monkey patch os.path to include relpath if python version is < 2.6 +if not hasattr(os.path, "relpath"): + def relpath(longPath, basePath): + if not longPath.startswith(basePath): + raise RuntimeError("Unexpected arguments") + if longPath == basePath: + return "." + i = len(basePath) + if not basePath.endswith(os.path.sep): + i += len(os.path.sep) + return longPath[i:] + + os.path.relpath = relpath + + + +class BindingData: + src_dir = os.path.dirname(__file__) + + def __init__(self, options = None): + self.headers = [] + # [(char,string)] + # where char is: + # - i: integer + # - s: string + self.constants = [] + self.structs = [] + self.struct_dict = {} + self.functions = [] + self.enums = [] + self.options = options + self.overrides = ET.parse(os.path.join(self.src_dir, 'overrides.xml')) + self.functions_toskip = dict() + self.structs_toskip = dict() + + for func in self.overrides.findall('func'): + if func.attrib.get('skip') == 'true': + self.functions_toskip[func.attrib.get('name')] = 1 + for struct in self.overrides.findall('struct'): + if struct.attrib.get('skip') == 'true': + self.structs_toskip[struct.attrib.get('name')] = 1 + + def match_tag_language(self,tag): + if self.options and self.options.language: + languages = tag.attrib.get('language') + if languages: + lang_list = languages.split(' ') + if self.options.language in lang_list: + return True + else: + return False + else: + return True + else: + return True + + def display_structs(self): + for struct in self.structs: + struct.display() + + def display_funcs(self): + for func in self.functions: + print func.return_type, func.name + for a in func.args: + print ' ', a + + def order_class_hierarchy(self): + new_order = [] + while self.structs: + for c in self.structs: + if c.parent == 'GObject' or c.parent in [x.name for x in new_order]: + self.structs.remove(c) + new_order.append(c) + break + self.structs = new_order + + def create_struct_dict(self): + for c in self.structs: + self.struct_dict[c.name] = c + + def attach_methods(self): + self.create_struct_dict() + for f in self.functions[:]: + if len(f.args) == 0: + continue + if f.name.endswith('_new') or '_new_' in f.name: + # constructor for another class + continue + arg_type = f.args[0][0] + if arg_type[-1] == '*': + arg_type = arg_type[:-1] + arg_type = arg_type.replace('const ','') + c = self.struct_dict.get(arg_type) + if not c: + continue +################## Only methods with the first arg is the same as the beginning of the function: +################## xxx_yyy_method_name(XxxYyy *xy,...) + if not f.name.startswith(format_as_underscored(c.name)): + continue +############################################ + c.methods.append(f) + if f.docstring and f.docstring.parameters: + # remove first parameter, which is self/this/etc. + f.docstring.parameters = f.docstring.parameters[1:] + + self.functions.remove(f) + + def look_for_docstrings(self, srcdir, exception_doc): + def getfunc(name): + funcs = [f for f in self.functions if f.name == name] + if not funcs: + return None + else: + return funcs[0] + regex = re.compile(r'\/\*\*\s(.*?)\*\/', re.DOTALL) + for base, dirnames, filenames in os.walk(srcdir): + if base.endswith('/.svn'): + # ignore svn directories + continue + if not 'Makefile.am' in filenames: + # not a source dir + continue + makefile_am = open(os.path.join(base, 'Makefile.am')).read() + filenames = [x for x in filenames if x.endswith('.c') if x in makefile_am] + for filename in filenames: + s = open(os.path.join(base, filename)).read() + docstrings = regex.findall(s) + for d in docstrings: + docstring = '\n'.join([x[3:] for x in d.splitlines()]) + function_name = docstring.splitlines(1)[0].strip().strip(':') + func = getfunc(function_name) + if not func: + continue + func.docstring = DocString(func, docstring, self) + if exception_doc: + lines = os.popen('perl ../utility-scripts/error-analyzer.pl %s' % srcdir, 'r').readlines() + for line in lines: + elts = re.split(r' +',line.strip()) + func = getfunc(elts[0]) + if func: + func.errors = elts[1:] + + +class Struct: + def __init__(self, name): + self.name = name[1:] # skip leading _ + self.parent = None + self.members = [] + self.methods = [] + + def __repr__(self): + return '' % (self.name, self.parent) + + def display(self): + print self.__repr__() + for m in self.members: + print ' ', m + for m in self.methods: + print ' ', m + + def getMember(self, name): + l = [m for m in self.members if arg_name(m) == name] + if l: + return l[0] + else: + return None + + def getMethod(self, name): + l = [m for m in self.methods if m.name == name] + if l: + return l[0] + else: + return None + +toskip = None + + +class Function: + return_type = None + return_type_qualifier = None + return_arg = None + name = None + rename = None + args = None + docstring = None + return_owner = True + skip = False + errors = None + + def __repr__(self): + return '' % ( + self.return_arg, self.name, self.args) + + def apply_overrides(self): + for func in binding.overrides.findall('func'): + if not binding.match_tag_language(func): + continue + if func.attrib.get('name') != self.name: + continue + for param in func.findall('param'): + try: + arg = [x for x in self.args if x[1] == param.attrib.get('name')][0] + except IndexError: + print >> sys.stderr, 'W: no such param (%s) in function (%s)' % ( + param.attrib.get('name'), self.name) + continue + if param.attrib.get('optional') == 'true': + arg[2]['optional'] = True + if param.attrib.get('default'): + arg[2]['default'] = param.attrib.get('default') + if param.attrib.get('type'): + arg[0] = param.attrib.get('type') + if param.attrib.get('elem_type'): + arg[2]['element-type'] = param.attrib.get('elem_type') + if func.attrib.get('rename'): + self.rename = func.attrib.get('rename') + if func.attrib.get('return_owner'): + self.return_owner = (func.attrib.get('return_owner') != 'false') + if func.attrib.get('return_type'): + self.return_type = func.attrib.get('return_type') + if func.attrib.get('skip'): + skip = func.attrib.get('skip') + if skip == 'true': + self.skip = True + elif binding.options.language in skip.split(','): + self.skip = True + if func.attrib.get('return_type_qualifier'): + self.return_type_qualifier = func.attrib.get('return_type_qualifier') + for param in binding.overrides.findall('arg'): + if not binding.match_tag_language(param): + continue + arg_name = param.attrib.get('name') + arg_sub = param.attrib.get('rename') + if arg_name and arg_sub: + args = [ x for x in self.args if x[1] == arg_name] + for arg in args: + arg[2]['original-name'] = arg[1] + arg[1] = arg_sub + + +class DocString: + orig_docstring = None + parameters = None + return_value = None + description = None + + def __init__(self, function, docstring, binding_data): + self.binding_data = binding_data + self.orig_docstring = docstring + self.parameters = [] + self.params = {} + lines = docstring.splitlines() + # ignore the first line, it has the symbol name + lines = lines[1:] + + # look for parameters + while lines[0].strip(): + if not self.parameters and not lines[0].startswith('@'): + # function without parameters + break + if not self.parameters: + self.parameters = [] + + if lines[0][0] == '@': + + splits = lines[0][1:].split(':', 2) + param_name = splits[0] + if len(splits) > 2: + param_options = splits[1] + param_desc = splits[2] + self.parameters.append([param_name, param_desc, param_options]) + self.params[param_name] = { 'desc': param_desc, 'options': param_options } + for a in function.args: + if a[1] == param_name or a[2].get('original-name') == param_name: + arg = a + break + else: + raise Exception('should not happen ' + param_name + ' ' + lines[0] + repr(function)) + self.annotation2arg(arg, param_options) + else: + param_desc = splits[1] + self.parameters.append([param_name, param_desc]) + self.params[param_name] = { 'desc': param_desc } + else: + # continuation of previous description + self.parameters[-1][1] = self.parameters[-1][1] + ' ' + lines[0].strip() + + lines = lines[1:] + + # blank line then description, till the end or the return value + lines = lines[1:] + self.description = '' + while not lines[0].startswith('Return value'): + self.description += lines[0] + '\n' + if len(lines) == 1: + self.description = self.description.strip() + return + lines = lines[1:] + self.description = self.description.strip() + + # return value + if lines[0].startswith('Return value') or lines[0].startswith('Returns'): + lines[0] = lines[0].split(':', 1)[1] + accu = '' + while lines[0].strip(): + accu = accu + ' ' + lines[0].strip() + if len(lines) == 1: + break + lines = lines[1:] + # find GObject-introspection annotations + if re.match(r'\s*\(', accu): + annotation, accu = accu.split(':', 1) + self.annotation2arg(function.return_arg, annotation) + self.return_value = accu.strip() # remove leading space + def annotation2arg(self, arg, annotation): + '''Convert GObject-introspection annotations to arg options''' + + if 'allow-none' in annotation: + arg[2]['optional'] = True + if re.search(r'\(\s*out\s*\)', annotation): + arg[2]['out'] = True + if re.search(r'\(\s*in\s*\)', annotation): + arg[2]['in'] = True + m = re.search(r'\(\s*default\s*([^ )]*)\s*\)', annotation) + if m: + prefix = '' + if is_boolean(arg): + prefix = 'b:' + elif is_int(arg, self.binding_data): + prefix = 'c:' + else: + raise Exception('should not happen: could not found type for default: ' + annotation) + arg[2]['default'] = prefix + m.group(1) + arg[2]['optional'] = True + m = re.search(r'\(\s*element-type\s+(\w+)(?:\s+(\w+))?', annotation) + if m: + if len(m.groups()) > 2: + arg[2]['key-type'] = \ + convert_type_from_gobject_annotation(m.group(1)) + arg[2]['value-type'] = \ + convert_type_from_gobject_annotation(m.group(2)) + else: + arg[2]['element-type'] = \ + convert_type_from_gobject_annotation(m.group(1)) + m = re.search(r'\(\s*transfer\s+(\w+)', annotation) + if m: + arg[2]['transfer'] = m.group(1) + +def normalise_var(type, name): + if name[0] == '*': + type += '*' + name = name[1:] +############## + if name[0] == '*': + type += '*' + name = name[1:] +############ + return type, name + +exclude_private = True + +def parse_header(header_file): + global binding + + struct_names = {} + in_comment = False + in_enum = False + in_struct = None + in_struct_private = False + in_ifdef_zero = False + + lines = file(header_file).readlines() + i = 0 + while i < len(lines): + line = lines[i] + while line.endswith('\\\n'): + i += 1 + line = line[:-2] + ' ' + lines[i].lstrip() + + if in_comment: + if '*/' in line: + in_comment = False + elif '/*' in line and not '*/' in line: + in_comment = True + elif in_ifdef_zero: + # minimal support for code sections commented with #if 0 + if line.startswith('#endif'): + in_ifdef_zero = False + elif line.startswith('#if 0'): + in_ifdef_zero = True + elif in_enum: + if line.startswith('}'): + in_enum = False + enum_name = line[2:].strip().strip(';') + binding.enums.append(enum_name) + else: + m = re.match('\s*([a-zA-Z0-9_]+)', line) + if m: + binding.constants.append(('i', m.group(1))) + elif line.startswith('#define'): + m = re.match(r'#define\s+([a-zA-Z0-9_]+)\s+([-\w"]+)', line) + if m: + constant_name = m.group(1) + if constant_name[0] != '_': + # ignore private constants + if '"' in line: + constant_type = 's' + elif m.group(2).startswith('CRYPTIC_'): + l = [ c for c in binding.constants if m.group(2) == c[1] ] + if l: + contant_type = l[0][0] + else: + raise Exception() + else: + constant_type = 'i' + constant = (constant_type, constant_name) + binding.constants.append(constant) + elif line.startswith('typedef enum {'): + in_enum = True + elif line.startswith('typedef struct'): + m = re.match('typedef struct ([a-zA-Z0-9_]+)', line) + if m: + struct_name = m.group(1) + if not (struct_name.endswith('Class') or struct_name.endswith('Private')): + struct_names[struct_name] = True + elif line.startswith('struct _'): + m = re.match('struct ([a-zA-Z0-9_]+)', line) + struct_name = m.group(1) + if struct_name in struct_names: + in_struct = Struct(struct_name) + in_struct_private = False + elif in_struct: + if line.startswith('}'): + if not in_struct.name in binding.structs_toskip: + binding.structs.append(in_struct) + else: + print >>sys.stderr, 'W: skipping structure %s due to overrides.xml' % in_struct.name + in_struct = None + elif '/*< public >*/' in line: + in_struct_private = False + elif '/*< private >*/' in line: + in_struct_private = True + elif in_struct_private and exclude_private: + pass + elif 'DEPRECATED' in line and exclude_private: + pass + else: + # TODO: Add parsing of OFTYPE +######## + #member_match = re.match('\s+(\w+)\s+(\*?\w+)', line) + member_match = re.match('\s+(\w+)\s+(\*{0,2}\w+)', line) +######## + if member_match: + member_type, member_name = normalise_var(member_match.group(1), member_match.group(2)) + field = (member_type, member_name, {}) + if member_type == 'void*': + print >>sys.stderr, 'W: skipping field %s.%s' % (in_struct.name, member_name) + else: + if is_glist(field) or is_hashtable(field): + found = re.search(r' of ([^*]*)', line) + if found: + field[2]['element-type'] = clean_type(found.group(1)) + if member_name == 'parent': + in_struct.parent = member_type + else: + in_struct.members.append(field) + elif line.startswith('CRYPTIC_EXPORT '): + while not line.strip().endswith(';'): + i += 1 + line = line[:-1] + ' ' + lines[i].lstrip() + + # parse the type, then the name, then argument list + m = re.match(r'CRYPTIC_EXPORT\s+([^(]*(?:\s|\*))(\w+)\s*\(\s*(.*?)\s*\)\s*;', line) + if m and (not exclude_private or not m.group(2).endswith('_get_type')): + return_type, function_name, args = m.groups() + return_type = return_type.strip() + f = Function() + if function_name[0] == '*': + return_type += '*' + function_name = function_name[1:] + if binding.functions_toskip.get(function_name) != 1: + if re.search(r'\', return_type): + f.return_owner = False + # clean the type + return_type = clean_type(return_type) + if return_type != 'void': + f.return_type = return_type + f.return_arg = (return_type, None, {}) + if function_name.endswith('_destroy') and exclude_private: + # skip the _destroy functions, they are just wrapper over + # g_object_unref + pass + else: + f.name = function_name + f.args = [] + for arg in [x.strip() for x in args.split(',')]: + arg = clean_type(arg) + if arg == 'void' or arg == '': + continue + m = re.match(r'(.*(?:\s|\*))(\w+)', arg) + if m: + type, name = m.groups() + type = clean_type(type) + f.args.append(list((type, name, {}))) + else: + print >>sys.stderr, 'failed to process:', arg, 'in line:', line + f.skip = True + f.apply_overrides() + if not f.skip: + binding.functions.append(f) + else: + print >>sys.stderr, 'W: skipping function', f + + i += 1 + + +def parse_headers(srcdir): + + srcdir = os.path.abspath(srcdir) + parentdir = os.path.dirname(srcdir) + + for base, dirnames, filenames in os.walk(srcdir): + if base.endswith('/.svn'): + # ignore svn directories + continue + #if not 'Makefile.am' in filenames: + # not a source dir + # continue + #makefile_am = open(os.path.join(base, 'Makefile.am')).read() + #filenames = [x for x in filenames if x.endswith('.h') if x in makefile_am] + filenames = [x for x in filenames if x.endswith('.h')] + for filename in filenames: + if 'private' in filename: + continue + header_path = os.path.join(base, filename) + header_relpath = os.path.relpath(header_path, parentdir) + + binding.headers.append(header_relpath) + parse_header(header_path) + +def main(): + global binding + + parser = OptionParser() + parser.add_option('-l', '--language', dest = 'language') + parser.add_option('-s', '--src-dir', dest = 'srcdir', default = '../cryptic/') + parser.add_option('--enable-id-wsf', dest = 'idwsf', action = 'store_true') + parser.add_option('--enable-exception-docs', dest= 'exception_doc', action = 'store_true') + + options, args = parser.parse_args() + if not options.language: + parser.print_help() + sys.exit(1) + + binding = BindingData(options) + parse_headers(options.srcdir) + binding.look_for_docstrings(options.srcdir, options.exception_doc) + binding.order_class_hierarchy() + binding.attach_methods() + + if options.language == 'python': + from python import lang + + python_binding = lang.Binding(binding) + python_binding.generate() + elif options.language == 'php5': + from php5 import lang + + php5_binding = lang.Binding(binding) + php5_binding.generate() + elif options.language == 'java': + from java import lang + + java_binding = lang.Binding(binding) + java_binding.generate() + elif options.language == 'java-list': + from java import lang + + java_binding = lang.Binding(binding) + java_binding.print_list_of_files() + elif options.language == 'perl': + from perl import lang + perl_binding = lang.Binding(binding) + perl_binding.generate() + +if __name__ == '__main__': + main() + diff --git a/bindings/ghashtable.h b/bindings/ghashtable.h new file mode 100644 index 0000000..dc230be --- /dev/null +++ b/bindings/ghashtable.h @@ -0,0 +1,81 @@ +#ifndef G_HASHTABLE_H +#define G_HASHTABLE_H 1 +#if (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 14) + +typedef struct _GHashNode GHashNode; + +struct _GHashNode +{ + gpointer key; + gpointer value; + GHashNode *next; + guint key_hash; +}; + +struct _GHashTable +{ + gint size; + gint nnodes; + GHashNode **nodes; + GHashFunc hash_func; + GEqualFunc key_equal_func; + volatile gint ref_count; + GDestroyNotify key_destroy_func; + GDestroyNotify value_destroy_func; +}; + +/* Helper functions to access JNI interface functions */ +#if (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 12) +static gboolean return_true(G_GNUC_UNUSED gpointer a, G_GNUC_UNUSED gpointer b, + G_GNUC_UNUSED gpointer c) +{ + return TRUE; +} + +void +g_hash_table_remove_all (GHashTable *hash_table) +{ + cryptic_return_if_fail(hash_table != NULL); + + g_hash_table_foreach_remove (hash_table, (GHRFunc)return_true, NULL); +} +#endif + /* copy of private struct and g_hash_table_get_keys from GLib internals + * (as this function is useful but new in 2.14) */ + + +static GList * +g_hash_table_get_keys (GHashTable *hash_table) +{ + GHashNode *node; + gint i; + GList *retval; + + cryptic_return_if_fail(hash_table != NULL, NULL); + + retval = NULL; + for (i = 0; i < hash_table->size; i++) + for (node = hash_table->nodes[i]; node; node = node->next) + retval = g_list_prepend (retval, node->key); + + return retval; +} + +GList * +g_hash_table_get_values (GHashTable *hash_table) +{ + GHashNode *node; + gint i; + GList *retval; + + cryptic_return_if_fail(hash_table != NULL, NULL); + + retval = NULL; + for (i = 0; i < hash_table->size; i++) + for (node = hash_table->nodes[i]; node; node = node->next) + retval = g_list_prepend (retval, node->value); + + return retval; +} +#endif +#endif /* G_HASHTABLE_H */ diff --git a/bindings/java/CrypticException_top.java b/bindings/java/CrypticException_top.java new file mode 100644 index 0000000..89350db --- /dev/null +++ b/bindings/java/CrypticException_top.java @@ -0,0 +1,31 @@ +package com.entrouvert.cryptic; + +public class CrypticException extends RuntimeException { + private static final long serialVersionUID = 6170037639785281128L; + public int errorCode; + private static boolean throws_for_recoverable_errors = true; + /** If set to true, enables throwing of exception for + * recoverable errors, i.e. errors with a positive error + * code. + * + * @param bool true if exception are throwed on recoverable errors. + */ + public static void setThrowsForRecoverableErrors(boolean bool) { + throws_for_recoverable_errors = bool; + } + public static boolean getThrowsForRecoverableErrors() { + return throws_for_recoverable_errors; + } + + protected CrypticException(int errorCode) { + //super(CrypticJNI.strError(errorCode)); + super(""); + this.errorCode = errorCode; + } + protected CrypticException(int errorCode, String message) { + super(message); + this.errorCode = errorCode; + } + protected static int throwError(int errorCode) throws CrypticException { + if (errorCode == 0 || (! throws_for_recoverable_errors && errorCode > 0)) + return errorCode; diff --git a/bindings/java/GObject.java b/bindings/java/GObject.java new file mode 100644 index 0000000..8df5ddf --- /dev/null +++ b/bindings/java/GObject.java @@ -0,0 +1,49 @@ +package com.entrouvert.cryptic; +import java.util.*; + +class GObject { + private long cptr; + + protected GObject(long ptr) { + if (ptr == 0) { + throw new RuntimeException("Error creating " + getClass().getName()); + } + cptr = ptr; + } + protected Map arrayToMap(Object[] arr) { + Map map = new HashMap(); + if (arr == null) + return map; + if (arr.length % 2 != 0) + throw new IllegalArgumentException("arr must of an even size"); + int i; + for (i=0;i $@ +# echo "OBJDIR=`libtool --config | grep ^objdir | sed s/.*=//`" >> $@ +# echo 'LD_LIBRARY_PATH=$$OBJDIR @JUNIT@ BindingTests' >> $@ +# echo 'LD_LIBRARY_PATH=$$OBJDIR @JUNIT@ LoginTest' >> $@ +# chmod +x $@ +#endif + + diff --git a/bindings/java/Myclass.java b/bindings/java/Myclass.java new file mode 100644 index 0000000..64454dd --- /dev/null +++ b/bindings/java/Myclass.java @@ -0,0 +1,27 @@ +import com.entrouvert.cryptic.*; + +class Myclass{ + public static void main(String[] arg){ + //System.out.println("yo"); + //System.out.println(System.getProperty("java.library.path")); + Clsig c = new Clsig(1024,80,300,0,0,0,5); + c.generateParameters(); + System.out.println("e: " + c.getExponent()); + + PrimeOrderGroup g = new PrimeOrderGroup(256); + g.moreBases(5); + System.out.println("nbbases: " + g.getnbBases()); +// System.out.println("g: " + g.getbases()); //Pb: getbases devrait retourner un tableau de int et pas une string. Si? +/* ZkpkSchnorr s = new ZkpkSchnorr(g.getBases(),3,g.getP()); + s.round1(); + String q1 = "1234567890c"; + String q2 = "1234567890b"; + String q3 = "1234567890a";*/ +// s.round2(g.order,"1234567890",(q1,q2,q3)); +// String dlrep = cryptic.getDlrep(3,(q1,q2,q3),g.bases,g.p); +// s2 = cryptic.ZkpkSchnorr(g.bases,3,g.p); +// int rc = s2.verifyInteractiveProof(dlrep,s.commitment,"1234567890",s.responses) +// System.out.println("proof: " + rc); + } +} + diff --git a/bindings/java/__init__.py b/bindings/java/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bindings/java/lang.py b/bindings/java/lang.py new file mode 100644 index 0000000..5d9a60f --- /dev/null +++ b/bindings/java/lang.py @@ -0,0 +1,978 @@ +# Cryptic -- Cryptographic tools and protocols +# Copyright (C) 2010 Mikael Ates +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + +import os +import sys +import re +import textwrap + +from utils import * + +cryptic_package_name = 'com.entrouvert.cryptic' +cryptic_java_path = 'com/entrouvert/cryptic/' + +debug = 0 + +def with_return_owner(d): + c = d.copy() + c['return_owner'] = 1 + return c + +def generate_arg_list(self,args): + def arg_to_decl(arg): + return self.java_arg_type(arg) + ' ' + format_as_camelcase(arg_name(arg)) + return ', '.join([ arg_to_decl(x) for x in args if not is_out(x)]) + +def generate_arg_list2(args): + def arg_to_decl(arg): + if is_out(arg): + return 'output' + return format_as_camelcase(arg_name(arg)) + return ', '.join([ arg_to_decl(x) for x in args ]) + +def generate_arg_list3(self, args): + def arg_to_decl(arg): + if is_out(arg): + return 'Object[] output' + r = self.java_arg_type(arg) + ' ' + format_as_camelcase(arg_name(arg)) + return r + return ', '.join([ arg_to_decl(x) for x in args]) + +def convert_class_name(cryptic_name): +###############################""" + return cryptic_name[7:] +###############################""" + +def mangle_name(name): + s = name + s = s.replace('_', '_1') + s = s.replace(';', '_2') + s = s.replace('[', '_3') + return s + +def jni_glist_elem_type(type): + if is_cstring(type): + return 'jstring' + elif is_xml_node(type): + return 'jstring' + elif is_object(type): + return 'jobject' + else: + return Exception('No jni_glist_elem_type for %s' % (type,)) + +def jni_hashtable_elem_type(type): + if is_object(type): + return 'jobject' + else: + return 'jstring' + +def JNI_elem_type(type): + if is_cstring(type): + return 'String' + elif is_xml_node(type): + return 'String' + elif is_object(type): + return convert_class_name(type) + else: + return 'Object' + +def wrapper_name(name): + return 'Java_com_entrouvert_cryptic_CrypticJNI_' + mangle_name(name) + +def error_to_exception(error_name): + if 'CRYPTIC_ERROR' in error_name: + name, = re.match('CRYPTIC_ERROR(_.*)', error_name).groups() + super = 'Cryptic' + else: + super, name = re.match('CRYPTIC(_.*)_ERROR(_.*)', error_name).groups() + super = format_as_camelcase(super.lower()) + name = format_as_camelcase(name.lower()) + return (super+name+'Exception',super+'Exception') + +def wrapper_decl(name, jnitype): + jniname = wrapper_name(name) + return 'JNIEXPORT %s JNICALL %s(JNIEnv *env, jclass clss' % (jnitype,jniname) + +def is_collection(type): + return is_glist(type) or is_hashtable(type) + +class Binding: + def __init__(self, binding_data): + self.binding_data = binding_data + self.src_dir = os.path.dirname(__file__) + + def print_list_of_files(self): + l = ['GObject.java','CrypticConstants.java','CrypticJNI.java','CrypticException.java', 'CrypticUndefinedException.java', 'CrypticUnimplementedException.java'] + for c in self.binding_data.structs: + class_name = convert_class_name(c.name) + l.append(class_name + '.java') + for c in self.binding_data.constants: + type, orig = c + if 'CRYPTIC_ERROR_' in orig or '_ERROR_' not in orig: + continue + name, super = error_to_exception(orig) + l.append(name + '.java') + if not super + '.java' in l: + l.append(super + '.java') + l = [ cryptic_java_path + p for p in l] + for p in l: + print p, + print + print + + def is_int_type(self, type): + return type in ['gboolean','int','gint'] + self.binding_data.enums + + + def is_gobject_type(self, t): + return t not in ['char*', 'const char*', 'gchar*', 'const gchar*', + 'const GList*','GList*', 'GHashTable*', + 'int', 'gint', 'gboolean', 'const gboolean', + 'int*', 'BIGNUM*', 'BIGNUM**'] + self.binding_data.enums + + def generate(self): + if not os.path.exists(cryptic_java_path): + os.makedirs(cryptic_java_path) + self.generate_Constants() + self.generate_JNI() + self.generate_wrapper() + self.generate_exception_classes() + self.generate_cryptic_classes() + + +# CrypticConstants + def generate_Constants(self): + fd = open(cryptic_java_path + 'CrypticConstants.java', 'w') + self.generate_Constants_header(fd) + self.generate_Constants_constants(fd) + self.generate_Constants_footer(fd) + fd.close() + + def generate_Constants_header(self, fd): + print >> fd, '''\ +/* this file has been generated automatically; do not edit */ + +package %s; + +public abstract interface CrypticConstants { +''' % cryptic_package_name + + def generate_Constants_constants(self, fd): + print >> fd, '/* Constants (both enums and defines) */' + # Declaration + for c in self.binding_data.constants: + print >> fd, 'static final ', + if c[0] == 'i': + print >> fd, 'int ', + elif c[0] == 's': + print >> fd, 'String ', + elif c[0] == 'b': + print >> fd, 'boolean ', +############################ + print >> fd, '%s = CrypticJNI.%s_get();' % (c[1][8:], c[1]) +############################ + + def generate_Constants_footer(self, fd): + print >> fd, '}' + + +# CrypticJNI + def generate_JNI(self): + fd = open(cryptic_java_path + 'CrypticJNI.java','w') + self.generate_JNI_header(fd) + self.generate_JNI_constants(fd) + for m in self.binding_data.functions: + self.generate_JNI_functions(m ,fd) + for c in self.binding_data.structs: + self.generate_JNI_member(c, fd) + for m in c.methods: + self.generate_JNI_functions(m, fd) + self.generate_JNI_footer(fd) + fd.close(); + + def generate_JNI_header(self, fd): + print >> fd, '''\ +/* this file has been generated automatically; do not edit */ + +package %s; + +public final class CrypticJNI { +protected static native void init2(); +protected static native void destroy(long cptr); +''' % cryptic_package_name + def generate_JNI_constants(self, fd): + print >>fd, '/* Constants getters */' + for c in self.binding_data.constants: + print >>fd, 'public static native ', + if c[0] == 'i': + print >>fd, 'int ', + elif c[0] == 's': + print >>fd, 'String ', + elif c[0] == 'b': + print >>fd, 'boolean ', + print >>fd, '%s_get();' % c[1] + + def java_arg_type(self, vtype): + if is_boolean(vtype): + return 'boolean' +############################ + elif is_bn(vtype): + return 'String' + elif is_tabbn(vtype) or is_tabint(vtype): + return 'Object[]' +############################ + elif is_int(vtype, self.binding_data): + return 'int' + elif is_cstring(vtype): + return 'String' + elif is_collection(vtype): + return 'Object[]' + elif is_xml_node(vtype): + return 'String' + elif is_object(vtype): + return convert_class_name(unpointerize(unconstify(vtype))) + else: + raise Exception('java_arg_type failed for %s' % vtype) + + def JNI_return_type(self, vtype): + if vtype: + m = re.match(r'(?:const\s*)?(.*)',vtype) + vtype = m.group(1) + if vtype == 'gboolean': + return 'boolean' + elif vtype in ['int','gint'] + self.binding_data.enums: + return 'int' + elif vtype in ('guchar*', 'char*', 'gchar*'): + return 'String' +# elif vtype in ('const GList*','GList*','GHashTable*'): +##################################" + elif vtype == 'BIGNUM*': + return 'String' + elif vtype in ('const GList*','GList*','GHashTable*', 'int*', 'BIGNUM**'): +##################################" + return 'Object[]' + elif vtype == 'xmlNode*': + return 'String' + elif isinstance(vtype,basestring) and vtype.startswith('Cryptic'): + if vtype.endswith('*'): + vtype = vtype[:-1] + return convert_class_name(vtype) + else: + return 'void' + + def JNI_member_type(self,member): + if is_glist(member): + return self.java_arg_type(element_type(member)) + elif is_hashtable(member): + return self.java_arg_type(element_type(member) or 'char*') + else: + return self.java_arg_type(member) + + def JNI_function_name(self, m): + if m.rename: + return m.rename + else: +##################################" + return m.name[8:] +##################################" + + def generate_JNI_functions(self, m, fd): + if m.name.endswith('_new'): + jtype = 'long' + else: + jtype = self.JNI_return_type(m.return_type) + name = self.JNI_function_name(m) + print >> fd, ' public static native %s %s(%s);' % (jtype,name, generate_arg_list3(self,m.args)) + + def JNI_member_function_prefix(self,c,m): +#############################" + klassname = c.name[7:] +#############################" + mname = format_as_camelcase(m[1]) + return '%s_%s' % (klassname,mname) + + def generate_JNI_member(self, c, fd): + for m in c.members: + prefix = self.JNI_member_function_prefix(c,m) + mname = format_as_camelcase(m[1]) + mtype = m[0] + + jtype = self.JNI_member_type(m) + if mtype == 'GList*'or mtype == 'const GList*': + name = '%s_get' % prefix + print >> fd, ' public static native %s[] %s(GObject obj);' % (jtype,name) + name = '%s_set' % prefix + print >> fd, ' public static native void %s(GObject obj, %s[] value);' % (name,jtype) + name = '%s_add' % prefix + print >> fd, ' public static native void %s(GObject obj, %s value);' % (name,jtype) + if not m[2].get('element-type') in ('xmlNode*',): + name = '%s_remove' % prefix + print >> fd, ' public static native void %s(GObject obj, %s value);' % (name,jtype) + elif mtype == 'GHashTable*': + name = '%s_get' % prefix + print >> fd, ' public static native %s[] %s(GObject obj);' % (jtype,name) + name = '%s_set' % prefix + print >> fd, ' public static native void %s(GObject obj, %s[] value);' % (name,jtype) + else: + name = '%s_get' % prefix + print >> fd, ' public static native %s %s(GObject obj);' % (jtype,name) + name = '%s_set' % prefix + print >> fd, ' public static native void %s(GObject obj, %s value);' % (name,jtype) + + def generate_JNI_footer(self, fd): + print >>fd, ''' + static { + System.loadLibrary("jnicryptic"); + init(); + init2(); + } +''' + print >>fd, '}' + + +# Wrappers + def generate_wrapper(self): + fd = open('com_entrouvert_cryptic_CrypticJNI.c', 'w') + self.generate_wrapper_header(fd) + self.generate_wrapper_constants(fd) + + print >> fd, '/* Declaration of standalone functions */' + for m in self.binding_data.functions: + self.generate_wrapper_function(m, fd) + print >> fd, '/* End of declaration of standalone functions */' + print >> fd, '/* Declaration of getter/setter methods */' + for c in self.binding_data.structs: + self.generate_wrapper_getter_setter(c, fd) + print >> fd, '/* End of declaration of getter/setter methods */' + for c in self.binding_data.structs: + for m in c.methods: + self.generate_wrapper_function(m, fd) + print >> fd, open(os.path.join(self.src_dir,'wrapper_bottom.c')).read() + fd.close() + + def generate_wrapper_header(self, fd): + print >> fd, open(os.path.join(self.src_dir,'wrapper_top.c')).read() + print >> fd, '' + for h in self.binding_data.headers: + print >> fd, '#include <%s>' % h + + + def generate_wrapper_constants(self, fd): + print >> fd, '/* Declaration of constants */' + for c in self.binding_data.constants: + s = c[1]+'_get' + if c[0] == 'i': + print >>fd, wrapper_decl(s,'jint') + print >>fd, ') {' + print >>fd, ' return %s;' % c[1] + print >>fd, '}' + elif c[0] == 's': + print >>fd, wrapper_decl(s,'jstring') + print >>fd, ') {' + print >>fd, ' return (*env)->NewStringUTF(env, %s);' % c[1] + print >>fd, '}' + elif c[0] == 'b': + print >>fd, wrapper_decl(s,'jboolean') + print >>fd, ') {' + print >>fd, '#ifdef %s' % c[1] + print >>fd, ' return 1;' + print >>fd, '#else' + print >>fd, ' return 0;' + print >>fd, '#endif' + print >>fd, '}' + print >> fd, '/* End of declaration of constants */' + + def jni_return_type(self, type): + if type is None: + return 'void' + elif is_boolean(type): + return 'jboolean' + elif is_int(type, self.binding_data): + return 'jint' + elif is_cstring(type): + return 'jstring' +#######################################""" + elif is_bn(type): + return 'jstring' + elif is_glist(type) or is_hashtable(type) or is_tabbn(type) or is_tabint(type): +#######################################""" + return 'jobjectArray' + elif is_xml_node(type): + return 'jstring' + elif is_object(type): + return 'jobject' + else: + raise Exception('No jni_return_type for %s' % type) + + def c_to_java_value(self, left, right, type): + if is_boolean(type): + return '%s = (jboolean)%s' % (left,right) +#################### + elif is_tabbn(type): + return 'get_list_of_bn(env, %s, &%s)' % (right, left) + elif is_bn(type): + return 'bignum_to_jstring(env, %s, &%s)' % (right, left) + elif is_tabint(type): + return 'get_list_of_int(env, %s, &%s)' % (right, left) +#################### + elif is_int(type, self.binding_data): + return '%s = (jint)%s' % (left, right) + elif is_cstring(type): + return 'string_to_jstring(env, %s, &%s)' % (right, left) + elif is_glist(type): + el_type = element_type(type) + if is_cstring(el_type): + return 'get_list_of_strings(env, %s, &%s)' % (right, left) + elif is_xml_node(el_type): + return 'get_list_of_xml_nodes(env, %s, &%s)' % (right, left) + elif is_object(el_type): + return 'get_list_of_objects(env, %s, &%s)' % (right, left) + else: + raise Exception('c_to_java_value failed, %s' % ((left, right, type),)) + elif is_hashtable(type): + el_type = element_type(type) + if is_object(el_type): + return 'get_hash_of_objects(env, %s, &%s)' % (right, left) + else: + return 'get_hash_of_strings(env, %s, &%s)' % (right, left) + elif is_xml_node(type): + return 'xml_node_to_jstring(env, %s, &%s)' % (right, left) + elif is_object(type): + if is_transfer_full(type): + return 'gobject_to_jobject(env, (GObject*)%s, &%s);' % (right, left) + else: + return 'gobject_to_jobject_and_ref(env, (GObject*)%s, &%s);' % (right, left) + else: + raise Exception('c_to_java_value failed, %s' % ((left, right, type),)) + + def java_to_c_value(self, left, right, type, full = False): + if is_boolean(type) or is_int(type, self.binding_data): + return '%s = (%s)%s;' % (left,arg_type(type),right) + elif is_cstring(type): + return 'jstring_to_string(env, %s, (char**)&%s);' % (right,left) +#################### + elif is_tabbn(type): + return 'set_list_of_bn(env, &%s,%s);' % (left,right) + elif is_bn(type): + return 'jstring_to_bignum(env, %s, (BIGNUM**)&%s);' % (right,left) + elif is_tabint(type): + return 'set_list_of_int(env, &%s,%s);' % (left,right) +#################### + elif is_glist(type): + el_type = element_type(type) + if is_cstring(el_type): + return 'set_list_of_strings(env, &%s,%s);' % (left,right) + elif is_xml_node(el_type): + return 'set_list_of_xml_nodes(env, &%s, %s);' % (left, right) + elif is_object(el_type): + return 'set_list_of_objects(env, &%s, %s);' % (left, right) + else: + raise Exception('java_to_c_value failed: %s' % ((left, right, type),)) + elif is_hashtable(type): + el_type = element_type(type) + if is_object(el_type): + return 'set_hash_of_objects(env, %s, %s);' % (left,right) + else: + return 'set_hash_of_strings(env, %s, %s);' % (left,right) + elif is_xml_node(type): + return 'jstring_to_xml_node(env, %s, &%s);' % (right, left) + elif is_object(type): + if is_transfer_full(type) or full: + return 'jobject_to_gobject(env, %s, (GObject**)&%s);' % (right, left) + else: + return 'jobject_to_gobject_noref(env, %s, (GObject**)&%s);' % (right, left) + else: + raise Exception('java_to_c_value failed: %s' % ((left, right, type),)) + + + def generate_wrapper_function(self, m, fd): + print >> fd, '/* Wrapper function for ', + if m.return_type: + print >> fd, m.return_type, + else: + print >> fd, 'void', + print >> fd, '%s(' % m.name, + for arg in m.args: + print >> fd, '%s %s %s,' % (arg[0],arg[1],arg[2]), + print >> fd, ') */' + if m.rename: + name = m.rename + else: +##################################" + name = m.name[8:] +##################################" +# self.wrapper_list.append(name) +# print >> fd, '''static PyObject* +#%s(PyObject *self, PyObject *args) +#{''' % name + if m.name.endswith('_new'): + jtype = 'jlong' + else: + jtype = self.jni_return_type(m.return_type) + print >>fd, wrapper_decl(name, jtype) + parse_tuple_format = [] + parse_tuple_args = [] + idx = 0 + # Declare java args + for arg in m.args: + idx = idx + 1 + arg_type, arg_name, arg_options = arg + print >> fd, ',%s jarg%s' % (self.jni_return_type(arg_type.replace('const ','')),idx), + print >> fd, ')' + print >> fd, ' {' + idx = 0 + if m.return_type: + print >> fd, ' %s r_value;' % jtype + # Declare C args + for arg in m.args: + idx = idx + 1 + arg_type, arg_name, arg_options = arg + if is_pointer(arg): + print >> fd, ' %s %s = NULL;' % (arg_type.replace('const ',''),arg_name) + else: + print >> fd, ' %s %s;' % (arg_type.replace('const ',''),arg_name) + # Declare return vars + if m.return_type: + print >> fd, ' %s return_value;' % m.return_type + idx = 0 + # Convert args + for arg in m.args: + idx = idx + 1 + arg_type, arg_name, arg_options = arg + print >> fd, ' %s' % self.java_to_c_value(arg_name, 'jarg%s' % idx, arg) + if debug: + print >> fd, ' printf("%s' % name, + arglist = '' + for arg in m.args: + arg_type, arg_name, arg_options = arg + arglist = arglist + ', %s' % arg_name + if self.is_int_type(arg_type): + print >> fd, '%i', + elif is_cstring(arg_type): + print >> fd, '%s', + else: + print >> fd, '%p', + print >> fd, '\\n"%s);' % arglist + # Call function + print >> fd, ' ', + if m.return_type: + print >> fd, 'return_value = ', + if 'new' in m.name: + print >>fd, '(%s)' % m.return_type, + def arg2ref(x): + if is_const(x): + return '(%s) %s' % (x[0],x[1]) + else: + return x[1] + print >> fd, '%s(%s);' % (m.name, ', '.join([arg2ref(x) for x in m.args])) + # Free const char * args + idx=0 + for arg in m.args: + idx=idx+1 + arg_type, arg_name, arg_options = arg + if is_cstring(arg_type): + print >> fd, ' if (%s)' % arg_name + print >> fd, ' g_free(%s);' % arg_name + elif arg_type == 'GList*' or arg_type == 'const GList*': + if is_cstring(element_type(arg)): + print >> fd, ' free_glist(&%s, (GFunc)free);' % arg_name + elif is_object(element_type(arg)): + print >> fd, ' free_glist(&%s, (GFunc)g_object_unref);' % arg_name + else: + raise Exception('Freeing args of type list of \'%s\' not supported.' % arg_options.get('element-type')) + + # Return + if m.return_type: + if m.name.endswith('_new'): + print >> fd, ' r_value = (jlong)(ptrdiff_t) return_value;' + else: + options = {} + if m.return_owner: + options = with_return_owner({}) + print >> fd, ' %s;' % self.c_to_java_value('r_value','return_value', m.return_arg) + if m.return_owner: + if m.return_type == 'GList*' or m.return_type == 'const GList*': + print >> fd, ' free_glist(&return_value, NULL);' + elif is_cstring(m.return_type) and not is_const(m.return_arg): + print >> fd, ' if (return_value)' + print >> fd, ' g_free(return_value);' + print >> fd, ' return r_value;' + print >> fd, ' }' + + def generate_wrapper_getter(self, c, m, fd): + type = arg_type(m) + name = arg_name(m) + klass = c.name + prefix = self.JNI_member_function_prefix(c,m) + return_type = self.jni_return_type(m) + signature = wrapper_decl("%s_get" % prefix, return_type) + field = 'gobj->%s' % name + d = locals() + print >>fd, ''' +/* Getter for %(type)s %(klass)s.%(name)s */ +%(signature)s, jobject jobj) { + %(klass)s *gobj = NULL; + jobject_to_gobject_noref(env, jobj, (GObject**)&gobj);''' % d + if debug: + print >> fd, ' printf("%(prefix)s_get %%p %%p\\n", gobj, %(field)s);' % d + print >> fd, ' %(return_type)s r_value = 0;' % d + print >> fd, ' if (gobj) {' + print >> fd, ' %s;' % self.c_to_java_value ('r_value', d['field'], m) + print >> fd, ''' } else { + throw_by_name(env, "java/lang/NullPointerException", "no gobject correspond to the given object"); + } + return r_value; + } +''' + + def generate_wrapper_setter(self, c, m, fd): + type = arg_type(m) + name = arg_name(m) + klass = c.name + prefix = self.JNI_member_function_prefix(c,m) + return_type = self.jni_return_type(m) + signature = wrapper_decl("%s_set" % prefix, 'void') + field = 'gobj->%s' % name + d = locals() + + print >> fd,'/* Setter for %(type)s %(klass)s.%(name)s */' % d + print >> fd, '%(signature)s, jobject jobj, %(return_type)s value)\n {' % d + print >> fd, ' %(klass)s *gobj = NULL;' % d + if debug: + print >> fd, ' printf("%(prefix)s_set %%p %%p\\n", gobj, value);' % d + print >> fd, ' jobject_to_gobject_noref(env, jobj, (GObject**)&gobj);' + print >> fd, ' if (!gobj) {' + print >> fd, ' throw_by_name(env, "java/lang/NullPointerException", "no gobject correspond to the given object");' + print >> fd, ' }' + print >> fd, ' %s' % self.java_to_c_value(d['field'], 'value', m, full = True) + print >> fd, '}' + + def generate_wrapper_adder(self, c, m, fd): + type = arg_type(m) + name = arg_name(m) + el_type = element_type(m) + jni_el_type = jni_glist_elem_type(el_type) + klass = c.name + prefix = self.JNI_member_function_prefix(c,m) + return_type = self.jni_return_type(m) + signature = wrapper_decl("%s_add" % prefix, 'void') + field = 'gobj->%s' % name + d = locals() + + print >> fd,'/* Adder for %(type)s<%(el_type)s> %(klass)s.%(name)s */' % d + print >> fd, '%(signature)s, jobject jobj, %(jni_el_type)s value)\n {' % d + print >> fd, ' %(klass)s *gobj = NULL;' % d + print >> fd, ' jobject_to_gobject_noref(env, jobj, (GObject**)&gobj);' + if is_cstring(el_type): + print >> fd, ' add_to_list_of_strings(env, &%(field)s, value);' % d + elif is_xml_node(el_type): + print >> fd, ' add_to_list_of_xml_nodes(env, &%(field)s, value);' % d + elif is_object(el_type): + print >> fd, ' add_to_list_of_objects(env, &%(field)s, value);' % d + else: + raise Exception('generate_wrapper_adder failed for %s.%s' % (c,m)) + print >> fd, '}' + + def generate_wrapper_remover(self, c, m, fd): + type = arg_type(m) + name = arg_name(m) + klass = c.name + el_type = element_type(m) + jni_el_type = jni_glist_elem_type(el_type) + prefix = self.JNI_member_function_prefix(c,m) + return_type = self.jni_return_type(m) + signature = wrapper_decl("%s_remove" % prefix, 'void') + field = 'gobj->%s' % name + d = locals() + + if is_xml_node(el_type): + print >>sys.stderr, 'W: remove for list of xml node not supported: %s' % (m,) + return + print >> fd,'/* Remover for %(type)s<%(el_type)s> %(klass)s.%(name)s */' % d + print >> fd, '%(signature)s, jobject jobj, %(jni_el_type)s value)\n {' % d + print >> fd, ' %(klass)s *gobj = NULL;' % d + print >> fd, ' jobject_to_gobject_noref(env, jobj, (GObject**)&gobj);' + if is_cstring(el_type): + print >> fd, ' remove_from_list_of_strings(env, &%(field)s,value);' % d + elif is_object(el_type): + print >> fd, ' remove_from_list_of_objects(env, &%(field)s,value);' % d + else: + raise Exception('remove_from_list unsupported for %s.%s' % (c,m,)) + print >> fd, '}' + print >> fd, '' + + def generate_wrapper_getter_setter(self, c, fd): + klassname = c.name + for m in c.members: + # getter + self.generate_wrapper_getter(c, m, fd) + self.generate_wrapper_setter(c, m, fd) + mtype = m[0] + prefix = self.JNI_member_function_prefix(c,m) + jtype = self.jni_return_type(mtype) + # add/remove + if is_glist(mtype): + self.generate_wrapper_adder(c, m, fd) + self.generate_wrapper_remover(c, m, fd) + + def generate_exception_switch_case(self, fd, name, orig): +##################################" +# print >> fd, ' if (errorCode == CrypticConstants.%s) {' % orig[6:] + print >> fd, ' if (errorCode == CrypticConstants.%s) {' % orig[8:] +##################################" + print >> fd, ' throw new %s(errorCode);' % name + print >> fd, ' }' + + def generate_exception_classes(self): + efd = open(cryptic_java_path + 'CrypticException.java', 'w') + print >> efd, open(os.path.join(self.src_dir,'CrypticException_top.java')).read() + # Generate the function to get class name by error code + supers = [] + for c in self.binding_data.constants: + type, orig = c + if 'CRYPTIC_ERROR_' in orig or '_ERROR_' not in orig: + continue + name, super = error_to_exception(orig) + self.generate_exception_switch_case(efd, name, orig) + if super not in supers: + supers.append(super) + self.generate_exception_class(name,super,0,orig) + for s in supers: + self.generate_exception_class(s,'CrypticException',1,'') + # Special errors, UNIMPLEMENTED and UNDEFINED + for c in self.binding_data.constants: + type, orig = c + if 'CRYPTIC_ERROR_' not in orig: + continue + name, = re.match('CRYPTIC_ERROR(.*)',orig).groups() + name = name.lower() + name = format_underscore_as_camelcase(name) + name = 'Cryptic%sException' % name + self.generate_exception_class(name, 'CrypticException', 0, orig) + self.generate_exception_switch_case(efd, name, orig) + print >> efd, ' throw new CrypticException(errorCode, "Uknown cryptic error code, maybe a bug in the binding, report it!");' + print >> efd, ' }' + print >> efd, '}' + efd.close() + + + def generate_exception_class(self, name, super,abstract,orig): + fd = open(cryptic_java_path + '%s.java' % name, 'w') + print >> fd, 'package %s;' % cryptic_package_name + print >> fd, '' + if abstract: + print >> fd, 'abstract ', + print >> fd, 'public class %s extends %s {' % (name,super) + print >> fd, ' private static final long serialVersionUID = 6170037639785281128L;' + if not abstract: + print >> fd, ' public %s() {' % name +#######################" +# print >> fd, ' super(CrypticConstants.%s);' % orig[6:] + print >> fd, ' super(CrypticConstants.%s);' % orig[8:] +#######################" + print >> fd, ' }' + print >> fd, ' protected %s(int errorCode) {' % name + print >> fd, ' super(errorCode);' + print >> fd, ' }' + print >> fd, '}' + fd.close() + + # Generate classes for Cryptic Objects + def generate_cryptic_classes(self): + def method_name(m,class_name): + prefix = len(class_name) + if m.rename: + return m.rename + else: +#######################" +# name = format_as_camelcase(m.name[6:]) + name = format_as_camelcase(m.name[8:]) +#######################" + name = name[prefix:] + return name[0].lower() + name[1:] + for c in self.binding_data.structs: + class_name = convert_class_name(c.name) + parent_name = c.parent + if parent_name != 'GObject': + parent_name = convert_class_name(parent_name) + path = cryptic_java_path + '%s.java' % class_name + fd = open(path,'w') + print >> fd, 'package %s;' % cryptic_package_name + do_import_util = 0 + for m in c.members: + if m[0] in ('const GList*','GList*','GHashTable*'): + do_import_util = 1 + for m in c.methods: + if m.return_type in ('const GList*','GList*','GHashTable*'): + do_import_util = 1 + if do_import_util: + print >> fd, 'import java.util.*;' + print >> fd, '' + print >> fd, 'public class %s extends %s {' % (class_name,parent_name) + # Constructeur private + print >> fd, ' /* Constructors */' + print >> fd, ' protected %s(long cptr) {' % class_name + print >> fd, ' super(cptr);' + print >> fd, ' }' + # Constructeur de base + def cprefix(name): + i = name.find('_new') + if i == -1: + return name + else: + return name[:i].replace('_','').lower() + cons = [ x for x in self.binding_data.functions if cprefix(x.name) == c.name.lower() and x.name.endswith('_new') ] + for m in cons: + print >> fd, ' public %s(%s) {' % (class_name, generate_arg_list(self,m.args)) + print >> fd, ' super(CrypticJNI.%s(%s));' % (self.JNI_function_name(m),generate_arg_list2(m.args)) + print >> fd, ' }' + # Constructeurs speciaux + cons = [ x for x in self.binding_data.functions if cprefix(x.name) == c.name.lower() and not x.name.endswith('_new') ] + for m in cons: + name = method_name(m,class_name) + print >> fd, ' static public %s %s(%s) {' % (class_name, name, generate_arg_list(self,m.args)) + print >> fd, ' return (%s) CrypticJNI.%s(%s);' % (class_name, self.JNI_function_name(m),generate_arg_list2(m.args)) + print >> fd, ' }' + print >> fd, ' /* Setters and getters */' + for m in c.members: + type, name, options = m + prefix = self.JNI_member_function_prefix(c,m) + jname = format_as_camelcase('_'+name) + jtype = self.JNI_member_type(m) + if type == 'GList*' or type == 'const GList*': + print >> fd, ' public void set%s(List list) {' % jname + print >> fd, ' %s[] arr = null;' % jtype + print >> fd, ' if (list != null) {' + print >> fd, ' arr = new %s[list.size()];' % jtype + print >> fd, ' listToArray(list, arr);' + print >> fd, ' }' + print >> fd, ' CrypticJNI.%s_set(this, arr);' % prefix + print >> fd, ' }' + print >> fd, ' public List get%s() {' % jname + print >> fd, ' %s[] arr = CrypticJNI.%s_get(this);' % (jtype,prefix) + print >> fd, ' if (arr != null)' + print >> fd, ' return Arrays.asList(arr);' + print >> fd, ' else' + print >> fd, ' return null;' + print >> fd, ' }' + print >> fd, ' public void addTo%s(%s value) {' % (jname,jtype) + print >> fd, ' CrypticJNI.%s_add(this, value);' % prefix + print >> fd, ' }' + if m[2].get('element-type') not in ('xmlNode*',): + print >> fd, ' public void removeFrom%s(%s value) {' % (jname,jtype) + print >> fd, ' CrypticJNI.%s_remove(this, value);' % prefix + print >> fd, ' }' + elif type == 'GHashTable*': + print >> fd, ' public void set%s(Map map) {' % jname + print >> fd, ' %s[] arr = null;' % jtype + print >> fd, ' if (map != null) {' + print >> fd, ' arr = new %s[map.size()*2];' % jtype + print >> fd, ' mapToArray(map,arr);' + print >> fd, ' }' + print >> fd, ' CrypticJNI.%s_set(this, arr);' % prefix + print >> fd, ' }' + print >> fd, ' public Map get%s() {' % jname + print >> fd, ' return arrayToMap(CrypticJNI.%s_get(this));' % prefix + print >> fd, ' }' + else: + print >> fd, ' public void set%s(%s value) {' % (jname,jtype) + print >> fd, ' CrypticJNI.%s_set(this, value);' % prefix + print >> fd, ' }' + print >> fd, ' public %s get%s() {' % (jtype,jname) + print >> fd, ' return CrypticJNI.%s_get(this);' % prefix + print >> fd, ' }' + print >> fd, ' /* Methods */' + for m in c.methods: + return_type = self.JNI_return_type(m.return_type) + jni_name = self.JNI_function_name(m) + mname = method_name(m,class_name) + args = m.args + doc = m.docstring + def normalize(str,first=' * '): + wrapper = textwrap.TextWrapper() + wrapper.initial_indent = first + wrapper.subsequent_indent = ' * ' + str = re.sub(r'\bNULL\b','null', str) + str = re.sub(r'#Cryptic(\w+)',r'{@@link \1}',str) + str = re.sub(r'[^.]*must *be *freed *by[^.]*\.?', '', str) + str = re.sub(r'[^.]*internally[^.]*\.?[^.]*freed[^.]*\.?', '', str) + + str = re.sub(r'[^.]*\bfreed?\b[^.]*\.?', '', str) + str = re.sub(r'(a +)?#?GList\*?','an array', str) + return wrapper.fill(re.sub(r'@\b(\w+)\b',r'\1',str)) + if doc: + first = normalize(doc.description, ' /** ') + if first: + print >> fd, first + else: + print >> fd, ' /**\n' + print >> fd, ' *' + for p in doc.parameters: + name = p[0] + desc = p[1] + print >> fd, normalize(desc, ' * @param %s ' % format_as_camelcase(name)) + if doc.return_value: + print >> fd, normalize(doc.return_value, ' * @return ') + if m.errors: + for err in m.errors: + err = error_to_exception(err)[0] + print >> fd, normalize(err,' * @throws ') + print >> fd, ' **/' + outarg = None + for a in args: + if is_out(a): + # only one output arg supported + assert not outarg + outarg = a + if outarg: + assert is_int(make_arg(m.return_type), self.binding_data) + new_return_type = self.JNI_return_type(var_type(outarg)) + print >> fd, ' public %s %s(%s) {' % (new_return_type, mname, generate_arg_list(self, args[1:])) + print >> fd, ' Object[] output = new Object[1];' + print >> fd, ' CrypticException.throwError(CrypticJNI.%s(this, %s));' % (jni_name, generate_arg_list2(args[1:])) + print >> fd, ' return (%s)output[0];' % new_return_type + print >> fd, ' }' + + elif m.return_type == 'GList*' or m.return_type == 'const GList*': + print >> fd, ' public List %s(%s) {' % (mname,generate_arg_list(self,args[1:])) + arglist = generate_arg_list2(args[1:]) + if arglist: + arglist = ', ' + arglist + print >> fd, ' Object[] arr = CrypticJNI.%s(this%s);' % (jni_name,arglist) + print >> fd, ' if (arr != null)' + print >> fd, ' return Arrays.asList(arr);' + print >> fd, ' else' + print >> fd, ' return null;' + print >> fd, ' }' + else: + print >> fd, ' public %s %s(%s) {' % (return_type,mname,generate_arg_list(self,args[1:])) + print >> fd, ' ', + if m.return_type: + print >> fd, 'return', + arglist = generate_arg_list2(args[1:]) + if arglist: + arglist = ', ' + arglist + if m.errors: + print >> fd, 'CrypticException.throwError(', + print >> fd,'CrypticJNI.%s(this%s)' % (jni_name,arglist), + if m.errors: + print >> fd, ');' + else: + print >> fd, ';' + print >> fd, ' }' + print >> fd, '}' + fd.close() diff --git a/bindings/java/wrapper_bottom.c b/bindings/java/wrapper_bottom.c new file mode 100644 index 0000000..e69de29 diff --git a/bindings/java/wrapper_top.c b/bindings/java/wrapper_top.c new file mode 100644 index 0000000..d7ea8ff --- /dev/null +++ b/bindings/java/wrapper_top.c @@ -0,0 +1,1006 @@ +#include +#include +#include +#include +#include +#include "com_entrouvert_cryptic_CrypticJNI.h" +#include +#include "../ghashtable.h" +#include "../../cryptic/utils.h" + +#define CRYPTIC_ROOT "com/entrouvert/cryptic/" +#define check_exception (*env)->ExceptionCheck(env) +#define g_return_val_if_exception(value) if ((*env)->ExceptionCheck(env)) return (value); +#define g_return_if_exception() if ((*env)->ExceptionCheck(env)) return; +#define convert_jlong_to_gobject(value) ((GObject*)(ptrdiff_t)value) +#define g_error_if_fail(value) { if (!(value)) { g_on_error_query("CrypticJNI"); } } +#define PTR_TO_JLONG(x) (jlong)((ptrdiff_t)x) + +static GQuark cryptic_wrapper_key = 0; +typedef int (*Converter)(JNIEnv *env, void *from, jobject *to); +typedef int *(*OutConverter)(JNIEnv *env, jobject from, gpointer *to); + +/* Static declarations */ +G_GNUC_UNUSED static int gpointer_equal(const gpointer p1, const gpointer p2); +G_GNUC_UNUSED static int new_object_with_gobject(JNIEnv *env, GObject *obj, const char *clsName, jobject *jobj); +G_GNUC_UNUSED static int jstring_to_local_string(JNIEnv *env, jstring jstr, const char **str); +G_GNUC_UNUSED static void release_local_string(JNIEnv *env, jstring str, const char *utf_str); +G_GNUC_UNUSED static int get_jlong_field(JNIEnv *env, jobject obj, const char *field, jlong *dest); +G_GNUC_UNUSED static jclass get_jclass_by_name(JNIEnv *env, const char *name); +G_GNUC_UNUSED static int get_array_element(JNIEnv *env, jobjectArray arr, jsize i, jobject *dest); +G_GNUC_UNUSED static int set_array_element(JNIEnv *env, jobjectArray arr, jsize i, jobject value); +G_GNUC_UNUSED static int get_array_size(JNIEnv *env, jobjectArray arr, jsize *dest); +G_GNUC_UNUSED static int create_object_array(JNIEnv *env, const char *clsName, jsize size, jobjectArray *jarr); +G_GNUC_UNUSED static jobject get_shadow_object(JNIEnv *env, GObject *obj); +G_GNUC_UNUSED static void set_shadow_object(JNIEnv *env, GObject *obj, jobject shadow_object); +G_GNUC_UNUSED static void exception(JNIEnv *env, const char *message); +G_GNUC_UNUSED static int string_to_jstring(JNIEnv *env, const char* str, jstring *jstr); +G_GNUC_UNUSED static int string_to_jstring_and_free(JNIEnv *env, char* str, jstring *jstr); +G_GNUC_UNUSED static int jstring_to_string(JNIEnv *env, jstring jstr, char **str); +////G_GNUC_UNUSED static int xml_node_to_jstring(JNIEnv *env, xmlNode *xmlnode, jstring *jstr); +////G_GNUC_UNUSED static int jstring_to_xml_node(JNIEnv *env, jstring jstr, xmlNode **xmlnode); +G_GNUC_UNUSED static int gobject_to_jobject_aux(JNIEnv *env, GObject *obj, gboolean doRef, jobject *job); +G_GNUC_UNUSED static int gobject_to_jobject(JNIEnv *env, GObject *obj, jobject *jobj); +G_GNUC_UNUSED static int gobject_to_jobject_and_ref(JNIEnv *env, GObject *obj, jobject *jobj); + +G_GNUC_UNUSED static int jobject_to_gobject(JNIEnv *env, jobject obj, GObject **gobj); +G_GNUC_UNUSED static int jobject_to_gobject_noref(JNIEnv *env, jobject obj, GObject **gobj); +G_GNUC_UNUSED static void free_glist(GList **list, GFunc free_function); +G_GNUC_UNUSED static int get_list(JNIEnv *env, const char *clsName, const GList *list, Converter convert, jobjectArray *jarr); +G_GNUC_UNUSED static int set_list(JNIEnv *env, GList **list, jobjectArray jarr, GFunc free_function, OutConverter convert); +G_GNUC_UNUSED static int remove_from_list(JNIEnv *env,GList **list,jobject obj,GFunc free_function,GCompareFunc compare,OutConverter convert); +G_GNUC_UNUSED static int add_to_list(JNIEnv* env, GList** list, jobject obj, OutConverter convert); +G_GNUC_UNUSED static int get_hash(JNIEnv *env, char *clsName, GHashTable *hashtable, Converter convert, jobjectArray *jarr); +G_GNUC_UNUSED static int set_hash_of_objects(JNIEnv *env, GHashTable *hashtable, jobjectArray jarr); +G_GNUC_UNUSED static int set_hash_of_strings(JNIEnv *env, GHashTable *hashtable, jobjectArray jarr); +G_GNUC_UNUSED static int remove_from_hash(JNIEnv *env, GHashTable *hashtable, jstring jkey); +G_GNUC_UNUSED static int add_to_hash(JNIEnv *env, GHashTable *hashtable, jstring jkey, jobject jvalue, OutConverter convert, GFunc free_function); +G_GNUC_UNUSED static int get_hash_by_name(JNIEnv *env, GHashTable *hashtable, jstring jkey, Converter convert, jobject *jvalue); +#define get_list_of_strings(env,list,jarr) get_list(env,"java/lang/String",list,(Converter)string_to_jstring,jarr) +////#define get_list_of_xml_nodes(env,list,jarr) get_list(env,"java/lang/String",list,(Converter)xml_node_to_jstring,jarr) +#define get_list_of_objects(env,list,jarr) get_list(env,"java/lang/Object",list,(Converter)gobject_to_jobject_and_ref,jarr) +#define set_list_of_strings(env,list,jarr) set_list(env,list,jarr,(GFunc)g_free,(OutConverter)jstring_to_string) +////#define set_list_of_xml_nodes(env,list,jarr) set_list(env,list,jarr,(GFunc)xmlFreeNode,(OutConverter)jstring_to_xml_node) +#define set_list_of_objects(env,list,jarr) set_list(env,list,jarr,(GFunc)g_object_unref,(OutConverter)jobject_to_gobject) +// remove_from_list_of_strings is now implemented directly +//#define remove_from_list_of_strings(env,list,obj) remove_from_list(env,list,obj,(GFunc)g_free,(GCompareFunc)strcmp,(OutConverter)jstring_to_local_string) +//#define remove_from_list_of_xml_nodes(env,list,obj) remove_from_list(env,list,obj,(GFunc)xmlFreeNode,(GCompareFunc)strcmp,(OutConverter)jstring_to_xml_node) +#define remove_from_list_of_objects(env,list,obj) remove_from_list(env,list,obj,(GFunc)g_object_unref,(GCompareFunc)gpointer_equal,(OutConverter)jobject_to_gobject_noref) +#define add_to_list_of_strings(env,list,obj) add_to_list(env,list,obj,(OutConverter)jstring_to_string) +////#define add_to_list_of_xml_nodes(env,list,obj) add_to_list(env,list,obj,(OutConverter)jstring_to_xml_node) +// Use jobject_to_gobject_for_list because ref count must be augmented by one when inserted inside a list +#define add_to_list_of_objects(env,list,obj) add_to_list(env,list,obj,(OutConverter)jobject_to_gobject) +#define get_hash_of_strings(env,hash,jarr) get_hash(env,"java/lang/String",hash,(Converter)string_to_jstring, jarr) +#define get_hash_of_objects(env,hash,jarr) get_hash(env,"java/lang/Object",hash,(Converter)gobject_to_jobject_and_ref, jarr) +//#define remove_from_hash_of_strings(env,hash,key) remove_from_hash(env,hash,key) +//#define remove_from_hash_of_objects(env,hash,key) remove_from_hash(env,hash,key) +#define add_to_hash_of_strings(env,hash,key,obj) add_to_hash(env,hash,key,obj,(OutConverter)jstring_to_string,(GFunc)g_free) +#define add_to_hash_of_objects(env,hash,key,obj) add_to_hash(env,hash,key,obj,(OutConverter)jobject_to_gobject,(GFunc)g_object_unref) +//#define get_hash_of_strings_by_name(end,hash,key) get_hash_by_name(end,hash,key,(Converter)string_to_jstring) +//#define get_hash_of_objects_by_name(end,hash,key) get_hash_by_name(end,hash,key,(Converter)gobject_to_jobject_and_ref) +G_GNUC_UNUSED static void throw_by_name(JNIEnv *env, const char *name, const char *msg); + +G_GNUC_UNUSED static int bignum_to_jstring(JNIEnv *env, BIGNUM *bn, jstring *jstr); +G_GNUC_UNUSED static int jstring_to_bignum(JNIEnv *env, jstring jstr, BIGNUM **bn); +G_GNUC_UNUSED static int set_list_of_bn(JNIEnv *env, BIGNUM ***list, jobjectArray jarr); +G_GNUC_UNUSED static int get_list_of_bn(JNIEnv *env, BIGNUM **list, jobjectArray *jarr); +#define get_list_of_bignum(env,list,jarr) get_list(env,"java/lang/String",list,(Converter)bignum_to_jstring,jarr) +#define set_list_of_bignum(env,list,jarr) set_list(env,list,jarr,(GFunc)g_free,(OutConverter)jstring_to_bignum) +#define add_to_list_of_bignum(env,list,obj) add_to_list(env,list,obj,(OutConverter)jstring_to_bignum) +#define get_hash_of_bignum(env,hash,jarr) get_hash(env,"java/lang/String",hash,(Converter)bignum_to_jstring, jarr) + +static int int_to_jint(JNIEnv *env, int i, jint *ji); +static int jint_to_int(JNIEnv *env, jint ji, int *i); +G_GNUC_UNUSED static int set_list_of_int(JNIEnv *env, int **list, jobjectArray jarr); +G_GNUC_UNUSED static int get_list_of_int(JNIEnv *env, int *list, jobjectArray *jarr); +static jint extractInt(JNIEnv *env, jobject arg); +#define add_to_list_of_int(env,list,obj) add_to_list(env,list,obj,(OutConverter)jint_to_int) +#define get_hash_of_int(env,hash,jarr) get_hash(env,"java/lang/Integer",hash,(Converter)int_to_jint, jarr) + + +static int +bignum_to_jstring(JNIEnv *env, BIGNUM *bn, jstring *jstr) +{ + if (bn) { + char *hex = BN_bn2hex(bn); + *jstr = (*env)->NewStringUTF(env, hex); + OPENSSL_free(hex); + cryptic_return_val_if_fail(jstr, 0); + } else { + *jstr = NULL; + } + return 1; +} + +static int +get_list_of_bn(JNIEnv *env, BIGNUM **list, jobjectArray *jarr) { + jsize i; + jclass cls; + + g_error_if_fail (env); + + int size = 0; + while(list[size] != NULL) size++; + + cls = get_jclass_by_name(env, "java/lang/String"); + cryptic_return_val_if_fail(cls, 0); + + cryptic_return_val_if_fail(create_object_array(env, "java/lang/String", size, jarr), 0); + for (i=0; iGetObjectClass(env, arg); + jmethodID ajf = (*env)->GetMethodID(env, argClass, "intValue", "()I"); + return (*env)->CallIntMethod(env, arg, ajf); +} + +static int +gpointer_equal(const gpointer p1, const gpointer p2) { + return p1 != p2; +} + +static int +new_object_with_gobject(JNIEnv *env, GObject *obj, const char *clsName, jobject *jobj) { + jclass cls; + jmethodID mid; + + g_error_if_fail(env && clsName && obj && G_IS_OBJECT(obj)); + + cryptic_return_val_if_fail((cls = (*env)->FindClass(env, clsName)), 0); + cryptic_return_val_if_fail((mid = (*env)->GetMethodID(env, cls, "", "(J)V")), 0); + cryptic_return_val_if_fail((*jobj = (*env)->NewObject(env, cls, mid, PTR_TO_JLONG(obj))), 0); + return 1; +} + +/** Convert a java string to a jstring */ +static int +jstring_to_local_string(JNIEnv *env, jstring jstr, const char **str) +{ + g_error_if_fail(env); + + if (jstr) { + *str = (*env)->GetStringUTFChars(env, jstr, NULL); + cryptic_return_val_if_fail(*str, 0); + } else { + *str = NULL; + } + return 1; +} + +/** Release a local string. IT'S MANDATORY TO CALL THIS !!! */ +static void +release_local_string(JNIEnv *env, jstring str, const char *utf_str) { + g_error_if_fail(env); + + if (utf_str && str) { + (*env)->ReleaseStringUTFChars(env, str, utf_str); + } +} + +static int +get_jlong_field(JNIEnv *env, jobject obj, const char *field, jlong *dest) +{ + jclass cls; + jfieldID fid; + + cls = (*env)->GetObjectClass(env, obj); + cryptic_return_val_if_fail(cls, 0); + fid = (*env)->GetFieldID(env, cls, field, "J"); + cryptic_return_val_if_fail(fid, 0); + *dest = (*env)->GetLongField(env, obj, fid); + g_return_val_if_exception(0); + + return 1; +} + +static jclass +get_jclass_by_name(JNIEnv *env, const char *name) { + return (*env)->FindClass(env,name); +} + +static int +get_array_element(JNIEnv *env, jobjectArray arr, jsize i, jobject *dest) { + *dest = (*env)->GetObjectArrayElement(env, arr, i); + cryptic_return_val_if_fail(! (*env)->ExceptionCheck(env), 0); + return 1; +} + +static int +set_array_element(JNIEnv *env, jobjectArray arr, jsize i, jobject value) { + (*env)->SetObjectArrayElement(env, arr, i, value); + g_return_val_if_exception(0); + return 1; +} +static int +get_array_size(JNIEnv *env, jobjectArray jarr, jsize *dest) { + *dest = (*env)->GetArrayLength(env, jarr); + g_return_val_if_exception(0); + return 1; +} +static int +create_object_array(JNIEnv *env, const char *clsName, jsize size, jobjectArray *jarr) { + jclass cls; + + g_error_if_fail(env && clsName && jarr); + + cls = get_jclass_by_name(env, clsName); + cryptic_return_val_if_fail(cls, 0); + *jarr = (*env)->NewObjectArray(env, size, get_jclass_by_name(env, clsName), NULL); + cryptic_return_val_if_fail(*jarr, 0); + return 1; +} +static int nullWeakRef(JNIEnv *env, jweak weakRef) { + return weakRef && (*env)->IsSameObject(env, weakRef, NULL); +} +/** Return the shadow object associated with the gobject. + * If the weak global reference is dead, frees it. + * If not shadow object is present, return NULL. */ +static jobject +get_shadow_object(JNIEnv *env, GObject *obj) { + jweak weakRef; + + g_error_if_fail (obj && env); + weakRef = (jweak)g_object_get_qdata(obj, cryptic_wrapper_key); + if (weakRef == NULL) { + return NULL; + } else if (nullWeakRef(env, weakRef)) { + /** Remove null weak ref. */ + (*env)->DeleteWeakGlobalRef(env, weakRef); + g_object_set_qdata(obj, cryptic_wrapper_key, NULL); + return NULL; + } else { + return (*env)->NewLocalRef(env, weakRef); + } +} +/** Sets the java shadow object associated with the GObject obj. + * If a shadow object is already present, frees its weak global reference. + * Replacing a non NULL weak global reference by another one should not happend. + * It means that two java shadow object for the same GObject exist at the same time + */ +static void +set_shadow_object(JNIEnv *env, GObject *obj, jobject shadow_object) { + jweak weakRef; + jweak old_weakRef; + + g_error_if_fail(obj && env); + + old_weakRef = (jweak)g_object_get_qdata(obj, cryptic_wrapper_key); + if (old_weakRef) { + if (shadow_object != NULL && ! (*env)->IsSameObject(env, old_weakRef, NULL)) { + g_warning("remplacement d'un shadow object non nulle par un shadow object non nulle %p %p", shadow_object, old_weakRef); + } + (*env)->DeleteWeakGlobalRef(env, old_weakRef); + } + g_object_set_qdata(obj, cryptic_wrapper_key, NULL); + if (shadow_object) { + weakRef = (*env)->NewWeakGlobalRef(env, shadow_object); + g_object_set_qdata(obj, cryptic_wrapper_key, weakRef); + } +} +/** Throw a new RuntimeException containing this message. */ +static void +exception(JNIEnv *env, const char *message) { + jclass cls = (*env)->FindClass(env, "java/lang/RuntimeException"); + if (cls != NULL) { + throw_by_name(env, "java/lang/RuntimeException", message); + } + (*env)->DeleteLocalRef(env, cls); +} + +/* Conversion fonctions */ +/** Convert a C string to java string. NULL is a valid C string giving a null + * java object. */ +static int +string_to_jstring(JNIEnv *env, const char* str, jstring *jstr) { + if (str) { + *jstr = (*env)->NewStringUTF(env, str); + cryptic_return_val_if_fail(jstr, 0); + } else { + *jstr = NULL; + } + return 1; +} + +/** Convert a string to a java string then free it. Don't frees it + * if conversion failed. */ +static int +string_to_jstring_and_free(JNIEnv *env, char* str, jstring *jstr) { + cryptic_return_val_if_fail(string_to_jstring(env, str, jstr), 0); + if (str) + g_free(str); + return 1; +} + +/** Convert a jstring to a C string and copy it. Returned string is owner by the caller.*/ +static int +jstring_to_string(JNIEnv *env, jstring jstr, char **str) { + const char *local_str = NULL; + + cryptic_return_val_if_fail(jstring_to_local_string(env, jstr, &local_str), 0); + if (local_str) { + cryptic_assign_string(*str, local_str); + release_local_string(env, jstr, local_str); + if (!str) { + /* Maybe launch a OutOfMemoryException. */ + exception(env, "could not alloc a copy of a jstring"); + return 0; + } + } else { + *str = NULL; + } + return 1; +} + + +/* xmlNode handling */ +/** +static int +xml_node_to_jstring(JNIEnv *env, xmlNode *xmlnode, jstring *jstr) { + xmlOutputBufferPtr buf = NULL; + + g_error_if_fail(env); + if (! xmlnode) { + *jstr = NULL; + return 1; + } + + buf = xmlAllocOutputBuffer(NULL); + if (buf) { + int ret = 1; + xmlNodeDumpOutput(buf, NULL, xmlnode, 0, 1, NULL); + xmlOutputBufferFlush(buf); + xmlChar *str = NULL; + if (buf->conv == NULL) { + str = buf->buffer->content; + } else { + str = buf->conv->content; + } + ret = string_to_jstring(env, (char*)str, jstr); + xmlOutputBufferClose(buf); + return ret; + } else { + exception(env, "could not alloc an xml output buffer"); + return 0; + } + return 1; +} +**/ + +/** Convert a java string to an xml node. Return 0 if it failed with an exception + * throwed. */ +/** +static int +jstring_to_xml_node(JNIEnv *env, jstring jstr, xmlNode **xmlnode) { + xmlDoc *doc = NULL; + xmlNode *node = NULL; + const char *local_str = NULL; + int ret = 1; + + g_error_if_fail(env && xmlnode); + cryptic_return_val_if_fail(jstring_to_local_string(env, jstr, &local_str), 0); + + if (local_str) { + doc = xmlReadDoc((unsigned char *)local_str, NULL, NULL, XML_PARSE_NONET); + if (!doc) { + exception(env, "could not read an xml document"); + ret = 0; + goto out; + } + node = xmlDocGetRootElement(doc); + } +out: + cryptic_assign_xml_node(*xmlnode, node) + if (doc) + cryptic_release_doc(doc); + if (jstr && local_str) + release_local_string(env, jstr, local_str); + return ret; +} +**/ +/* cryptic objects handling impl */ +static void +create_class_name(char *dest, const char *typename) { + char *ret = NULL; + + ret = strstr(typename, "Cryptic"); + if (ret) { + typename = ret+5; + } + strncpy(dest+sizeof(CRYPTIC_ROOT)-1, typename,50); + dest[sizeof(CRYPTIC_ROOT)+49] = 0; +} +/** Convert the GObject obj to a java object encapsulating it. + * If obj is NULL, return NULL. + * Throws if obj is not a GObject or if anyhting fail. */ +static int +gobject_to_jobject_aux(JNIEnv *env, GObject *obj, gboolean doRef, jobject *jobj) { + jobject self = NULL; + int ret = 1; + + if (obj == NULL) { + goto out; + } + + if (! G_IS_OBJECT(obj)) { + exception(env, "tried to convert something that is not a GObject to a Java object"); + ret = 0; + goto out; + } + + /* Try to get an already created java object. */ + self = get_shadow_object(env, obj); + if (self) { + goto out; + } else { + /* Create the shadow object */ + char clsName[sizeof(CRYPTIC_ROOT)+50] = CRYPTIC_ROOT; + const char *typename = NULL; + + typename = G_OBJECT_TYPE_NAME(obj); + create_class_name(clsName, typename); + if (! new_object_with_gobject(env, obj, clsName, &self)) { + ret = 0; + goto out; + } + set_shadow_object(env, obj, self); + /** If all goes well increment reference count eventually. */ + if (doRef) { + g_object_ref(obj); + } + } +out: + *jobj = self; + return ret; +} +/** Get or create static int +get_list(JNIEnv *env, const char *clsName, const GList *list, Converter convert, jobjectArray *jarr) { + jsize l,i; + jclass cls; + + g_error_if_fail (env && clsName && convert); + l = g_list_length((GList*)list); + if (!l) { + *jarr = NULL; + goto out; + } + cls = get_jclass_by_name(env, clsName); + cryptic_return_val_if_fail(cls, 0); + + cryptic_return_val_if_fail(create_object_array(env, clsName, l, jarr), 0); + for (i=0;idata, &item), 0); + cryptic_return_val_if_fail(set_array_element(env, *jarr, i, item), 0); + list = g_list_next(list); + } +out: + return 1; +} +a new java object encapsulating this cryptic GObject, do not increase ref count if created. */ +static int +gobject_to_jobject(JNIEnv *env, GObject *obj, jobject *jobj) { + return gobject_to_jobject_aux(env, obj, FALSE, jobj); +} +/** Get or create a new java object encapsulating this cryptic GObject, increase ref count if created. */ +static int +gobject_to_jobject_and_ref(JNIEnv *env, GObject *obj, jobject *jobj) { + return gobject_to_jobject_aux(env, obj, TRUE, jobj); +} + +/** Get the gobject encapsulated by the java object obj. If cptr is + * null return NULL. + * It throws and return 0 if anything fail unexpectedly. */ +static int +jobject_to_gobject(JNIEnv *env, jobject obj, GObject **gobj) { + jlong value = 0; + GObject *gobject = NULL; + + g_error_if_fail(env); + + if (! obj) { + *gobj = NULL; + return 1; + } + cryptic_return_val_if_fail(get_jlong_field(env, obj, "cptr", &value), 0); + gobject = convert_jlong_to_gobject(value); + if (gobject && ! G_IS_OBJECT(gobject)) { +#define s "jobject->cptr is not a pointer on a gobject: XXXXXXXXXXXXXXXXXXXXXXX" + char str[] = s; + snprintf(str, sizeof(s)-1, "jobject->cptr is not a pointer on a gobject = %p", gobject); + exception(env, str); +#undef s + return 0; + } else { + cryptic_assign_gobject(*gobj, gobject); + return 1; + } +} + +/** Get the gobject encapsulated by the java object obj and increase its ref count. The only + * use for this function is composed with set_list_of_objects or set_hash_of_object. */ +static int +jobject_to_gobject_noref(JNIEnv *env, jobject obj, GObject **gobj) { + cryptic_return_val_if_fail(jobject_to_gobject(env, obj, gobj), 0); + if (*gobj) { + g_object_unref(*gobj); + } + return 1; +} + +/* List handling */ +static void +free_glist(GList **list, GFunc free_function) { + cryptic_return_if_fail(list); + if (*list) { + if (free_function) { + g_list_foreach(*list, free_function, NULL); + } + g_list_free(*list); + } + *list = NULL; +} + +/** Get an object array from a GList*, convert C object to java object using + * the convert function. + * + * Can throw. If list is null or empty, return NULL. + */ +static int +get_list(JNIEnv *env, const char *clsName, const GList *list, Converter convert, jobjectArray *jarr) { + jsize l,i; + jclass cls; + + g_error_if_fail (env && clsName && convert); + l = g_list_length((GList*)list); + if (!l) { + *jarr = NULL; + goto out; + } + cls = get_jclass_by_name(env, clsName); + cryptic_return_val_if_fail(cls, 0); + + cryptic_return_val_if_fail(create_object_array(env, clsName, l, jarr), 0); + for (i=0;idata, &item), 0); + cryptic_return_val_if_fail(set_array_element(env, *jarr, i, item), 0); + list = g_list_next(list); + } +out: + return 1; +} + +/** Sets a GList* field using a java array of object. Use free_function if an old list exist. + * Use convert to convert the java objects to C values. */ +static int +set_list(JNIEnv *env, GList **list, jobjectArray jarr, GFunc free_function, OutConverter convert) { + jobject element = NULL; + jsize size = 0; + jsize i = 0; + GList *new = NULL; + + g_error_if_fail (list && free_function && convert && env); + if (jarr) { + if (! get_array_size(env, jarr, &size)) + goto error; + for (i=0; i < size; i++) { + gpointer result = NULL; + + if (! get_array_element(env, jarr, i, &element) + || ! convert(env, element, &result)) { + goto error; + } + new = g_list_append(new, result); + } + } + + free_glist(list, free_function); + *list = new; + return 1; + +error: + free_glist(&new, free_function); + return 0; +} +/** Remove a value obtained via the convert function on obj from *list. + * It is searched inside *list using the compare function. + * If pointer is found, it is freed using the free_function. + * Return 0 if an exception was throwed. + **/ +static int +remove_from_list(JNIEnv *env, GList **list, jobject obj, GFunc free_function, GCompareFunc compare, OutConverter convert) { + gpointer data = NULL; + GList *found = NULL; + + g_error_if_fail(env && list && compare && convert && free_function); + cryptic_return_val_if_fail(obj, 1); + cryptic_return_val_if_fail(convert(env, obj, &data), 0); + found = g_list_find_custom(*list, data, compare); + if (found) { + free_function(found->data, NULL); + *list = g_list_delete_link(*list, found); + } + return 1; +} +static int +remove_from_list_of_strings(JNIEnv *env, GList **list, jstring jstr) { + const char *local_string = NULL; + GList *found = NULL; + + g_error_if_fail(env && list); + cryptic_return_val_if_fail(jstr, 1); + cryptic_return_val_if_fail(jstring_to_local_string(env, jstr, &local_string), 0); + found = g_list_find_custom(*list, local_string, (GCompareFunc)strcmp); + if (found) { + g_free(found->data); + *list = g_list_delete_link(*list, found); + } + release_local_string(env, jstr, local_string); + return 1; +} +/** Add obj to GList *list. + * Returns 1. + * Returns 0 and throws if anything fail. + */ +static int +add_to_list(JNIEnv* env, GList** list, jobject obj, OutConverter convert) { + gpointer data = NULL; + + g_error_if_fail(env && list && convert); + cryptic_return_val_if_fail(convert(env, obj, &data), 0); + if (data) + *list = g_list_append(*list, data); + return 1; +} + +/* Ghash table handling impl */ +/** Create a java array from a GHashTable, using the convert function. */ +static int +get_hash(JNIEnv *env, char *clsName, GHashTable *hashtable, Converter convert, jobjectArray *jarr) +{ + jsize l = 0, i = 0; + + GList *keys = NULL, *values = NULL; + int ret = 1; + + g_error_if_fail (env && hashtable && convert); + l = g_hash_table_size(hashtable); + cryptic_return_val_if_fail(create_object_array(env, clsName, 2*l, jarr), 0); + keys = g_hash_table_get_keys(hashtable); + values = g_hash_table_get_values(hashtable); + if (! (keys && values)) { + ret = 0; + exception(env, "cannot allocate for converting GHashTable to an array"); + goto out; + } + for (i=0; i < 2*l && keys && values; i+=2) { + jstring key = NULL; + jobject value = NULL; + + if (! (string_to_jstring(env, (char*)keys->data, &key) + && convert(env, (gpointer)values->data, &value) + && set_array_element(env, *jarr, i, key) + && set_array_element(env, *jarr, i+1, value))) { + ret = 0; + goto out; + } + keys = g_list_next(keys); + values = g_list_next(values); + } +out: + if (keys) + g_list_free(keys); + if (values) + g_list_free(values); + return ret; +} +/** Fill a GHashTable with content of java array arr. + * Even indexed element coressponds to keys (jstring) and + * odd indexed one to value (GObject). + * Returns 1. + * Returns 0 and thows an exception if anything fail. + */ +static int +set_hash_of_objects(JNIEnv *env, GHashTable *hashtable, jobjectArray jarr) +{ + jsize l = 0, i = 0; + + g_error_if_fail (env && hashtable); + if (jarr) { + /** First increment ref count of object in jarr */ + cryptic_return_val_if_fail(get_array_size(env, jarr, &l), 0); + if (l % 2 != 0) { + exception(env, "java array not of an even size"); + return 0; + } + for (i = 1; i < l; i += 2) { + jobject jobj = NULL; + GObject *gobj = NULL; + + cryptic_return_val_if_fail(get_array_element(env, jarr, i, &jobj), 0); + cryptic_return_val_if_fail(jobject_to_gobject_noref(env, jobj, &gobj), 0); + (*env)->DeleteLocalRef(env, jobj); + } + /* increment ref count of objects */ + for (i = 1; i < l; i += 2) { + jobject jobj = NULL; + GObject *gobj = NULL; + + get_array_element(env, jarr, i, &jobj); + jobject_to_gobject(env, jobj, &gobj); + (*env)->DeleteLocalRef(env, jobj); + } + } + /** Remove old values, if hashtable is well initialized + * it should unref objects automatically. */ + g_hash_table_remove_all(hashtable); + /** Insert new values */ + if (jarr) { + for (i = 0; i < l; i += 2) { + jstring jkey = NULL; + char *key = NULL; + jobject jvalue = NULL; + GObject *value = NULL; + + cryptic_return_val_if_fail(get_array_element(env, jarr, i, &jkey), 0); + cryptic_return_val_if_fail(get_array_element(env, jarr, i+1, &jvalue), 0); + cryptic_return_val_if_fail(jstring_to_string(env, jkey, &key), 0); + if (! jobject_to_gobject_noref(env, jvalue, &value)) { + if (key) + g_free(key); + g_hash_table_remove_all(hashtable); + return 0; + } + g_hash_table_insert (hashtable, key, value); + (*env)->DeleteLocalRef(env, jkey); + (*env)->DeleteLocalRef(env, jvalue); + } + } + return 1; +} +/** Insert a java String array, containing + * keys at odd indexes, and values at even indexes into an existing + * GHashTable. Old entries are lost, but hopefully deallocated by + * the hashtable free functions --- setted at creation, see GLib + * documentation. + * + * @param env the JNI context given by the JVM + * @param hashtable an existing GHashTable + * @param a ref to a java object Array of size multiple of two + * + * @return 1 if successful, 0 if anything bad happen. + */ +static int +set_hash_of_strings(JNIEnv *env, GHashTable *hashtable, jobjectArray jarr) { + jsize l = 0, i = 0; + + g_error_if_fail (env && hashtable); + + g_hash_table_remove_all(hashtable); + if (jarr) { + cryptic_return_val_if_fail(get_array_size(env, jarr, &l), 0); + if (l % 2 != 0) { + exception(env, "java array not of an even size"); + return 0; + } + for (i = 0; i < l; i += 2) { + jstring jkey = NULL; + char *key = NULL; + jstring jvalue = NULL; + char *value = NULL; + + cryptic_return_val_if_fail(get_array_element(env, jarr, i, &jkey) + && get_array_element(env, jarr, i+1, &jvalue) + && jstring_to_string(env, jkey, &key), 0); + if (! key) { + exception(env, "key is null"); + return 0; + } + if (! jstring_to_string(env, jvalue, &value)) { + if (key) + g_free(key); + g_hash_table_remove_all(hashtable); + return 0; + } + /* Can use insert because hash table is empty */ + g_hash_table_insert(hashtable, key, value); + (*env)->DeleteLocalRef(env, jkey); + (*env)->DeleteLocalRef(env, jvalue); + } + } + return 1; +} + +/** Remove the value for the given key from hashtable. */ +static int +remove_from_hash(JNIEnv *env, GHashTable *hashtable, jstring jkey) { + const char *key = NULL; + + g_error_if_fail (env && hashtable); + + cryptic_return_val_if_fail(jstring_to_local_string(env, jkey, &key), 0); + g_hash_table_remove(hashtable, key); + release_local_string(env, jkey, key); + return 1; +} +/** Add a jobject to an hashtable */ +static int +add_to_hash(JNIEnv *env, GHashTable *hashtable, jstring jkey, jobject jvalue, OutConverter convert, GFunc free_function) +{ + void *value = NULL; + char *key = NULL; + + g_error_if_fail (env && hashtable && key && convert); + + if (! (convert(env, jvalue, &value) + && jstring_to_string(env, jkey, &key))) + goto error; + + g_hash_table_replace(hashtable, key, value); + return 1; +error: + if (key) + g_free(key); + if (value) + free_function(value, NULL); + return 0; +} +static int +get_hash_by_name(JNIEnv *env, GHashTable *hashtable, jstring jkey, Converter convert, jobject *jvalue) +{ + const char *key = NULL; + gpointer value = NULL; + + g_error_if_fail (env && hashtable && convert); + + cryptic_return_val_if_fail(jstring_to_local_string(env, jkey, &key), 0); + value = g_hash_table_lookup(hashtable, key); + release_local_string(env, jkey, key); + return convert(env, value, jvalue); +} +static void +throw_by_name(JNIEnv *env, const char *name, const char *msg) +{ + jclass cls = (*env)->FindClass(env, name); + /* if cls is NULL, an exception has already been thrown */ + if (cls != NULL) { + (*env)->ThrowNew(env, cls, msg); + } + /* free the local ref */ + (*env)->DeleteLocalRef(env, cls); +} + + +/* JNI Functions */ +JNIEXPORT void JNICALL Java_com_entrouvert_cryptic_CrypticJNI_init2(JNIEnv *env, jclass cls) { + cryptic_wrapper_key = g_quark_from_static_string("JavaCryptic::wrapper"); +} +JNIEXPORT void JNICALL Java_com_entrouvert_cryptic_CrypticJNI_destroy(JNIEnv *env, jclass cls, jlong cptr) { + GObject *obj = (GObject*)(ptrdiff_t)cptr; + set_shadow_object(env, obj, NULL); + g_object_unref(obj); +} +JNIEXPORT void JNICALL Java_com_entrouvert_cryptic_CrypticJNI_set_1shadow_1object(JNIEnv *env, jclass cls, jlong cptr, jobject shadow_object) { + GObject *gobj = NULL; + + gobj = convert_jlong_to_gobject(cptr); + set_shadow_object(env, gobj, shadow_object); +} diff --git a/bindings/overrides.xml b/bindings/overrides.xml new file mode 100644 index 0000000..0f39145 --- /dev/null +++ b/bindings/overrides.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/bindings/python/Makefile.am b/bindings/python/Makefile.am new file mode 100644 index 0000000..1fc4b76 --- /dev/null +++ b/bindings/python/Makefile.am @@ -0,0 +1,33 @@ +MAINTAINERCLEANFILES = Makefile.in +MOSTLYCLEANFILES = __init__.pyc lang.pyc + +if PYTHON_ENABLED +INCLUDES = \ + -DPACKAGE=\"@PACKAGE@\" \ + -I$(top_builddir) \ + -I$(top_srcdir) \ + $(SASL_CFLAGS) \ + $(CRYPTIC_CFLAGS) + +pythondir= $(PY_SITE_PACKAGES) +nodist_python_DATA = cryptic.py +python_LTLIBRARIES = _cryptic.la + +nodist__cryptic_la_SOURCES = _cryptic.c +_cryptic_la_CFLAGS = -fno-strict-aliasing $(cryptic_CORE_CFLAGS) $(PY_CFLAGS) $(AM_CFLAGS) +_cryptic_la_LIBADD = $(top_builddir)/cryptic/libcryptic.la $(cryptic_LIBS) +_cryptic_la_LDFLAGS = -no-undefined -module -avoid-version + +BUILT_SOURCES = _cryptic.c + +_cryptic.c cryptic.py: $(top_srcdir)/cryptic/*/*.h $(top_srcdir)/cryptic/*/*.c $(top_srcdir)/cryptic/*/*/*.h $(top_srcdir)/cryptic/*/*/*.c + +EXTRA_DIST=lang.py wrapper_bottom.c wrapper_top.c __init__.py examples + +cryptic.py _cryptic.c: lang.py wrapper_top.c wrapper_bottom.c ../bindings.py + $(AM_V_GEN) $(PYTHON) $(top_srcdir)/bindings/bindings.py -l python --src-dir=$(top_srcdir)/cryptic/ $(EXTRA_ARGS) + +clean-local: + -rm -f cryptic.py cryptic.pyc _cryptic.c + +endif diff --git a/bindings/python/Makefile.in b/bindings/python/Makefile.in new file mode 100644 index 0000000..9aa1217 --- /dev/null +++ b/bindings/python/Makefile.in @@ -0,0 +1,705 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = bindings/python +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/ac_check_class.m4 \ + $(top_srcdir)/m4/ac_check_classpath.m4 \ + $(top_srcdir)/m4/ac_check_junit.m4 \ + $(top_srcdir)/m4/ac_prog_jar.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/ac_prog_javah.m4 \ + $(top_srcdir)/m4/ac_try_compile_java.m4 \ + $(top_srcdir)/m4/as-compiler-flag.m4 \ + $(top_srcdir)/m4/dps_java_check_class.m4 \ + $(top_srcdir)/m4/dps_xtra_classpath.m4 \ + $(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/libtool.m4 \ + $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ + $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(pythondir)" "$(DESTDIR)$(pythondir)" +LTLIBRARIES = $(python_LTLIBRARIES) +@PYTHON_ENABLED_TRUE@_cryptic_la_DEPENDENCIES = \ +@PYTHON_ENABLED_TRUE@ $(top_builddir)/cryptic/libcryptic.la +@PYTHON_ENABLED_TRUE@nodist__cryptic_la_OBJECTS = \ +@PYTHON_ENABLED_TRUE@ _cryptic_la-_cryptic.lo +_cryptic_la_OBJECTS = $(nodist__cryptic_la_OBJECTS) +AM_V_lt = $(am__v_lt_$(V)) +am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) +am__v_lt_0 = --silent +_cryptic_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(_cryptic_la_CFLAGS) \ + $(CFLAGS) $(_cryptic_la_LDFLAGS) $(LDFLAGS) -o $@ +@PYTHON_ENABLED_TRUE@am__cryptic_la_rpath = -rpath $(pythondir) +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_$(V)) +am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) +am__v_CC_0 = @echo " CC " $@; +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_$(V)) +am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) +am__v_CCLD_0 = @echo " CCLD " $@; +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; +SOURCES = $(nodist__cryptic_la_SOURCES) +DIST_SOURCES = +DATA = $(nodist_python_DATA) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_CFLAGS = @AM_CFLAGS@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AS = @AS@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CHECK_CFLAGS = @CHECK_CFLAGS@ +CHECK_LIBS = @CHECK_LIBS@ +CLASSPATH_JUNIT = @CLASSPATH_JUNIT@ +CLASSPATH_OPT = @CLASSPATH_OPT@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CRYPTIC_APP_DEFINES = @CRYPTIC_APP_DEFINES@ +CRYPTIC_CFLAGS = @CRYPTIC_CFLAGS@ +CRYPTIC_CORE_CFLAGS = @CRYPTIC_CORE_CFLAGS@ +CRYPTIC_CORE_LIBS = @CRYPTIC_CORE_LIBS@ +CRYPTIC_DEFINES = @CRYPTIC_DEFINES@ +CRYPTIC_DOCDIR = @CRYPTIC_DOCDIR@ +CRYPTIC_LIBS = @CRYPTIC_LIBS@ +CRYPTIC_PUB_CFLAGS = @CRYPTIC_PUB_CFLAGS@ +CRYPTIC_STATIC_BINARIES = @CRYPTIC_STATIC_BINARIES@ +CRYPTIC_VERSION_INFO = @CRYPTIC_VERSION_INFO@ +CSHARPCILINTERPRETER = @CSHARPCILINTERPRETER@ +CSHARPCOMPILER = @CSHARPCOMPILER@ +CSHARPCYGPATH_W = @CSHARPCYGPATH_W@ +CSHARPDYNAMICLINKING = @CSHARPDYNAMICLINKING@ +CSHARPLIBRARYPREFIX = @CSHARPLIBRARYPREFIX@ +CYGPATH_W = @CYGPATH_W@ +DEBUGGING = @DEBUGGING@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DLL_FILENAME = @DLL_FILENAME@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GACUTIL = @GACUTIL@ +GREP = @GREP@ +GTKDOC_CHECK = @GTKDOC_CHECK@ +GTKDOC_MKPDF = @GTKDOC_MKPDF@ +GTKDOC_REBASE = @GTKDOC_REBASE@ +HTML_DIR = @HTML_DIR@ +INKSCAPE = @INKSCAPE@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_FLAGS = @JAVAC_FLAGS@ +JAVAH = @JAVAH@ +JAVAH_FLAGS = @JAVAH_FLAGS@ +JAVA_INCLUDE = @JAVA_INCLUDE@ +JAVA_JUNIT = @JAVA_JUNIT@ +JAVA_VERSION = @JAVA_VERSION@ +JDK_INCLUDE = @JDK_INCLUDE@ +JUNIT = @JUNIT@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBTOOL_DEPS = @LIBTOOL_DEPS@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ +PERLINSTALLSITEARCH = @PERLINSTALLSITEARCH@ +PERLMAN3DIR = @PERLMAN3DIR@ +PERL_VERSION = @PERL_VERSION@ +PHP5 = @PHP5@ +PHP5_CONFIG = @PHP5_CONFIG@ +PHP5_CONFIG_DIR = @PHP5_CONFIG_DIR@ +PHP5_EXTENSION_DIR = @PHP5_EXTENSION_DIR@ +PHP5_INCLUDES = @PHP5_INCLUDES@ +PHP5_INCLUDE_DIR = @PHP5_INCLUDE_DIR@ +PHP5_LDFLAGS = @PHP5_LDFLAGS@ +PHP5_LIBS = @PHP5_LIBS@ +PHP5_PREFIX = @PHP5_PREFIX@ +PHP5_UNPREFIXED_EXTENSION_DIR = @PHP5_UNPREFIXED_EXTENSION_DIR@ +PHP5_VERSION = @PHP5_VERSION@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +PYTHON = @PYTHON@ +PYTHON_VERSION = @PYTHON_VERSION@ +PY_CFLAGS = @PY_CFLAGS@ +PY_DYNLOAD = @PY_DYNLOAD@ +PY_EXTRA_LIBS = @PY_EXTRA_LIBS@ +PY_LIB_A = @PY_LIB_A@ +PY_LIB_LOC = @PY_LIB_LOC@ +PY_SITE_PACKAGES = @PY_SITE_PACKAGES@ +RANLIB = @RANLIB@ +RC = @RC@ +REST2HTML = @REST2HTML@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +SWIG = @SWIG@ +SWIG_PYTHON_ARGS = @SWIG_PYTHON_ARGS@ +SWIG_VERSION = @SWIG_VERSION@ +TAR = @TAR@ +TESTS_JUNIT = @TESTS_JUNIT@ +U = @U@ +UPCASED_DLL_FILENAME = @UPCASED_DLL_FILENAME@ +VERSION = @VERSION@ +VERSION_UNDERSCORED = @VERSION_UNDERSCORED@ +WINDOWS_VERSION = @WINDOWS_VERSION@ +XSLTPROC = @XSLTPROC@ +Z_CFLAGS = @Z_CFLAGS@ +Z_LIBS = @Z_LIBS@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +lt_ECHO = @lt_ECHO@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +MAINTAINERCLEANFILES = Makefile.in +MOSTLYCLEANFILES = __init__.pyc lang.pyc +@PYTHON_ENABLED_TRUE@INCLUDES = \ +@PYTHON_ENABLED_TRUE@ -DPACKAGE=\"@PACKAGE@\" \ +@PYTHON_ENABLED_TRUE@ -I$(top_builddir) \ +@PYTHON_ENABLED_TRUE@ -I$(top_srcdir) \ +@PYTHON_ENABLED_TRUE@ $(SASL_CFLAGS) \ +@PYTHON_ENABLED_TRUE@ $(CRYPTIC_CFLAGS) + +@PYTHON_ENABLED_TRUE@pythondir = $(PY_SITE_PACKAGES) +@PYTHON_ENABLED_TRUE@nodist_python_DATA = cryptic.py +@PYTHON_ENABLED_TRUE@python_LTLIBRARIES = _cryptic.la +@PYTHON_ENABLED_TRUE@nodist__cryptic_la_SOURCES = _cryptic.c +@PYTHON_ENABLED_TRUE@_cryptic_la_CFLAGS = -fno-strict-aliasing $(cryptic_CORE_CFLAGS) $(PY_CFLAGS) $(AM_CFLAGS) +@PYTHON_ENABLED_TRUE@_cryptic_la_LIBADD = $(top_builddir)/cryptic/libcryptic.la $(cryptic_LIBS) +@PYTHON_ENABLED_TRUE@_cryptic_la_LDFLAGS = -no-undefined -module -avoid-version +@PYTHON_ENABLED_TRUE@BUILT_SOURCES = _cryptic.c +@PYTHON_ENABLED_TRUE@EXTRA_DIST = lang.py wrapper_bottom.c wrapper_top.c __init__.py examples +all: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign bindings/python/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign bindings/python/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-pythonLTLIBRARIES: $(python_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(pythondir)" || $(MKDIR_P) "$(DESTDIR)$(pythondir)" + @list='$(python_LTLIBRARIES)'; test -n "$(pythondir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(pythondir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(pythondir)"; \ + } + +uninstall-pythonLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(python_LTLIBRARIES)'; test -n "$(pythondir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(pythondir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(pythondir)/$$f"; \ + done + +clean-pythonLTLIBRARIES: + -test -z "$(python_LTLIBRARIES)" || rm -f $(python_LTLIBRARIES) + @list='$(python_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +_cryptic.la: $(_cryptic_la_OBJECTS) $(_cryptic_la_DEPENDENCIES) + $(AM_V_CCLD)$(_cryptic_la_LINK) $(am__cryptic_la_rpath) $(_cryptic_la_OBJECTS) $(_cryptic_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/_cryptic_la-_cryptic.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +_cryptic_la-_cryptic.lo: _cryptic.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(_cryptic_la_CFLAGS) $(CFLAGS) -MT _cryptic_la-_cryptic.lo -MD -MP -MF $(DEPDIR)/_cryptic_la-_cryptic.Tpo -c -o _cryptic_la-_cryptic.lo `test -f '_cryptic.c' || echo '$(srcdir)/'`_cryptic.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/_cryptic_la-_cryptic.Tpo $(DEPDIR)/_cryptic_la-_cryptic.Plo +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='_cryptic.c' object='_cryptic_la-_cryptic.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(_cryptic_la_CFLAGS) $(CFLAGS) -c -o _cryptic_la-_cryptic.lo `test -f '_cryptic.c' || echo '$(srcdir)/'`_cryptic.c + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs +install-nodist_pythonDATA: $(nodist_python_DATA) + @$(NORMAL_INSTALL) + test -z "$(pythondir)" || $(MKDIR_P) "$(DESTDIR)$(pythondir)" + @list='$(nodist_python_DATA)'; test -n "$(pythondir)" || list=; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(pythondir)'"; \ + $(INSTALL_DATA) $$files "$(DESTDIR)$(pythondir)" || exit $$?; \ + done + +uninstall-nodist_pythonDATA: + @$(NORMAL_UNINSTALL) + @list='$(nodist_python_DATA)'; test -n "$(pythondir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + test -n "$$files" || exit 0; \ + echo " ( cd '$(DESTDIR)$(pythondir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(pythondir)" && rm -f $$files + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) check-am +all-am: Makefile $(LTLIBRARIES) $(DATA) +installdirs: + for dir in "$(DESTDIR)$(pythondir)" "$(DESTDIR)$(pythondir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + -test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES) + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) + -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) +@PYTHON_ENABLED_FALSE@clean-local: +clean: clean-am + +clean-am: clean-generic clean-libtool clean-local \ + clean-pythonLTLIBRARIES mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: install-nodist_pythonDATA install-pythonLTLIBRARIES + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-nodist_pythonDATA uninstall-pythonLTLIBRARIES + +.MAKE: all check install install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-local clean-pythonLTLIBRARIES ctags \ + distclean distclean-compile distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-man install-nodist_pythonDATA \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-pythonLTLIBRARIES install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-nodist_pythonDATA \ + uninstall-pythonLTLIBRARIES + + +@PYTHON_ENABLED_TRUE@_cryptic.c cryptic.py: $(top_srcdir)/cryptic/*/*.h $(top_srcdir)/cryptic/*/*.c $(top_srcdir)/cryptic/*/*/*.h $(top_srcdir)/cryptic/*/*/*.c + +@PYTHON_ENABLED_TRUE@cryptic.py _cryptic.c: lang.py wrapper_top.c wrapper_bottom.c ../bindings.py +@PYTHON_ENABLED_TRUE@ $(AM_V_GEN) $(PYTHON) $(top_srcdir)/bindings/bindings.py -l python --src-dir=$(top_srcdir)/cryptic/ $(EXTRA_ARGS) + +@PYTHON_ENABLED_TRUE@clean-local: +@PYTHON_ENABLED_TRUE@ -rm -f cryptic.py cryptic.pyc _cryptic.c + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/bindings/python/__init__.py b/bindings/python/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bindings/python/lang.py b/bindings/python/lang.py new file mode 100644 index 0000000..70b4243 --- /dev/null +++ b/bindings/python/lang.py @@ -0,0 +1,1054 @@ +# Cryptic -- Cryptographic tools and protocols +# +# Copyright (C) 2004-2010 Entr'ouvert +# http://www.entrouvert.org +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import os +import sys +import re +import textwrap +from utils import * + + +def remove_bad_optional(args): + args.reverse() + non_opt = False + new_args = [] + for x in args: + if not '=' in x: + non_opt = True + elif non_opt: + print >>sys.stderr, 'W: changed', x, + x = re.sub(' *=.*', '', x) + print >>sys.stderr, 'to', x + new_args.append(x) + new_args.reverse() + return new_args + +def defval_to_python_value(defval): + if defval is None: + return 'None' + if defval.startswith('b:'): + if defval[2:].lower() == 'true': + return 'True' + if defval[2:].lower() == 'false': + return 'False' + if defval.startswith('c:'): + try: + return str(int(defval[2:])) + except: + return defval[8:] + raise Exception('Could not convert %s to python value' % defval) + +def get_python_arg_decl(arg): + if is_optional(arg): + return '%s = %s' % (arg_name(arg), defval_to_python_value(arg_default(arg))) + else: + return arg_name(arg) + +class Binding: + def __init__(self, binding_data): + self.binding_data = binding_data + self.src_dir = os.path.dirname(__file__) + + def free_value(self, fd, type, name = None): + if not name: + name = arg_anme(type) + if not name: + raise Exception('Cannot free, missing a name') + if is_cstring(type): + print >>fd, ' %s_release_string(%s);' % (library.lower(),name) + elif is_tabbn(type): + print >> fd, ' if(%s){' % name + print >> fd, ' int counter;' + print >> fd, ' while(%s[counter]!=0){' % name + print >> fd, ' %s_release_bn(%s[counter]);' % (library.lower(),name) + print >> fd, ' counter++;' + print >> fd, ' }' + print >> fd, ' }' +###################### + elif is_bn(type): + print >> fd, ' %s_release_bn(%s);' % (library.lower(),name) + elif is_tabint(type): + print >> fd, ' g_free(%s);' % name + elif is_int(type, self.binding_data): + pass +###################### + elif is_xml_node(type): + print >>fd, ' %s_release_xml_node(%s);' % (library.lower(),name) + elif is_glist(type): + etype = element_type(type) + if is_cstring(etype): + ' %s_release_list_of_strings(%s);' % (library.lower(),name) + elif is_object(etype): + ' %s_release_list_of_gobjects(%s);' % (library.lower(),name) + else: + raise Exception('Unsupported caller owned return type %s' % ((repr(type), name),)) + elif is_hashtable(type): + raise Exception('Unsupported caller owned return type %s' % ((repr(type), name),)) + elif is_object(type): +#################""BUG: Put %s instead return_value + print >> fd, ' if (return_value) g_object_unref(%s);' % name + else: + raise Exception('Unsupported caller owned return type %s' % ((repr(type), name),)) + + + def generate(self): + global library + library = 'Cryptic' + fd = open(library.lower() + '.py', 'w') + self.generate_header(fd) + self.generate_exceptions(fd) + self.generate_constants(fd) + for clss in self.binding_data.structs: + self.generate_class(clss, fd) + self.generate_functions(fd) + self.generate_footer(fd) + fd.close() + + fd = open('_' + library.lower() + '.c', 'w') + self.generate_wrapper(fd) + fd.close() + + def generate_header(self, fd): + print >> fd, '''\ +# this file has been generated automatically; do not edit + +import _''' + library.lower() + ''' + +_''' + library.lower() + '''.init() + +def cptrToPy(cptr): + if cptr is None: + return None + klass = getattr(''' + library.lower() + ''', cptr.typename) + o = klass.__new__(klass) + o._cptr = cptr + return o + +class frozendict(dict): + \'\'\'Immutable dict\'\'\' + # from Python Cookbook: + # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/414283 + def _blocked_attribute(obj): + raise AttributeError('A frozendict cannot be modified.') + _blocked_attribute = property(_blocked_attribute) + + __delitem__ = __setitem__ = clear = _blocked_attribute + pop = popitem = setdefault = update = _blocked_attribute + + def __new__(cls, *args): + new = dict.__new__(cls) + dict.__init__(new, *args) + return new + + def __init__(self, *args): + pass + + def __hash__(self): + try: + return self._cached_hash + except AttributeError: + h = self._cached_hash = hash(tuple(sorted(self.items()))) + return h + + def __repr__(self): + return 'frozendict(%s)' % dict.__repr__(self) +''' + + def generate_exceptions(self, fd): + done_cats = [] + print >> fd, '''\ +class Error(Exception): + code = None + + @staticmethod + def raise_on_rc(rc): + global exceptions_dict + exception = exceptions_dict.get(rc, Error()) + exception.code = rc + raise exception + + def __str__(self): + return '<''' + library.lower() + '''.%s(%s): %s>' % (self.__class__.__name__, self.code, _''' + library.lower() + '''.strError(self.code)) + + def __getitem__(self, i): + # compatibility with SWIG bindings + if i == 0: + return self.code + elif i == 1: + return _''' + library.lower() + '''.strError(self.code) + else: + raise IndexError() +''' + for exc_cat in self.binding_data.overrides.findall('exception/category'): + cat = exc_cat.attrib.get('name') + done_cats.append(cat) + parent_cat = exc_cat.attrib.get('parent', '') + print >> fd, '''\ +class %sError(%sError): + pass +''' % (cat, parent_cat) + + exceptions_dict = {} + + for c in self.binding_data.constants: + regex = r'%s_(\w+)_ERROR_(.*)' % library.upper() + m = re.match(regex, c[1]) + if not m: + continue + cat, detail = m.groups() + cat = cat.title().replace('_', '') + detail = (cat + '_' + detail).title().replace('_', '') + if not cat in done_cats: + done_cats.append(cat) + for exc_cat in self.binding_data.overrides.findall('exception/category'): + if exc_cat.attrib.get('name') == cat: + parent_cat = exc_cat.attrib.get('parent') + break + else: + parent_cat = '' + + print >> fd, '''\ +class %sError(%sError): + pass +''' % (cat, parent_cat) + + exceptions_dict[detail] = c[1][(len(library)+1):] + + if (detail, cat) == ('UnsupportedProfile', 'Logout'): + # skip Logout/UnsupportedProfile exception as its name would + # be the same as Profile/UnsupportedProfile; it is not a + # problem skipping it as they both inherit from ProfileError + # and the exception code will correctly be set by raise_on_rc + # afterwards. (actually it is even totally unnecessary to skip + # it here as Profile/UnsupportedProfile is handled after + # Logout/UnsupportedProfile, this is just done in the case the + # ordering would change) + continue + + print >> fd, '''\ +class %sError(%sError): + pass +''' % (detail, cat) + + print >> fd, 'exceptions_dict = {' + for k, v in exceptions_dict.items(): + print >> fd, ' _%s.%s: %sError,' % (library.lower(), v, k) + print >> fd, '}' + print >> fd, '' + + def generate_footer(self, fd): +###############" + print >> fd, 'import %s' % library.lower() +###############" + + def generate_constants(self, fd): + print >> fd, '### Constants (both enums and defines)' + for c in self.binding_data.constants: + print >> fd, '%s = _%s.%s' % (c[1][(len(library)+1):], library.lower(), c[1][(len(library)+1):]) + for c in self.binding_data.overrides.findall('constant'): + name = c.attrib.get('name') + if c.attrib.get('value'): + name = name[(len(library)+1):] # dropping LIBRARY_ + value = c.attrib.get('value') + if value == 'True': + print >> fd, '%s = True' % name + else: + print >> sys.stderr, 'E: unknown value for constant: %r' % value + print >> fd, '' + + def generate_class(self, clss, fd): + klassname = clss.name[len(library):] # remove Library from class name + if clss.parent == 'GObject': + parentname = 'object' + else: + parentname = clss.parent[len(library):] + + print >> fd, '''class %(klassname)s(%(parentname)s):''' % locals() + if not clss.members and not clss.methods: + print >> fd, ' pass' + print >> fd, '' + return + + methods = clss.methods[:] + # constructor(s) + method_prefix = '%s_' % library.lower() + format_as_underscored(klassname) + '_' + for m in self.binding_data.functions: + if m.name == method_prefix + 'new': + c_args = [] + py_args = [] + for arg in m.args: + py_args.append(get_python_arg_decl(arg)) +###################" + if not is_int(arg, self.binding_data) and not is_tabbn(arg) and not is_bn(arg) and is_object(arg): +#################### + c_args.append('%(name)s and %(name)s._cptr' % { 'name' : arg_name(arg) }) + else: + c_args.append(arg_name(arg)) + py_args = remove_bad_optional(py_args) + + c_args = ', '.join(c_args) + py_args = ', ' + ', '.join(py_args) + print >> fd, ' def __init__(self%s):' % py_args + # XXX: could check self._cptr.typename to see if it got the + # right class type + print >> fd, ' self._cptr = _%s.%s(%s)' % ( + library.lower(), m.name[(len(library)+1):], c_args) + print >> fd, ' if self._cptr is None:' + print >> fd, ' raise Error(\'failed to create object\')' + print >> fd, '' + + for m in self.binding_data.functions: + if m.name.startswith(method_prefix + 'new_'): + constructor_name = format_as_camelcase(m.name[len(method_prefix):]) + c_args = [] + py_args = [] + for arg in m.args: + aname = arg_name(arg) + py_args.append(get_python_arg_decl(arg)) +############################" + if not is_int(arg, self.binding_data) and not is_tabbn(arg) and not is_bn(arg) and is_object(arg): +#####################" + c_args.append('%s and %s._cptr' % (aname, aname)) + else: + c_args.append(aname) + opt = False + py_args = remove_bad_optional(py_args) + for x in py_args: + if '=' in x: + opt = True + elif opt: + print >>sys.stderr, 'W: non-optional follows optional,', m + c_args = ', '.join(c_args) + py_args = ', ' + ', '.join(py_args) + print >> fd, ' @classmethod' + print >> fd, ' def %s(cls%s):' % (constructor_name, py_args) + print >> fd, ' return cptrToPy(_%s.%s(%s))' % (library.lower(), m.name[(len(library)+1):], c_args) + print >> fd, '' + + # create properties for members + for m in clss.members: + mname = format_as_camelcase(m[1]) + options = m[2] + # getter + print >> fd, ' def get_%s(self):' % mname + print >> fd, ' t = _%s.%s_%s_get(self._cptr)' % ( + library.lower(), klassname, mname) +######## + if is_int(m, self.binding_data) or is_xml_node(m) or is_cstring(m) or is_boolean(m) or is_tabbn(m) or is_bn(m): +######## + pass + elif is_object(m): + print >> fd, ' t = cptrToPy(t)' + elif is_glist(m): + el_type = element_type(m) + if is_cstring(el_type): + pass + elif is_xml_node(el_type): + pass + elif is_object(el_type): + print >> fd, ' if not t: return t' + print >> fd, ' t = tuple([cptrToPy(x) for x in t])' + else: + raise Exception('Unsupported python getter %s.%s' % (clss, m)) + elif is_hashtable(m): + el_type = element_type(m) + print >> fd, ' if not t: return t' + if is_object(el_type): + print >> fd, ' d2 = {}' + print >> fd, ' for k, v in t.items():' + print >> fd, ' d2[k] = cptrToPy(v)' + print >> fd, ' t = frozendict(d2)' + else: + print >> fd, ' t = frozendict(t)' +############" BUG repetition + elif is_boolean(m) or is_int(m, self.binding_data) or is_xml_node(m) or is_cstring(m): + pass + else: + raise Exception('Unsupported python getter %s.%s' % (clss, m)) + print >> fd, ' return t;' + # setter + print >> fd, ' def set_%s(self, value):' % mname +######## + if is_int(m, self.binding_data) or is_xml_node(m) or is_cstring(m) or is_boolean(m) or is_tabbn(m) or is_bn(m): +######## + pass + elif is_object(m): + print >> fd, ' if value is not None:' + print >> fd, ' value = value and value._cptr' + elif is_glist(m): + el_type = element_type(m) + if is_cstring(el_type) or is_xml_node(el_type): + pass + elif is_object(el_type): + print >> fd, ' if value is not None:' + print >> fd, ' value = tuple([x._cptr for x in value])' + else: + raise Exception('Unsupported python setter %s.%s' % (clss, m)) + elif is_hashtable(m): + print >> sys.stderr, 'W: unsupported setter for hashtable %s' % (m,) + else: + print >> sys.stderr, 'W: unsupported setter for %s' % (m,) + print >> fd, ' _%s.%s_%s_set(self._cptr, value)' % ( + library.lower(), klassname, mname) + print >> fd, ' %s = property(get_%s, set_%s)' % (mname, mname, mname) + print >> fd, '' + + # first pass on methods, getting accessors + # second pass on methods, real methods + for m in methods: + if m.name.endswith('_new') or m.name.endswith('_new_from_dump') or \ + m.name.endswith('_new_full'): + continue + if not m.name.startswith(method_prefix): + print >> sys.stderr, 'W:', m.name, 'vs', method_prefix + continue + + if m.rename: + mname = m.rename[len(method_prefix):] + function_name = m.rename[(len(library)+1):] + else: + mname = m.name[len(method_prefix):] + function_name = m.name[(len(library)+1):] + py_args = [] + c_args = [] + outarg = None + for arg in m.args[1:]: + if is_out(arg): + assert not outarg + outarg = arg + outvar = '_%s_out' % arg_name(arg) + else: + py_args.append(get_python_arg_decl(arg)) + + if is_out(arg): + c_args.append(outvar) +######## + elif is_xml_node(arg) or is_boolean(arg) or is_cstring(arg)or is_tabint(arg) or is_int(arg, self.binding_data) or is_glist(arg) or is_hashtable(arg) or is_time_t_pointer(arg) or is_tabbn(arg) or is_bn(arg): +######## + c_args.append(arg_name(arg)) + elif is_object(arg): + c_args.append('%(name)s and %(name)s._cptr' % { 'name': arg_name(arg) }) + else: + raise Exception('Does not handle argument of type: %s' % ((m, arg),)) + # check py_args + py_args = remove_bad_optional(py_args) + opt = False + for x in py_args: + if '=' in x: + opt = True + elif opt: + print >>sys.stderr, 'W: non-optional follow optional,', m + + if py_args: + py_args = ', ' + ', '.join(py_args) + else: + py_args = '' + if c_args: + c_args = ', ' + ', '.join(c_args) + else: + c_args = '' + + print >> fd, ' def %s(self%s):' % ( + format_underscore_as_camelcase(mname), py_args) + if m.docstring: + print >> fd, " '''" + print >> fd, self.format_docstring(m, mname, 8) + print >> fd, " '''" + + if outarg: + print >> fd, " %s = list((None,))" % outvar + return_type = m.return_type + return_type_qualifier = m.return_type_qualifier + assert is_int(make_arg(return_type),self.binding_data) or not outarg + if return_type in (None, 'void'): + print >> fd, ' _%s.%s(self._cptr%s)' % ( + library.lower(), function_name, c_args) + elif is_rc(m.return_arg): + print >> fd, ' rc = _%s.%s(self._cptr%s)' % ( + library.lower(), function_name, c_args) +#######################################"" + #func = re.search(r'\w+(?=verify)\w+', m.name) + #if(func != None): + #print func.group(0) + if m.name.startswith('cryptic_zkpk_schnorr_verify_interactive') or m.name.startswith('cryptic_proofrange_qrg_verify_interactive') or m.name.startswith('cryptic_clsig_verify') or m.name.startswith('cryptic_clsig_load_certificate'): +############################## + print >> fd, ' return(rc)' + else: + print >> fd, ' if rc != 0:' + print >> fd, ' raise Error.raise_on_rc(rc)' +########## + elif is_int(m.return_arg, self.binding_data) or is_xml_node(m.return_arg) or is_cstring(m.return_arg) or is_boolean(m.return_arg) or is_tabbn(m.return_arg) or is_bn(m.return_arg): +############ + print >> fd, ' return _%s.%s(self._cptr%s)' % ( + library.lower(), function_name, c_args) + elif is_glist(m.return_arg): + el_type = element_type(m.return_arg) + if is_object(el_type): + print >> fd, ' value = _%s.%s(self._cptr%s)' % ( + library.lower(), function_name, c_args) + print >> fd, ' if value is not None:' + print >> fd, ' value = tuple([cptrToPy(x) for x in value])' + print >> fd, ' return value' + elif is_cstring(el_type): + print >> fd, ' return _%s.%s(self._cptr%s)' % ( + library.lower(), function_name, c_args) + else: + raise Exception('Return Type GList<%s> is not supported' % el_type) + elif is_hashtable(m.return_arg): + raise Exception('Return type GHashTable unsupported') + elif is_object(m.return_arg): + print >> fd, ' return cptrToPy(_%s.%s(self._cptr%s))' % ( + library.lower(), function_name, c_args) + else: + raise Exception('Return type %s is unsupported' % (m.return_arg,)) + if outarg: + print >> fd, ' return %s[0]' % outvar + print >> fd, '' + # transform methods to properties + for m in methods: + if len(m.args) > 1: + continue + name = m.rename or m.name + suffix = name[len(method_prefix)+len('get_'):] + if clss.getMember(suffix): +#################### Why raising a warning, normal behavior: getter existing for a public parameter, then do not create it (with the same name) + #print >>sys.stderr, 'W: method %s and member %s clashes' % (m.name, arg_name(clss.getMember(suffix))) + continue + #tests: + if not name.startswith(method_prefix) or not name[len(method_prefix):].startswith('get_'): + continue + setter_suffix = 'set_' + suffix + setter = None + for n in methods: + if n.name.endswith(setter_suffix) and len(n.args) == 2: + setter = n + pname = format_as_camelcase(name[len(method_prefix)+len('get_'):]) + fname = format_as_camelcase(name[len(method_prefix):]) + if not setter: + print >> fd, ' %s = property(%s)' % (pname, fname) + else: + f2name = format_as_camelcase(setter.name[len(method_prefix):]) + print >> fd, ' %s = property(%s, %s)' % (pname, fname, f2name) + + print >> fd, '' + + def format_docstring(self, func, method_name, indent): + if func.args: + first_arg_name = func.args[0][1] + else: + first_arg_name = None + + def format_inlines_sub(s): + type = s.group(1)[0] + var = s.group(1)[1:] + if type == '#': # struct + if var.startswith(library): + return 'L{%s}' % var[len(library):] + elif type == '%': # %TRUE, %FALSE + if var == 'TRUE': + return 'True' + if var == 'FALSE': + return 'False' + print >> sys.stderr, 'W: unknown docstring thingie: %s' % s.group(1) + elif type == '@': + if var == first_arg_name: + var = 'self' + return 'C{%s}' % var + return s.group(1) + + regex = re.compile(r'([\#%@]\w+)', re.DOTALL) + + def format_inline(s): + s = regex.sub(format_inlines_sub, s) + return s.replace('NULL', 'None') + + docstring = func.docstring + s = [] + + if docstring.description: + for paragraph in docstring.description.split('\n\n'): + if '' in paragraph: + before, after = paragraph.split('' ,1) + if before: + s.append('\n'.join(textwrap.wrap( + format_inline(before), 70))) + + # remove tags + after = after.replace('', '') + after = after.replace('', '') + + for listitem in after.split(''): + listitem = listitem.replace('', '').strip() + s.append('\n'.join(textwrap.wrap( + format_inline(listitem), 70, + initial_indent = ' - ', + subsequent_indent = ' '))) + s.append('\n\n') + + else: + s.append('\n'.join(textwrap.wrap( + format_inline(paragraph), 70))) + s.append('\n\n') + + for param in docstring.parameters: + s.append('\n'.join(textwrap.wrap( + format_inline(param[1]), 70, + initial_indent = '@param %s: ' % param[0], + subsequent_indent = 4*' '))) + s.append('\n') + if docstring.return_value: + rv = docstring.return_value + exceptions_instead = ['0 on success; or a negative value otherwise.', + '0 on success; a negative value if an error occured.', + '0 on success; another value if an error occured.'] + if not rv in exceptions_instead: + owner_info = ['This xmlnode must be freed by caller.', + 'The string must be freed by the caller.', + 'It must be freed by the caller.', + 'This string must be freed by the caller.'] + for o_i in owner_info: + rv = rv.replace(o_i, '') + s.append('\n'.join(textwrap.wrap( + format_inline(rv), 70, + initial_indent = '@return: ', + subsequent_indent = 4*' '))) + s.append('\n') + + + if s: + s[-1] = s[-1].rstrip() # remove trailing newline from last line + + return '\n'.join([(indent*' ')+x for x in ''.join(s).splitlines()]) + + + def generate_functions(self, fd): + for m in self.binding_data.functions: + if m.name.endswith('_new') or '_new_' in m.name: + continue + if m.rename: + pname = m.rename + name = m.rename + if name.startswith(library.lower() + '_'): + name = name[(len(library)+1):] + pname = format_as_camelcase(name) + else: + name = m.name[(len(library)+1):] + pname = format_as_camelcase(name) + print >> fd, '%s = _%s.%s' % (pname, library.lower(), name) + + + def generate_wrapper(self, fd): + print >> fd, open(os.path.join(self.src_dir,'wrapper_top.c')).read() + for h in self.binding_data.headers: + print >> fd, '#include <%s>' % h + print >> fd, '' + + self.generate_constants_wrapper(fd) + + self.wrapper_list = [] + for m in self.binding_data.functions: + self.generate_function_wrapper(m, fd) + for c in self.binding_data.structs: + self.generate_member_wrapper(c, fd) + for m in c.methods: + self.generate_function_wrapper(m, fd) + self.generate_wrapper_list(fd) + print >> fd, open(os.path.join(self.src_dir,'wrapper_bottom.c')).read() + + def generate_constants_wrapper(self, fd): + print >> fd, '''static void +register_constants(PyObject *d) +{ + PyObject *obj; +''' + for c in self.binding_data.constants: + if c[0] == 'i': + print >> fd, ' obj = PyInt_FromLong(%s);' % c[1] + elif c[0] == 's': + print >> fd, ' obj = PyString_FromString(%s);' % c[1] + elif c[0] == 'b': + print >> fd, '''\ +#ifdef %s + obj = Py_True; +#else + obj = Py_False; +#endif''' % c[1] + else: + print >> sys.stderr, 'E: unknown constant type: %r' % c[0] + print >> fd, ' PyDict_SetItemString(d, "%s", obj);' % c[1][(len(library)+1):] + print >> fd, ' Py_DECREF(obj);' + print >> fd, '}' + print >> fd, '' + + + def generate_member_wrapper(self, c, fd): + klassname = c.name + for m in c.members: + name = arg_name(m) + mname = format_as_camelcase(arg_name(m)) + # getter + print >> fd, '''static PyObject* +%s_%s_get(G_GNUC_UNUSED PyObject *self, PyObject *args) +{''' % (klassname[len(library):], mname) + self.wrapper_list.append('%s_%s_get' % (klassname[len(library):], mname)) + + ftype = arg_type(m) + if is_cstring(m): + ftype = 'char*' + print >> fd, ' %s return_value;' % ftype + print >> fd, ' PyObject* return_pyvalue;' + print >> fd, ' PyGObjectPtr* cvt_this;' + print >> fd, ' %s* this;' % klassname + print >> fd, '' + print >> fd, ' if (! PyArg_ParseTuple(args, "O", &cvt_this)) return NULL;' + print >> fd, ' this = (%s*)cvt_this->obj;' % klassname + print >> fd, ' return_value = this->%s;' % arg_name(m) + try: + self.return_value(fd, m) + except: + print >>sys.stderr, 'W: cannot make an assignment for', c, m + raise + print >> fd, ' return return_pyvalue;' + print >> fd, '}' + print >> fd, '' + + # setter + print >> fd, '''static PyObject* +%s_%s_set(G_GNUC_UNUSED PyObject *self, PyObject *args) +{''' % (klassname[len(library):], mname) + self.wrapper_list.append('%s_%s_set' % (klassname[len(library):], mname)) + + print >> fd, ' PyGObjectPtr* cvt_this;' + print >> fd, ' %s* this;' % klassname + type = m[0] + # Determine type class + if is_cstring(m): + type = type.replace('const ', '') + parse_format = 'z' + parse_arg = '&value' + print >> fd, ' %s value;' % type + elif is_int(m, self.binding_data): + parse_format = 'i' + parse_arg = '&value' + print >> fd, ' %s value;' % type +############ + elif is_glist(m) or is_hashtable(m) or is_xml_node(m) or is_boolean(m) or is_tabbn(m) or is_bn(m) or is_tabint(m): +############ + parse_format = 'O' + print >> fd, ' PyObject *cvt_value;' + parse_arg = '&cvt_value' + elif is_object(m): + parse_format = 'O' + print >> fd, ' PyGObjectPtr *cvt_value;' + parse_arg = '&cvt_value' + else: + raise Exception('Unsupported field: %s' % (m,)) + # Get GObject + print >> fd, ' if (! PyArg_ParseTuple(args, "O%s", &cvt_this, %s)) return NULL;' % ( + parse_format, parse_arg) + print >> fd, ' this = (%s*)cvt_this->obj;' % klassname + # Change value + if is_int(m, self.binding_data): + print >> fd, ' this->%s = value;' % name + elif is_boolean(m): + print >> fd, ' this->%s = PyInt_AS_LONG(cvt_value) ? TRUE : FALSE;' % name + elif is_cstring(m): + print >> fd, ' %s_assign_string(this->%s, value);' % (library.lower(), name) +################### + elif is_tabbn(m): + print >> fd, ' this->%s = set_list_of_bignum(cvt_value);' % name + elif is_bn(m): + print >> fd, ' this->%s = get_bignum_from_pylong(cvt_value);' % name + elif is_tabint(m): + print >> fd, ' this->%s = set_list_of_int(cvt_value);' % name +################### + elif is_xml_node(m): + print >> fd, ' if (this->%s) xmlFreeNode(this->%s);' % (name, name) + print >> fd, ' this->%s = get_xml_node_from_pystring(cvt_value);' % name + elif is_glist(m): + el_type = element_type(m) + if is_cstring(el_type): + print >> fd, ' set_list_of_strings(&this->%s, cvt_value);' % name + elif is_xml_node(el_type): + print >> fd, ' set_list_of_xml_nodes(&this->%s, cvt_value);' % name + elif is_object(el_type): + print >> fd, ' set_list_of_pygobject(&this->%s, cvt_value);' % name + else: + raise Exception('Unsupported setter for %s' % (m,)) + elif is_hashtable(m): + el_type = element_type(m) + if is_object(el_type): + print >> fd, ' set_hashtable_of_pygobject(this->%s, cvt_value);' % name + else: + print >> fd, ' set_hashtable_of_strings(this->%s, cvt_value);' % name + elif is_object(m): + print >> fd, ' set_object_field((GObject**)&this->%s, cvt_value);' % name + else: + raise Exception('Unsupported member %s.%s' % (klassname, m)) + print >> fd, ' return noneRef();' + print >> fd, '}' + print >> fd, '' + + + def return_value(self, fd, arg, return_var_name = 'return_value', return_pyvar_name = 'return_pyvalue'): + if is_boolean(arg): + print >> fd, ' if (%s) {' % return_var_name + print >> fd, ' Py_INCREF(Py_True);' + print >> fd, ' %s = Py_True;' % return_pyvar_name + print >> fd, ' } else {' + print >> fd, ' Py_INCREF(Py_False);' + print >> fd, ' %s = Py_False;' % return_pyvar_name + print >> fd, ' }' +############ + elif is_tabbn(arg): + print >> fd, ' if (%s) {' % return_var_name + print >> fd, ' %s = get_list_of_bignum(%s);' % (return_pyvar_name, return_var_name) + print >> fd, ' } else {' + print >> fd, ' %s = noneRef();' % return_pyvar_name + print >> fd, ' }' + elif is_bn(arg): + print >> fd, ' if (%s) {' % return_var_name + print >> fd, ' %s = get_pylong_from_bignum(%s);' % (return_pyvar_name, return_var_name) + print >> fd, ' } else {' + print >> fd, ' %s = noneRef();' % return_pyvar_name + print >> fd, ' }' + elif is_tabint(arg): + print >> fd, ' if (%s) {' % return_var_name + print >> fd, ' %s = get_list_of_int(%s);' % (return_pyvar_name, return_var_name) + print >> fd, ' } else {' + print >> fd, ' %s = noneRef();' % return_pyvar_name + print >> fd, ' }' +############ + elif is_int(arg, self.binding_data): + print >> fd, ' %s = PyInt_FromLong(%s);' % (return_pyvar_name, return_var_name) + elif is_cstring(arg) and is_transfer_full(arg): + print >> fd, ' if (%s) {' % return_var_name + print >> fd, ' %s = PyString_FromString(%s);' % (return_pyvar_name, return_var_name) + print >> fd, ' } else {' + print >> fd, ' %s = noneRef();' % return_pyvar_name + print >> fd, ' }' + elif is_cstring(arg): + print >> fd, ' if (%s) {' % return_var_name + print >> fd, ' %s = PyString_FromString(%s);' % (return_pyvar_name, return_var_name) + print >> fd, ' } else {' + print >> fd, ' %s = noneRef();' % return_pyvar_name + print >> fd, ' }' + elif is_glist(arg): + el_type = element_type(arg) + if is_object(el_type): + print >> fd, ' %s = get_list_of_pygobject(%s);' % (return_pyvar_name, return_var_name) + elif is_cstring(el_type): + print >> fd, ' %s = get_list_of_strings(%s);' % (return_pyvar_name, return_var_name) + elif is_xml_node(el_type): + print >> fd, ' %s = get_list_of_xml_nodes(%s);' % (return_pyvar_name, return_var_name) + else: + raise Exception('failed to make an assignment for %s' % (arg,)) + elif is_hashtable(arg): + el_type = element_type(arg) + if is_object(el_type): + print >> fd, ' %s = get_dict_from_hashtable_of_objects(%s);' % (return_pyvar_name, return_var_name) + else: + print >> fd, ' %s = get_dict_from_hashtable_of_strings(%s);' % (return_pyvar_name, return_var_name) + elif is_xml_node(arg): + # convert xmlNode* to strings + print >> fd, ' if (%s) {' % return_var_name + print >> fd, ' %s = get_pystring_from_xml_node(%s);' % (return_pyvar_name, return_var_name) + print >> fd, ' } else {' + print >> fd, ' %s = noneRef();' % return_pyvar_name + print >> fd, ' }' + elif is_object(arg): + # return a PyGObjectPtr (wrapper around GObject) + print >> fd, '''\ + if (%s) { + %s = PyGObjectPtr_New(G_OBJECT(%s)); + } else { + %s = noneRef(); + } +''' % (return_var_name, return_pyvar_name, return_var_name, return_pyvar_name) + else: + raise Exception('failed to make an assignment for %s' % (arg,)) + + def generate_function_wrapper(self, m, fd): + if m.rename: + name = m.rename + if name.startswith(library.lower() + '_'): + name = name[(len(library)+1):] + else: + name = m.name[(len(library)+1):] + self.wrapper_list.append(name) + print >> fd, '''static PyObject* +%s(G_GNUC_UNUSED PyObject *self, PyObject *args) +{''' % name + parse_tuple_format = [] + parse_tuple_args = [] + for arg in m.args: + atype = arg_type(arg) + aname = arg_name(arg) + arg_def = None + python_cvt_def = None + defval = None + if is_optional(arg): + if not '|' in parse_tuple_format: + parse_tuple_format.append('|') + if is_cstring(arg): + atype = unconstify(atype) + if is_optional(arg): + parse_tuple_format.append('z') + else: + parse_tuple_format.append('s') + parse_tuple_args.append('&%s' % aname) + arg_def = ' %s %s = NULL;' % (arg[0], arg[1]) + elif is_int(arg, self.binding_data) or is_boolean(arg): + parse_tuple_format.append('i') + parse_tuple_args.append('&%s' % aname) + if arg_default(arg): + defval = arg_default(arg) + if defval.startswith('b:'): + defval = defval[2:].upper() + else: + defval = defval[2:] + arg_def = ' %s %s = %s;' % (arg[0], arg[1], defval) + else: + arg_def = ' %s %s;' % (arg[0], arg[1]) +###############" + elif is_xml_node(arg) or is_list(arg) or is_time_t_pointer(arg) or is_tabbn(arg) or is_bn(arg) or is_tabint(arg): +###############" + parse_tuple_format.append('O') + parse_tuple_args.append('&cvt_%s' % aname) + arg_def = ' %s %s = NULL;' % (arg[0], arg[1]) + python_cvt_def = ' PyObject *cvt_%s = NULL;' % aname + else: + parse_tuple_format.append('O') + parse_tuple_args.append('&cvt_%s' % aname) + arg_def = ' %s %s = NULL;' % (arg[0], arg[1]) + python_cvt_def = ' PyGObjectPtr *cvt_%s = NULL;' % aname + if is_out(arg): + arg_def = ' %s %s = NULL;' % (var_type(arg), arg[1]) + parse_tuple_format.pop() + parse_tuple_format.append('O') + parse_tuple_args.pop() + parse_tuple_args.append('&cvt_%s_out' % aname) + python_cvt_def = ' PyObject *cvt_%s_out = NULL;' % aname + print >> fd, ' PyObject *out_pyvalue = NULL;' + print >> fd, arg_def + if python_cvt_def: + print >> fd, python_cvt_def + + if m.return_type: + print >> fd, ' %s return_value;' % m.return_type + print >> fd, ' PyObject* return_pyvalue = NULL;' + print >> fd, '' + + parse_tuple_args = ', '.join(parse_tuple_args) + if parse_tuple_args: + parse_tuple_args = ', ' + parse_tuple_args + + print >> fd, ' if (! PyArg_ParseTuple(args, "%s"%s)) return NULL;' % ( + ''.join(parse_tuple_format), parse_tuple_args) + + for f, arg in zip([ x for x in parse_tuple_format if x != '|'], m.args): + if is_out(arg): + continue + if is_list(arg): + qualifier = element_type(arg) + if is_cstring(qualifier): + print >> fd, ' set_list_of_strings(&%s, cvt_%s);' % (arg[1], arg[1]) + elif qualifier == 'xmlNode*': + print >> fd, ' set_list_of_xml_nodes(&%s, cvt_%s);' % (arg[1], arg[1]) + elif isinstance(qualifier, basestring) and qualifier.startswith(library): + print >> fd, ' set_list_of_pygobject(&%s, cvt_%s);' % (arg[1], arg[1]) + else: + print >> sys.stderr, 'E: unqualified GList argument in', name, qualifier, arg +################## + elif is_tabbn(arg): + print >> fd, ' %s = set_list_of_bignum(cvt_%s);' % (arg[1], arg[1]) + elif is_bn(arg): + print >> fd, ' %s = get_bignum_from_pylong(cvt_%s);' % (arg[1], arg[1]) + elif is_tabint(arg): + print >> fd, ' %s = set_list_of_int(cvt_%s);' % (arg[1], arg[1]) +################## + elif is_xml_node(arg): + print >> fd, ' %s = get_xml_node_from_pystring(cvt_%s);' % (arg[1], arg[1]) + elif is_time_t_pointer(arg): + print >> fd, ' %s = get_time_t(cvt_%s);' % (arg[1], arg[1]) + elif f == 'O': + if is_optional(arg): + print >> fd, ' if (PyObject_TypeCheck((PyObject*)cvt_%s, &PyGObjectPtrType)) {' % arg[1] + print >> fd, ' %s = (%s)cvt_%s->obj;' % (arg[1], arg[0], arg[1]) + print >> fd, ' } else {' + print >> fd, ' %s = NULL;' % arg[1] + print >> fd, ' }' + else: + print >> fd, ' if (PyObject_TypeCheck((PyObject*)cvt_%s, &PyGObjectPtrType)) {' % arg[1] + print >> fd, ' %s = (%s)cvt_%s->obj;' % (arg[1], arg[0], arg[1]) + print >> fd, ' } else {' + print >> fd, ' PyErr_SetString(PyExc_TypeError, "value should be a PyGObject");' + print >> fd, ' return NULL;' + print >> fd, ' }' + + + if m.return_type: + print >> fd, ' return_value =', + if 'new' in m.name: + print >> fd, '(%s)' % m.return_type, + else: + print >> fd, ' ', + print >> fd, '%s(%s);' % (m.name, ', '.join([ref_name(x) for x in m.args])) + + for f, arg in zip(parse_tuple_format, m.args): + if is_out(arg): + self.return_value(fd, arg, return_var_name = arg[1], return_pyvar_name = 'out_pyvalue') + print >> fd, ' PyList_SetItem(cvt_%s_out, 0, out_pyvalue);' % arg[1] + elif arg[0] == 'GList*': + qualifier = arg[2].get('element-type') + if qualifier == 'char*': + print >> fd, ' free_list(&%s, (GFunc)g_free);' % arg[1] + elif qualifier == 'xmlNode*': + print >> fd, ' free_list(&%s, (GFunc)xmlFreeNode);' % arg[1] + elif qualifier == 'LassoNode': + print >> fd, ' free_list(&%s, (GFunc)g_object_unref);' % arg[1] + elif is_time_t_pointer(arg): + print >> fd, ' if (%s) free(%s);' % (arg[1], arg[1]) + + if not m.return_type: + print >> fd, ' return noneRef();' + else: + # Constructor so decrease refcount (it was incremented by PyGObjectPtr_New called + # in self.return_value + try: + self.return_value(fd, m.return_arg) + except: + print >>sys.stderr, 'W: cannot assign return value of', m + raise + + if is_transfer_full(m.return_arg): + self.free_value(fd, m.return_arg, name = 'return_value') + print >> fd, ' return return_pyvalue;' + print >> fd, '}' + print >> fd, '' + + def generate_wrapper_list(self, fd): + print >> fd, ''' +static PyMethodDef ''' + library.lower() + '''_methods[] = {''' + for m in self.wrapper_list: + print >> fd, ' {"%s", %s, METH_VARARGS, NULL},' % (m, m) + print >> fd, ' {NULL, NULL, 0, NULL}' + print >> fd, '};' + print >> fd, '' + diff --git a/bindings/python/wrapper_bottom.c b/bindings/python/wrapper_bottom.c new file mode 100644 index 0000000..ff634e3 --- /dev/null +++ b/bindings/python/wrapper_bottom.c @@ -0,0 +1,18 @@ +PyMODINIT_FUNC +init_cryptic(void) +{ + PyObject *m, *d; + + if (PyType_Ready(&PyGObjectPtrType) < 0) + return; + + m = Py_InitModule3("_cryptic", cryptic_methods, "_cryptic wrapper module"); + d = PyModule_GetDict(m); + register_constants(d); + + cryptic_wrapper_key = g_quark_from_static_string("PyLasso::wrapper"); + + Py_INCREF(&PyGObjectPtrType); + PyModule_AddObject(m, "PyGObjectPtr", (PyObject *)&PyGObjectPtrType); +} + diff --git a/bindings/python/wrapper_top.c b/bindings/python/wrapper_top.c new file mode 100644 index 0000000..e431374 --- /dev/null +++ b/bindings/python/wrapper_top.c @@ -0,0 +1,777 @@ +#include +#include +#include +#include +#include "../ghashtable.h" +#include "../../cryptic/utils.h" +#include +//#include + +#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) +typedef int Py_ssize_t; +#define PY_SSIZE_T_MAX INT_MAX +#define PY_SSIZE_T_MIN INT_MIN +#endif + +GQuark cryptic_wrapper_key; + +PyMODINIT_FUNC init_cryptic(void); + +//G_GNUC_UNUSED static PyObject* get_pystring_from_xml_node(xmlNode *xmlnode); +//G_GNUC_UNUSED static xmlNode* get_xml_node_from_pystring(PyObject *string); +G_GNUC_UNUSED static PyObject* get_dict_from_hashtable_of_objects(GHashTable *value); +G_GNUC_UNUSED static PyObject* get_dict_from_hashtable_of_strings(GHashTable *value); +G_GNUC_UNUSED static PyObject* PyGObjectPtr_New(GObject *obj); +G_GNUC_UNUSED static void set_hashtable_of_pygobject(GHashTable *a_hash, PyObject *dict); +G_GNUC_UNUSED static void set_hashtable_of_strings(GHashTable *a_hash, PyObject *dict); +G_GNUC_UNUSED static void set_list_of_strings(GList **a_list, PyObject *seq); +//G_GNUC_UNUSED static void set_list_of_xml_nodes(GList **a_list, PyObject *seq); +G_GNUC_UNUSED static void set_list_of_pygobject(GList **a_list, PyObject *seq); +G_GNUC_UNUSED static PyObject *get_list_of_strings(const GList *a_list); +//G_GNUC_UNUSED static PyObject *get_list_of_xml_nodes(const GList *a_list); +G_GNUC_UNUSED static PyObject *get_list_of_pygobject(const GList *a_list); +G_GNUC_UNUSED static gboolean valid_seq(PyObject *seq); +G_GNUC_UNUSED static void free_list(GList **a_list, GFunc free_help); +G_GNUC_UNUSED static time_t* get_time_t(PyObject *time); + +G_GNUC_UNUSED static PyObject* get_pylong_from_bignum(BIGNUM *bn); +G_GNUC_UNUSED static PyObject* get_list_of_bignum(BIGNUM **tabbn); +G_GNUC_UNUSED static BIGNUM* get_bignum_from_pylong(PyObject *pylong); +G_GNUC_UNUSED BIGNUM** set_list_of_bignum(PyObject *seq); +G_GNUC_UNUSED static PyObject* get_list_of_int(int *tabi); +G_GNUC_UNUSED int* set_list_of_int(PyObject *seq); + +typedef struct { + PyObject_HEAD + GObject *obj; + PyObject *typename; +} PyGObjectPtr; +static PyTypeObject PyGObjectPtrType; + +/* utility functions */ +static PyObject * +noneRef() { + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* +get_dict_from_hashtable_of_objects(GHashTable *value) +{ + GList *keys, *begin; + PyObject *dict,*proxy; + GObject *item_value; + PyObject *item; + + dict = PyDict_New(); + + begin = keys = g_hash_table_get_keys(value); + for (; keys; keys = g_list_next(keys)) { + item_value = g_hash_table_lookup(value, keys->data); + if (item_value) { + item = PyGObjectPtr_New(G_OBJECT(item_value)); + PyDict_SetItemString(dict, (char*)keys->data, item); + Py_DECREF(item); + } else { + PyErr_Warn(PyExc_RuntimeWarning, "hashtable contains a null value"); + } + } + g_list_free(begin); + + proxy = PyDictProxy_New(dict); + Py_DECREF(dict); + return proxy; +} + +static PyObject* +get_dict_from_hashtable_of_strings(GHashTable *value) +{ + GList *keys, *begin; + PyObject *dict,*proxy; + char *item_value; + PyObject *item; + + dict = PyDict_New(); + + begin = keys = g_hash_table_get_keys(value); + for (; keys; keys = g_list_next(keys)) { + item_value = g_hash_table_lookup(value, keys->data); + if (item_value) { + item = PyString_FromString(item_value); + PyDict_SetItemString(dict, (char*)keys->data, item); + Py_DECREF(item); + } else { + PyErr_Warn(PyExc_RuntimeWarning, "hashtable contains a null value"); + } + } + g_list_free(begin); + + proxy = PyDictProxy_New(dict); + Py_DECREF(dict); + return proxy; +} +/* +static PyObject* +get_pystring_from_xml_node(xmlNode *xmlnode) +{ + xmlOutputBufferPtr buf; + PyObject *pystring = NULL; + + if (xmlnode == NULL) { + return NULL; + } + + buf = xmlAllocOutputBuffer(NULL); + if (buf == NULL) { + pystring = NULL; + } else { + xmlNodeDumpOutput(buf, NULL, xmlnode, 0, 1, NULL); + xmlOutputBufferFlush(buf); + if (buf->conv == NULL) { + pystring = PyString_FromString((char*)buf->buffer->content); + } else { + pystring = PyString_FromString((char*)buf->conv->content); + } + xmlOutputBufferClose(buf); + } + + return pystring; +} +*/ +static gboolean +valid_seq(PyObject *seq) { + if (! seq || ( seq != Py_None && ! PyTuple_Check(seq))) { + PyErr_SetString(PyExc_TypeError, "value should be tuple"); + return 0; + } + return 1; +} + +static void +free_list(GList **a_list, GFunc free_help) { + if (*a_list) { + g_list_foreach(*a_list, free_help, NULL); + g_list_free(*a_list); + } +} + +/** Remove all elements from a_hash and replace them with + * the key-values pairs from the python dict. + * Increase reference of new values before removeing + * values from the hash, so if there are somme common + * values with RefCoun = 1 they won't be deallocated. + * */ +static void +set_hashtable_of_pygobject(GHashTable *a_hash, PyObject *dict) { + PyObject *key, *value; + Py_ssize_t i; + + if (! a_hash) { + PyErr_SetString(PyExc_TypeError, "hashtable does not exist"); + return; + } + if (dict != Py_None && ! PyDict_Check(dict)) { + PyErr_SetString(PyExc_TypeError, "value should be a frozen dict"); + return; + } + i = 0; + // Increase ref count of common object between old and new + // value of the hashtable + while (PyDict_Next(dict, &i, &key, &value)) { + if (! PyString_Check(key) || ! PyObject_TypeCheck(value, &PyGObjectPtrType)) + { + PyErr_SetString(PyExc_TypeError, + "value should be a dict, " + "with string keys " + "and GObjectPtr values"); + goto failure; + } + g_object_ref(((PyGObjectPtr*)value)->obj); + } + g_hash_table_remove_all (a_hash); + i = 0; + while (PyDict_Next(dict, &i, &key, &value)) { + char *ckey = g_strdup(PyString_AsString(key)); + g_hash_table_replace (a_hash, ckey, ((PyGObjectPtr*)value)->obj); + } + return; +failure: + i = 0; + while (PyDict_Next(dict, &i, &key, &value)) { + if (! PyString_Check(key) || ! PyObject_TypeCheck(value, &PyGObjectPtrType)) + break; + g_object_unref((PyGObjectPtr*)value); + } +} + +static void +set_hashtable_of_strings(GHashTable *a_hash, PyObject *dict) +{ + PyObject *key, *value; + Py_ssize_t i; + + if (! a_hash) { + PyErr_SetString(PyExc_TypeError, "hashtable does not exist"); + return; + } + if (dict != Py_None && ! PyDict_Check(dict)) { + PyErr_SetString(PyExc_TypeError, "value should be a frozen dict"); + return; + } + i = 0; + // Increase ref count of common object between old and new + // value of the hashtable + while (PyDict_Next(dict, &i, &key, &value)) { + if (! PyString_Check(key) || ! PyString_Check(value)) + { + PyErr_SetString(PyExc_TypeError, + "value should be a dict, " + "with string keys " + "and string values"); + goto failure; + } + } + g_hash_table_remove_all (a_hash); + i = 0; + while (PyDict_Next(dict, &i, &key, &value)) { + char *ckey = PyString_AsString(key); + char *cvalue = PyString_AsString(value); + g_hash_table_insert (a_hash, g_strdup(ckey), g_strdup(cvalue)); + } +failure: + return; +} + +/** Set the GList* pointer, pointed by a_list, to a pointer on a new GList + * created by converting the python seq into a GList of char*. + */ +static void +set_list_of_strings(GList **a_list, PyObject *seq) { + GList *list = NULL; + int l = 0,i; + + cryptic_return_if_fail(valid_seq(seq)); + if (seq != Py_None) { + l = PySequence_Length(seq); + } + for (i=0; iobj); + list = g_list_append(list, gobject); + } + free_list(a_list, (GFunc)g_object_unref); + *a_list = list; + return; +failure: + free_list(&list, (GFunc)g_object_unref); +} +/* +static xmlNode* +get_xml_node_from_pystring(PyObject *string) { + xmlDoc *doc; + xmlNode *node; + + doc = xmlReadDoc((xmlChar*)PyString_AsString(string), NULL, NULL, XML_PARSE_NONET); + node = xmlDocGetRootElement(doc); + if (node != NULL) { + node = xmlCopyNode(node, 1); + } + cryptic_release_doc(doc); + + return node; +} +*/ +/** Return a tuple containing the string contained in a_list */ +static PyObject * +get_list_of_strings(const GList *a_list) { + PyObject *a_tuple = NULL; + int i = 0; + + if (! a_list) { + return noneRef(); + } + /* Cast because g_list_length does not take const but is a const function */ + a_tuple = PyTuple_New(g_list_length((GList*)a_list)); + if (! a_tuple) + goto failure; + while (a_list) { + if (a_list->data) { + PyObject *str = PyString_FromString((const char*)a_list->data); + if (!str) { + goto failure; + } + PyTuple_SetItem(a_tuple, i, str); + i++; + } else { + PyErr_Warn(PyExc_RuntimeWarning, + "list contains a NULL value"); + } + a_list = a_list->next; + } + if (_PyTuple_Resize(&a_tuple, i)) + goto failure; + return a_tuple; +failure: + PyErr_SetString(PyExc_TypeError, "Allocation problem in get_list_of_strings"); + Py_XDECREF(a_tuple); + return noneRef(); +} +/* +static PyObject * +get_list_of_xml_nodes(const GList *a_list) { + PyObject *a_tuple = NULL; + int i = 0; + + if (! a_list) { + return noneRef(); + } + /* Cast because g_list_length does not take const but is a const function * + a_tuple = PyTuple_New(g_list_length((GList*)a_list)); + if (! a_tuple) + goto failure; + while (a_list) { + if (a_list->data) { + PyObject *str = get_pystring_from_xml_node((xmlNode*)a_list->data); + if (str) { + PyTuple_SetItem(a_tuple, i, str); + i++; + } else { + PyErr_Warn(PyExc_RuntimeWarning, + "could not convert an xmlNode to a string"); + } + } else { + PyErr_Warn(PyExc_RuntimeWarning, + "list contains a NULL value"); + } + a_list = a_list->next; + } + if (_PyTuple_Resize(&a_tuple, i)) + goto failure; + return a_tuple; +failure: + PyErr_SetString(PyExc_TypeError, "Allocation problem in get_list_of_strings"); + Py_XDECREF(a_tuple); + return noneRef(); +} +*/ +static PyObject * +get_list_of_pygobject(const GList *a_list) { + PyObject *a_tuple = NULL; + int i = 0; + + if (! a_list) { + return noneRef(); + } + /* Cast because g_list_length does not take const but is a const function */ + a_tuple = PyTuple_New(g_list_length((GList*)a_list)); + if (! a_tuple) + goto failure; + while (a_list) { + if (a_list->data) { + PyObject *pygobject; + pygobject = PyGObjectPtr_New((GObject*)a_list->data); + if (pygobject) { + PyTuple_SetItem(a_tuple, i, pygobject); + i++; + } else { + PyErr_Warn(PyExc_RuntimeWarning, + "could not convert a GObject to a PyGobject"); + } + } else { + PyErr_Warn(PyExc_RuntimeWarning, + "list contains a NULL value"); + } + a_list = a_list->next; + } + if (_PyTuple_Resize(&a_tuple, i)) + goto failure; + return a_tuple; +failure: + PyErr_SetString(PyExc_TypeError, "Allocation problem in get_list_of_strings"); + Py_XDECREF(a_tuple); + return noneRef(); +} + +/** + * get_time_t: + * @time: a #PyInt + * + * Convert a python integer object to a time_t value, considering it is a unsigned 32 bit integer + * value. + * + * Return: a time_t* value if time is a python integer, NULL otherwise. + */ +static time_t* +get_time_t(PyObject *time) +{ + if (time != Py_None && PyInt_Check(time)) { + time_t *val = malloc(sizeof(time_t)); + + *val = (time_t)PyInt_AS_LONG(time); + return val; + } + return NULL; +} + +/* wrapper around GObject */ +static void +PyGObjectPtr_dealloc(PyGObjectPtr *self) +{ +/* if (cryptic_flag_memory_debug) { + fprintf(stderr, "dealloc (%p ptr to %p (type:%s, rc:%d))\n", + self, self->obj, + G_OBJECT_TYPE_NAME(self->obj), + self->obj->ref_count); + }*/ + g_object_set_qdata_full(self->obj, cryptic_wrapper_key, NULL, NULL); + g_object_unref(self->obj); + Py_XDECREF(self->typename); + self->ob_type->tp_free((PyObject*)self); +} + +static int +startswith(const char *string, const char *prefix) +{ + return strncmp(string, prefix, strlen(prefix)) == 0; +} + +static PyObject* +PyGObjectPtr_New(GObject *obj) +{ + PyGObjectPtr *self; + + if (obj == NULL) { + return noneRef(); + } + + self = (PyGObjectPtr*)g_object_get_qdata(obj, cryptic_wrapper_key); + if (self != NULL) { + Py_INCREF(self); + } else { + const char *typename; + + self = (PyGObjectPtr*)PyObject_NEW(PyGObjectPtr, &PyGObjectPtrType); + g_object_set_qdata_full(obj, cryptic_wrapper_key, self, NULL); + self->obj = g_object_ref(obj); + typename = G_OBJECT_TYPE_NAME(obj); + /* XXX: Fixme !!!!! */ + if (startswith(typename, "Cryptic")) { + self->typename = PyString_FromString(typename+7); + } else { + self->typename = PyString_FromString(typename); + } + } + return (PyObject*)self; +} + +static PyObject * +PyGObjectPtr_repr(PyGObjectPtr *obj) +{ + return PyString_FromFormat("", + obj->obj, + G_OBJECT_TYPE_NAME(obj->obj), + obj->obj->ref_count); +} + +static PyMemberDef PyGObjectPtr_members[] = { + {"typename", T_OBJECT, offsetof(PyGObjectPtr, typename), 0, "typename"}, + {NULL, 0, 0, 0, NULL} +}; + +static PyObject* +PyGObjectPtr_get_refcount(PyGObjectPtr *self, G_GNUC_UNUSED void *closure) +{ + PyObject *refcount; + + refcount = PyInt_FromLong(self->obj->ref_count); + Py_INCREF(refcount); + return refcount; +} + +static PyGetSetDef PyGObjectPtr_getseters[] = { + {"refcount", (getter)PyGObjectPtr_get_refcount, NULL, + "reference count of intern GObject*", NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ +}; + + +static PyTypeObject PyGObjectPtrType = { + PyObject_HEAD_INIT(NULL) + 0, /* ob_size */ + "_cryptic.PyGObjectPtr", /* tp_name */ + sizeof(PyGObjectPtr), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)PyGObjectPtr_dealloc, /* tp_dealloc */ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + .tp_setattr = 0, /*tp_setattr*/ + 0, /*tp_compare*/ + (reprfunc)PyGObjectPtr_repr, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + "PyGObjectPtr objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + PyGObjectPtr_members, /* tp_members */ + PyGObjectPtr_getseters, /* tp_getset */ + NULL, + NULL +}; + +static void +set_object_field(GObject **a_gobject_ptr, PyGObjectPtr *a_pygobject) { + if (*a_gobject_ptr) { + g_object_unref(*a_gobject_ptr); + } + if ((PyObject*)a_pygobject == Py_None) { + *a_gobject_ptr = NULL; + } else { + *a_gobject_ptr = g_object_ref(a_pygobject->obj); + } +} + +static PyObject* +get_pylong_from_bignum(BIGNUM *bn) +{ + PyObject *pylong = NULL; + char *hex = BN_bn2hex(bn); + pylong = PyLong_FromString(hex, NULL, 16); + OPENSSL_free(hex); + return pylong; +} + +static BIGNUM* +get_bignum_from_pylong(PyObject *pylong) +{ + PyObject *str; + char *buf; + BIGNUM *result = NULL; + int r; + assert(PyLong_Check(pylong)); + assert(pylong && pylong->ob_type + && pylong->ob_type->tp_as_number + && pylong->ob_type->tp_as_number->nb_hex); + + if (!(str = pylong->ob_type->tp_as_number->nb_hex(pylong))) + return NULL; + + buf = PyString_AsString(str); + if (!buf) { + Py_DECREF(str); + return NULL; + } + + if(buf[0] == '-'){ + r = BN_hex2bn(&result, &buf[3]); + BN_set_negative(result,1); + }else{ + r = BN_hex2bn(&result, &buf[2]); + } + + if (r<0 || result == NULL) { + Py_DECREF(str); return NULL; + } + + Py_DECREF(str); + return result; +} + +static PyObject * +get_list_of_bignum(BIGNUM** tabbn) { + PyObject *a_tuple = NULL; + int i = 0; + + if (! tabbn) { + return noneRef(); + } + while (tabbn[i]!=NULL) {i++;} + a_tuple = PyTuple_New(i); + if (! a_tuple) + goto failure; + i = 0; + while (tabbn[i]!=NULL) { + PyObject *bn = get_pylong_from_bignum((BIGNUM*)tabbn[i]); + if (bn) { + PyTuple_SetItem(a_tuple, i, bn); + i++; + } else { + PyErr_Warn(PyExc_RuntimeWarning, "could not convert a BIGNUM to a Long"); + } + } + if (_PyTuple_Resize(&a_tuple, i)) + goto failure; + return a_tuple; +failure: + PyErr_SetString(PyExc_TypeError, "Allocation problem in get_list_of_bignum"); + Py_XDECREF(a_tuple); + return noneRef(); +} + +BIGNUM** +set_list_of_bignum(PyObject *seq) +{ + BIGNUM **tabbn = NULL; + int l=0,i; + + if (seq != Py_None) { + l = PySequence_Length(seq); + } + + tabbn = g_malloc0(l * sizeof (**tabbn)); + if(tabbn == NULL){ + goto cleanup; + } + + for (i=0; i \&wanted}, $p); + +foreach my $function (keys %$functions) { + potential_errors($function); +} + +foreach my $name (sort (keys %$functions)) { + my $record = $functions->{$name}; + next if $record->{'return-type'} !~ /\bg?int\b/ || $record->{'return-type'} =~ /\bstatic\b/; + my @derr = @{$record->{'errors'}}; + my @inherr = @{$record->{'inherited-errors'}[0]}; + my $path = $record->{'file'}; + print "$name "; + my %temp = (); + @temp{@inherr} = (); + for (@derr) { + delete $temp{$_}; + print "$_ "; + } + if (keys %temp) { + foreach (keys %temp) { + print "$_ "; + } + } + print "\n"; +} + +exit; + +sub potential_errors { + my $function = shift; + + + return ([],[[],[]]) if ! exists $functions->{$function}; + my $record = $functions->{$function}; + + return ([],[[],[]]) if $record->{'return-type'} !~ /\bg?int\b/ || $record->{'recursing'}; + + if (! exists $record->{'inherited-errors'}) { + my @inheritederrors; + my @froms; + $record->{'recursing'} = 1; + + foreach my $call (@{$record->{'calls'}}) { + my ($err,$inh) = potential_errors($call); + my ($suberr,$subfrom) = @$inh; + + if (@$err || @$suberr) { + push @froms, $call; + push @inheritederrors, (@$err, @$suberr); + } + } + $record->{'inherited-errors'} = [[ unique(@inheritederrors) ],[@froms]]; + delete $record->{'recursing'}; + } + return ($record->{'errors'},$record->{'inherited-errors'}); +} + + +sub parse_file { + my $file = shift; + my $path = shift; + my $lastline; + my $curfunction; + my $curtype; + my @curerrors; + my @curcalls; + my $infunction = 0; + open FD, "<$file"; + while () { + + MATCHING: { + if ($infunction) { + if (/^\}/) { + #print "finished funcctions $curfunction\n"; + $functions->{$curfunction} = { name => $curfunction, 'return-type' => $curtype, 'errors' => [ unique(@curerrors) ], 'calls' => [ @curcalls], 'file' => $path}; + $infunction = 0; + last MATCHING; + } + while (/(?:\breturn\b|=).*?([A-Za-z_]+)\(/g) { + push @curcalls, $1; + } + pos = 0; + while (/(LASSO_[A-Z_]*_ERROR_[A-Z_]*|LASSO_ERROR_[A-Z_]*)/g) { + push @curerrors, $1; + } + last MATCHING; + } + if (/^([a-z_]+)\([^;]*$/) { + $curfunction = $1; + chop $lastline; + $curtype = $lastline; + @curerrors = (); + @curcalls = (); + last MATCHING; + } + if ($curfunction && /^\{/) { + $infunction = 1; + last MATCHING; + } + } + $lastline = $_; + + } + close FD; +} + +sub wanted { + my ($dev,$ino,$mode,$nlink,$uid,$gid); + + parse_file($_,$File::Find::name) if ($_ =~ /^.*\.c$/s && $File::Find::name !~ /^.*\.svn.*/); +} + diff --git a/bindings/utils.py b/bindings/utils.py new file mode 100644 index 0000000..33ae2c7 --- /dev/null +++ b/bindings/utils.py @@ -0,0 +1,258 @@ +# Lasso - A free implementation of the Liberty Alliance specifications. +# +# Copyright (C) 2004-2007 Entr'ouvert +# http://lasso.entrouvert.org +# +# Authors: See AUTHORS file in top-level directory. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import re +import string + +_mapping_convert_type_from_gobject_annotation = { + 'utf8': 'char*' +} + +def convert_type_from_gobject_annotation(type): + return _mapping_convert_type_from_gobject_annotation.get(type, type) + +def clean_type(type): + if not type: + return type + type = type.strip() + type = re.sub('\s+', ' ', type) + return re.sub('\s*\*\s*', '*', type) + +def format_as_camelcase(var): + '''Format an identifier name into CamelCase''' + if '_' in var: +############################ A_rand devient Arand et non aRand + # return format_underscore_as_camelcase(var) + var = format_underscore_as_camelcase(var) + if var[0] in string.uppercase: + var = var[0].lower() + var[1:] + var = re.sub(r'([a-z])(ID)([A-Z]|$)', r'\1Id\3', var) # replace standing ID by Id + return var + +def format_as_underscored(var): + '''Format an identifier name into underscored_name''' + def rep(s): + return s.group(0)[0] + '_' + s.group(1).lower() + var = re.sub(r'[a-z0-9]([A-Z])', rep, var).lower() + var = var.replace('id_wsf2_', 'idwsf2_') + var = var.replace('_saslresponse', '_sasl_response') + var = var.replace('ws_addr_', 'wsa_') + return var + +def format_underscore_as_camelcase(var): + '''Format an underscored identifier name into CamelCase''' + def rep(s): + return s.group(1)[0].upper() + s.group(1)[1:] + var = re.sub(r'_([A-Za-z0-9]+)', rep, var) + var = re.sub(r'([a-z])(ID)([A-Z]|$)', r'\1Id\3', var) # replace standing ID by Id + return var + + + +def last(x): + return x[len(x)-1] + +def common_prefix(x,y): + max = min(len(x),len(y)) + last = 0 + for i in range(max): + if x[i] != y[i]: + return min(i,last+1) + if x[i] == '_': + last = i + return max + +def pgroup(group,prev): + level, l = group + i = 0 + for x in l: + if i == 0: + prefix = prev + else: + prefix = level + if isinstance(x,tuple): + pgroup(x,prefix) + else: + print prefix * ' ' + x[prefix:] + i = i + 1 + +def group(list): + list.sort() + pile = [(0,[])] + prev = "" + for x in list: + l, g = last(pile) + u = common_prefix(x,prev) + # Find the good level of insertion + while u < l: + pile.pop() + l, g = last(pile) + # Insert here + if u == l: + g.append(x) + elif u > l: + t = (u, [g.pop(),x]) + g.append(t) + pile.append(t) + prev = x + return pile[0] + +def _test_arg(arg, what): + if isinstance(arg, tuple) or isinstance(arg, list): + return bool(arg[2].get(what)) + return False + +def is_optional(arg): + return _test_arg(arg, 'optional') + +def element_type(arg): + return arg[2].get('element-type') + +def key_type(arg): + return arg[2].get('key-type') + +def value_type(arg): + return arg[2].get('value-type') + +#modified to ignore BIGNUM** +def is_out(arg): + return _test_arg(arg, 'out') or (arg_type(arg).endswith('**') and not _test_arg(arg, 'in') and not arg_type(arg).startswith('BIGNUM**')) + + +def is_glist(arg): + return re.match('GList', unconstify(var_type(arg))) + +def is_hashtable(arg): + return re.match('GHashTable', unconstify(var_type(arg))) + +def var_type(arg): + '''Return the type of variable to store content''' + arg = arg_type(arg) + if is_out(arg): + return arg[:-1] + else: + return arg + +def unref_type(arg): + return (var_type(arg), arg[1], arg[2]) + +def ref_name(arg): + if is_out(arg): + return '&%s' % arg[1] + else: + return arg[1] + +def arg_type(arg): + if isinstance(arg, tuple) or isinstance(arg, list): + return arg[0] + else: + return arg + +def arg_name(arg): + return arg[1] + +def unconstify(type): + type = arg_type(type) + if isinstance(type, str): + return re.sub(r'\bconst\b\s*', '', type).strip() + else: + return type + +def make_arg(type): + return (type,'',{}) + +def arg_default(arg): + return arg[2].get('default') + +def remove_modifiers(type): + if isinstance(type, str): + type = re.sub(r'\s*\bunsigned\b\s*', ' ', type).strip() + type = re.sub(r'\s*\bconst\b\s*', ' ', type).strip() + type = re.sub(r'\s*\bsigned\b\s*', ' ', type).strip() + type = re.sub(r'\s*\bvolatile\b\s*', ' ', type).strip() + return clean_type(type) + else: + return type + +def is_const(arg): + return bool(re.search(r'\bconst\b', arg_type(arg))) + +def is_cstring(arg): + arg = arg_type(arg) + return clean_type(unconstify(arg)) in ('char*','gchar*','guchar*','string','utf8','strings') + +def is_xml_node(arg): + arg = unconstify(arg_type(arg)) + return arg and arg.startswith('xmlNode') + +def is_boolean(arg): + return arg_type(arg) in ('gboolean','bool') + +def is_pointer(arg): + return arg_type(arg).endswith('*') + +def unpointerize(arg): + return arg_type(arg).replace('*','') + +def is_list(arg): + return unconstify(arg_type(arg)).startswith('GList') + +def is_rc(arg): + return arg_type(arg) in [ 'int', 'gint' ] +############# +def is_tabint(arg): +# arg = arg_type(arg) +# return clean_type(unconstify(arg)) in ('BIGNUM**') + arg = unconstify(arg_type(arg)) + return arg and arg.startswith('int*') +def is_tabbn(arg): +# arg = arg_type(arg) +# return clean_type(unconstify(arg)) in ('BIGNUM**') + arg = unconstify(arg_type(arg)) + return arg and arg.startswith('BIGNUM**') +def is_bn(arg): +# arg = arg_type(arg) +# return clean_type(unconstify(arg)) in ('BIGNUM*') + arg = unconstify(arg_type(arg)) + return arg and arg.startswith('BIGNUM*') +############# +def is_int(arg, binding_data): + return remove_modifiers(arg_type(arg)) in [ 'time_t', 'int', 'gint', 'long', 'glong'] + binding_data.enums + +def is_time_t_pointer(arg): + return re.match(r'\btime_t\*', unconstify(arg_type(arg))) + +def is_transfer_full(arg): + if not isinstance(arg, tuple): + return False + transfer = arg[2].get('transfer') + if transfer: + return transfer == 'full' + else: + return is_out(arg) or is_object(arg) + +_not_objects = ( 'GHashTable', 'GList', 'GType' ) +#### bidouile binding java avant gestion type +#_not_objects = ( 'GHashTable', 'GList', 'GType', 'BIGNUM*', 'BIGNUM**') + +def is_object(arg): + t = unconstify(arg_type(arg)) + return t and t[0] in string.uppercase and not [ x for x in _not_objects if x in t ] diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..5035791 --- /dev/null +++ b/configure.ac @@ -0,0 +1,827 @@ +dnl -*- Mode: sh -*- +dnl +dnl configure.ac - top level autoconf file for Cryptic +dnl (Process this file with autoconf to produce a configure script.) +dnl +dnl +dnl See COPYING at the top of this package for the full license terms. +dnl +dnl + +dnl Declare package and package version. +dnl (r-c).a.r +dnl - First number is the lowest supported API version number. +dnl - Second number is the number of supported API versions where API version > +dnl first number. +dnl - Third number is the current API version implementation version number. +dnl See libtool explanations about current, age and release, later in this file. +AC_INIT([cryptic], 1.0.0, cryptic-devel@lists.labs.libre-entreprise.org) +dnl Check if autoconf ver > 2.53 +AC_PREREQ(2.53) +AC_CONFIG_MACRO_DIR([m4]) +dnl Perform only subset commands and variable relevant to the host type. +AC_CANONICAL_HOST +AC_CANONICAL_SYSTEM +dnl Check existence of a relative pathed source file. +AC_CONFIG_SRCDIR(cryptic/cryptic.c) +dnl Copy stamp REVISIO-INFO in the configure script. +AC_REVISION($Revision: 1 $) + +dnl Run many macros mostly needed by configure.ac. +AM_INIT_AUTOMAKE([foreign tar-pax]) +dnl Support automake 1.11 silent mode +m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) + +dnl Create rules to automaticaly regenerate the config header. +AM_CONFIG_HEADER([config.h]) +dnl Add --enable-maintainer-mode option to configure. +AM_MAINTAINER_MODE + +dnl ========================================================================== +dnl Perform host specific configuration +dnl ========================================================================== +NULL= + +### Sun Java environment needs to be told about platform... +SUN_EXTRA_INCLUDE= +case "${host}" in + *-pc-mingw32) + SUN_EXTRA_INCLUDE="win32" + ;; + *-pc-cygwin) + SUN_EXTRA_INCLUDE="win32" + ;; + *linux*) + SUN_EXTRA_INCLUDE="linux" + ;; +esac + +### adapting build environment for different platforms... +MINGW=0 +DARWIN=0 +case "${host}" in + *aix*) + CFLAGS="${CFLAGS} -D_ALL_SOURCE" + ;; + *-pc-mingw32) + case "${build}" in + *-pc-cygwin) + CC="gcc -mno-cygwin" + CFLAGS="${CFLAGS} -D_MSC_VER -DIN_CRYPTIC -DMINGW -DWIN32 -D_WIN32 -I/usr/local/include" + LDFLAGS="${LDFLAGS} -L/usr/local/lib" + MINGW=1 + ;; + esac + ;; + *-darwin*) + DARWIN=1 + ;; +esac + +# OSX Fink +if test -d /sw/bin ; then + PATH=$PATH:/sw/bin +fi + +dnl +dnl Check for programs +dnl +AC_PROG_CC +CFLAGS="" +AM_CFLAGS="" +AC_HEADER_STDC +LT_AC_PROG_RC +AC_EXEEXT +AC_PROG_CC_C_O +AM_SANITY_CHECK +AC_PROG_AWK +AC_PROG_LN_S +AC_LIBTOOL_WIN32_DLL +AM_PROG_LIBTOOL +AC_SUBST(LIBTOOL_DEPS) +AS_COMPILER_FLAGS(WARNING_FLAGS, "-Wall -Wextra -Wno-missing-field-initializers -Wno-unused-parameter -Wold-style-definition -Wdeclaration-after-statement -Wmissing-declarations -Wredundant-decls -Wmissing-noreturn -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Winline -Wformat-nonliteral -Wformat-security -Wswitch-enum -Wswitch-default -Winit-self -Wmissing-include-dirs -Wundef -Waggregate-return -Wmissing-format-attribute -Wnested-externs") + +dnl Find tar command for make dist +AC_CHECK_PROGS(TAR, gnutar gtar tar) + +dnl Check existence of binding programs +AC_CHECK_CLASSPATH +AC_PROG_JAVAC +AC_PROG_JAVA +AC_PROG_JAVAH +AC_PROG_JAR +DPS_XTRA_CLASSPATH(CLASSPATH_JUNIT, junit.framework.Test, junit.jar) +old_cp=$CLASSPATH +export CLASSPATH=${CLASSPATH}:${CLASSPATH_JUNIT} +AC_CHECK_JUNIT +if test "x$old_cp" = "x"; then + unset CLASSPATH +else + $CLASSPATH=$old_cp +fi +unset old_cp +dnl AC_CHECK_PROGS(JAVA, gij java) +dnl AC_CHECK_PROGS(JAVAC, gcj javac) +dnl AC_CHECK_PROGS(JAVAH, gjavah gcjh javah) +dnl AC_CHECK_PROGS(JAR, fastjar jar) + +AC_CHECK_PROGS(PERL, perl) +AC_CHECK_PROGS(PHP5, php5 php) +AC_CHECK_PROGS(PHP5_CONFIG, php-config5 php-config) +AC_CHECK_PROGS(PYTHON, python) +AC_CHECK_PROGS(SWIG, swig) + +dnl Make sure we have an ANSI compiler +AM_C_PROTOTYPES +test "z$U" != "z" && AC_MSG_ERROR(Compiler not ANSI compliant) + +dnl Check for variadic macros +AC_CACHE_CHECK([for variadic cpp macros], + [ac_cv_cpp_variadic_macros], + [AC_TRY_COMPILE( + [#include + #define a(b,c...) printf(b,##c)], + [a("foo");a("%s","bar");a("%s%s","baz","quux");], + ac_cv_cpp_variadic_macros=yes, + ac_cv_cpp_variadic_macros=no)]) +if test "x${ac_cv_cpp_variadic_macros}" != "xno"; then + AC_DEFINE(HAVE_VARIADIC_MACROS, 1, Support for variadic macros) +fi + + +dnl ========================================================================== +dnl Version Super.Size.Me.L +dnl ========================================================================== + +changequote(<<, >>)dnl +VERSION_MAJOR=`echo $VERSION | $SED -e 's/^\([^\.]*\)\.\([^\.]*\)\.\(.*\)$/\1/'` +VERSION_MINOR=`echo $VERSION | $SED -e 's/^\([^\.]*\)\.\([^\.]*\)\.\(.*\)$/\2/'` +VERSION_RELEASE=`echo $VERSION | $SED -e 's/^\([^\.]*\)\.\([^\.]*\)\.\(.*\)$/\3/'` +changequote([, ])dnl +VERSION_UNDERSCORED=`echo $VERSION | $SED -e 's/\./_/g'` +AC_SUBST(VERSION_UNDERSCORED) + + +dnl Add versionning & package defines to cryptic_.h +AC_DEFINE_UNQUOTED(CRYPTIC_VERSION_MAJOR, $VERSION_MAJOR, [Major version number]) +AC_DEFINE_UNQUOTED(CRYPTIC_VERSION_MINOR, $VERSION_MINOR, [Minor version number]) +AC_DEFINE_UNQUOTED(CRYPTIC_VERSION_SUBMINOR, $VERSION_RELEASE, [Release version number]) + +dnl Dirty hack in order to have dynamic resource version numbering. +WINDOWS_VERSION=`echo $VERSION_MAJOR,$VERSION_MINOR,$VERSION_RELEASE,0` +AC_SUBST(WINDOWS_VERSION) + +dnl CURRENT, REVISION, AGE +dnl - library source changed -> increment REVISION +dnl - interfaces added/removed/changed -> increment CURRENT, REVISION = 0 +dnl - interfaces added -> increment AGE +dnl - interfaces removed -> AGE = 0 + +# syntax: CURRENT[:REVISION[:AGE]] +# So if M=major, m=minor, r=release: +# c = M + a = M + m; +# m = a +# r = r +current=`expr $VERSION_MAJOR + $VERSION_MINOR` +CRYPTIC_VERSION_INFO="10:1:7" +AC_SUBST(CRYPTIC_VERSION_INFO) + +dnl Compute the minimal supported ABI version for Win32 scripts and resources files. +minimal_version=`echo $CRYPTIC_VERSION_INFO | $AWK -F: '{printf("%d\n",$1-$3)};'` +UPCASED_DLL_FILENAME="LIBCRYPTIC-$minimal_version.DLL" +DLL_FILENAME="libcryptic-$minimal_version.dll" +AC_SUBST(UPCASED_DLL_FILENAME) +AC_SUBST(DLL_FILENAME) + +dnl ========================================================================== +dnl Swig +dnl ========================================================================== +SWIG_MIN_VERSION=1.3.28 +AC_MSG_CHECKING(SWIG support) +if test "X$SWIG" != "X"; then + SWIG_VERSION=`$SWIG -version 2>&1 | $SED -ne 's/^SWIG Version //p'` + SWIG_VERSION_DEC=`echo $SWIG_VERSION | $AWK -F. '{printf("%d\n", 10000*$1 + 100*$2 + $3)};'` + + if test $SWIG_VERSION_DEC -ge 010314; then + SWIG_PYTHON_ARGS=-noproxy + fi + + SWIG_MIN_VERSION_DEC=`echo $SWIG_MIN_VERSION | $AWK -F. '{printf("%d\n", 10000*$1 + 100*$2 + $3)};'` + + if test $SWIG_VERSION_DEC -ge $SWIG_MIN_VERSION_DEC; then + AC_MSG_RESULT($SWIG_VERSION - OK) + else + AC_MSG_RESULT($SWIG_VERSION - too old to generate language interfaces) + if test -r $srcdir/python/cryptic_wrap.c ; then + AC_MSG_WARN(Pre-generated language interface files are present) + AC_MSG_WARN(If you want to change the interfaces you will need) + AC_MSG_WARN(SWIG version $SWIG_MIN_VERSION from http://www.swig.org/) + else + AC_MSG_WARN(There are no pre-generated language interface files) + AC_MSG_WARN(cryptic language interfaces will NOT build.) + AC_MSG_WARN(If you want to build them you will need) + AC_MSG_WARN(SWIG version $SWIG_MIN_VERSION from http://www.swig.org/) + AC_MSG_WARN(Alternatively copy the pre-generated interface) + AC_MSG_WARN(files from a released version) + fi + fi +else + AC_MSG_RESULT(not present - using pre-generated interface files) + SWIG="echo" +fi +AC_SUBST(SWIG_PYTHON_ARGS) + +dnl Detect available languages binding. +languages_available= + + +# ------------ +# JAVA binding +# ------------ + +dnl Check if java is explicitly disabled. +AC_ARG_ENABLE(java, [ --disable-java disable the Java binding],, + enable_java="yes") +AC_ARG_WITH(java-home, + [ --with-java-home=(JAVA_HOME) set the full path to the java home directory.]) +SUN=no + +dnl If the java compiler seems to be a Sun JDK-like compile (Kaffe, Sun JDK...) +if test "x$JAVAC" = "xjavac"; then + JAVAC_PATH=`which $JAVAC` + if test "x$with_java_home" = "x"; then + with_java_home=`readlink -f $JAVAC_PATH | sed s#/bin/.*##` + fi + dnl If we have a java compiler + dnl need to change quotes to allow square brackets + changequote(<<, >>)dnl + JAVA_VERSION=`$JAVA -version 2>&1 | $SED -ne 's/java version "\([^"]*\)".*/\1/p' 2>/dev/null` + changequote([, ])dnl + dnl If no java version found, perphas it is a kaffee environment... + if test "x$JAVA_VERSION" = x; then + JAVA_VERSION=`$JAVA -version 2>&1 | grep "Java Version" | $SED 's/^.*Java Version: //g'` + dnl If the java environment is kaffe, specify the JAVA_INCLUDE directory. + else + dnl We assume it is a SUN environment. + SUN=yes + fi + JAVAC_FLAGS="-target 1.4 -source 1.4" + CLASSPATH_OPT="-classpath" +fi + +if test "x$with_java_home" != x; then + JAVA_INCLUDE="$with_java_home/include" +fi + +if ! test -f "$JAVA_INCLUDE/jni.h"; then + JAVA_VERSION="" +fi + +dnl GNU java environment +if test "x$JAVAH" = "xgcjh" || test "x$JAVAH" = "xgjavah" ; then + dnl JNI compatible header files. (not used with SWIG.) + JAVAH_FLAGS="-jni" + JAVA_INCLUDE="" +fi + +dnl If the java compiler is the GNU Java Compiler. +if echo "$JAVAC" | grep -q "gcj"; then + changequote(<<, >>)dnl + JAVA_VERSION=`$JAVAC --version 2>&1 | $SED -ne 's/gcj[^[:blank:]]* ([^)]*) \([^ ]*\).*/\1/p' 2>/dev/null` + MAJOR=`echo $JAVA_VERSION | sed 's/.*[^[:digit:]]\?\([[:digit:]]\+\)\.[[:digit:]]\+\.[[:digit:]]\+/\1/'` + MINOR=`echo $JAVA_VERSION | sed 's/.*[^[:digit:]]\?[[:digit:]]\+\.\([[:digit:]]\+\)\.[[:digit:]]\+/\1/'` + RELEASE=`echo $JAVA_VERSION | sed 's/.*[^[:digit:]]\?[[:digit:]]\+\.[[:digit:]]\+\.\([[:digit:]]\+\).*/\1/'` + changequote([, ])dnl + dnl Byte-compiled .class file + if test $MAJOR -gt 4 -o \( $MAJOR -eq 4 -a $MINOR -gt 1 \) -o \( $MAJOR -eq 4 -a $MINOR -eq 1 -a $RELEASE -ge 3 \); then + JAVAC_FLAGS="-fsource=1.4 -ftarget=1.4" + fi + unset MAJOR + unset MINOR + unset RELEASE + dnl Checking for jni.h if gcj is the java interpreter. + AC_CHECK_HEADERS([jni.h], [], [JAVA_VERSION=""]) + CLASSPATH_OPT="--classpath" +fi + +dnl Now transform JAVA_INCLUDE in CFLAG option if applicable. +if test "X$JAVA_INCLUDE" != "X"; then + dnl If it is a sun environment + if test "x$SUN" = "xyes"; then + JAVA_INCLUDE="$JAVA_INCLUDE -I$JAVA_INCLUDE/$SUN_EXTRA_INCLUDE" + fi + JAVA_INCLUDE=-I$JAVA_INCLUDE +fi + +dnl If we found a java version information, we have java compilation environment. +if test "X$JAVA_VERSION" != "X" && test "X$JAR" != "X" && test "x$JAVAH" != "x"; then + languages_available="$languages_available $JAVA($JAVA_VERSION)" +else + enable_java=no + JAVA_VERSION="" +fi + +dnl Conditional java sub dir test. +AM_CONDITIONAL([JAVA_ENABLED],[test "x$enable_java" = "xyes"]) +AM_CONDITIONAL([JUNIT_ENABLED],[test "x$JUNIT" != "x"]) +AC_SUBST(JAVA_VERSION) +AC_SUBST(JAVAC_FLAGS) +AC_SUBST(JAVAH_FLAGS) +AC_SUBST(JAVA_INCLUDE) +AC_SUBST(CLASSPATH_OPT) +JDK_INCLUDE=$JAVA_INCLUDE +AC_SUBST(JDK_INCLUDE) + + +# -------------- +# Python binding +# -------------- + +dnl Check if python is explicitly disabled. +AC_ARG_ENABLE(python, [ --disable-python disable the Python binding],, + enable_python="yes") + +dnl Check if user passed a specific python program. +AC_ARG_WITH(python, + [ --with-python=(PYTHON) set the full path to the python program to use.]) + +dnl specific program passed, set PYTHON to it. +if test "X$with_python" != "X"; then + PYTHON=$with_python +fi + + +dnl need to change quotes to allow square brackets +changequote(<<, >>)dnl +PYTHON_VERSION=`$PYTHON -c 'import sys; print sys.version[:3]' 2>/dev/null` +changequote([, ])dnl + +test "x$PYTHON" != "x" || AC_MSG_ERROR(Python must be installed to compile cryptic) + +AC_MSG_CHECKING(for Python development files) +dnl Check if we were be able to extract a good version number. +if test "X$PYTHON_VERSION" != "X"; then + PY_PREFIX=`$PYTHON -c 'import sys ; print sys.prefix'` + PY_EXEC_PREFIX=`$PYTHON -c 'import sys ; print sys.exec_prefix'` + changequote(<<, >>)dnl + PY_VERSION=`$PYTHON -c 'import sys ; print sys.version[0:3]'` + changequote([, ])dnl + PYTHON_H=$PY_PREFIX/include/python$PY_VERSION/Python.h + LIBPYTHON_SO=$PY_PREFIX/lib/libpython$PY_VERSION.so + if test -f $PYTHON_H; then + dnl Not useful unless we make a test on the python version. + PYTHON="python$PY_VERSION" + PY_CFLAGS="-I$PY_PREFIX/include/python$PY_VERSION" + PY_MAKEFILE="$PY_EXEC_PREFIX/lib/python$PY_VERSION/config/Makefile" + PY_OTHER_LIBS=`$SED -n -e 's/^LIBS=\(.*\)/\1/p' $PY_MAKEFILE` + PY_EXTRA_LIBS="$PY_LOCALMODLIBS $PY_BASEMODLIBS $PY_OTHER_LIBS" + PY_SITE_PACKAGES="\${prefix}/lib/python$PY_VERSION/site-packages" + AC_SUBST(PYTHON) + AC_SUBST(PY_LIB_LOC) + AC_SUBST(PY_CFLAGS) + AC_SUBST(PY_EXTRA_LIBS) + AC_SUBST(PY_DYNLOAD) + AC_SUBST(PY_LIB_A) + AC_SUBST(PY_SITE_PACKAGES) + languages_available="$languages_available python($PYTHON_VERSION)" + else + enable_python=no + fi +else + enable_python=no +fi +AM_CONDITIONAL([PYTHON_ENABLED],[test "x$enable_python" = "xyes"]) +AC_MSG_RESULT($enable_python) +AC_SUBST(PYTHON_VERSION) + +# ----------- +# PHP 5 binding +# ----------- + +dnl Check if php is explicitly enabled. +AC_ARG_ENABLE(php5, [ --enable-php5 enable the PHP 5 binding],, + enable_php5="yes") + +AC_ARG_WITH(php5-config, + [ --with-php5-config=(PHP5_CONFIG) Specify full path to php-config5.]) + +AC_ARG_ENABLE(php5-force, [ --enable-php5-force always enable of the PHP 5 binding (win32)], + [ENABLE_PHP5_FORCE="yes"], + [ENABLE_PHP5_FORCE="no"]) + + +dnl Check if user passed a specific php-config program. +if test "X$with_php5_config" != "X" ; then + PHP5_CONFIG=$with_php5_config +fi + +if test "X$PHP5_CONFIG" != "X" ; then + PHP5_INCLUDES=`$PHP5_CONFIG --includes` + PHP5_LDFLAGS=`$PHP5_CONFIG --ldflags` + PHP5_LIBS=`$PHP5_CONFIG --libs` + PHP5_PREFIX=`$PHP5_CONFIG --prefix` + PHP5_QUOTED_PREFIX=$(echo $PHP5_PREFIX | $SED 's/\//\\\//g') + PHP5_UNPREFIXED_EXTENSION_DIR=$($PHP5_CONFIG --extension-dir | $SED "s/$PHP5_QUOTED_PREFIX//g") +else + # We assume PHP are in /usr/local directory. + if test $MINGW -eq 1; then + CFLAGS="$CFLAGS -DZTS -DZEND_WIN32 -DWIN32 -D_MBCS" + fi + PHP5_INCLUDES="-I/usr/local/include/php5 -I/usr/local/include/php5/main -I/usr/local/include/php5/Zend -I/usr/local/include/php5/TSRM -I/usr/local/include/php5/win32" + PHP5_LDFLAGS= + PHP5_LIBS="-lphp5ts -lxmlparse -lxmltok" + PHP5_UNPREFIXED_EXTENSION_DIR= + PHP5_PREFIX= +fi + +AC_ARG_WITH(php5-include-dir, + [ --with-php5-include-dir=(PHP5_INCLUDE_DIR) Specify full path to php 5 include dir.], + [PHP5_INCLUDE_DIR="$withval"],[PHP5_INCLUDE_DIR=${datadir}/php]) + +AC_ARG_WITH(php5-config-dir, + [ --with-php5-config-dir=(PHP5_CONFIG_DIR) Specify full path to php 5 config dir.], + [PHP5_CONFIG_DIR="$withval"],[PHP5_CONFIG_DIR=${sysconfdir}/php5/conf.d/]) + +AC_SUBST(PHP5_INCLUDES) +AC_SUBST(PHP5_LDFLAGS) +AC_SUBST(PHP5_LIBS) +AC_SUBST(PHP5_UNPREFIXED_EXTENSION_DIR) +AC_SUBST(PHP5_EXTENSION_DIR) +AC_SUBST(PHP5_PREFIX) +AC_SUBST(PHP5_INCLUDE_DIR) +AC_SUBST(PHP5_CONFIG_DIR) + +dnl Check for expat +have_expat_include=no +if test $MINGW -eq 1; then + AC_CHECK_LIB(xmlparse, XML_ParserCreate, have_expat_lib=yes, have_expat_lib=no) +else + AC_CHECK_LIB(expat, XML_ParserCreate, have_expat_lib=yes, have_expat_lib=no) +fi + +if test x$have_expat_lib = xno; then + enable_php5=no +fi + +AC_MSG_CHECKING(for PHP 5 development files) +if $PHP5_CONFIG --version | grep -q "^5" || test "x$ENABLE_PHP5_FORCE" = "xyes" +then + PHP5_VERSION=`$PHP5_CONFIG --version 2> /dev/null` + languages_available="$languages_available php5($PHP5_VERSION)" +else + enable_php5=no +fi + +AC_MSG_RESULT($enable_php5) +AM_CONDITIONAL([PHP5_ENABLED], [test "x$enable_php5" = "xyes"]) +AC_SUBST(PHP5_VERSION) + + +### # ---------- +### # C# binding (disabled for the moment) +### # ---------- +### +### AC_ARG_ENABLE(csharp, [ --disable-csharp disable the C Sharp binding],, +### enable_csharp="yes") +### +### AC_ARG_WITH(cil-interpreter, [ --with-cil-interpreter=path set location of CIL interpreter for CSharp],[CSHARPBIN="$withval"], [CSHARPBIN=]) +### AC_ARG_WITH(csharp-compiler, [ --with-csharp-compiler=path set location of CSharp compiler],[CSHARPCOMPILERBIN="$withval"], [CSHARPCOMPILERBIN=]) +### +### if test -z "$CSHARPCOMPILERBIN" ; then +### case $host in +### *-*-cygwin* | *-*-mingw*) +### AC_CHECK_PROGS(CSHARPCOMPILER, mcs.bat cscc csc);; +### *)AC_CHECK_PROGS(CSHARPCOMPILER, mcs cscc);; +### esac +### else +### CSHARPCOMPILER="$CSHARPCOMPILERBIN" +### fi +### +### CSHARPPATHSEPARATOR="/" +### CSHARPCYGPATH_W=echo +### if test -z "$CSHARPBIN" ; then +### #languages_available="$languages_available C#($CSHARPCOMPILER)" +### CSHARPCILINTERPRETER="" +### if test "cscc" = "$CSHARPCOMPILER" ; then +### AC_CHECK_PROGS(CSHARPCILINTERPRETER, ilrun) +### else +### if test "mcs" = "$CSHARPCOMPILER"; then +### # Check that mcs is the C# compiler and not the Unix mcs utility by examining the output of 'mcs --version' +### # The Mono compiler should emit: Mono C# compiler version a.b.c.d +### csharp_version_raw=`(mcs --version) 2>/dev/null` +### csharp_version_searched=`(mcs --version | sed -n "/C#\|Mono/p") 2>/dev/null` +### CSHARPCOMPILER=""; +### if test -n "$csharp_version_raw" ; then +### if test "$csharp_version_raw" = "$csharp_version_searched" ; then +### CSHARPCOMPILER="mcs" +### fi +### fi +### +### # mono interpreter (ver 0.26 doesn't seem to work on Windows platforms) +### case $host in +### *-*-cygwin* | *-*-mingw*) +### ;; +### *)AC_CHECK_PROGS(CSHARPCILINTERPRETER, mint);; +### esac +### else +### if test "csc" = "$CSHARPCOMPILER"; then +### CSHARPPATHSEPARATOR="\\\\" +### CSHARPCYGPATH_W='cygpath -w' +### fi +### fi +### fi +### else +### CSHARPCILINTERPRETER="$CSHARPBIN" +### fi + +# Cygwin requires the Windows standard (Pascal) calling convention as it is a Windows executable and not a Cygwin built executable +case $host in +*-*-cygwin* | *-*-mingw*) + if test "$GCC" = yes; then + CSHARPDYNAMICLINKING=" -Wl,--add-stdcall-alias" + else + CSHARPDYNAMICLINKING="" + fi ;; +*)CSHARPDYNAMICLINKING="";; +esac + +AC_CHECK_PROGS(GACUTIL, gacutil) + +AC_SUBST(CSHARPCILINTERPRETER) +AC_SUBST(CSHARPCYGPATH_W) +AC_SUBST(CSHARPCOMPILER) +AC_SUBST(CSHARPDYNAMICLINKING) +AC_SUBST(CSHARPLIBRARYPREFIX) # Is this going to be used? +AC_SUBST(GACUTIL) + +if test "X$CSHARPCOMPILER" = X; then + enable_csharp=no +fi +if test "X$GACUTIL" = X; then + enable_csharp=no +fi +AM_CONDITIONAL([CSHARP_ENABLED], [test "x$enable_csharp" = "xyes"]) + + +# ------------ +# Perl binding +# ------------ + +AC_ARG_ENABLE(perl, [ --disable-perl disable the Perl binding],, + enable_perl="yes") + +if test "X$PERL" != "X"; then + PERLINSTALLSITEARCH=`$PERL -MConfig -e 'print $Config{installsitearch};'` + PERLMAN3DIR=`$PERL -MConfig -e 'print $Config{man3dir};'` +else + PERLINSTALLSITEARCH=none + PERLMAN3DIR=none +fi +AC_SUBST(PERLINSTALLSITEARCH) +AC_SUBST(PERLMAN3DIR) + +AC_MSG_CHECKING(for Perl API) +if test "X$enable_perl" != "Xno" ; then + if test "X$enable_perl" != "Xyes"; then + PERL=$enable_perl + fi + enable_perl=yes +fi + +PERL_VERSION=`$PERL -MConfig -e 'print $Config{version}' 2>/dev/null` +if test "X$PERL_VERSION" != "X"; then + languages_available="$languages_available perl($PERL_VERSION)" + if test $enable_perl = yes; then + languages="$languages perl" + fi +fi +AM_CONDITIONAL([PERL_ENABLED],[test "x$enable_perl" = "xyes"]) +AC_MSG_RESULT($enable_perl) +AC_SUBST(PERL_VERSION) + + +dnl Checks for zlib library (code adapted from libxml2 configure.in) +_cppflags="${CPPFLAGS}" +_ldflags="${LDFLAGS}" + +AC_ARG_WITH(zlib, +[ --with-zlib[[=DIR]] use libz in DIR],[ + if test "$withval" != "no" -a "$withval" != "yes"; then + Z_DIR=$withval + CPPFLAGS="${CPPFLAGS} -I$withval/include" + LDFLAGS="${LDFLAGS} -L$withval/lib" + fi +]) +saved_LIB=$LIBS +LIBS= +AC_CHECK_HEADERS(zlib.h, + AC_SEARCH_LIBS(gzread, [z zlib1],[ + AC_DEFINE([HAVE_LIBZ], [], [Have compression library]) + if test "x${Z_DIR}" != "x"; then + Z_CFLAGS="-I${Z_DIR}/include" + Z_LIBS="-L${Z_DIR}/lib $LIBS" + [case ${host} in + *-*-solaris*) + Z_LIBS="-L${Z_DIR}/lib -R${Z_DIR}/lib $LIBS" + ;; + esac] + else + Z_LIBS="$LIBS" + fi])) +LIBS=$saved_LIB +test "z$Z_LIBS" != "z" || AC_MSG_ERROR(missing zlib) + +AC_SUBST(Z_CFLAGS) +AC_SUBST(Z_LIBS) + +CPPFLAGS=${_cppflags} +LDFLAGS=${_ldflags} + +dnl ========================================================================== +dnl Test suite (requires check) +dnl ========================================================================== +dnl Check if user disabled the tests. +AC_ARG_ENABLE(tests, [ --disable-tests disable the test suite],, + enable_tests="yes") +if test "x$enable_tests" = xyes ; then + AC_CHECK_LIB(check, srunner_set_log, enable_tests="yes", enable_tests="no") + CHECK_CFLAGS="" + CHECK_LIBS="-lcheck" + AC_SUBST(CHECK_CFLAGS) + AC_SUBST(CHECK_LIBS) + AC_CHECK_LIB(check, srunner_set_xml, [AC_DEFINE(CHECK_IS_XML, [], [Define if check available with XML support])]) +fi + +AM_CONDITIONAL(WITH_TESTS, [test "x$enable_tests" = "xyes"]) + +dnl Final step, add missing programs. +AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir) +AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir) +AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir) +AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir) + +dnl API Reference documentation support +GTK_DOC_CHECK(1.9) +if test "z$with_html_dir" != "z" ; then + CRYPTIC_DOCDIR=$with_html_dir +else + CRYPTIC_DOCDIR='$(datadir)/doc/cryptic' +fi +AC_SUBST(CRYPTIC_DOCDIR) + +AC_ARG_WITH(html-dir, [ --with-html-dir=PATH path to installed docs ]) + +if test "x$with_html_dir" = "x" ; then + HTML_DIR='${datadir}/gtk-doc/html' +else + HTML_DIR=$with_html_dir +fi +AC_SUBST(HTML_DIR) + + +dnl pkg-config path +AC_ARG_WITH(pkg-config, [ --with-pkg-config=PATH set pkg-config metadata search path.], + PKG_CONFIG_PATH="${withval}", PKG_CONFIG_PATH="") +if test "z$PKG_CONFIG_PATH" != "z"; then + export PKG_CONFIG_PATH +fi + +PKG_CHECK_MODULES(CRYPTIC, glib-2.0 >= 2.4.0 gobject-2.0 >= 2.4.0 openssl) + +AC_CHECK_PROGS(REST2HTML, rest2html rst2html) +AM_CONDITIONAL(HAVE_REST2HTML, test -n "$ac_cv_prog_REST2HTML") + +AC_CHECK_PROGS(XSLTPROC, xsltproc) +AM_CONDITIONAL(HAVE_XSLTPROC, test -n "$ac_cv_prog_XSLTPROC") + +AC_CHECK_PROGS(INKSCAPE, inkscape) +AM_CONDITIONAL(HAVE_INKSCAPE, test -n "$ac_cv_prog_INKSCAPE") + + +dnl Debug +AC_MSG_CHECKING(for debugging) +AC_ARG_ENABLE(debugging, [ --enable-debugging enable debuging optimization flags (no)]) +if test "z$enable_debugging" = "zyes" ; then + enable_debugging=yes + CRYPTIC_DEFINES="$CRYPTIC_DEFINES -DCRYPTIC_DEBUG" + AM_CFLAGS="-O0 -g -Wall -Wextra -Werror" +else + enable_debugging=no +fi +AM_CONDITIONAL([DEBUGGING],[test "x$enable_debugging" = "xyes"]) +AC_MSG_RESULT($enable_debugging) +AC_SUBST(DEBUGGING) +AC_SUBST(AM_CFLAGS) + +dnl Profiling +AC_MSG_CHECKING(for profiling) +AC_ARG_ENABLE(profiling, [ --enable-profiling enable profiling compilation flags (no)]) +if test "z$enable_profiling" = "zyes" ; then + AM_CFLAGS="$AM_CFLAGS -pg" + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fi + +dnl ========================================================================== +dnl Pedantic compilation +dnl ========================================================================== +AC_MSG_CHECKING(for pedantic) +AC_ARG_ENABLE(pedantic, [ --enable-pedantic enable pedantic compilation flags (no)]) +if test "z$enable_pedantic" = "zyes" ; then + CFLAGS="$CFLAGS -O -pedantic -Wall -ansi -fno-inline -W -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls" + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fi + +dnl ========================================================================== +dnl Static linking +dnl ========================================================================== +CRYPTIC_STATIC_BINARIES="" +AC_MSG_CHECKING(for static linking) +AC_ARG_ENABLE(static_linking, [ --enable-static-linking enable static linking (no)]) +if test "z$enable_static_linking" = "zyes" ; then + CRYPTIC_STATIC_BINARIES="-static" + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fi +AC_SUBST(CRYPTIC_STATIC_BINARIES) + +dnl ========================================================================== +dnl Final steps: cryptic config +dnl ========================================================================== +CRYPTIC_PUB_CFLAGS="$CRYPTIC_DEFINES" +CRYPTIC_CORE_CFLAGS="$CRYPTIC_CFLAGS $CRYPTIC_DEFINES $Z_CFLAGS -DCRYPTIC_INTERNALS" +if test $MINGW -eq 1; then + CRYPTIC_CORE_LIBS="-lcryptic-0" +else + CRYPTIC_CORE_LIBS="-lcryptic " +fi +AC_SUBST(CRYPTIC_CORE_CFLAGS) +AC_SUBST(CRYPTIC_CORE_LIBS) + +CRYPTIC_CFLAGS="$CRYPTIC_CFLAGS" +CRYPTIC_LIBS="-L${libdir} $Z_LIBS $CRYPTIC_LIBS" +AC_SUBST(CRYPTIC_CFLAGS) +AC_SUBST(CRYPTIC_LIBS) + +AC_SUBST(CRYPTIC_PUB_CFLAGS) +AC_SUBST(CRYPTIC_DEFINES) +AC_SUBST(CRYPTIC_APP_DEFINES) +AC_SUBST(CFLAGS) +AC_SUBST(CPPFLAGS) +AC_SUBST(LDFLAGS) +AC_SUBST(CLASSPATH_JUNIT) +AC_SUBST(SWIG_VERSION) + +dnl Dirty system often means dirty hacks... +AM_CONDITIONAL(MINGW, test $MINGW -eq 1) +AM_CONDITIONAL(DARWIN, test $DARWIN -eq 1) + +dnl bindings + + +dnl ========================================================================== +dnl Writing result files +dnl ========================================================================== +AC_CONFIG_FILES([cryptic-src-config], [chmod +x cryptic-src-config]) +AC_OUTPUT( +[Makefile +cryptic/Makefile +tests/Makefile +cryptic.pc +bindings/Makefile +bindings/java/Makefile +bindings/python/Makefile +]) + +languages_available=`echo $languages_available | sed -e "s/^ //" ` +AC_MSG_RESULT( + +============= +Configuration +============= + +Main +---- + +Compiler: ${CC} +CFLAGS: ${AM_CFLAGS} ${CFLAGS} +Install prefix: ${prefix} +Debugging: $enable_debugging + +Optionals builds +---------------- + +Available languages: ${languages_available} + +Java binding: ${enable_java} +Perl binding: ${enable_perl} +PHP 5 binding: ${enable_php5} +Python binding: ${enable_python} + +C API references: ${enable_gtk_doc} +Tests suite: ${enable_tests} +) diff --git a/cryptic-src-config.in b/cryptic-src-config.in new file mode 100644 index 0000000..bdcbc47 --- /dev/null +++ b/cryptic-src-config.in @@ -0,0 +1,93 @@ +#!/bin/sh +# +# $Id: cryptic-src-config.in 2031 2005-01-02 22:37:25Z fpeters $ +# +# Copyright (C) 2002-2004 David Beckett - http://purl.org/net/dajobe/ +# Institute for Learning and Research Technology - http://www.ilrt.bris.ac.uk/ +# University of Bristol - http://www.bristol.ac.uk/ +# +# This package is Free Software or Open Source available under the +# following licenses (these are alternatives): +# 1. GNU Lesser General Public License (LGPL) +# 2. GNU General Public License (GPL) +# 3. Mozilla Public License (MPL) +# +# See LICENSE.html or LICENSE.txt at the top of this package for the +# full license terms. +# +# +# + +usage() +{ + cat<&2 +fi + + +while test $# -gt 0; do + case "$1" in + -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; + *) optarg= ;; + esac + + case $1 in + --version) + echo @VERSION@ + exit 0 + ;; + --cflags) + echo_cflags=yes + ;; + --libs) + echo_libs=yes + ;; + --usage) + usage 0 1>&2 + ;; + --run) + lpath=@abs_top_builddir@/cryptic/.libs + if test -d .libs; then + lpath=".libs:$lpath" + fi + if test `uname` = Darwin; then + DYLD_LIBRARY_PATH=$lpath:$DYLD_LIBRARY_PATH + export DYLD_LIBRARY_PATH + else + LD_LIBRARY_PATH=$lpath:$LD_LIBRARY_PATH + export LD_LIBRARY_PATH + fi + shift + exec ${1+"$@"} + ;; + + *) + usage 1 1>&2 + ;; + esac + + shift +done + +if test "$echo_cflags" = "yes"; then + echo -I@abs_top_srcdir@/cryptic +fi +if test "$echo_libs" = "yes"; then + echo -L@abs_top_builddir@/cryptic/.libs @CRYPTIC_CORE_LIBS@ @CRYPTIC_LIBS@ +fi diff --git a/cryptic.pc.in b/cryptic.pc.in new file mode 100644 index 0000000..bb8064d --- /dev/null +++ b/cryptic.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: cryptic +Version: @VERSION@ +Description: A free implementation of the crypto tools +Requires: openssl xmlsec1 +Cflags: -I${includedir}/cryptic +Libs: -lcryptic diff --git a/cryptic/Makefile.am b/cryptic/Makefile.am new file mode 100644 index 0000000..5033310 --- /dev/null +++ b/cryptic/Makefile.am @@ -0,0 +1,40 @@ +lib_LTLIBRARIES = libcryptic.la +libcryptic_la_SOURCES = cryptic.c \ + protocols/clsig/clsig_utl.c \ + protocols/clsig/clsig_sign.c \ + protocols/clsig/clsig_vrf.c \ + protocols/clsig/clsig_gen.c \ + protocols/clsig/commit_data_store.c \ + protocols/pok_schnorr/commitments_utils.c \ + protocols/pok_schnorr/schnorr_zkpk.c \ + protocols/pok_schnorr/hash_for_ni_proofs.c \ + protocols/proof_range/proof_range_in_qrg.c \ + maths/group_prime_order.c \ + maths/quadratic_residues_group.c \ + maths/decompose_integer.c \ + maths/maths_utils.c \ + utils/print.c + +libcryptic_la_LIBADD = $(CRYPTIC_LIBS) +INCLUDES = $(CRYPTIC_CFLAGS) + +EXTRA_DIST = utils.h + +libcrypticincludedir = $(includedir)/cryptic +libcrypticinclude_HEADERS = export.h cryptic.h errors.h utils.h + +libcrypticincludeprotocolsclsigdir = $(libcrypticincludedir)/protocols/clsig +libcrypticincludeprotocolsclsig_HEADERS = protocols/clsig/clsig.h protocols/clsig/commit_data_store.h + +libcrypticincludeprotocolspokschnorrdir = $(libcrypticincludedir)/protocols/pok_schnorr +libcrypticincludeprotocolspokschnorr_HEADERS = protocols/pok_schnorr/schnorr_zkpk.h protocols/pok_schnorr/hash_for_ni_proofs.h protocols/pok_schnorr/commitments_utils.h + + +libcrypticincludeprotocolsproofrangedir = $(libcrypticincludedir)/protocols/proof_range +libcrypticincludeprotocolsproofrange_HEADERS = protocols/proof_range/proof_range_in_qrg.h + +libcrypticincludemathsdir = $(libcrypticincludedir)/maths +libcrypticincludemaths_HEADERS = maths/group_prime_order.h maths/quadratic_residues_group.h maths/decompose_integer.h maths/maths_utils.h + +libcrypticincludeutilsdir = $(libcrypticincludedir)/utils +libcrypticincludeutils_HEADERS = utils/print.h diff --git a/cryptic/cryptic.c b/cryptic/cryptic.c new file mode 100644 index 0000000..d872c14 --- /dev/null +++ b/cryptic/cryptic.c @@ -0,0 +1,58 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2010 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include + +#include "cryptic.h" +#include "errors.h" + +#include "maths/decompose_integer.h" +#include "maths/quadratic_residues_group.h" +#include "maths/group_prime_order.h" +#include "protocols/pok_schnorr/schnorr_zkpk.h" +#include "protocols/pok_schnorr/hash_for_ni_proofs.h" +#include "protocols/proof_range/proof_range_in_qrg.h" +#include "protocols/clsig/clsig.h" +#include "protocols/clsig/commit_data_store.h" + +/** + * cryptic_init: + * + * Initializes Cryptic library. + * + * Return value: 0 on success; or a negative value otherwise. + **/ +int cryptic_init() +{ + + g_type_init(); + + /* Init Cryptic classes */ + cryptic_decompose_integer_get_type(); + cryptic_qrg_get_type(); + cryptic_prime_order_group_get_type(); + cryptic_zkpk_schnorr_get_type(); + cryptic_proofrange_qrg_get_type(); + cryptic_commit_data_store_get_type(); + cryptic_clsig_get_type(); + cryptic_hash_for_ni_proofs_get_type(); + + return(CRYPTIC_NO_ERROR); +} + diff --git a/cryptic/cryptic.h b/cryptic/cryptic.h new file mode 100644 index 0000000..a1d695b --- /dev/null +++ b/cryptic/cryptic.h @@ -0,0 +1,47 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef CRYPTIC_H +#define CRYPTIC_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include "protocols/clsig/clsig.h" +#include "protocols/clsig/commit_data_store.h" +#include "protocols/pok_schnorr/commitments_utils.h" +#include "protocols/pok_schnorr/schnorr_zkpk.h" +#include "protocols/pok_schnorr/hash_for_ni_proofs.h" +#include "protocols/proof_range/proof_range_in_qrg.h" +#include "maths/group_prime_order.h" +#include "maths/quadratic_residues_group.h" +#include "maths/decompose_integer.h" +#include "maths/maths_utils.h" +#include "utils/print.h" +#include "errors.h" +#include "utils.h" +#include "export.h" + +CRYPTIC_EXPORT int cryptic_init(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* CRYPTIC_H */ diff --git a/cryptic/errors.h b/cryptic/errors.h new file mode 100644 index 0000000..af5d5bc --- /dev/null +++ b/cryptic/errors.h @@ -0,0 +1,644 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/************************************************************** +* - Functions usually return a negative error code on failure +* and 0 either +* - Verify functions return 1 on success and <= 0 on failure +* - Getters return NULL if no member +***************************************************************/ + +/** CRYPTIC GENERIC ERROR CODES **/ +/** + * CRYPTIC_NO_ERROR: + * + * Undefined error. + */ +#define CRYPTIC_NO_ERROR 0 +/** + * CRYPTIC_ERROR_UNDEFINED: + * + * Undefined error. + */ +#define CRYPTIC_ERROR_UNDEFINED -1 +/** + * CRYPTIC_ERROR_UNIMPLEMENTED: + * + * Unimplemented part. + */ +#define CRYPTIC_ERROR_UNIMPLEMENTED -2 +/** + * CRYPTIC_ERROR_OUT_OF_MEMORY: + * + * Out of memory. + */ +#define CRYPTIC_ERROR_OUT_OF_MEMORY -3 +/** + * CRYPTIC_MEMORY_ALLOCATION_FAILURE: + * + * Memory allocation failure. + */ +#define CRYPTIC_MEMORY_ALLOCATION_FAILURE -4 +/** + * CRYPTIC_ERROR_CAST_FAILED: + * + * Expected GObject class was not found, cast failed + */ +#define CRYPTIC_ERROR_CAST_FAILED -5 +/** + * CRYPTIC_ERROR_GET_MEMBER_FAILURE: + * + * Member cannot be returned. + */ +#define CRYPTIC_ERROR_GET_MEMBER_FAILURE -6 +/** + * CRYPTIC_ERROR_BAD_SIGNATURE: + * + * Member cannot be returned. + */ +#define CRYPTIC_ERROR_BAD_SIGNATURE -7 +/** + * CRYPTIC_ERROR_FUNCTION_PARAMETER_NOT_ALLOCATED: + * + * A function parameter is not allocated. + */ +#define CRYPTIC_ERROR_FUNCTION_PARAMETER_NOT_ALLOCATED -8 + +/** MATHS **/ +/** + * CRYPTIC_MATHS_NUMBER_NOT_PRIME: + * + * The number is not prime. + */ +#define CRYPTIC_MATHS_NUMBER_NOT_PRIME -101 + +/** PRIME ORDER GROUP **/ +/** + * CRYPTIC_MATHS_PRIME_ORDER_GROUP_NB_BASES_EXCEEDED: + * + * Number of new bases too large. + */ +#define CRYPTIC_MATHS_PRIME_ORDER_GROUP_NB_BASES_EXCEEDED -111 + +/** QR GROUP **/ +/** + * CRYPTIC_MATHS_QR_GROUP_MODULUS_SIZE_NOT_EVEN: + * + * The modulus size given for the QR group is not even. + */ +#define CRYPTIC_MATHS_QR_GROUP_MODULUS_SIZE_NOT_EVEN -121 +/** + * CRYPTIC_MATHS_QR_GROUP_MODULUS_SIZE_TOO_SMALL: + * + * The modulus size is too small. + */ +#define CRYPTIC_MATHS_QR_GROUP_MODULUS_SIZE_TOO_SMALL -122 +/** + * CRYPTIC_MATHS_QR_GROUP_PICKING_BASE_FAILED: + * + * Error picking a QRn base. + */ +#define CRYPTIC_MATHS_QR_GROUP_PICKING_BASE_FAILED -123 +/** + * CRYPTIC_MATHS_QR_GROUP_MISSING_ELEMENT: + * + * Missing element for minimal loading. + */ +#define CRYPTIC_MATHS_QR_GROUP_MISSING_ELEMENT -124 +/** + * CRYPTIC_MATHS_QR_GROUP_BASE_UNALLOCATED: + * + * Bases not allocated. + */ +#define CRYPTIC_MATHS_QR_GROUP_BASE_UNALLOCATED -125 +/** + * CRYPTIC_MATHS_QR_GROUP_NO_QR_TO_VERIFY: + * + * No qr to verify. + */ +#define CRYPTIC_MATHS_QR_GROUP_NO_QR_TO_VERIFY -126 +/** + * CRYPTIC_MATHS_QR_GROUP_NOT_A_QR: + * + * Not a qr. + */ +#define CRYPTIC_MATHS_QR_GROUP_NOT_A_QR -127 +/** + * CRYPTIC_MATHS_QR_GROUP_MODULUS_MISSING: + * + * The modulus is missing. + */ +#define CRYPTIC_MATHS_QR_GROUP_MODULUS_MISSING -128 + +/** + * CRYPTIC_MATHS_DECOMPOSITION_4_SQUARES_FAILED: + * + * Decomposition integer in four squares failed. + */ +#define CRYPTIC_MATHS_DECOMPOSITION_4_SQUARES_FAILED -131 + +/** CLSIG **/ +/** + * CRYPTIC_CLSIG_MODULUS_TOO_SMALL: + * + * The modulus size is too small. + */ +#define CRYPTIC_CLSIG_MODULUS_TOO_SMALL -301 +/** + * CRYPTIC_CLSIG_MODULUS_MUST_BE_EVEN: + * + * The modulus must be even. + */ +#define CRYPTIC_CLSIG_MODULUS_MUST_BE_EVEN -302 +/** + * CRYPTIC_CLSIG_MESSAGE_SIZE_MUST_BE_LESS_THAN_MODULUS: + * + * The message size must be less than the modulus. + */ +#define CRYPTIC_CLSIG_MESSAGE_SIZE_MUST_BE_LESS_THAN_MODULUS -303 +/** + * CRYPTIC_CLSIG_MESSAGE_SIZE_MUST_BE_LESS_THAN_MODULUS: + * + * CLSIG not correctly initialized. + */ +#define CRYPTIC_CLSIG_NOT_CORRECTLY_INITIALIZED -304 +/** + * CRYPTIC_CLSIG_PARAMETERS_NOT_CORRECTLY_LOADED: + * + * CLSIG parameters not correctly loaded. + */ +#define CRYPTIC_CLSIG_PARAMETERS_NOT_CORRECTLY_LOADED -305 +/** + * CRYPTIC_CLSIG_UNABLE_LOAD_PARAMETERS_ELEMENT_MISSING: + * + * Unable to load CLSIG public parameters: element missing. + */ +#define CRYPTIC_CLSIG_UNABLE_LOAD_PARAMETERS_ELEMENT_MISSING -306 +/** + * CRYPTIC_CLSIG_BAD_RSA_KEY_PAIR: + * + * Bad RSA Key Pair. + */ +#define CRYPTIC_CLSIG_BAD_RSA_KEY_PAIR -307 +/** + * CRYPTIC_CLSIG_EXPONENTIATION_S_NOT_INVERSIBLE: + * + * S exponentiation not inversible, S is surely a bad generator. + */ +#define CRYPTIC_CLSIG_EXPONENTIATION_S_NOT_INVERSIBLE -308 +/** + * CRYPTIC_CLSIG_CHALENGE_TOO_SMALL: + * + * The challenge size must be larger or equal to the secutiry parameter. + */ +#define CRYPTIC_CLSIG_CHALENGE_TOO_SMALL -309 +/** + * CRYPTIC_CLSIG_EXPONENT_TOO_SMALL: + * + * The exponent is too small. + */ +#define CRYPTIC_CLSIG_EXPONENT_TOO_SMALL -309 +/** + * CRYPTIC_CLSIG_TOO_MUCH_QUANTITIES: + * + * Too much quantities asked. + */ +#define CRYPTIC_CLSIG_TOO_MUCH_QUANTITIES -310 +/** + * CRYPTIC_CLSIG_MISSING_QUANTITIES: + * + * Missing quantities. + */ +#define CRYPTIC_CLSIG_MISSING_QUANTITIES -311 +/** + * CRYPTIC_CLSIG_QUANTITY_TOO_LARGE: + * + * Too large quantity. + */ +#define CRYPTIC_CLSIG_QUANTITY_TOO_LARGE -312 +/** + * CRYPTIC_CLSIG_MISSING_BASES: + * + * Missing bases. + */ +#define CRYPTIC_CLSIG_MISSING_BASES -313 +/** + * CRYPTIC_CLSIG_NO_VALID_QUANTITIES_NUMBER: + * + * The number of quantity is not positive. + */ +#define CRYPTIC_CLSIG_NO_VALID_QUANTITIES_NUMBER -314 +/** + * CRYPTIC_CLSIG_EXPONENT_BAD_SIZE: + * + * The exponent is of bad size. + */ +#define CRYPTIC_CLSIG_EXPONENT_BAD_SIZE -315 +/** + * CRYPTIC_CLSIG_MISSING_SIGN_BLIND_RANDOM: + * + * Missing blind value for commitment. + */ +#define CRYPTIC_CLSIG_MISSING_SIGN_BLIND_RANDOM -316 +/** + * CRYPTIC_CLSIG_MISSING_SIGN_BLIND_COMMITMENT: + * + * Missing commitment of blinded signed quantities. + */ +#define CRYPTIC_CLSIG_MISSING_SIGN_BLIND_COMMITMENT -317 +/** + * CRYPTIC_CLSIG_SIGNATURE_NOT_CORRECTLY_LOADED: + * + * CLSIG singature not correctly loaded. + */ +#define CRYPTIC_CLSIG_SIGNATURE_NOT_CORRECTLY_LOADED -318 +/** + * CRYPTIC_CLSIG_LOADING_CERTIFICATE_MISSING_ELEMENT: + * + * Missing element for loading certificate. + */ +#define CRYPTIC_CLSIG_LOADING_CERTIFICATE_MISSING_ELEMENT -319 +/** + * CRYPTIC_CLSIG_SIGNATURE_WITH_COMMIT_MISSING_ELEMENT: + * + * Missing commitment for signature. + */ +#define CRYPTIC_CLSIG_SIGNATURE_WITH_COMMIT_MISSING_ELEMENT -320 +/** + * CRYPTIC_CLSIG_SIGNATURE_NOT_VALIDATED_TO_RANDOMIZE: + * + * No valid signature to randomize. + */ +#define CRYPTIC_CLSIG_SIGNATURE_NOT_VALIDATED_TO_RANDOMIZE -321 +/** + * CRYPTIC_CLSIG_SIGNATURE_NOT_RANDOMIZED: + * + * No valid randomized signature to verify. + */ +#define CRYPTIC_CLSIG_SIGNATURE_NOT_RANDOMIZED -322 +/** + * CRYPTIC_CLSIG_UNABLE_TO_CREATE_QRG: + * + * Unable to create a quadratic residue group. + */ +#define CRYPTIC_CLSIG_UNABLE_TO_CREATE_QRG -323 +/** + * CRYPTIC_CLSIG_UNABLE_TO_LOAD_QRG: + * + * Unable to load a quadratic residue group. + */ +#define CRYPTIC_CLSIG_UNABLE_TO_LOAD_QRG -324 +/** + * CRYPTIC_QRG_UNABLE_TO_LOAD_QRG_MINIMAL: + * + * Missing element for minimal loading. + */ +#define CRYPTIC_QRG_UNABLE_TO_LOAD_QRG_MINIMAL -325 +/** + * CRYPTIC_QRG_MODULUS_SIZE_TOO_SMALL: + * + * Missing element for minimal loading. + */ +#define CRYPTIC_QRG_MODULUS_SIZE_TOO_SMALL -326 +/** + * CRYPTIC_QRG_MODULUS_SIZE_NOT_EVEN: + * + * Modulus size not even. + */ +#define CRYPTIC_QRG_MODULUS_SIZE_NOT_EVEN -327 + + +/** PROOF GENERIC **/ +/** + * CRYPTIC_PROOF_GENERIC_COMMITMENT_MISSING: + * + * No valid commitment value provided. + */ +#define CRYPTIC_PROOF_GENERIC_COMMITMENT_MISSING -501 +/** + * CRYPTIC_PROOF_GENERIC_CHALLENGE_MISSING: + * + * No valid challenge value provided. + */ +#define CRYPTIC_PROOF_GENERIC_CHALLENGE_MISSING -502 +/** + * CRYPTIC_PROOF_GENERIC_CHALLENGE_SIZE_NOT_VALID: + * + * Challenge Size too small. + */ +#define CRYPTIC_PROOF_GENERIC_CHALLENGE_SIZE_NOT_VALID -503 +/** + * CRYPTIC_PROOF_GENERIC_RESPONSES_MISSING: + * + * No valid responses value provided. + */ +#define CRYPTIC_PROOF_GENERIC_RESPONSES_MISSING -504 +/** + * CRYPTIC_PROOF_GENERIC_NB_RESPONSES_NOT_VALID: + * + * Number of responses not valid. + */ +#define CRYPTIC_PROOF_GENERIC_NB_RESPONSES_NOT_VALID -505 +/** + * CRYPTIC_PROOF_GENERIC_AT_LEAST_ONE_RESPONSE_MISSING: + * + * A response value is missing. + */ +#define CRYPTIC_PROOF_GENERIC_AT_LEAST_ONE_RESPONSE_MISSING -506 +/** + * CRYPTIC_PROOF_GENERIC_NB_QUANTITIES_NULL: + * + * The number of quantity cannot be null. + */ +#define CRYPTIC_PROOF_GENERIC_NB_QUANTITIES_NULL -507 +/** + * CRYPTIC_PROOF_GENERIC_BASES_MISSING: + * + * At least one base is missing. + */ +#define CRYPTIC_PROOF_GENERIC_BASES_MISSING -508 +/** + * CRYPTIC_PROOF_GENERIC_MODULUS_MISSING: + * + * Missing modulus. + */ +#define CRYPTIC_PROOF_GENERIC_MODULUS_MISSING -509 +/** + * CRYPTIC_PROOF_RANDOMS_RESPONSES_MISSING: + * + * Some randoms value are missing. + */ +#define CRYPTIC_PROOF_GENERIC_RANDOMS_MISSING -510 +/** + * CRYPTIC_PROOF_GENERIC_DLREP_MISSING: + * + * Missing DL representation. + */ +#define CRYPTIC_PROOF_GENERIC_DLREP_MISSING -511 +/** + * CRYPTIC_PROOF_GENERIC_ROUND1_NOT_DONE: + * + * Round 1 - building commitment - not done. + */ +#define CRYPTIC_PROOF_GENERIC_ROUND1_NOT_DONE -512 +/** + * CRYPTIC_PROOF_GENERIC_HASH_OR_CHALLENGE_MISSING: + * + * Hash or challenge missing. + */ +#define CRYPTIC_PROOF_GENERIC_HASH_OR_CHALLENGE_MISSING -513 +/** + * CRYPTIC_PROOF_GENERIC_ORDER_MISSING: + * + * Order missing. + */ +#define CRYPTIC_PROOF_GENERIC_ORDER_MISSING -514 +/** + * CRYPTIC_PROOF_GENERIC_STRUCTURE_NOT_INIT: + * + * The structure is not well initialized. + */ +#define CRYPTIC_PROOF_GENERIC_STRUCTURE_NOT_INIT -515 +/** + * CRYPTIC_PROOF_GENERIC_QUANTITY_MISSING: + * + * Missing quantity. + */ +#define CRYPTIC_PROOF_GENERIC_QUANTITY_MISSING -516 + +/** ZKPK INTERACTIVE SCHNORR **/ +/** + * CRYPTIC_ZKPK_INTERACTIVE_SCHNORR_STRUCTURE_NOT_INIT: + * + * The zkpk interactive schnorr structure is not well initialized. + */ +#define CRYPTIC_ZKPK_INTERACTIVE_SCHNORR_STRUCTURE_NOT_INIT -601 +/** + * CRYPTIC_ZKPK_INTERACTIVE_SCHNORR_RANDOMS_MISSING: + * + * Missing randoms to compute commitment. + */ +#define CRYPTIC_ZKPK_INTERACTIVE_SCHNORR_RANDOMS_MISSING -602 +/** + * CRYPTIC_ZKPK_INTERACTIVE_SCHNORR_NUMBER_OF_RANDOMS_MISMATCH: + * + * Number of randoms passed is not the sames as the number of bases. + */ +#define CRYPTIC_ZKPK_INTERACTIVE_SCHNORR_NUMBER_OF_RANDOMS_MISMATCH -603 +/** + * CRYPTIC_ZKPK_NONINTERACTIVE_SCHNORR_BAD_HASH_SIZE: + * + * Hash size not supported. + */ +#define CRYPTIC_ZKPK_NONINTERACTIVE_SCHNORR_BAD_HASH_SIZE -651 + +/** PROOF RANGE **/ +/** + * CRYPTIC_PROOF_RANGE_STRUCTURE_NOT_INIT: + * + * The proof range structure is not well initialized. + */ +#define CRYPTIC_PROOF_RANGE_STRUCTURE_NOT_INIT -701 +/** + * CRYPTIC_PROOF_RANGE_NO_QUANTITY: + * + * No quantity on which a range proof can be led. + */ +#define CRYPTIC_PROOF_RANGE_NO_QUANTITY -702 +/** + * CRYPTIC_PROOF_RANGE_STRUCTURE_NO_BOUND: + * + * No bound on which a range proof can be led. + */ +#define CRYPTIC_PROOF_RANGE_NO_BOUND -703 +/** + * CRYPTIC_PROOF_RANGE_STRUCTURE_RELATION_UNKNOWN: + * + * Proof range relation unknown. + */ +#define CRYPTIC_PROOF_RANGE_RELATION_UNKNOWN -704 +/** + * CRYPTIC_PROOF_RANGE_DELTA_NEGATIVE: + * + * Proof range delta negative. + */ +#define CRYPTIC_PROOF_RANGE_DELTA_NEGATIVE -705 +/** + * CRYPTIC_PROOF_RANGE_DECOMPOSITION_FAILED: + * + * Proof range decomposition failed. + */ +#define CRYPTIC_PROOF_RANGE_DECOMPOSITION_FAILED -706 +/** + * CRYPTIC_PROOF_RANGE_VERIFY_TAB_DLREPS_EMPTY: + * + * Missing tab of representations. + */ +#define CRYPTIC_PROOF_RANGE_VERIFY_TAB_DLREPS_EMPTY -707 +/** + * CRYPTIC_PROOF_RANGE_VERIFY_TAB_COMMITMENTS_EMPTY: + * + * Missing tab of commitments. + */ +#define CRYPTIC_PROOF_RANGE_VERIFY_TAB_COMMITMENTS_EMPTY -708 +/** + * CRYPTIC_PROOF_RANGE_VERIFY_TAB_RESPONSES_EMPTY: + * + * Missing tab of responses. + */ +#define CRYPTIC_PROOF_RANGE_VERIFY_TAB_RESPONSES_EMPTY -709 +/** + * CRYPTIC_PROOF_RANGE_VERIFY_DLREP_FIRST_SQRROOT_MISSING: + * + * Missing representation of the first square root. + */ +#define CRYPTIC_PROOF_RANGE_VERIFY_DLREP_FIRST_SQRROOT_MISSING -710 +/** + * CRYPTIC_PROOF_RANGE_VERIFY_DLREP_SECOND_SQRROOT_MISSING: + * + * Missing representation of the SECOND square root. + */ +#define CRYPTIC_PROOF_RANGE_VERIFY_DLREP_SECOND_SQRROOT_MISSING -711 +/** + * CRYPTIC_PROOF_RANGE_VERIFY_DLREP_THIRD_SQRROOT_MISSING: + * + * Missing representation of the THIRD square root. + */ +#define CRYPTIC_PROOF_RANGE_VERIFY_DLREP_THIRD_SQRROOT_MISSING -712 +/** + * CRYPTIC_PROOF_RANGE_VERIFY_DLREP_FORTH_SQRROOT_MISSING: + * + * Missing representation of the FORTH square root. + */ +#define CRYPTIC_PROOF_RANGE_VERIFY_DLREP_FORTH_SQRROOT_MISSING -713 +/** + * CRYPTIC_PROOF_RANGE_VERIFY_DLREP_DELTA_MISSING: + * + * Missing representation of the DELTA square root. + */ +#define CRYPTIC_PROOF_RANGE_VERIFY_DLREP_DELTA_MISSING -714 +/** + * CRYPTIC_PROOF_RANGE_VERIFY_COMMIT_FIRST_SQRROOT_MISSING: + * + * Missing commitment of the first square root. + */ +#define CRYPTIC_PROOF_RANGE_VERIFY_COMMIT_FIRST_SQRROOT_MISSING -715 +/** + * CRYPTIC_PROOF_RANGE_VERIFY_COMMIT_SECOND_SQRROOT_MISSING: + * + * Missing commitment of the SECOND square root. + */ +#define CRYPTIC_PROOF_RANGE_VERIFY_COMMIT_SECOND_SQRROOT_MISSING -716 +/** + * CRYPTIC_PROOF_RANGE_VERIFY_COMMIT_THIRD_SQRROOT_MISSING: + * + * Missing commitment of the THIRD square root. + */ +#define CRYPTIC_PROOF_RANGE_VERIFY_COMMIT_THIRD_SQRROOT_MISSING -717 +/** + * CRYPTIC_PROOF_RANGE_VERIFY_COMMIT_FORTH_SQRROOT_MISSING: + * + * Missing commitment of the FORTH square root. + */ +#define CRYPTIC_PROOF_RANGE_VERIFY_COMMIT_FORTH_SQRROOT_MISSING -718 +/** + * CRYPTIC_PROOF_RANGE_VERIFY_COMMIT_DELTA_MISSING: + * + * Missing commitment of the DELTA square root. + */ +#define CRYPTIC_PROOF_RANGE_VERIFY_COMMIT_DELTA_MISSING -719 +/** + * CRYPTIC_PROOF_RANGE_VERIFY_COMMIT_Q_MISSING: + * + * Missing commitment of the DELTA square root. + */ +#define CRYPTIC_PROOF_RANGE_VERIFY_COMMIT_Q_MISSING -720 + +/** + * CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_FIRST_SQRROOT_MISSING: + * + * Missing responses of the first square root. + */ +#define CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_FIRST_SQRROOT_MISSING -721 +/** + * CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_SECOND_SQRROOT_MISSING: + * + * Missing responses of the SECOND square root. + */ +#define CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_SECOND_SQRROOT_MISSING -722 +/** + * CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_THIRD_SQRROOT_MISSING: + * + * Missing responses of the THIRD square root. + */ +#define CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_THIRD_SQRROOT_MISSING -723 +/** + * CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_FORTH_SQRROOT_MISSING: + * + * Missing responses of the forth square root. + */ +#define CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_FORTH_SQRROOT_MISSING -724 +/** + * CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_DELTA_MISSING: + * + * Missing responses of DELTA. + */ +#define CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_DELTA_MISSING -725 +/** + * CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_RHO_MISSING: + * + * Missing response rho. + */ +#define CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_RHO_MISSING -726 +/** + * CRYPTIC_PROOF_RANGE_VERIFICATION_FAILURE: + * + * Range proof not valid. + */ +#define CRYPTIC_PROOF_RANGE_VERIFICATION_FAILURE -727 +/** + * CRYPTIC_PROOF_RANGE_INTERACTIVE_ROUND_1_UNCOMPLETE: + * + * Proof range prover round 1 not complete. + */ +#define CRYPTIC_PROOF_RANGE_INTERACTIVE_ROUND_1_UNCOMPLETE -728 +/** + * CRYPTIC_PROOF_RANGE_INTERACTIVE_ROUND_2_NO_CHALLENGE: + * + * Challenge missing. + */ +#define CRYPTIC_PROOF_RANGE_INTERACTIVE_ROUND_2_NO_CHALLENGE -729 + +/** + * CRYPTIC_HASH_NI_PROOFS_NULL_VALUE: + * + * Asked to add a new value before hash computing, but is null. + */ +#define CRYPTIC_HASH_NI_PROOFS_NULL_VALUE -801 +/** + * CRYPTIC_HASH_NI_PROOFS_ERROR_COMPUTATION: + * + * Error computing Hash. + */ +#define CRYPTIC_HASH_NI_PROOFS_ERROR_COMPUTATION -802 +/** + * CRYPTIC_ERROR_SSL: + * + * Error SSL function. + */ +#define CRYPTIC_ERROR_SSL -900 diff --git a/cryptic/export.h b/cryptic/export.h new file mode 100644 index 0000000..680df42 --- /dev/null +++ b/cryptic/export.h @@ -0,0 +1,89 @@ +/* $Id: export.h 3990 2008-09-12 15:06:58Z bdauvergne $ + * + * Cryptic -- Cryptographic tools and protocols + * + * Copyright (C) 2010 Entr'ouvert + * + * Authors: See AUTHORS file in top-level directory. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __CRYPTIC_EXPORT_H__ +#define __CRYPTIC_EXPORT_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* Now, the export orgy begins. The following we must do for the + * Windows platform with MSVC compiler. */ + +#if !defined CRYPTIC_EXPORT +# if (defined _MSC_VER || defined MINGW32) + /* if we compile libxmlsec itself: */ +# if defined(IN_CRYPTIC) +# if !defined(CRYPTIC_STATIC) +# define CRYPTIC_EXPORT __declspec(dllexport) +# else +# define CRYPTIC_EXPORT extern +# endif + /* if a client program includes this file: */ +# else +# if !defined(CRYPTIC_STATIC) +# define CRYPTIC_EXPORT __declspec(dllimport) +# else +# define CRYPTIC_EXPORT +# endif +# endif + /* This holds on all other platforms/compilers, which are easier to + handle in regard to this. */ +# else +# define CRYPTIC_EXPORT +# endif +#endif + +#if !defined CRYPTIC_EXPORT_VAR +# if (defined _MSC_VER || defined MINGW32) + /* if we compile libxmlsec itself: */ +# if defined(IN_CRYPTIC) +# if !defined(CRYPTIC_STATIC) +# define CRYPTIC_EXPORT_VAR __declspec(dllexport) extern +# else +# define CRYPTIC_EXPORT_VAR extern +# endif + /* if we compile libxmlsec-crypto itself: */ +# elif defined(IN_CRYPTIC_CRYPTO) +# define CRYPTIC_EXPORT_VAR extern + /* if a client program includes this file: */ +# else +# if !defined(CRYPTIC_STATIC) +# define CRYPTIC_EXPORT_VAR __declspec(dllimport) extern +# else +# define CRYPTIC_EXPORT_VAR extern +# endif +# endif + /* This holds on all other platforms/compilers, which are easier to + handle in regard to this. */ +# else +# define CRYPTIC_EXPORT_VAR extern +# endif +#endif + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __CRYPTIC_EXPORT_H__ */ diff --git a/cryptic/maths/decompose_integer.c b/cryptic/maths/decompose_integer.c new file mode 100644 index 0000000..7b036b6 --- /dev/null +++ b/cryptic/maths/decompose_integer.c @@ -0,0 +1,607 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2010 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include + +#include "../errors.h" +#include "../utils.h" + +#include "decompose_integer.h" + +/*****************************************************************************/ +/* private methods */ +/*****************************************************************************/ + +static GObjectClass *parent_class = NULL; + +/*****************************************************************************/ +/* overridden parent class methods */ +/*****************************************************************************/ + +static void +dispose(GObject *object) +{ + CrypticDecomposeInteger *di = CRYPTIC_DECOMPOSEINTEGER(object); + + cryptic_release_bn(di->ONE); + cryptic_release_bn(di->TWO); + cryptic_release_bn(di->THREE); + cryptic_release_bn(di->FOUR); + cryptic_release_bn(di->FIVE); + cryptic_release_bn(di->SEVEN); + cryptic_release_bn(di->EIGHT); + cryptic_release_bn(di->a); + cryptic_release_bn(di->b); + cryptic_release_bn(di->c); + cryptic_release_bn(di->d); + + G_OBJECT_CLASS(parent_class)->dispose(G_OBJECT(di)); +} + +/*****************************************************************************/ +/* instance and class init functions */ +/*****************************************************************************/ + +static void +instance_init(CrypticDecomposeInteger *di) +{ + di->ONE = NULL; + di->TWO = NULL; + di->THREE = NULL; + di->FOUR = NULL; + di->FIVE = NULL; + di->SEVEN = NULL; + di->EIGHT = NULL; + di->a = NULL; + di->b = NULL; + di->c = NULL; + di->d = NULL; +} + +static void +class_init(CrypticDecomposeIntegerClass *klass) +{ + parent_class = g_type_class_peek_parent(klass); + + G_OBJECT_CLASS(klass)->dispose = dispose; +} + +/*****************************************************************************/ +/* public methods */ +/*****************************************************************************/ + +GType +cryptic_decompose_integer_get_type() +{ + static GType this_type = 0; + + if (!this_type) { + static const GTypeInfo this_info = { + sizeof (CrypticDecomposeIntegerClass), + NULL, + NULL, + (GClassInitFunc) class_init, + NULL, + NULL, + sizeof(CrypticDecomposeInteger), + 0, + (GInstanceInitFunc) instance_init, + NULL + }; + + this_type = g_type_register_static(G_TYPE_OBJECT, + "CrypticDecomposeInteger", &this_info, 0); + } + return this_type; +} + +/** + * cryptic_decompose_integer_new + * @numToDecompose: interger to decompose in four squares. + * + * Creates a new #CrypticDecomposeInteger. + * Perform the decomposition + * + * Return value: a newly created #CrypticDecomposeInteger object if decimposition is successful; or NULL if an error + * occured or the decomposition failed. + **/ +CrypticDecomposeInteger* +cryptic_decompose_integer_new(BIGNUM *numToDecompose) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + CrypticDecomposeInteger *di; + di = g_object_new(CRYPTIC_TYPE_DECOMPOSEINTEGER, NULL); + + BIGNUM *tmp1 = NULL, *tmp2 = NULL, *tmp3 = NULL, *tmp4 = NULL; + BIGNUM *approxSquareRoot = NULL, *z = NULL, *svg_num = NULL; + BN_CTX *ctx = NULL; + + if(BN_is_zero(numToDecompose)){ + rc = CRYPTIC_NO_ERROR; + goto cleanup; + } + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp2 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp3 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp4 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(approxSquareRoot = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(z = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(svg_num = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + cryptic_release_bn(di->ONE); + cryptic_release_bn(di->TWO); + cryptic_release_bn(di->THREE); + cryptic_release_bn(di->FOUR); + cryptic_release_bn(di->FIVE); + cryptic_release_bn(di->SEVEN); + cryptic_release_bn(di->EIGHT); + goto_cleanup_if_fail_with_rc_with_warning_openssl(di->ONE = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(di->ONE,1) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(di->TWO = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(di->TWO,2) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(di->THREE = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(di->THREE,3) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(di->FOUR = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(di->FOUR,4) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(di->FIVE = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(di->FIVE,5) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(di->SEVEN = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(di->SEVEN,7) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(di->EIGHT = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(di->EIGHT,8) == 1); + + cryptic_release_bn(di->a); + cryptic_release_bn(di->b); + cryptic_release_bn(di->c); + cryptic_release_bn(di->d); + goto_cleanup_if_fail_with_rc_with_warning_openssl(di->a = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(di->a,0) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(di->b = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(di->b,0) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(di->c = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(di->c,0) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(di->d = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(di->d,0) == 1); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(svg_num, numToDecompose)); + + int specialCaseRS[17][4] = { + 2, 1, 1, 0, + 3, 1, 1, 1, + 10, 3, 1, 0, + 34, 3, 3, 4, + 58, 3, 7, 0, + 85, 6, 7, 0, + 130, 3, 11, 0, + 214, 3, 6, 13, + 226, 8, 9, 9, + 370, 8, 9, 15, + 526, 6, 7, 21, + 706, 15, 15, 16, + 730, 1, 27, 0, + 1414, 6, 17, 33, + 1906, 13, 21, 36, + 2986, 21, 32, 39, + 9634, 56, 57, 57}; + + BIGNUM *specialCaseRSBN[17][5]; + int i,j; + for(i=0;i<17;i++){ + for(j=0;j<5;j++){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(specialCaseRSBN[i][j] = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(specialCaseRSBN[i][j], specialCaseRS[i][j]) == 1); + } + } + + /******************************************** + *** Reduction: mod 4 of NTD + *********************************************/ + int red = 0; + while(1){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod(tmp1, numToDecompose, di->FOUR, ctx) == 1); + if(!BN_is_zero(tmp1))break; + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_div(tmp1,tmp2,numToDecompose, di->FOUR,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(numToDecompose,tmp1)); + red++; + } + + /******************************************** + *** Special decomposition + *********************************************/ + int found=-1; + for(i=0;i<17;i++){ + if(!BN_cmp(specialCaseRSBN[i][0],numToDecompose)){ + found=i;i=17; + } + } + if(found>-1){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(di->a,specialCaseRSBN[found][1])); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(di->b,specialCaseRSBN[found][2])); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(di->c,specialCaseRSBN[found][3])); + cryptic_check_good_rc(cryptic_decompose_integer_back_reduction(di,red)); + goto finalize; + } + + /******************************************** + *** Approximative square root of NTDmod4 + *********************************************/ + cryptic_check_good_rc(cryptic_decompose_integer_square_root(di, numToDecompose, approxSquareRoot)); + + /******************************************** + *** cleanup if the NTDmod4 is a square root + *********************************************/ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(tmp2,approxSquareRoot,di->TWO,ctx)); + if(!BN_cmp(numToDecompose,tmp2)){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(di->a,approxSquareRoot)); + cryptic_check_good_rc(cryptic_decompose_integer_back_reduction(di,red)); + goto finalize; + } + + /******************************************** + *** We work with 4n+1: + *** Primes writable 4n+1 (8k+1 & 8k+5) may be a square + *** (All primes can be written 4n+1 or 4n-1) + *********************************************/ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod(tmp1,numToDecompose,di->FOUR,ctx) == 1); + if(BN_is_one(tmp1) && BN_is_prime_ex(numToDecompose,BN_prime_checks,ctx,NULL)){ + cryptic_check_good_rc(cryptic_decompose_integer_sum_two_squares(di,numToDecompose)); + if(!BN_is_zero(di->a)){ + cryptic_check_good_rc(cryptic_decompose_integer_back_reduction(di,red)); + goto finalize; + } + } + + /******************************************** + *** The only case where d is set (to 1) is + *** when NDTmod4 = 4n-1 with n odd (8k+7). + *** NDTmod4 = 8k+6+1 + *********************************************/ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod(tmp1,numToDecompose,di->EIGHT,ctx) == 1); + if(BN_cmp(tmp1,di->SEVEN) == 0){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(di->d,1) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(numToDecompose,numToDecompose,di->ONE) == 1); + } + + /******************************************** + *** if x==8k+1, 8k+2, 8k+5, 8k+6: three squares and x==z^2+(4k+1) + *********************************************/ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod(tmp1,numToDecompose,di->FOUR,ctx) == 1); + if(!BN_cmp(tmp1,di->ONE) || !BN_cmp(tmp1,di->TWO)){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(z, approxSquareRoot)); + while(!BN_is_zero(z)){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(tmp1,z,di->TWO,ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(tmp1,numToDecompose,tmp1) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod(tmp2,tmp1,di->FOUR,ctx) == 1); + if(BN_is_one(tmp2) && BN_is_prime_ex(tmp1,BN_prime_checks,ctx,NULL)){ + cryptic_check_good_rc(cryptic_decompose_integer_sum_two_squares(di,tmp1)); + if(!BN_is_zero(di->a)){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(di->c,z)); + cryptic_check_good_rc(cryptic_decompose_integer_back_reduction(di,red)); + goto finalize; + } + } + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(z,z,di->ONE) == 1); + } + } + + /******************************************** + *** if x==8k+3: three squares and x==z^2+(2*(4k+1)) + *********************************************/ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod(tmp1,numToDecompose,di->EIGHT,ctx) == 1); + if(BN_cmp(tmp1,di->THREE) == 0){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(z, approxSquareRoot)); + while(!BN_is_zero(z)){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(tmp1,z,di->TWO,ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(tmp1,numToDecompose,tmp1) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod(tmp2,tmp1,di->EIGHT,ctx) == 1); + if(BN_cmp(tmp2,di->TWO)>1){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(z,z,di->ONE) == 1); + } + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_div(tmp1,tmp2,tmp1,di->TWO,ctx) == 1); + if(BN_is_prime_ex(tmp1,BN_prime_checks,ctx,NULL)){ + cryptic_check_good_rc(cryptic_decompose_integer_sum_two_squares(di,tmp1)); + if(!BN_is_zero(di->a)){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(di->b,di->a,di->b) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mul(tmp1,di->a,di->TWO,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(di->a,di->b,tmp1) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(di->c,z)); + cryptic_check_good_rc(cryptic_decompose_integer_back_reduction(di,red)); + goto finalize; + } + } + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(z,z,di->ONE) == 1); + } + } + +finalize: + /* Correction if necessary + * To avoid this correction, catch before why d is not set to one.*/ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(tmp1,di->a,di->TWO,ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(tmp2,di->b,di->TWO,ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(tmp3,di->c,di->TWO,ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(tmp4,di->d,di->TWO,ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(tmp1,tmp1,tmp2) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(tmp1,tmp1,tmp3) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(tmp1,tmp1,tmp4) == 1); + if(BN_cmp(svg_num,tmp1) > 0) { + if(BN_is_zero(di->d)){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(tmp1,svg_num,tmp1) == 1); + cryptic_check_good_rc(cryptic_decompose_integer_square_root(di, tmp1, tmp2)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(tmp3,tmp2,di->TWO,ctx)); + if(!BN_cmp(tmp1,tmp3)){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(di->d,tmp2)); + }else{ + cryptic_critical("Decomposition failed - 2"); + rc = CRYPTIC_MATHS_DECOMPOSITION_4_SQUARES_FAILED; + goto cleanup; + } + }else{ + cryptic_critical("Decomposition failed - 1"); + rc = CRYPTIC_MATHS_DECOMPOSITION_4_SQUARES_FAILED; + goto cleanup; + } + } + + if(red>0){ + for (i=0;iFOUR,ctx) == 1); + } + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(tmp1); + cryptic_release_bn(tmp2); + cryptic_release_bn(tmp3); + cryptic_release_bn(tmp4); + cryptic_release_bn(approxSquareRoot); + cryptic_release_bn(z); + cryptic_release_bn(svg_num); + for(i=0;i<17;i++){ + for(j=0;j<5;j++){ + cryptic_release_bn(specialCaseRSBN[i][j]); + } + } + if(rc == CRYPTIC_NO_ERROR) {return di;} + else{ + cryptic_release_gobject(di); + return (CrypticDecomposeInteger*) rc; + } +} + +int +cryptic_decompose_integer_sum_two_squares(CrypticDecomposeInteger *di, BIGNUM *numToDecompose) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i=1; + BIGNUM *tmp1 = NULL, *tmp2 = NULL, *h = NULL, *root = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp2 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(h = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(root = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod(tmp1, numToDecompose, di->FOUR, ctx) == 1); + if(!BN_is_one(tmp1)){ + goto cleanup; + } + + if(BN_is_one(numToDecompose)){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(di->a,di->ONE)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(di->b,0) == 1); + rc = CRYPTIC_NO_ERROR; + goto cleanup; + } + + do{ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(di->a,i) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(tmp1,di->a,di->TWO,ctx)); + if(BN_cmp(numToDecompose,tmp1)<=0){ + goto cleanup; + } + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(tmp2,numToDecompose,tmp1) == 1); + cryptic_check_good_rc(cryptic_decompose_integer_square_root(di, tmp2, root)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(tmp2,root,di->TWO,ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(tmp1,tmp1,tmp2) == 1); + i++; + }while(BN_cmp(tmp1,numToDecompose)); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(di->b, root)); + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(tmp1); + cryptic_release_bn(tmp2); + cryptic_release_bn(h); + cryptic_release_bn(root); + return rc; +} + +//result in root +int +cryptic_decompose_integer_newton_iteration(CrypticDecomposeInteger *di, BIGNUM *square, BIGNUM *root) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BIGNUM *tmp1 = NULL, *tmp2 = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp2 = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_div(tmp1,tmp2,square,root,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(root,root,tmp1) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_div(root,square,root,di->TWO,ctx) == 1); + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(tmp1); + cryptic_release_bn(tmp2); + return rc; +} + +int +cryptic_decompose_integer_square_root(CrypticDecomposeInteger *di, BIGNUM *square, BIGNUM *root) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BIGNUM *tmp1 = NULL, *tmp2 = NULL, *tmp3 = NULL, *oldroot = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp2 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp3 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(oldroot = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(root,di->ONE)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(oldroot,di->ONE)); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tmp3,square)); + cryptic_check_good_rc(cryptic_decompose_integer_newton_iteration(di,tmp3,root)); + + while(1){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(tmp1,root,oldroot) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(tmp2,root,di->TWO,ctx)); + if((BN_is_zero(tmp1) || BN_is_one(tmp1)) || !BN_cmp(tmp2,square))break; + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(oldroot,root)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tmp3,square)); + cryptic_check_good_rc(cryptic_decompose_integer_newton_iteration(di,tmp3,root)); + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(tmp1); + cryptic_release_bn(tmp2); + cryptic_release_bn(tmp3); + cryptic_release_bn(oldroot); + return rc; +} + +int +cryptic_decompose_integer_back_reduction(CrypticDecomposeInteger *di, int reduction) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BIGNUM *tmp = NULL, *redBN = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(redBN = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(redBN,reduction) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(tmp,di->TWO,redBN, ctx) == 1); + + if (di->a) goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mul(di->a,di->a,tmp,ctx) == 1); + if (di->b) goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mul(di->b,di->b,tmp,ctx) == 1); + if (di->c) goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mul(di->c,di->c,tmp,ctx) == 1); + if (di->d) goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mul(di->d,di->d,tmp,ctx) == 1); + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(tmp); + cryptic_release_bn(redBN); + return rc; +} + +int +cryptic_decompose_integer_verify_decomposition(CrypticDecomposeInteger *di,BIGNUM *numToDecompose) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BIGNUM *tmp1 = NULL, *tmp2 = NULL, *tmp3 = NULL, *tmp4 = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp2 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp3 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp4 = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(tmp1,di->a,di->TWO,ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(tmp2,di->b,di->TWO,ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(tmp3,di->c,di->TWO,ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(tmp4,di->d,di->TWO,ctx)); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(tmp1,tmp1,tmp2) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(tmp1,tmp1,tmp3) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(tmp1,tmp1,tmp4) == 1); + + if(BN_cmp(tmp1,numToDecompose) == 0) { + rc = 1; + } else { + rc = CRYPTIC_NO_ERROR; + } + +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(tmp1); + cryptic_release_bn(tmp2); + cryptic_release_bn(tmp3); + cryptic_release_bn(tmp4); + return rc; +} + +BIGNUM* +cryptic_getSqrRoot1(CrypticDecomposeInteger *di) +{ + cryptic_return_null_if_fail(di->a); + return di->a; +} + +BIGNUM* +cryptic_getSqrRoot2(CrypticDecomposeInteger *di) +{ + cryptic_return_null_if_fail(di->b); + return di->b; +} + +BIGNUM* +cryptic_getSqrRoot3(CrypticDecomposeInteger *di) +{ + cryptic_return_null_if_fail(di->c); + return di->c; +} + +BIGNUM* +cryptic_getSqrRoot4(CrypticDecomposeInteger *di) +{ + cryptic_return_null_if_fail(di->d); + return di->d; +} diff --git a/cryptic/maths/decompose_integer.h b/cryptic/maths/decompose_integer.h new file mode 100644 index 0000000..08b7272 --- /dev/null +++ b/cryptic/maths/decompose_integer.h @@ -0,0 +1,100 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef CRYPTIC_MATHS_DECOMPOSE_INTEGER_H +#define CRYPTIC_MATHS_DECOMPOSE_INTEGER_H + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +#include +#include +#include + +#include "../export.h" + + +#define CRYPTIC_TYPE_DECOMPOSEINTEGER (cryptic_decompose_integer_get_type()) +#define CRYPTIC_DECOMPOSEINTEGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CRYPTIC_TYPE_DECOMPOSEINTEGER, CrypticDecomposeInteger)) +#define CRYPTIC_DECOMPOSEINTEGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), CRYPTIC_TYPE_DECOMPOSEINTEGER, CrypticDecomposeIntegerClass)) +#define CRYPTIC_IS_DECOMPOSEINTEGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), CRYPTIC_TYPE_DECOMPOSEINTEGER)) +#define CRYPTIC_IS_DECOMPOSEINTEGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CRYPTIC_TYPE_DECOMPOSEINTEGER)) +#define CRYPTIC_DECOMPOSEINTEGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CRYPTIC_TYPE_DECOMPOSEINTEGER, CrypticDecomposeIntegerClass)) + +typedef struct _CrypticDecomposeInteger CrypticDecomposeInteger; +typedef struct _CrypticDecomposeIntegerClass CrypticDecomposeIntegerClass; + +/** + * CrypticDecomposeInteger: + * @a: First square. + * @b: Second square. + * @c: Third square. + * @d: Forth square. + * + * Decompose an integer in four squares. + * + */ +struct _CrypticDecomposeInteger{ + GObject parent; + + /*< public >*/ + BIGNUM *a; + BIGNUM *b; + BIGNUM *c; + BIGNUM *d; + + /*< private >*/ + BIGNUM *ONE; + BIGNUM *TWO; + BIGNUM *THREE; + BIGNUM *FOUR; + BIGNUM *FIVE; + BIGNUM *SEVEN; + BIGNUM *EIGHT; + +}; + +struct _CrypticDecomposeIntegerClass { + GObjectClass parent_class; +}; + +CRYPTIC_EXPORT GType cryptic_decompose_integer_get_type(void); + +CRYPTIC_EXPORT CrypticDecomposeInteger* cryptic_decompose_integer_new(BIGNUM *numToDecompose); +CRYPTIC_EXPORT int cryptic_decompose_integer_sum_two_squares(CrypticDecomposeInteger *di, BIGNUM *numToDecompose); +CRYPTIC_EXPORT int cryptic_decompose_integer_newton_iteration(CrypticDecomposeInteger *di, BIGNUM *square, BIGNUM *root); +CRYPTIC_EXPORT int cryptic_decompose_integer_square_root(CrypticDecomposeInteger *di, BIGNUM *square, BIGNUM *root); +CRYPTIC_EXPORT int cryptic_decompose_integer_back_reduction(CrypticDecomposeInteger *di, int reduction); +CRYPTIC_EXPORT int cryptic_decompose_integer_verify_decomposition(CrypticDecomposeInteger *di, BIGNUM *numToDecompose); + +/* Accessors */ +BIGNUM* cryptic_getSqrRoot1(CrypticDecomposeInteger *di); +BIGNUM* cryptic_getSqrRoot2(CrypticDecomposeInteger *di); +BIGNUM* cryptic_getSqrRoot3(CrypticDecomposeInteger *di); +BIGNUM* cryptic_getSqrRoot4(CrypticDecomposeInteger *di); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* CRYPTIC_MATHS_DECOMPOSE_INTEGER_H */ diff --git a/cryptic/maths/group_prime_order.c b/cryptic/maths/group_prime_order.c new file mode 100755 index 0000000..37693c1 --- /dev/null +++ b/cryptic/maths/group_prime_order.c @@ -0,0 +1,281 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include + +#include "../errors.h" +#include "../utils.h" + +#include "group_prime_order.h" + +/*****************************************************************************/ +/* private methods */ +/*****************************************************************************/ + +static GObjectClass *parent_class = NULL; + +/*****************************************************************************/ +/* overridden parent class methods */ +/*****************************************************************************/ + +static void +dispose(GObject *object) +{ + CrypticPrimeOrderGroup *group = CRYPTIC_GROUPSPRIMEORDER(object); + + cryptic_release_bn(group->p); + cryptic_release_bn(group->pp); + cryptic_release_bn(group->generator); + cryptic_release_bn(group->order); + int i; + if(group->bases){ + for(i=group->nb_bases-1; i = 0; i--){ + cryptic_release_bn(group->bases[i]); + } + } + cryptic_release(group->bases); + + G_OBJECT_CLASS(parent_class)->dispose(G_OBJECT(group)); +} + +/*****************************************************************************/ +/* instance and class init functions */ +/*****************************************************************************/ + +static void +instance_init(CrypticPrimeOrderGroup *group) +{ + group->p = NULL; + group->pp = NULL; + group->generator = NULL; + group->order = NULL; + group->bases = NULL; +} + +static void +class_init(CrypticPrimeOrderGroupClass *klass) +{ + parent_class = g_type_class_peek_parent(klass); + + G_OBJECT_CLASS(klass)->dispose = dispose; +} + +/*****************************************************************************/ +/* public methods */ +/*****************************************************************************/ + +GType +cryptic_prime_order_group_get_type() +{ + static GType this_type = 0; + + if (!this_type) { + static const GTypeInfo this_info = { + sizeof (CrypticPrimeOrderGroupClass), + NULL, + NULL, + (GClassInitFunc) class_init, + NULL, + NULL, + sizeof(CrypticPrimeOrderGroup), + 0, + (GInstanceInitFunc) instance_init, + NULL + }; + + this_type = g_type_register_static(G_TYPE_OBJECT, + "CrypticPrimeOrderGroup", &this_info, 0); + } + return this_type; +} + +/** + * cryptic_prime_order_group_new + * @lg_modulus: length of the modulus of the group. + * + * Creates a new #CrypticPrimeOrderGroup. + * p prime, modulus of the group Zp^*. + * p is a safe prime, the order q is prime. + * cf. Handbook of Applied Cryptography : 11.78 p459 + * a in Zp^* ; g = a^(p-1/q) mod p ; h = g^2,3,... mod p + * q | p-1 ; q -| p-1/q ; g^q = h^q = 1 mod p + * Or cf. 2.132.iv p70; + * a generator of Zp^* if a^(phi(p)/y) not 1 mod p for each prime divisor y of phi(p) (Handbook of Crypto Fact 2.132(iv)) + * p = 2pp+1 => phi(p)=2pp y1=pp y2=2 + * a^pp not 1 mod p and a^2 not 1 mod p + * + * Return value: a newly created #CrypticPrimeOrderGroup object; or NULL if an error + * occured + **/ +CrypticPrimeOrderGroup* +//cryptic_prime_order_group_new(int lg_modulus, BN_GENCB *cb) +cryptic_prime_order_group_new(int lg_modulus) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int found=0,found2=0; + BIGNUM *two = NULL, *gcd = NULL, *tmp1 = NULL; + BN_CTX *ctx = NULL; + + CrypticPrimeOrderGroup *group; + group = g_object_new(CRYPTIC_TYPE_GROUPSPRIMEORDER, NULL); + + BN_GENCB *cb = NULL; + + goto_cleanup_if_fail_with_rc_with_warning_openssl(gcd = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(two = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(two,2) == 1); + cryptic_release_bn(group->p); + cryptic_release_bn(group->pp); + cryptic_release_bn(group->generator); + cryptic_release_bn(group->order); + goto_cleanup_if_fail_with_rc_with_warning_openssl(group->p = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(group->pp = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(group->order = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(group->generator = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + /* TODO: p = bq + 1 with b != 2 */ + while(!found2){ + found=0; + while(!found){ + BN_generate_prime_ex(group->p,lg_modulus,1,NULL,NULL,cb); + /* Redundant check (already cleanup by safe prime generation) */ + if(BN_is_prime_ex(group->p,BN_prime_checks,ctx, cb)){ + found=1; + } + } + /* pp = (p-1)/2 */ + /* div approx makes minus one useless */ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_div(group->pp,NULL,group->p,two,ctx) == 1); + //assert(BN_div(group->pp,NULL,group->p,two,ctx) == 1); + /* Redundant check (already cleanup by safe prime generation) */ + if(BN_is_prime_ex(group->pp,BN_prime_checks,ctx, cb)){ + found2=1; + } + } + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(group->order,group->p,BN_value_one()) == 1); + + /* Generator picking */ + found=0; + while(!found){ + cryptic_check_good_rc(cryptic_find_random_with_range_value(group->generator,group->p)); + /* Check if a in Zp^* */ + /* a in Zp^* if gcd(a,p) = 1 with p prime*/ + /* Fermat theorem: if gcd(a,p) = 1 with p prime, a^phi(p)=a^(p-1) = 1 mod p*/ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_gcd(gcd, group->p, group->generator, ctx) == 1); + if (BN_ucmp(gcd, BN_value_one()) == 0 && BN_ucmp(group->generator, BN_value_one()) != 0) {found = 1;} + } + /* g^2 and g^p' mod p must be != 1*/ + /* The group generated by p (safe prime) means that any member of the group is a generator */ + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(tmp1); + cryptic_release_bn(gcd); + cryptic_release_bn(two); + if(rc == CRYPTIC_NO_ERROR) {return group;} + else{ + cryptic_release_gobject(group); + return NULL; + } +} + +/** + * cryptic_prime_order_group_more_bases: + * @nb: number of new bases to pick. + * + * Pick nb ganarators in the prime order group. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + */ +int +cryptic_prime_order_group_more_bases(CrypticPrimeOrderGroup *group, int nb) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + BIGNUM *tmp1 = NULL; + BN_CTX *ctx = NULL; + BN_MONT_CTX *mont = NULL; + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(mont = BN_MONT_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_MONT_CTX_set(mont, group->p, ctx)); + + if(group->nb_bases == 0) { + cryptic_release(group->bases); + group->bases = g_malloc0(nb * sizeof (**group->bases)); + if(group->bases == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + for (i=0;ibases[i] = NULL; + goto_cleanup_if_fail_with_rc_with_warning_openssl(group->bases[i] = BN_new()); + int found=0; + while(!found){ + cryptic_check_good_rc(cryptic_find_random_with_range_value(tmp1,group->p)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(group->bases[i],group->generator,tmp1,group->p,ctx,mont)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp1,group->bases[i],group->pp,group->p,ctx,mont)); + if(BN_ucmp(tmp1,BN_value_one()) == 0){ /* g^q = 1 mod p */ + found=1; + group->nb_bases++; + } + } + } + }else{ + BIGNUM **tmp = NULL; + tmp = group->bases; + group->bases = g_realloc(group->bases,(group->nb_bases+nb) * sizeof (**group->bases)); + if(group->bases == NULL){ + group->bases = tmp; + tmp = NULL; + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + for (i=0;ibases[group->nb_bases] = NULL; + goto_cleanup_if_fail_with_rc_with_warning_openssl(group->bases[group->nb_bases] = BN_new()); + int found=0; + while(!found){ + cryptic_check_good_rc(cryptic_find_random_with_range_value(tmp1,group->p)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(group->bases[group->nb_bases],group->generator,tmp1,group->p,ctx,mont)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp1,group->bases[group->nb_bases],group->pp,group->p,ctx,mont)); + if(BN_ucmp(tmp1,BN_value_one()) == 0){ /* g^q = 1 mod p */ + found=1; + group->nb_bases++; + } + } + } + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_mont(mont); + cryptic_release_bn(tmp1); + return rc; +} diff --git a/cryptic/maths/group_prime_order.h b/cryptic/maths/group_prime_order.h new file mode 100755 index 0000000..711a35e --- /dev/null +++ b/cryptic/maths/group_prime_order.h @@ -0,0 +1,82 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef CRYPTIC_MATHS_PRIME_ORDER_GROUP_H +#define CRYPTIC_MATHS_PRIME_ORDER_GROUP_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +#include +#include +#include + +#include "../export.h" + +#define CRYPTIC_TYPE_GROUPSPRIMEORDER (cryptic_prime_order_group_get_type()) +#define CRYPTIC_GROUPSPRIMEORDER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CRYPTIC_TYPE_GROUPSPRIMEORDER, CrypticPrimeOrderGroup)) +#define CRYPTIC_GROUPSPRIMEORDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), CRYPTIC_TYPE_GROUPSPRIMEORDER, CrypticPrimeOrderGroupClass)) +#define CRYPTIC_IS_GROUPSPRIMEORDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), CRYPTIC_TYPE_GROUPSPRIMEORDER)) +#define CRYPTIC_IS_GROUPSPRIMEORDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CRYPTIC_TYPE_GROUPSPRIMEORDER)) +#define CRYPTIC_GROUPSPRIMEORDER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CRYPTIC_TYPE_GROUPSPRIMEORDER, CrypticPrimeOrderGroupClass)) + +typedef struct _CrypticPrimeOrderGroup CrypticPrimeOrderGroup; +typedef struct _CrypticPrimeOrderGroupClass CrypticPrimeOrderGroupClass; + +/** + * CrypticPrimeOrderGroup: + * @p: Nb of quantities in the DL representation to prove. + * @pp: base for the DL representation. + * @order: DL representation to prove. + * @generator: modulus of the group. + * @bases: Randoms used for the commitment. + * @nb_generator: The commitment. + * + * Group of prime order. + * + */ +struct _CrypticPrimeOrderGroup{ + GObject parent; + + /*< public >*/ + BIGNUM *p; + BIGNUM *pp; + BIGNUM *order; + BIGNUM *generator; + BIGNUM **bases; + int nb_bases; +}; + +struct _CrypticPrimeOrderGroupClass { + GObjectClass parent_class; +}; + +CRYPTIC_EXPORT GType cryptic_prime_order_group_get_type(void); + +//CRYPTIC_EXPORT CrypticPrimeOrderGroup* cryptic_prime_order_group_new(int lg_modulus, BN_GENCB *cb); +CRYPTIC_EXPORT CrypticPrimeOrderGroup* cryptic_prime_order_group_new(int lg_modulus); +CRYPTIC_EXPORT int cryptic_prime_order_group_more_bases(CrypticPrimeOrderGroup *group, int nb); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* CRYPTIC_MATHS_PRIME_ORDER_GROUP_H */ diff --git a/cryptic/maths/maths_utils.c b/cryptic/maths/maths_utils.c new file mode 100644 index 0000000..73b494a --- /dev/null +++ b/cryptic/maths/maths_utils.c @@ -0,0 +1,169 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include "../errors.h" +#include "../utils.h" + +/** + * cryptic_find_random + * @size: number of bits for the random.. + * + * Find a random of size bits. + * + * Return value: CRYPTIC_NO_ERROR if successful; or an error code if an error + * occured + **/ +int +cryptic_find_random(BIGNUM *ret, int size) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BIGNUM *s = NULL, *two = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail_with_rc_with_warning_openssl(s = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(two = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(two,2) == 1); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(s,size) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(s,two,s,ctx) == 1); + + do{ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_rand_range(ret,s) == 1); + } while(BN_num_bits(ret) != size); + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(s); + cryptic_release_bn(two); + return rc; +} + +/** + * cryptic_find_random_with_range_value + * @value: reference value. + * + * Find a random of a same number of bits as value. + * + * Return value: CRYPTIC_NO_ERROR if successful; or an error code if an error + * occured + **/ +int +cryptic_find_random_with_range_value(BIGNUM *ret, BIGNUM *value) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BN_CTX *ctx = NULL; + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + int size = BN_num_bits(value); + + do{ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_rand_range(ret,value) == 1); + } while(BN_num_bits(ret) != size); + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + return rc; +} +/** + * cryptic_ret_random + * @size: number of bits for the random.. + * + * Find a random of size bits. + * + * Return value: CRYPTIC_NO_ERROR if successful; or an error code if an error + * occured + **/ + +BIGNUM* +cryptic_ret_random(int size) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BIGNUM *s = NULL, *two = NULL, *ret = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail_with_rc_with_warning_openssl(s = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(ret = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(two = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(two,2) == 1); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(s,size) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(s,two,s,ctx) == 1); + + do{ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_rand_range(ret,s) == 1); + } while(BN_num_bits(ret) != size); + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(s); + cryptic_release_bn(two); + if(rc != CRYPTIC_NO_ERROR){ + cryptic_release_bn(ret); + return NULL; + } + return ret; +} + +/** + * cryptic_ret_random_with_range_value + * @value: reference value. + * + * Find a random of a same number of bits as value. + * + * Return value: CRYPTIC_NO_ERROR if successful; or an error code if an error + * occured + **/ +BIGNUM* +cryptic_ret_random_with_range_value(BIGNUM *value) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BIGNUM *ret = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ret = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + int size = BN_num_bits(value); + + do{ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_rand_range(ret,value) == 1); + } while(BN_num_bits(ret) != size); + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + if(rc != CRYPTIC_NO_ERROR){ + cryptic_release_bn(ret); + return NULL; + } + return ret; +} diff --git a/cryptic/maths/maths_utils.h b/cryptic/maths/maths_utils.h new file mode 100644 index 0000000..9294517 --- /dev/null +++ b/cryptic/maths/maths_utils.h @@ -0,0 +1,40 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef CRYPTIC_MATHS_UTILS_H +#define CRYPTIC_MATHS_UTILS_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include + +#include "../export.h" + +CRYPTIC_EXPORT int cryptic_find_random(BIGNUM *ret, int size); +CRYPTIC_EXPORT int cryptic_find_random_with_range_value(BIGNUM *ret, BIGNUM *value); + +CRYPTIC_EXPORT BIGNUM* cryptic_ret_random(int size); +CRYPTIC_EXPORT BIGNUM* cryptic_ret_random_with_range_value(BIGNUM *value); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* CRYPTIC_MATHS_UTILS_H */ diff --git a/cryptic/maths/quadratic_residues_group.c b/cryptic/maths/quadratic_residues_group.c new file mode 100644 index 0000000..6bf8e23 --- /dev/null +++ b/cryptic/maths/quadratic_residues_group.c @@ -0,0 +1,528 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include + +#include "../errors.h" +#include "../utils.h" + +#include "quadratic_residues_group.h" + +/*****************************************************************************/ +/* private methods */ +/*****************************************************************************/ + +static GObjectClass *parent_class = NULL; + +/*****************************************************************************/ +/* overridden parent class methods */ +/*****************************************************************************/ + +static void +dispose(GObject *object) +{ + CrypticQRG *qrg = CRYPTIC_QRGROUP(object); + cryptic_release_bn(qrg->pp); + cryptic_release_bn(qrg->p); + cryptic_release_bn(qrg->qq); + cryptic_release_bn(qrg->q); + cryptic_release_bn(qrg->n); + cryptic_release_bn(qrg->order); + cryptic_release_bn(qrg->phi); + cryptic_release_bn(qrg->two); + cryptic_release_bn(qrg->base); + G_OBJECT_CLASS(parent_class)->dispose(G_OBJECT(qrg)); +} + +/*****************************************************************************/ +/* instance and class init functions */ +/*****************************************************************************/ + +static void +instance_init(CrypticQRG *qrg) +{ + qrg->pp = NULL; + qrg->p = NULL; + qrg->qq = NULL; + qrg->q = NULL; + qrg->n = NULL; + qrg->order = NULL; + qrg->phi = NULL; + qrg->two = NULL; + qrg->base = NULL; +} + +static void +class_init(CrypticQRGClass *klass) +{ + parent_class = g_type_class_peek_parent(klass); + + G_OBJECT_CLASS(klass)->dispose = dispose; +} + +/*****************************************************************************/ +/* public methods */ +/*****************************************************************************/ + +GType +cryptic_qrg_get_type() +{ + static GType this_type = 0; + if (!this_type) { + static const GTypeInfo this_info = { + sizeof (CrypticQRGClass), + NULL, + NULL, + (GClassInitFunc) class_init, + NULL, + NULL, + sizeof(CrypticQRG), + 0, + (GInstanceInitFunc) instance_init, + NULL + }; + this_type = g_type_register_static(G_TYPE_OBJECT, + "CrypticQRG", &this_info, 0); + } + return this_type; +} + +/** + * cryptic_qrg_new + * @lg_modulus: bases of the DL representation. + * + * Creates a new #CrypticQRG. + * + * Return value: a newly created #CrypticQRG object; or NULL if an error occured + * + **/ +CrypticQRG* +//cryptic_qrg_new(int lg_modulus, BN_GENCB *cb) +cryptic_qrg_new(int lg_modulus) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BIGNUM *tmp1 = NULL, *tmp2 = NULL, *gcd = NULL; + BN_CTX *ctx = NULL; + BN_MONT_CTX *mont = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(lg_modulus >= CRYPTIC_MATHS_QR_GROUP_TEST_MODULUS_SIZE, + CRYPTIC_QRG_MODULUS_SIZE_TOO_SMALL); + + BN_GENCB *cb = NULL; + + CrypticQRG *qrg; + qrg = g_object_new(CRYPTIC_TYPE_QRGROUP, NULL); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp2 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(gcd = BN_new()); + cryptic_release_bn(qrg->pp); + cryptic_release_bn(qrg->p); + cryptic_release_bn(qrg->qq); + cryptic_release_bn(qrg->q); + cryptic_release_bn(qrg->n); + cryptic_release_bn(qrg->order); + cryptic_release_bn(qrg->phi); + cryptic_release_bn(qrg->two); + cryptic_release_bn(qrg->base); + goto_cleanup_if_fail_with_rc_with_warning_openssl(qrg->p = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(qrg->pp = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(qrg->q = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(qrg->qq = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(qrg->n = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(qrg->order = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(qrg->phi = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(qrg->base = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(qrg->two = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(qrg->two,2) == 1); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(mont=BN_MONT_CTX_new()); + + qrg->lg_modulus = lg_modulus; + int s=0; + s = (qrg->lg_modulus/2); + + /************************************************************ + * Find a safe prime q = 2*qq +1 with qq prime + *************************************************************/ + + int found=0,found2=0; + while(!found2){ + found=0; + while(!found){ + BN_generate_prime_ex(qrg->q,s,1,NULL,NULL,cb); + /* Redundant check (already cleanup by safe prime generation) */ + if(BN_is_prime_ex(qrg->q,BN_prime_checks,ctx, cb)){ + found=1; + } + } + /* div by 2 of an even number give the same result as if one is substracted before */ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_div(qrg->qq,NULL,qrg->q,qrg->two,ctx) == 1); + /* Redundant check (already cleanup by safe prime generation) */ + if(BN_is_prime_ex(qrg->qq,BN_prime_checks,ctx, cb)){ + found2=1; + } + } + + /************************************************************ + * Find a safe prime p = 2*pp +1 with pp prime + *************************************************************/ + + found=0,found2=0; + while(!found2){ + found=0; + while(!found){ + BN_generate_prime_ex(qrg->p,s,1,NULL,NULL,cb); + /* Redundant check (already cleanup by safe prime generation) */ + if(BN_is_prime_ex(qrg->p,BN_prime_checks,ctx, cb)){ + found=1; + } + } + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_div(qrg->pp,NULL,qrg->p,qrg->two,ctx) == 1); + /* Redundant check (already cleanup by safe prime generation) */ + if(BN_is_prime_ex(qrg->pp,BN_prime_checks,ctx, cb)){ + found2=1; + } + } + + /************************************************************ + * n = pq -> Z_n^* multiplicative groupe with generator + *************************************************************/ + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mul(qrg->n,qrg->p,qrg->q,ctx) == 1); + + /************************************************************ + * order = ppqq -> |Z_n^*| + *************************************************************/ + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mul(qrg->order,qrg->pp,qrg->qq,ctx) == 1); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(tmp1,qrg->p,BN_value_one()) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(tmp2,qrg->q,BN_value_one()) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mul(qrg->phi,tmp1,tmp2,ctx) == 1); + + /************************************************************ + * random r of size n + * qr = r^2 mod n + * qr != 1 and coprime(qr-1,n) + *************************************************************/ + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_MONT_CTX_set(mont,qrg->n,ctx)); + do{ + cryptic_check_good_rc(cryptic_find_random_with_range_value(tmp1,qrg->n)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(qrg->base,tmp1,qrg->two,qrg->n,ctx,mont)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(tmp1,qrg->base,BN_value_one())); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_gcd(gcd, tmp1, qrg->n, ctx) == 1); + }while (BN_ucmp(qrg->base, BN_value_one()) == 0 || BN_ucmp(gcd, BN_value_one()) != 0); + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_mont(mont); + cryptic_release_bn(tmp1); + cryptic_release_bn(tmp2); + cryptic_release_bn(gcd); + if(rc == CRYPTIC_NO_ERROR) {return qrg;} + else{ + cryptic_release_gobject(qrg); + return NULL; + } +} + +/** + * cryptic_qrg_new_load: + * @p: A safe prime + * @n: Modulus + * + * Build a group of quadratic residues from a modulus and a safe prime. + * + * Return value: #CrypticQRG if successful, an error code otherwise. + * + */ +CrypticQRG* +//cryptic_qrg_new_load(BIGNUM *p, BIGNUM *n, BN_GENCB *cb) +cryptic_qrg_new_load(BIGNUM *p, BIGNUM *n, BIGNUM *base) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BIGNUM *tmp1 = NULL, *tmp2 = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(p != NULL, + CRYPTIC_QRG_UNABLE_TO_LOAD_QRG_MINIMAL); + goto_cleanup_if_fail_with_rc_with_warning(n != NULL, + CRYPTIC_QRG_UNABLE_TO_LOAD_QRG_MINIMAL); + goto_cleanup_if_fail_with_rc_with_warning(base != NULL, + CRYPTIC_QRG_UNABLE_TO_LOAD_QRG_MINIMAL); + + BN_GENCB *cb = NULL; + + CrypticQRG *qrg; + qrg = g_object_new(CRYPTIC_TYPE_QRGROUP, NULL); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp2 = BN_new()); + cryptic_release_bn(qrg->pp); + cryptic_release_bn(qrg->p); + cryptic_release_bn(qrg->qq); + cryptic_release_bn(qrg->q); + cryptic_release_bn(qrg->n); + cryptic_release_bn(qrg->order); + cryptic_release_bn(qrg->phi); + cryptic_release_bn(qrg->two); + cryptic_release_bn(qrg->base); + goto_cleanup_if_fail_with_rc_with_warning_openssl(qrg->p = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(qrg->pp = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(qrg->q = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(qrg->qq = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(qrg->n = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(qrg->order = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(qrg->phi = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(qrg->base = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(qrg->two = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(qrg->two,2) == 1); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + goto_cleanup_if_fail_with_rc_with_warning(BN_is_prime_ex(p,BN_prime_checks, ctx, cb), + CRYPTIC_MATHS_NUMBER_NOT_PRIME); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(qrg->p,p)); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(qrg->pp, qrg->p, BN_value_one()) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_div(qrg->pp, NULL, qrg->pp, qrg->two, ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning(BN_is_prime_ex(qrg->pp, BN_prime_checks, ctx, cb), + CRYPTIC_MATHS_NUMBER_NOT_PRIME); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(qrg->n,n)); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_div(qrg->q, NULL, qrg->n, qrg->p, ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning(BN_is_prime_ex(qrg->q,BN_prime_checks, ctx, cb), + CRYPTIC_MATHS_NUMBER_NOT_PRIME); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(qrg->qq,qrg->q,BN_value_one()) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_div(qrg->qq,NULL,qrg->qq,qrg->two,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning(BN_is_prime_ex(qrg->qq,BN_prime_checks,ctx, cb), + CRYPTIC_MATHS_NUMBER_NOT_PRIME); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(qrg->base,base)); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mul(qrg->order,qrg->pp,qrg->qq,ctx) == 1); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(tmp1,qrg->p,BN_value_one()) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(tmp2,qrg->q,BN_value_one()) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mul(qrg->phi,tmp1,tmp2,ctx) == 1); + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(tmp1); + cryptic_release_bn(tmp2); + if(rc == CRYPTIC_NO_ERROR) {return qrg;} + else{ + cryptic_release_gobject(qrg); + return NULL; + } +} + +/** + * cryptic_qrg_verif_generator: + * + * Verify the group of quadratic residues. + * + * Here we test that the base is in QRn with the Legendre symbol + * (a/p) = 0 if p/a, A, 1 if a in QRp, -1 if a in QRp + * a in QRn in QRp in QRq + * (a/p) = a^((p-1)/2) mod p + * + * Return value: 1 if the group is ok, an error code otherwise. + * + */ +/*int +cryptic_qrg_verif_generator(CrypticQRG *qrg) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + if( (cryptic_qrg_check_qr(qrg->base,qrg->p)<0) || (cryptic_qrg_check_qr(qrg->base,qrg->q)<0)){ + return(CRYPTIC_MATHS_QR_GROUP_NOT_A_QR); + } + + return 1; +}*/ + +int +cryptic_qrg_check_qr(BIGNUM *qr, BIGNUM *modulus) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BIGNUM *tmp1 = NULL, *two = NULL; + BN_CTX *ctx = NULL; + BN_MONT_CTX *mont = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(qr != NULL, + CRYPTIC_MATHS_QR_GROUP_NO_QR_TO_VERIFY); + goto_cleanup_if_fail_with_rc_with_warning(modulus != NULL, + CRYPTIC_MATHS_QR_GROUP_MODULUS_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(BN_ucmp(qr, BN_value_one()) != 0, + CRYPTIC_MATHS_QR_GROUP_NOT_A_QR); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(two = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(two,2) == 1); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(mont=BN_MONT_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_MONT_CTX_set(mont,modulus,ctx)); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(tmp1,modulus,BN_value_one())); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_div(tmp1,NULL,tmp1,two,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp1,qr,tmp1,modulus,ctx,mont)); + goto_cleanup_if_fail_with_rc_with_warning(BN_ucmp(tmp1, BN_value_one()) == 0, + CRYPTIC_MATHS_QR_GROUP_NOT_A_QR); + + rc = 1; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_mont(mont); + cryptic_release_bn(tmp1); + cryptic_release_bn(two); + return rc; +} + +/** + * cryptic_qrg_pick_base: + * @out_base: Contain the base picked. + * + * Pick a base. + * + * Return value: CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + */ +int +cryptic_qrg_pick_base(CrypticQRG *qrg, BIGNUM *out_base) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BIGNUM *rand = NULL; + BN_CTX *ctx = NULL; + BN_MONT_CTX *mont = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(out_base != NULL, + CRYPTIC_MATHS_QR_GROUP_BASE_UNALLOCATED); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(rand = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(mont=BN_MONT_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_MONT_CTX_set(mont,qrg->n,ctx)); + + cryptic_check_good_rc(cryptic_find_random_with_range_value(rand,qrg->order)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(out_base,qrg->base,rand,qrg->n,ctx,mont)); + + if( (cryptic_qrg_check_qr(out_base,qrg->p)<0) || (cryptic_qrg_check_qr(out_base,qrg->q)<0)){ + return(CRYPTIC_MATHS_QR_GROUP_NOT_A_QR); + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_mont(mont); + cryptic_release_bn(rand); + return rc; +} + +/** + * cryptic_qrg_pick_k_bases: + * @out_bases: Contain the bases picked. + * @nb_bases: Number of bases to pick. + * + * Pick nb_bases bases. + * + * Return value: CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + */ +int +cryptic_qrg_pick_k_bases(CrypticQRG *qrg, BIGNUM **out_bases, int nb_bases) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + cryptic_return_val_if_fail(out_bases != NULL,CRYPTIC_MATHS_QR_GROUP_BASE_UNALLOCATED); + int i; + for(i=0;ip); + return qrg->p; +} + +BIGNUM* +cryptic_qrg_get_pp(CrypticQRG *qrg) +{ + cryptic_return_null_if_fail(qrg->pp); + return qrg->pp; +} + +BIGNUM* +cryptic_qrg_get_q(CrypticQRG *qrg) +{ + cryptic_return_null_if_fail(qrg->q); + return qrg->q; +} + +BIGNUM* +cryptic_qrg_get_qq(CrypticQRG *qrg) +{ + cryptic_return_null_if_fail(qrg->qq); + return qrg->qq; +} + +BIGNUM* +cryptic_qrg_get_order(CrypticQRG *qrg) +{ + cryptic_return_null_if_fail(qrg->order); + return qrg->order; +} + +BIGNUM* +cryptic_qrg_get_phi(CrypticQRG *qrg) +{ + cryptic_return_null_if_fail(qrg->phi); + return qrg->phi; +} + +BIGNUM* +cryptic_qrg_get_n(CrypticQRG *qrg) +{ + cryptic_return_null_if_fail(qrg->n); + return qrg->n; +} diff --git a/cryptic/maths/quadratic_residues_group.h b/cryptic/maths/quadratic_residues_group.h new file mode 100644 index 0000000..2671727 --- /dev/null +++ b/cryptic/maths/quadratic_residues_group.h @@ -0,0 +1,107 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef CRYPTIC_MATHS_QR_GROUP_H +#define CRYPTIC_MATHS_QR_GROUP_H + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#define CRYPTIC_MATHS_QR_GROUP_MODULUS_SIZE 2048 +#define CRYPTIC_MATHS_QR_GROUP_TEST_MODULUS_SIZE 1024 + +#include +#include +#include +#include + +#include "../export.h" + +#define CRYPTIC_TYPE_QRGROUP (cryptic_qrg_get_type()) +#define CRYPTIC_QRGROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CRYPTIC_TYPE_QRGROUP, CrypticQRG)) +#define CRYPTIC_QRGROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), CRYPTIC_TYPE_QRGROUP, CrypticQRGClass)) +#define CRYPTIC_IS_QRGROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), CRYPTIC_TYPE_QRGROUP)) +#define CRYPTIC_IS_QRGROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CRYPTIC_TYPE_QRGROUP)) +#define CRYPTIC_QRGROUP_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CRYPTIC_TYPE_QRGROUP, CrypticQRGClass)) + +typedef struct _CrypticQRG CrypticQRG; +typedef struct _CrypticQRGClass CrypticQRGClass; + +/** + * CrypticZkpkInteractiveSchnorr: + * @p: Safe prime. + * @q: Safe prime. + * @pp: pp = (p-1)/2 + * @qq: qq = (q-1)/2 + * @n: modulus (p*q). + * @order: Order of the group (pp*qq). + * @phi: Euler phi(n) = (4*pp*qq). + * + * Group of quadratic residues. + * + */ +struct _CrypticQRG{ + GObject parent; + + /*< public >*/ + BIGNUM *p; + BIGNUM *q; + BIGNUM *pp; + BIGNUM *qq; + BIGNUM *n; + BIGNUM *order; + BIGNUM *phi; + BIGNUM *base; + BIGNUM *two; + int lg_modulus; +}; + +struct _CrypticQRGClass { + GObjectClass parent_class; +}; + +CRYPTIC_EXPORT GType cryptic_qrg_get_type(void); + +//CRYPTIC_EXPORT CrypticQRG* cryptic_qrg_new(int lg_modulus, BN_GENCB *cb); +CRYPTIC_EXPORT CrypticQRG* cryptic_qrg_new(int lg_modulus); +//CRYPTIC_EXPORT CrypticQRG* cryptic_qrg_new_load(BIGNUM *p, BIGNUM *n, BN_GENCB *cb); +CRYPTIC_EXPORT CrypticQRG* cryptic_qrg_new_load(BIGNUM *p, BIGNUM *n, BIGNUM *base); + +//CRYPTIC_EXPORT int cryptic_qrg_verif_generator(CrypticQRG *qrg); +CRYPTIC_EXPORT int cryptic_qrg_check_qr(BIGNUM *qr, BIGNUM *modulus); +CRYPTIC_EXPORT int cryptic_qrg_pick_base(CrypticQRG *qrg, BIGNUM *out_base); +CRYPTIC_EXPORT int cryptic_qrg_pick_k_bases(CrypticQRG *qrg, BIGNUM **out_bases, int nb_bases); + +/* Accessors */ +CRYPTIC_EXPORT BIGNUM* cryptic_qrg_get_p(CrypticQRG *qrg); +CRYPTIC_EXPORT BIGNUM* cryptic_qrg_get_pp(CrypticQRG *qrg); +CRYPTIC_EXPORT BIGNUM* cryptic_qrg_get_q(CrypticQRG *qrg); +CRYPTIC_EXPORT BIGNUM* cryptic_qrg_get_qq(CrypticQRG *qrg); +CRYPTIC_EXPORT BIGNUM* cryptic_qrg_get_order(CrypticQRG *qrg); +CRYPTIC_EXPORT BIGNUM* cryptic_qrg_get_phi(CrypticQRG *qrg); +CRYPTIC_EXPORT BIGNUM* cryptic_qrg_get_n(CrypticQRG *qrg); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* CRYPTIC_MATHS_QR_GROUP_H */ diff --git a/cryptic/protocols/clsig/clsig.h b/cryptic/protocols/clsig/clsig.h new file mode 100755 index 0000000..4447f64 --- /dev/null +++ b/cryptic/protocols/clsig/clsig.h @@ -0,0 +1,302 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef CLSIG_H +#define CLSIG_H + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +#define CRYPTIC_CLSIG_MODULUS_SIZE 2048 //ln +#define CRYPTIC_CLSIG_COMMITMENT_GROUP_MODULUS_SIZE 1632 //lRHO +#define CRYPTIC_CLSIG_COMMITMENT_GROUP_PRIME_ORDER_SIZE 256 //lrho +#define CRYPTIC_CLSIG_QUANTITIES_SIZE 256 //lm +#define CRYPTIC_CLSIG_EXPONENT_VALUES 596 //le +#define CRYPTIC_CLSIG_EXPONENT_INTERVAL 120 //lei +#define CRYPTIC_CLSIG_BLIND_VALUES 2723 //lv +#define CRYPTIC_CLSIG_CHALLENGE_SIZE 256 //challenge: lH for non interactive proofs - lc for interactive proofs +#define CRYPTIC_CLSIG_ZK_SEC_PARAM 80 //l0 +#define CRYPTIC_CLSIG_SEC_PARAM 160 //lk +#define CRYPTIC_CLSIG_SEC_PARAM_CRED_SYS 80 //lr + +#define CRYPTIC_CLSIG_TEST_MODULUS_SIZE 1024 //ln +#define CRYPTIC_CLSIG_TEST_COMMITMENT_GROUP_MODULUS_SIZE 816 //lRHO +#define CRYPTIC_CLSIG_TEST_COMMITMENT_GROUP_PRIME_ORDER_SIZE 128 //lrho +#define CRYPTIC_CLSIG_TEST_QUANTITIES_SIZE 128 //lm +#define CRYPTIC_CLSIG_TEST_EXPONENT_VALUES 298 //le +#define CRYPTIC_CLSIG_TEST_EXPONENT_INTERVAL 60 //lei +#define CRYPTIC_CLSIG_TEST_BLIND_VALUES 1461 //lv +#define CRYPTIC_CLSIG_TEST_CHALLENGE_SIZE 128 //challenge: lH for non interactive proofs - lc for interactive proofs +#define CRYPTIC_CLSIG_TEST_ZK_SEC_PARAM 40 //l0 +#define CRYPTIC_CLSIG_TEST_SEC_PARAM 80 //lk +#define CRYPTIC_CLSIG_TEST_SEC_PARAM_CRED_SYS 40 //lr + + /** Constraints + * lH (hash) for non interactive proofs - lc (chalenge) for interactive proofs + * 1- le > l0 + lH + max( lm+4 , lei+2 ) + * 2- lv > ln + l0 + lH + max ( lm+lr+3 , l0+2 ) + * 3- lH >= lk + * 4- lH < le (cf. 1) + * 5- lei < le - l0 - lH - 3 (computed after checking 1) + * 6- lm = lH (The larger the better and lm <= lH thus we only care of lm) + * 7- lrand = ln + l0 + */ + +#include +#include +#include + +#include "../../export.h" + +#include "../../maths/quadratic_residues_group.h" +#include "../pok_schnorr/schnorr_zkpk.h" +#include "commit_data_store.h" + +#define CRYPTIC_TYPE_CLSIG (cryptic_clsig_get_type()) +#define CRYPTIC_CLSIG(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CRYPTIC_TYPE_CLSIG, CrypticClsig)) +#define CRYPTIC_CLSIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), CRYPTIC_TYPE_CLSIG, CrypticClsigClass)) +#define CRYPTIC_IS_CLSIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), CRYPTIC_TYPE_CLSIG)) +#define CRYPTIC_IS_CLSIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CRYPTIC_TYPE_CLSIG)) +#define CRYPTIC_CLSIG_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CRYPTIC_TYPE_CLSIG, CrypticClsigClass)) + +typedef struct _CrypticClsig CrypticClsig; +typedef struct _CrypticClsigClass CrypticClsigClass; + +/** + * CrypticClsig: + * @lg_quantities: lm - we only care of lm + * @lg_modulus: ln + * @lg_exponent: le + * @interval_exponent: lei + * @lg_blind: lv + * @lg_randomize: lrand + * @lg_sec_param: lk + * @lg_zk_sec_param: l0 + * @lg_clsig_sec_param: lr + * @nb_quantities: + * @nb_bases: number of bases not including S and Z + * @modulus: n + * @S: base to blind dlrep + * @Z: dlrep to prove to prove a certificate + * @bases: bases to rep quantities + * @quantities: quantities signed + * @dlrep: quantities representes in DL + * @A: Signature value + * @v: quantity to blind the representation of quantities + * @e: RSA exponent + * @d: RSA private exponent + * @r: random used to randomize the signature + * @A_rand: Signature randomized + * @v_rand: quantity used to blind the representation after randomization + * @e_corrected: the RSA exponent corrected + * @qrg: quadratic residues group + * + * Camenisch-Lysyanskaya Signature. + * + */ +struct _CrypticClsig{ + GObject parent; + + /*< public >*/ + int lg_quantities; /* lm */ + int lg_modulus; /* ln */ + int lg_exponent; /* le */ + int interval_exponent; /* lei */ + int lg_blind; /* lv */ + int lg_randomize; /* lrand */ + int lg_sec_param; /* lk */ + int lg_zk_sec_param; /* l0 */ + int lg_clsig_sec_param; /* lr */ + int nb_quantities; + int nb_bases; /* number of bases not including S and Z*/ + + BIGNUM *modulus; /* n */ + BIGNUM *S; /* base to blind dlrep */ + BIGNUM *Z; /* dlrep to prove to prove a certificate */ + BIGNUM **bases; /* bases to rep quantities */ + BIGNUM **quantities; /* quantities signed */ + BIGNUM *dlrep; /* quantities representes in DL */ + BIGNUM *A; /* Signature value */ + BIGNUM *v; /* quantity to blind the representation of quantities */ + BIGNUM *e; /* RSA exponent */ + BIGNUM *d; /* RSA private exponent */ + BIGNUM *r; /* random used to randomize the signature */ + BIGNUM *A_rand; /* Signature randomized */ + BIGNUM *v_rand; /* quantity used to blind the representation after randomization */ + BIGNUM *e_corrected; + + CrypticQRG *qrg; + + /*< private >*/ + int sigrandomized; + int sigverified; + int sigloaded; + int init; +}; + +struct _CrypticClsigClass { + GObjectClass parent_class; +}; + +CRYPTIC_EXPORT GType cryptic_clsig_get_type(void); + +CRYPTIC_EXPORT CrypticClsig* cryptic_clsig_new(int lg_modulus, int lg_quantities, int lg_exponent, int lg_sec_param, int lg_zk_sec_param, int lg_clsig_sec_param, int nb_bases); + +/* Issuer: 1a */ +//CRYPTIC_EXPORT int cryptic_clsig_generate_parameters(CrypticClsig *clsig, BN_GENCB *cb); +CRYPTIC_EXPORT int cryptic_clsig_generate_parameters(CrypticClsig *clsig); +//CRYPTIC_EXPORT int cryptic_clsig_find_rsa_param(CrypticClsig *clsig, int lg_exponent, BN_GENCB *cb); +CRYPTIC_EXPORT int cryptic_clsig_find_rsa_param(CrypticClsig *clsig, int lg_exponent); +//CRYPTIC_EXPORT int cryptic_clsig_find_rsa_param_from_pubexp(CrypticClsig *clsig, BIGNUM *e, BN_GENCB *cb); +CRYPTIC_EXPORT int cryptic_clsig_find_rsa_param_from_pubexp(CrypticClsig *clsig, BIGNUM *e); + +CRYPTIC_EXPORT int cryptic_clsig_add_n_bases(CrypticClsig *clsig, int nb); + +/* Issuer: 1b */ +CRYPTIC_EXPORT CrypticClsig* cryptic_clsig_new_load_parameters_issuer(BIGNUM *p, + BIGNUM *Z, + BIGNUM *S, + int nb_bases, + BIGNUM **bases, + int lg_quantities, + int lg_exponent, + BIGNUM *modulus, + int lg_sec_param, + int lg_zk_sec_param, + int lg_clsig_sec_param); +// int lg_clsig_sec_param, +// BN_GENCB *cb); + +/* Prover and Verifier: 1 */ +CRYPTIC_EXPORT CrypticClsig* cryptic_clsig_new_load_public_parameters(BIGNUM *Z, + BIGNUM *S, + int nb_bases, + BIGNUM **bases, + int lg_quantities, + int lg_exponent, + BIGNUM *modulus, + int lg_sec_param, + int lg_zk_sec_param, + int lg_clsig_sec_param); + +/* Issuer: 2 */ +/* 2.1 */ +/* Helper functions to represent quantities */ +CRYPTIC_EXPORT int cryptic_clsig_compute_dlrep_with_random_quantities(CrypticClsig *clsig, int nb_quantities); +CRYPTIC_EXPORT int cryptic_clsig_compute_dlrep_by_index(CrypticClsig *clsig, BIGNUM **quantities, int *index, int nb_quantities); +CRYPTIC_EXPORT int cryptic_clsig_compute_dlrep_bulk_from_offset(CrypticClsig *clsig, BIGNUM **quantities, int offset, int nb_quantities); +/* 2.2 */ +CRYPTIC_EXPORT int cryptic_clsig_sign(CrypticClsig *clsig); +CRYPTIC_EXPORT int cryptic_clsig_sign_with_committed_value(CrypticClsig *clsig, BIGNUM *commitment); + +/* Prover: 3 */ +CRYPTIC_EXPORT int cryptic_clsig_compute_committed_value(CrypticClsig *clsig, + CrypticCommitDataStore *pdc, + BIGNUM** bases, + BIGNUM** quantities, int nb_quantities); +CRYPTIC_EXPORT int cryptic_clsig_compute_committed_value_with_index(CrypticClsig *clsig, + CrypticCommitDataStore *pdc, + int *index, + BIGNUM** quantities, int nb_quantities); +CRYPTIC_EXPORT int cryptic_clsig_load_certificate(CrypticClsig *clsig, + BIGNUM *A, + BIGNUM *e, + BIGNUM *v, + BIGNUM **quantities, int nb_quantities, + int sig_checking); +CRYPTIC_EXPORT int cryptic_clsig_load_certificate_with_index(CrypticClsig *clsig, + BIGNUM *A, + BIGNUM *e, + BIGNUM *v, + BIGNUM **quantities, + int nb_quantities, + int* index, + int sig_checking); +CRYPTIC_EXPORT int cryptic_clsig_load_certificate_with_committed_value(CrypticClsig *clsig, + BIGNUM *A, + BIGNUM *e, + BIGNUM *v, + BIGNUM **quantities, int nb_quantities, + BIGNUM **quantitiesC, int nb_quantitiesC, + BIGNUM *commitment, BIGNUM *vprime); +CRYPTIC_EXPORT int cryptic_clsig_load_certificate_with_index_with_committed_value(CrypticClsig *clsig, + BIGNUM *A, + BIGNUM *e, + BIGNUM *v, + BIGNUM **quantities, int nb_quantities, + BIGNUM **quantitiesC, int nb_quantitiesC, + BIGNUM *commitment, BIGNUM *vprime, + int *index); +CRYPTIC_EXPORT int cryptic_clsig_randomize_signature(CrypticClsig *clsig); + +CRYPTIC_EXPORT int cryptic_clsig_run_zkpk_schnorr_round1(CrypticClsig *clsig, CrypticZkpkSchnorr *shn); + +/* Issuer and Prover and Verifier */ +CRYPTIC_EXPORT int cryptic_clsig_verify_rsa_param(CrypticClsig *clsig); +CRYPTIC_EXPORT int cryptic_clsig_verify_signature_not_randomized(CrypticClsig *clsig); +CRYPTIC_EXPORT int cryptic_clsig_verify_signature_randomized(CrypticClsig *clsig); + +CRYPTIC_EXPORT BIGNUM* cryptic_clsig_correct_dlrep_before_proving(CrypticClsig *clsig, BIGNUM* dlrep); +CRYPTIC_EXPORT BIGNUM* cryptic_clsig_build_dlrep_before_proving(CrypticClsig *clsig, int* index_quantities, int* index_bases, int nb_quantities); + +/* Helper functions to extract parameters */ +CRYPTIC_EXPORT int cryptic_clsig_copy_generators_in_tab(BIGNUM **ret, CrypticClsig *clsig); +CRYPTIC_EXPORT int cryptic_clsig_copy_generators_by_index_in_tab(BIGNUM **ret, CrypticClsig *clsig, int *index, int nb_gen); +CRYPTIC_EXPORT int cryptic_clsig_copy_generators_bulk_from_offset_in_tab(BIGNUM **ret, CrypticClsig *clsig, int offset, int nb_gen); +CRYPTIC_EXPORT int cryptic_clsig_copy_quantities_in_tab(BIGNUM **ret, CrypticClsig *clsig); + +/* Accessors */ +CRYPTIC_EXPORT BIGNUM* cryptic_clsig_get_private_composite(CrypticClsig *clsig); /* p */ +CRYPTIC_EXPORT BIGNUM* cryptic_clsig_get_modulus(CrypticClsig *clsig); +CRYPTIC_EXPORT BIGNUM* cryptic_clsig_get_order(CrypticClsig *clsig); +CRYPTIC_EXPORT BIGNUM* cryptic_clsig_get_exponent(CrypticClsig *clsig); +CRYPTIC_EXPORT BIGNUM* cryptic_clsig_get_exponent_corrected(CrypticClsig *clsig); +CRYPTIC_EXPORT BIGNUM* cryptic_clsig_get_private_exponent(CrypticClsig *clsig); +CRYPTIC_EXPORT BIGNUM* cryptic_clsig_get_signature(CrypticClsig *clsig); +CRYPTIC_EXPORT BIGNUM* cryptic_clsig_get_randomized_signature(CrypticClsig *clsig); +CRYPTIC_EXPORT BIGNUM* cryptic_clsig_get_random_for_randomized_signature(CrypticClsig *clsig); +CRYPTIC_EXPORT BIGNUM* cryptic_clsig_get_DL_representation(CrypticClsig *clsig); +CRYPTIC_EXPORT BIGNUM* cryptic_clsig_get_blind(CrypticClsig *clsig); +CRYPTIC_EXPORT BIGNUM* cryptic_clsig_get_random_blind(CrypticClsig *clsig); +CRYPTIC_EXPORT BIGNUM* cryptic_clsig_get_S(CrypticClsig *clsig); +CRYPTIC_EXPORT BIGNUM* cryptic_clsig_get_Z(CrypticClsig *clsig); +CRYPTIC_EXPORT BIGNUM** cryptic_clsig_get_bases(CrypticClsig *clsig); +CRYPTIC_EXPORT BIGNUM** cryptic_clsig_get_quantities(CrypticClsig *clsig); +CRYPTIC_EXPORT BIGNUM* cryptic_clsig_get_i_base(CrypticClsig *clsig, int i); +CRYPTIC_EXPORT BIGNUM* cryptic_clsig_get_i_quantity(CrypticClsig *clsig, int i); +int cryptic_clsig_get_nb_bases(CrypticClsig *clsig); +int cryptic_clsig_get_nb_quantities(CrypticClsig *clsig); +int cryptic_clsig_get_lg_quantities(CrypticClsig *clsig); +int cryptic_clsig_get_lg_modulus(CrypticClsig *clsig); +int cryptic_clsig_get_lg_blind(CrypticClsig *clsig); +int cryptic_clsig_get_lg_randomize(CrypticClsig *clsig); +int cryptic_clsig_get_lg_exponent(CrypticClsig *clsig); +int cryptic_clsig_get_interval_exponent(CrypticClsig *clsig); +int cryptic_clsig_get_lg_sec_param(CrypticClsig *clsig); +int cryptic_clsig_get_lg_zk_sec_param(CrypticClsig *clsig); +int cryptic_clsig_get_lg_clsig_sec_param(CrypticClsig *clsig); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* CLSIG_H */ diff --git a/cryptic/protocols/clsig/clsig_gen.c b/cryptic/protocols/clsig/clsig_gen.c new file mode 100755 index 0000000..52cb070 --- /dev/null +++ b/cryptic/protocols/clsig/clsig_gen.c @@ -0,0 +1,675 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include + +#include "../../errors.h" +#include "../../utils.h" + +#include "clsig.h" +#include "maths/quadratic_residues_group.h" + +/*****************************************************************************/ +/* private methods */ +/*****************************************************************************/ + +static GObjectClass *parent_class = NULL; + +/*****************************************************************************/ +/* overridden parent class methods */ +/*****************************************************************************/ + +static void +dispose(GObject *object) +{ + CrypticClsig *clsig = CRYPTIC_CLSIG(object); + + int i; + if(clsig->bases){ + for(i=0;inb_bases;i++){ + cryptic_release_bn(clsig->bases[i]); + } + } + cryptic_release(clsig->bases); + if(clsig->quantities){ + for(i=0;inb_quantities;i++){ + cryptic_release_bn(clsig->quantities[i]); + } + } + cryptic_release(clsig->quantities); + cryptic_release_bn(clsig->S); + cryptic_release_bn(clsig->Z); + cryptic_release_bn(clsig->modulus); + cryptic_release_bn(clsig->e); + cryptic_release_bn(clsig->d); + cryptic_release_bn(clsig->dlrep); + cryptic_release_bn(clsig->v); + cryptic_release_bn(clsig->v_rand); + cryptic_release_bn(clsig->A); + cryptic_release_bn(clsig->A_rand); + cryptic_release_bn(clsig->r); + + cryptic_release_gobject(clsig->qrg); + + G_OBJECT_CLASS(parent_class)->dispose(G_OBJECT(clsig)); +} + +/*****************************************************************************/ +/* instance and class init functions */ +/*****************************************************************************/ + +static void +instance_init(CrypticClsig *clsig) +{ + clsig->bases = NULL; + clsig->quantities = NULL; + clsig->S = NULL; + clsig->Z = NULL; + clsig->modulus = NULL; + clsig->e = NULL; + clsig->d = NULL; + clsig->dlrep = NULL; + clsig->v = NULL; + clsig->v_rand = NULL; + clsig->A = NULL; + clsig->A_rand = NULL; + clsig->r = NULL; + clsig->qrg = NULL; +} + +static void +class_init(CrypticClsigClass *klass) +{ + parent_class = g_type_class_peek_parent(klass); + + G_OBJECT_CLASS(klass)->dispose = dispose; +} + +/*****************************************************************************/ +/* public methods */ +/*****************************************************************************/ + +GType +cryptic_clsig_get_type() +{ + static GType this_type = 0; + + if (!this_type) { + static const GTypeInfo this_info = { + sizeof (CrypticClsigClass), + NULL, + NULL, + (GClassInitFunc) class_init, + NULL, + NULL, + sizeof(CrypticClsig), + 0, + (GInstanceInitFunc) instance_init, + NULL + }; + + this_type = g_type_register_static(G_TYPE_OBJECT, + "CrypticClsig", &this_info, 0); + } + return this_type; +} + /* + #define CRYPTIC_CLSIG_MODULUS_SIZE 2048 //ln + #define CRYPTIC_CLSIG_COMMITMENT_GROUP_MODULUS_SIZE 1632 //lRHO + #define CRYPTIC_CLSIG_COMMITMENT_GROUP_PRIME_ORDER_SIZE 256 //lrho + #define CRYPTIC_CLSIG_QUANTITIES_SIZE 256 //lm + #define CRYPTIC_CLSIG_EXPONENT_VALUES 596 //le + #define CRYPTIC_CLSIG_EXPONENT_INTERVAL 120 //lei + #define CRYPTIC_CLSIG_BLIND_VALUES 2723 //lv + #define CRYPTIC_CLSIG_CHALLENGE_SIZE 256 //challenge: lH for non interactive proofs - lc for interactive proofs + #define CRYPTIC_CLSIG_ZK_SEC_PARAM 80 //l0 + #define CRYPTIC_CLSIG_SEC_PARAM 160 //lk + #define CRYPTIC_CLSIG_SEC_PARAM_CRED_SYS 80 //lr + */ + + /** Constraints + * 1- le > l0 + lH + max( lm+4 , lei+2 ) + * 2- lv > ln + l0 + lH + max ( lm+lr+3 , l0+2 ) + * 3- lH >= lk + * 4- lH < le (cf. 1) + * 5- lei < le - l0 - lH - 3 (computed after checking 1) + * 6- lm = lH (The larger the better and lm <= lH) + * 7- lrand = ln + l0 + */ + + /** Attributes + * non numerical attributes (string) should be hash + * numerical attributes should be expresses in a meaningful way to be used in proof + * ex: DateOfBirth: yyyymmddhhmm allows comparison of dates + */ + + /** Mapping + * le - lg_exponent - CRYPTIC_CLSIG_EXPONENT_VALUES + * lei - interval_exponent - CRYPTIC_CLSIG_EXPONENT_INTERVAL + * lH or lc - lg_quantities - CRYPTIC_CLSIG_CHALLENGE_SIZE + * lv - lg_blind - CRYPTIC_CLSIG_BLIND_VALUES + * lrand - lg_randomize + * lm - lg_quantities - CRYPTIC_CLSIG_QUANTITIES_SIZE + * lk - lg_sec_param - CRYPTIC_CLSIG_SEC_PARAM + * l0 - lg_zk_sec_param - CRYPTIC_CLSIG_ZK_SEC_PARAM + * lr - lg_clsig_sec_param - CRYPTIC_CLSIG_SEC_PARAM_CRED_SYS + */ + + /* lc is only given to the issuer to compute sizes */ + /* The prover has to take care to not use challenge larger */ + /* For message size, the larger the better */ + /* lm = lc */ + /* lei = le - l0 - lH - 4 */ + +/** + * cryptic_clsig_new + * @lg_modulus: bit length of the modulus. + * @lg_quantities: bit length of the quantities. + * @lg_exponent: bit length of the RSA exponent. + * @lg_sec_param: security parameter. + * @lg_zk_sec_param: security parameter for the zkpk. + * @lg_clsig_sec_param: security parameter for the clsig system. + * @nb_bases: nb of bases of represnetation. + * + * Creates a new #CrypticClsig. + * + * Return value: a newly created #CrypticClsig object; or NULL if an error + * occured + **/ +CrypticClsig* +cryptic_clsig_new(int lg_modulus, int lg_quantities, int lg_exponent, int lg_sec_param, int lg_zk_sec_param, int lg_clsig_sec_param, int nb_bases) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + CrypticClsig *clsig; + clsig = g_object_new(CRYPTIC_TYPE_CLSIG, NULL); + + clsig->qrg = NULL; + + if(lg_sec_param < CRYPTIC_CLSIG_TEST_SEC_PARAM) { clsig->lg_sec_param = CRYPTIC_CLSIG_TEST_SEC_PARAM;} + else { clsig->lg_sec_param = lg_sec_param; } + + if(lg_zk_sec_param < CRYPTIC_CLSIG_TEST_ZK_SEC_PARAM) { clsig->lg_zk_sec_param = CRYPTIC_CLSIG_TEST_ZK_SEC_PARAM;} + else { clsig->lg_zk_sec_param = lg_zk_sec_param; } + + if(lg_clsig_sec_param < CRYPTIC_CLSIG_TEST_SEC_PARAM_CRED_SYS) { clsig->lg_clsig_sec_param = CRYPTIC_CLSIG_TEST_SEC_PARAM_CRED_SYS;} + else { clsig->lg_clsig_sec_param = lg_clsig_sec_param; } + + if(lg_quantities < clsig->lg_sec_param) { /* lc = lm*/ + cryptic_critical("The challenge size must be larger or equal to the secutiry parameter (%d bits)",clsig->lg_sec_param); + goto error; + } + + clsig->lg_quantities = lg_quantities; + + if(lg_modulus < CRYPTIC_CLSIG_TEST_MODULUS_SIZE) { + cryptic_critical("The modulus is too small (min value: %d bits)",CRYPTIC_CLSIG_TEST_MODULUS_SIZE); + goto error; + } + if(lg_modulus%2){ + cryptic_critical("The modulus bit size must be even"); + goto error; + } + clsig->lg_modulus = lg_modulus; + + if(lg_exponent < CRYPTIC_CLSIG_TEST_EXPONENT_VALUES) { + cryptic_critical("The exponent is too small: %d (min value: %d bits)",lg_exponent,CRYPTIC_CLSIG_TEST_EXPONENT_VALUES); + goto error; + } + if( lg_exponent < (clsig->lg_sec_param + (2*lg_quantities) + 4) ) { + cryptic_critical("The exponent is too small due to constraints (min value: %d bits)",(clsig->lg_sec_param + (2*lg_quantities) + 4)); + goto error; + } + clsig->lg_exponent = lg_exponent; + + clsig->interval_exponent = clsig->lg_exponent - clsig->lg_zk_sec_param - lg_quantities - 4; + + if((clsig->lg_quantities + clsig->lg_clsig_sec_param + 3) > (clsig->lg_zk_sec_param + 2)){ + clsig->lg_blind = clsig->lg_modulus + clsig->lg_zk_sec_param + lg_quantities + clsig->lg_quantities + clsig->lg_clsig_sec_param + 3; + }else{ + clsig->lg_blind = clsig->lg_modulus + clsig->lg_zk_sec_param + lg_quantities + clsig->lg_zk_sec_param + 2; + } + + clsig->lg_randomize = clsig->lg_modulus + clsig->lg_zk_sec_param; + + clsig->nb_bases = nb_bases; + + clsig->init = 1; + clsig->sigloaded = 0; + clsig->sigverified = 0; + clsig->sigrandomized = 0; + + return clsig; +error: + cryptic_release_gobject(clsig); + return NULL; +} + +/** + * cryptic_clsig_generate_parameters + * + * Generate clsig parameters if the object has been well initialized. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + **/ +int +//cryptic_clsig_generate_parameters(CrypticClsig *clsig, BN_GENCB *cb) +cryptic_clsig_generate_parameters(CrypticClsig *clsig) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BN_GENCB *cb = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(clsig->init == 1, + CRYPTIC_CLSIG_NOT_CORRECTLY_INITIALIZED); + + cryptic_release_gobject(clsig->qrg); + //clsig->qrg = cryptic_qrg_new(clsig->lg_modulus, cb); + clsig->qrg = cryptic_qrg_new(clsig->lg_modulus); + goto_cleanup_if_fail_with_rc_with_warning(clsig->qrg != NULL, + CRYPTIC_CLSIG_UNABLE_TO_CREATE_QRG); + + cryptic_release_bn(clsig->modulus); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->modulus = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(clsig->modulus,cryptic_qrg_get_n(clsig->qrg))); + + cryptic_release_bn(clsig->S); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->S = BN_new()); + cryptic_check_good_rc(cryptic_qrg_pick_base(clsig->qrg, clsig->S)); + + cryptic_release_bn(clsig->Z); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->Z = BN_new()); + cryptic_check_good_rc(cryptic_qrg_pick_base(clsig->qrg, clsig->Z)); + + cryptic_release(clsig->bases); + clsig->bases = g_malloc0(clsig->nb_bases * sizeof (**clsig->bases)); + if(clsig->bases == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + + int i; + for(i=0;inb_bases;i++){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->bases[i] = BN_new()); + } + cryptic_check_good_rc(cryptic_qrg_pick_k_bases(clsig->qrg,clsig->bases,clsig->nb_bases)); + + //if( (rc = cryptic_clsig_find_rsa_param(clsig, clsig->lg_exponent, cb)) < 0) return rc; + cryptic_check_good_rc(cryptic_clsig_find_rsa_param(clsig, clsig->lg_exponent)); + + rc = CRYPTIC_NO_ERROR; +cleanup: + return rc; +} + +/** + * cryptic_clsig_find_rsa_param + * @lg_exponent: bit length of the exponent + * + * Generate a RSA key pair of length given in parameter. + * lg_exponent is kept in parameter of this function to make it usable without requiring to call init before. + * Can be used to update the key pair + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + **/ +int +//cryptic_clsig_find_rsa_param(CrypticClsig *clsig, int lg_exponent, BN_GENCB *cb) +cryptic_clsig_find_rsa_param(CrypticClsig *clsig, int lg_exponent) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BN_GENCB *cb = NULL; + + BIGNUM *tmp1 = NULL,*tmp2 = NULL,*gcd = NULL,*two = NULL,*lg = NULL,*lg2 = NULL; + BN_CTX *ctx = NULL; + + cryptic_release_bn(clsig->e); + cryptic_release_bn(clsig->d); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->e = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->d = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp2 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(gcd = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(lg = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(lg2 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(two = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(two,2) == 1); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + /************************************************************************** + * gcd(e,phi(n)) = 1 to be able to find d = 1/e mod(phi(n)) + * if a div b or a div c then a div bc + * it is then easy to show that if a not div b AND a not div c then a not div bc + * We need to test that coprime(e,phi(n)=(p-1)(q-1)) + * so we need to test that coprime(e,p-1) and coprime(e,q-1) + * Both gave the same result but the complexity in space is better with the second test. + ***************************************************************************/ + + /************************************************************************** + * BN_generate_prime_ex use has a random generator but e not need to be prime + * Having e prime does not seem to bring benefit except that computing coprimity is faster. + ***************************************************************************/ + + /* TODO: if e is prime and greater than 2, then the less-expensive test (p mod e)!=1 is enough instead of gcd(p-1,e)==1 */ + + /* Take e in [2^le-1, 2^le-1 + 2^lei-1] */ + /* Pick prime of size le-1: e in [2^le-1, 2^le -1] */ + /* Then take e < 2^le-1 + 2^lei-1 */ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(tmp1,clsig->lg_exponent-1) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(lg2,two,tmp1, ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(lg,clsig->interval_exponent-1) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(lg,two,lg, ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(lg,lg2,lg)); + + int found=0; + while(!found){ + cryptic_check_good_rc(cryptic_find_random(tmp1,clsig->interval_exponent-1)); //r_rho + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(clsig->e,tmp1,lg2)); + if(BN_ucmp(clsig->e,lg) < 0){ + if(BN_is_prime_ex(clsig->e, BN_prime_checks, ctx, cb)){ + BN_sub(tmp1, cryptic_qrg_get_p(clsig->qrg), BN_value_one()); + BN_gcd(tmp2, tmp1, clsig->e, ctx); + BN_sub(tmp1, cryptic_qrg_get_q(clsig->qrg), BN_value_one()); + BN_gcd(tmp1, tmp1, clsig->e, ctx); + if(BN_is_one(tmp1) && BN_is_one(tmp2)){found=1;} + } + } + } + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_inverse(clsig->d,clsig->e,cryptic_qrg_get_phi(clsig->qrg),ctx)); + goto_cleanup_if_fail_with_warning(clsig->d != NULL); + /* TODO: test that d is big enough (Wiener attack)*/ + + goto_cleanup_if_fail_with_warning(cryptic_clsig_verify_rsa_param(clsig) == 1); + + clsig->lg_exponent = lg_exponent; + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(two); + cryptic_release_bn(lg2); + cryptic_release_bn(lg); + cryptic_release_bn(gcd); + cryptic_release_bn(tmp2); + cryptic_release_bn(tmp1); + return(rc); +} + +/** + * cryptic_clsig_find_rsa_param + * @e: public exponent + * + * Compute the private exponent given the public exponent. + * The order of n only known by the issuer is given in clsig. + * Can be used to update the key pair + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + **/ +int +//cryptic_clsig_find_rsa_param_from_pubexp(CrypticClsig *clsig, BIGNUM *e, BN_GENCB *cb) +cryptic_clsig_find_rsa_param_from_pubexp(CrypticClsig *clsig, BIGNUM *e) +{ + /************************************************************************** + * WARNING: n is computed before choosing e + * It means that it must be checked before that coprime(e,phi(n)) + * Generally you fix e and then you compute n testing that d is big enough + * If n does not fit, you compute an other n. + * You cannot do this here. You have to change e! + ***************************************************************************/ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BN_GENCB *cb = NULL; + + BIGNUM *tmp1 = NULL,*tmp2 = NULL,*two = NULL,*lg = NULL; + BN_CTX *ctx = NULL; + + cryptic_release_bn(clsig->e); + cryptic_release_bn(clsig->d); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->e = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->d = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp2 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(lg = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(two = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(two,2) == 1); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + /* Take e in [2^le-1, 2^le-1 + 2^lei-1] */ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(lg,clsig->lg_exponent-1) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(tmp1,two,lg, ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(lg,clsig->interval_exponent-1) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(lg,two,lg, ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(lg,tmp1,lg)); + + goto_cleanup_if_fail_with_rc_with_warning(BN_num_bits(e) == clsig->lg_exponent, + CRYPTIC_CLSIG_EXPONENT_BAD_SIZE); + goto_cleanup_if_fail_with_rc_with_warning(BN_ucmp(e,lg) < 0, + CRYPTIC_CLSIG_EXPONENT_BAD_SIZE); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(clsig->e,e)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_inverse(clsig->d,clsig->e,cryptic_qrg_get_phi(clsig->qrg),ctx)); + goto_cleanup_if_fail_with_warning(clsig->d != NULL); + + goto_cleanup_if_fail_with_warning(cryptic_clsig_verify_rsa_param(clsig) == 1); + + clsig->lg_exponent = BN_num_bits(clsig->e); + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(two); + cryptic_release_bn(lg); + cryptic_release_bn(tmp2); + cryptic_release_bn(tmp1); + return(rc); +} + +/** + * cryptic_clsig_new_load_parameters_issuer + * @lg_modulus: bit length of the modulus. + * @lg_quantities: bit length of the quantities. + * @lg_exponent: bit length of the RSA exponent. + * @lg_sec_param: security parameter. + * @lg_zk_sec_param: security parameter for the zkpk. + * @lg_clsig_sec_param: security parameter for the clsig system. + * @nb_bases: nb of bases of represnetation. + * @bases: representation bases. + * @S: Blind base + * @Z: Base to proof a certificate + * @p: secret prime only known by the certificate issuer + * + * Creates a new #CrypticClsig. + * All parameters of the object are given in parameters + * + * Return value: a newly created #CrypticClsig object; or NULL if an error + * occured + **/ +CrypticClsig* +cryptic_clsig_new_load_parameters_issuer(BIGNUM *p, + BIGNUM *Z, + BIGNUM *S, + int nb_bases, + BIGNUM **bases, + int lg_quantities, + int lg_exponent, + BIGNUM *modulus, + int lg_sec_param, + int lg_zk_sec_param, + int lg_clsig_sec_param) +// int lg_clsig_sec_param, +// BN_GENCB *cb) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BN_GENCB *cb = NULL; + + CrypticClsig *clsig; + + clsig = cryptic_clsig_new_load_public_parameters(Z,S,nb_bases,bases,lg_quantities,lg_exponent,modulus,lg_sec_param, lg_zk_sec_param, lg_clsig_sec_param); + if(clsig == NULL){ + return NULL; + } + + cryptic_release_gobject(clsig->qrg); + //clsig->qrg = cryptic_qrg_new_load(p,modulus, cb); + clsig->qrg = cryptic_qrg_new_load(p,modulus,S); + if(clsig->qrg == NULL){ + cryptic_critical("Unable to load a quadratic residue group"); + return NULL; + } + + //if(cryptic_clsig_find_rsa_param(clsig, clsig->lg_exponent, cb) < 0) return NULL; + cryptic_check_good_rc(cryptic_clsig_find_rsa_param(clsig, clsig->lg_exponent)); + + return clsig; +cleanup: + cryptic_release_gobject(clsig); + return NULL; +} + +/** + * cryptic_clsig_new_load_parameters_issuer + * @lg_modulus: bit length of the modulus. + * @lg_quantities: bit length of the quantities. + * @lg_exponent: bit length of the RSA exponent. + * @lg_sec_param: security parameter. + * @lg_zk_sec_param: security parameter for the zkpk. + * @lg_clsig_sec_param: security parameter for the clsig system. + * @nb_bases: nb of bases of represnetation. + * @bases: representation bases. + * @S: Blind base + * @Z: Base to proof a certificate + * + * Creates a new #CrypticClsig. + * All public parameters of the object are given in parameters + * + * Return value: a newly created #CrypticClsig object; or NULL if an error + * occured + **/ +CrypticClsig* +cryptic_clsig_new_load_public_parameters(BIGNUM *Z, + BIGNUM *S, + int nb_bases, + BIGNUM **bases, + int lg_quantities, + int lg_exponent, + BIGNUM *modulus, + int lg_sec_param, + int lg_zk_sec_param, + int lg_clsig_sec_param) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + CrypticClsig *clsig = NULL; + + if(!Z || !S || !bases || !modulus){ + cryptic_critical("Unable to load CLSIG public parameters: element missing"); + return NULL; + } + int i; + for(i=0;imodulus); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->modulus = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(clsig->modulus, modulus)); + cryptic_release_bn(clsig->S); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->S = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(clsig->S, S)); + cryptic_release_bn(clsig->Z); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->Z = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(clsig->Z, Z)); + + cryptic_release(clsig->bases); + clsig->bases = g_malloc0(clsig->nb_bases * sizeof (**clsig->bases)); + if(clsig->bases == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + + for(i=0;ibases[i] = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(clsig->bases[i], bases[i])); + } + + cryptic_release_bn(clsig->e); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->e = BN_new()); + + rc = CRYPTIC_NO_ERROR; +cleanup: + if(rc == CRYPTIC_NO_ERROR) return clsig; + return NULL; +} + +int +cryptic_clsig_add_n_bases(CrypticClsig *clsig, int nb) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + if(clsig->nb_bases == 0) { + cryptic_release(clsig->bases); + clsig->bases = g_malloc0(nb * sizeof (**clsig->bases)); + if(clsig->bases == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + for(i=0;ibases[i] = BN_new()); + } + cryptic_check_good_rc(cryptic_qrg_pick_k_bases(clsig->qrg,clsig->bases,clsig->nb_bases)); + clsig->nb_bases = nb; + }else{ + BIGNUM **tmp = NULL; + tmp = clsig->bases; + clsig->bases = g_realloc(clsig->bases,(clsig->nb_bases+nb) * sizeof (**clsig->bases)); + if(clsig->bases == NULL){ + clsig->bases = tmp; + tmp = NULL; + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + for(i=0;ibases[clsig->nb_bases+i] = BN_new()); + } + cryptic_check_good_rc(cryptic_qrg_pick_k_bases(clsig->qrg,clsig->bases+clsig->nb_bases,nb)); + clsig->nb_bases = clsig->nb_bases + nb; + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + return rc; +} diff --git a/cryptic/protocols/clsig/clsig_sign.c b/cryptic/protocols/clsig/clsig_sign.c new file mode 100755 index 0000000..e74554d --- /dev/null +++ b/cryptic/protocols/clsig/clsig_sign.c @@ -0,0 +1,215 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include "../../errors.h" +#include "../../utils.h" + +#include "clsig.h" + +/** + * cryptic_clsig_sign + * + * Produce a signature value for a DL representation. + * In other words, makes a certificate and signed it. + * tuple (A,e,v) + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + **/ +int +cryptic_clsig_sign(CrypticClsig *clsig) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BIGNUM *tmp1 = NULL,*tmp2 = NULL,*gcd = NULL, *two = NULL; + BN_CTX *ctx = NULL; + BN_MONT_CTX *mont = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(clsig->init == 1, + CRYPTIC_CLSIG_NOT_CORRECTLY_INITIALIZED); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp2 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(gcd = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(two = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(two,2) == 1); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(mont=BN_MONT_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_MONT_CTX_set(mont,clsig->modulus,ctx)); + + cryptic_release_bn(clsig->v); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->v = BN_new()); + cryptic_check_good_rc(cryptic_find_random(clsig->v,clsig->lg_blind)); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp1,clsig->S,clsig->v,clsig->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(tmp1,tmp1,clsig->dlrep,clsig->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_gcd(gcd, tmp1, clsig->modulus, ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning(BN_ucmp(gcd, BN_value_one()) == 0, + CRYPTIC_CLSIG_EXPONENTIATION_S_NOT_INVERSIBLE); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_inverse(tmp2,tmp1,clsig->modulus,ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(tmp1,clsig->Z,tmp2,clsig->modulus,ctx) == 1); + + /****************************************************** + * TODO: computation of the signature + * using the Chinese Remainder Theorem (CRT) + * we need dmp = d mod p, dmq = d mod q and iqmp = 1/q mod p AND p>q + * m1 = c^dmp mod p + * m2 = c^dmq mod q + * h = iqmp(m1 - m2) mod p + * signed_value = m2 + q*h + * The complexity in time is four time better: + * lq env = lp env = ln/2 and the complexity in time is squared + *******************************************************/ + /* New RSA key pair for each certificate */ + cryptic_check_good_rc(cryptic_clsig_find_rsa_param(clsig, clsig->lg_exponent)); + + cryptic_release_bn(clsig->A); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->A = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(clsig->A,tmp1,clsig->d,clsig->modulus,ctx,mont) == 1); + + clsig->sigloaded = 1; + clsig->sigverified = 0; + clsig->sigrandomized = 0; + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_mont(mont); + cryptic_release_bn(two); + cryptic_release_bn(gcd); + cryptic_release_bn(tmp2); + cryptic_release_bn(tmp1); + return rc; +} + +/** + * cryptic_clsig_sign_with_committed_value + * + * Produce a signature value for a DL representation + * with a commited value given in parameter. + * In other words, makes a certificate and signed it. + * tuple (A,e,v) + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + **/ +int +cryptic_clsig_sign_with_committed_value(CrypticClsig *clsig, BIGNUM *commitment) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BN_CTX *ctx = NULL; + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + goto_cleanup_if_fail_with_rc_with_warning(clsig->init == 1, + CRYPTIC_CLSIG_NOT_CORRECTLY_INITIALIZED); + goto_cleanup_if_fail_with_rc_with_warning(commitment != NULL, + CRYPTIC_CLSIG_SIGNATURE_WITH_COMMIT_MISSING_ELEMENT); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(clsig->dlrep,clsig->dlrep,commitment,clsig->modulus,ctx) == 1); + + cryptic_check_good_rc(cryptic_clsig_sign(clsig)); + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + return rc; +} + +/** + * cryptic_clsig_randomize_signature + * + * Randomize a signature. + * tuple (A_rand,e_corrected,v_rand) + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + **/ +int +cryptic_clsig_randomize_signature(CrypticClsig *clsig) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BIGNUM *tmp = NULL,*gcd = NULL,*two = NULL,*lg = NULL; + BN_CTX *ctx = NULL; + BN_MONT_CTX *mont = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(clsig->sigverified == 1, + CRYPTIC_CLSIG_SIGNATURE_NOT_VALIDATED_TO_RANDOMIZE); + goto_cleanup_if_fail_with_rc_with_warning(clsig->A != NULL, + CRYPTIC_CLSIG_SIGNATURE_NOT_VALIDATED_TO_RANDOMIZE); + goto_cleanup_if_fail_with_rc_with_warning(clsig->e != NULL, + CRYPTIC_CLSIG_SIGNATURE_NOT_VALIDATED_TO_RANDOMIZE); + goto_cleanup_if_fail_with_rc_with_warning(clsig->v != NULL, + CRYPTIC_CLSIG_SIGNATURE_NOT_VALIDATED_TO_RANDOMIZE); + goto_cleanup_if_fail_with_rc_with_warning(clsig->S != NULL, + CRYPTIC_CLSIG_SIGNATURE_NOT_VALIDATED_TO_RANDOMIZE); + + cryptic_release_bn(clsig->r); + cryptic_release_bn(clsig->A_rand); + cryptic_release_bn(clsig->v_rand); + cryptic_release_bn(clsig->e_corrected); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->r = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->A_rand = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->v_rand = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->e_corrected = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(gcd = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(lg = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(two = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(two,2) == 1); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(mont=BN_MONT_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_MONT_CTX_set(mont,clsig->modulus,ctx)); + + /* ln + l0 */ + cryptic_check_good_rc(cryptic_find_random(clsig->r,clsig->lg_modulus + clsig->lg_zk_sec_param)); //r_rho + + /* A_rand = A.S^r */ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp,clsig->S,clsig->r,clsig->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(clsig->A_rand,clsig->A,tmp,clsig->modulus,ctx) == 1); + + /* v_rand = v -e.r */ + /* in Z -> no modulo to randomize v_rand */ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mul(tmp,clsig->e,clsig->r,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(clsig->v_rand,clsig->v,tmp) == 1); + + /* e_corrected = e - 2^le-1*/ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(tmp,clsig->lg_exponent-1) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(lg,two,tmp,ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(clsig->e_corrected,clsig->e,lg) == 1); + + clsig->sigrandomized = 1; + + rc = CRYPTIC_NO_ERROR; + +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_mont(mont); + cryptic_release_bn(two); + cryptic_release_bn(lg); + cryptic_release_bn(gcd); + cryptic_release_bn(tmp); + return rc; +} + diff --git a/cryptic/protocols/clsig/clsig_utl.c b/cryptic/protocols/clsig/clsig_utl.c new file mode 100755 index 0000000..20b1aca --- /dev/null +++ b/cryptic/protocols/clsig/clsig_utl.c @@ -0,0 +1,792 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include "../../errors.h" +#include "../../utils.h" + +#include "clsig.h" +#include "../../maths/quadratic_residues_group.h" +#include "../pok_schnorr/schnorr_zkpk.h" +#include "commit_data_store.h" + +/** + * cryptic_clsig_compute_dlrep_with_random_quantities: + * @nb_quantities: Number of quantities to generate + * + * Mainly a test function, generate random quantities. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + **/ +int +cryptic_clsig_compute_dlrep_with_random_quantities(CrypticClsig *clsig, int nb_quantities) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BIGNUM *tmp = NULL; + BN_CTX *ctx = NULL; + BN_MONT_CTX *mont = NULL; + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(mont=BN_MONT_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_MONT_CTX_set(mont,clsig->modulus,ctx)); + + goto_cleanup_if_fail_with_rc_with_warning(clsig->init == 1, + CRYPTIC_CLSIG_NOT_CORRECTLY_INITIALIZED); + goto_cleanup_if_fail_with_rc_with_warning(nb_quantities <= clsig->nb_bases, + CRYPTIC_CLSIG_TOO_MUCH_QUANTITIES); + + clsig->nb_quantities = nb_quantities; + + cryptic_release(clsig->quantities); + clsig->quantities = g_malloc0(clsig->nb_quantities * sizeof (**clsig->quantities)); + if(clsig->quantities == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + + /* Random mesages */ + int i; + for(i=0;inb_quantities;i++){ + clsig->quantities[i] = NULL; + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->quantities[i] = BN_new()); + cryptic_check_good_rc(cryptic_find_random(clsig->quantities[i],clsig->lg_quantities)); + } + + cryptic_release_bn(clsig->dlrep); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->dlrep = BN_new()); + BN_copy(clsig->dlrep,BN_value_one()); + + for(i=0;inb_quantities;i++){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp,clsig->bases[i],clsig->quantities[i],clsig->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(clsig->dlrep,clsig->dlrep,tmp,clsig->modulus,ctx) == 1); + } + +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_mont(mont); + cryptic_release_bn(tmp); + return(CRYPTIC_NO_ERROR); +} + +/** + * cryptic_clsig_compute_dlrep_with_random_quantities: + * @quantities: Quantities to represent + * @nb_quantities: Number of quantities to represent + * @index: Index of the base of representation + * + * Helper function to represent quantities. + * The quantities given are represented with the bases indicated by the index. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + **/ +int +cryptic_clsig_compute_dlrep_by_index(CrypticClsig *clsig, BIGNUM **quantities, int *index, int nb_quantities) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + BIGNUM *tmp = NULL; + BN_CTX *ctx = NULL; + BN_MONT_CTX *mont = NULL; + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(mont=BN_MONT_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_MONT_CTX_set(mont,clsig->modulus,ctx)); + + goto_cleanup_if_fail_with_rc_with_warning(clsig->init == 1, + CRYPTIC_CLSIG_NOT_CORRECTLY_INITIALIZED); + goto_cleanup_if_fail_with_rc_with_warning(nb_quantities <= clsig->nb_bases, + CRYPTIC_CLSIG_TOO_MUCH_QUANTITIES); + + clsig->nb_quantities = nb_quantities; + + goto_cleanup_if_fail_with_rc_with_warning(quantities != NULL, + CRYPTIC_CLSIG_MISSING_QUANTITIES); + for(i=0;inb_quantities;i++){ + goto_cleanup_if_fail_with_rc_with_warning(quantities[i] != NULL, + CRYPTIC_CLSIG_MISSING_QUANTITIES); + goto_cleanup_if_fail_with_rc_with_warning(BN_num_bits(quantities[i]) <= clsig->lg_quantities, + CRYPTIC_CLSIG_QUANTITY_TOO_LARGE); + } + + cryptic_release(clsig->quantities); + clsig->quantities = g_malloc0(clsig->nb_quantities * sizeof (**clsig->quantities)); + if(clsig->quantities == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + + cryptic_release_bn(clsig->dlrep); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->dlrep = BN_new()); + BN_copy(clsig->dlrep,BN_value_one()); + + for(i=0;inb_quantities;i++){ + clsig->quantities[i] = NULL; + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->quantities[i] = BN_new()); + BN_copy(clsig->quantities[i],quantities[i]); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp,clsig->bases[index[i]],quantities[i],clsig->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(clsig->dlrep,clsig->dlrep,tmp,clsig->modulus,ctx) == 1); + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_mont(mont); + cryptic_release_bn(tmp); + return rc; +} + +/** + * cryptic_clsig_compute_dlrep_with_random_quantities: + * @quantities: Quantities to represent + * @nb_quantities: Number of quantities to represent + * @index: position of the first base. + * + * Helper function to represent quantities. + * The quantities given are represented with the bases ordered from the position given by the offset. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + **/ +int +cryptic_clsig_compute_dlrep_bulk_from_offset(CrypticClsig *clsig, BIGNUM **quantities, int offset, int nb_quantities) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + BIGNUM *tmp = NULL; + BN_CTX *ctx = NULL; + BN_MONT_CTX *mont = NULL; + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(mont=BN_MONT_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_MONT_CTX_set(mont,clsig->modulus,ctx)); + + goto_cleanup_if_fail_with_rc_with_warning(clsig->init == 1, + CRYPTIC_CLSIG_NOT_CORRECTLY_INITIALIZED); + goto_cleanup_if_fail_with_rc_with_warning(nb_quantities <= clsig->nb_bases, + CRYPTIC_CLSIG_TOO_MUCH_QUANTITIES); + + clsig->nb_quantities = nb_quantities; + + goto_cleanup_if_fail_with_rc_with_warning(quantities != NULL, + CRYPTIC_CLSIG_MISSING_QUANTITIES); + for(i=0;inb_quantities;i++){ + goto_cleanup_if_fail_with_rc_with_warning(quantities[i] != NULL, + CRYPTIC_CLSIG_MISSING_QUANTITIES); + goto_cleanup_if_fail_with_rc_with_warning(BN_num_bits(quantities[i]) <= clsig->lg_quantities, + CRYPTIC_CLSIG_QUANTITY_TOO_LARGE); + } + + cryptic_release(clsig->quantities); + clsig->quantities = g_malloc0(clsig->nb_quantities * sizeof (**clsig->quantities)); + if(clsig->quantities == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + + cryptic_release_bn(clsig->dlrep); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->dlrep = BN_new()); + BN_copy(clsig->dlrep,BN_value_one()); + + for(i=0;inb_quantities;i++){ + clsig->quantities[i] = NULL; + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->quantities[i] = BN_new()); + BN_copy(clsig->quantities[i],quantities[i]); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp,clsig->bases[i+offset],quantities[i],clsig->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(clsig->dlrep,clsig->dlrep,tmp,clsig->modulus,ctx) == 1); + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_mont(mont); + cryptic_release_bn(tmp); + return rc; +} + +/** + * cryptic_clsig_compute_committed_value: + * @quantities: Quantities to represent + * @nb_quantities: Number of quantities to represent + * @bases: bases of representation + * @vprime: blind factor randomly generated + * @dlrep: the resulting representation + * + * Compute the representation of quantities to commit. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + **/ +int +cryptic_clsig_compute_committed_value(CrypticClsig *clsig, CrypticCommitDataStore *pdc, BIGNUM** bases, BIGNUM** quantities, int nb_quantities) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + BIGNUM *tmp = NULL; + BN_CTX *ctx = NULL; + BN_MONT_CTX *mont = NULL; + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(mont=BN_MONT_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_MONT_CTX_set(mont,clsig->modulus,ctx)); + + goto_cleanup_if_fail_with_rc_with_warning(clsig->init == 1, + CRYPTIC_CLSIG_NOT_CORRECTLY_INITIALIZED); + goto_cleanup_if_fail_with_rc_with_warning(pdc != NULL, + CRYPTIC_ERROR_FUNCTION_PARAMETER_NOT_ALLOCATED); + goto_cleanup_if_fail_with_rc_with_warning(nb_quantities > 0, + CRYPTIC_CLSIG_NO_VALID_QUANTITIES_NUMBER); + + goto_cleanup_if_fail_with_rc_with_warning(quantities != NULL, + CRYPTIC_CLSIG_MISSING_QUANTITIES); + for(i=0;ilg_quantities, + CRYPTIC_CLSIG_QUANTITY_TOO_LARGE); + } + + goto_cleanup_if_fail_with_rc_with_warning(bases != NULL, + CRYPTIC_CLSIG_MISSING_BASES); + for(i=0;idlrep); + cryptic_release_bn(pdc->vprime); + goto_cleanup_if_fail_with_rc_with_warning_openssl(pdc->dlrep = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(pdc->vprime = BN_new()); + + cryptic_check_good_rc(cryptic_find_random(pdc->vprime, clsig->lg_modulus + clsig->lg_zk_sec_param)); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(pdc->dlrep,clsig->S,pdc->vprime,clsig->modulus,ctx,mont) == 1); + for(i=0;imodulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(pdc->dlrep,pdc->dlrep,tmp,clsig->modulus,ctx) == 1); + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_mont(mont); + cryptic_release_bn(tmp); + return rc; +} + +/** + * cryptic_clsig_compute_committed_value_with_index: + * @quantities: Quantities to represent + * @nb_quantities: Number of quantities to represent + * @index: index of the bases of representation + * @vprime: blind factor randomly generated + * @dlrep: the resulting representation + * + * Compute the representation of quantities to commit. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + **/ +int +cryptic_clsig_compute_committed_value_with_index(CrypticClsig *clsig, CrypticCommitDataStore *pdc, int *index, BIGNUM** quantities, int nb_quantities) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + BIGNUM *tmp = NULL; + BN_CTX *ctx = NULL; + BN_MONT_CTX *mont = NULL; + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(mont=BN_MONT_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_MONT_CTX_set(mont,clsig->modulus,ctx)); + + goto_cleanup_if_fail_with_rc_with_warning(clsig->init == 1, + CRYPTIC_CLSIG_NOT_CORRECTLY_INITIALIZED); + goto_cleanup_if_fail_with_rc_with_warning(pdc != NULL, + CRYPTIC_ERROR_FUNCTION_PARAMETER_NOT_ALLOCATED); + goto_cleanup_if_fail_with_rc_with_warning(nb_quantities > 0, + CRYPTIC_CLSIG_NO_VALID_QUANTITIES_NUMBER); + + goto_cleanup_if_fail_with_rc_with_warning(quantities != NULL, + CRYPTIC_CLSIG_MISSING_QUANTITIES); + for(i=0;ilg_quantities, + CRYPTIC_CLSIG_QUANTITY_TOO_LARGE); + } + + goto_cleanup_if_fail_with_rc_with_warning(clsig->bases != NULL, + CRYPTIC_CLSIG_MISSING_BASES); + for(i=0;ibases[i] != NULL, + CRYPTIC_CLSIG_MISSING_BASES); + } + + cryptic_release_bn(pdc->dlrep); + cryptic_release_bn(pdc->vprime); + goto_cleanup_if_fail_with_rc_with_warning_openssl(pdc->dlrep = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(pdc->vprime = BN_new()); + + cryptic_check_good_rc(cryptic_find_random(pdc->vprime, clsig->lg_modulus + clsig->lg_zk_sec_param)); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(pdc->dlrep,clsig->S,pdc->vprime,clsig->modulus,ctx,mont) == 1); + for(i=0;ibases[index[i]],quantities[i],clsig->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(pdc->dlrep,pdc->dlrep,tmp,clsig->modulus,ctx) == 1); + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_mont(mont); + cryptic_release_bn(tmp); + return rc; +} + +/* Z. Ri^mi * A_rand^-(2le-1) = A_rand^e_corrected . S^v_rand . Rj^mj */ + +BIGNUM* +cryptic_clsig_correct_dlrep_before_proving(CrypticClsig *clsig, BIGNUM* dlrep) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BIGNUM *two = NULL, *lg = NULL, *tmp = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(lg = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(two = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(two,2) == 1); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(tmp,clsig->lg_exponent-1) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(lg,two,tmp,ctx)); /* 2le-1 */ + BN_copy(tmp,clsig->A_rand); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_inverse(tmp,tmp,clsig->modulus,ctx)); /* A_rand^-*/ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp(tmp,tmp,lg,clsig->modulus,ctx) == 1); /* A_rand^-(2le-1) */ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(tmp,dlrep,tmp,clsig->modulus,ctx) == 1); /* * A_rand^-(2le-1) */ + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(two); + cryptic_release_bn(lg); + cryptic_release_bn(tmp); + return tmp; +} + +BIGNUM* +cryptic_clsig_build_dlrep_before_proving(CrypticClsig *clsig, int* index_quantities, int* index_bases, int nb_quantities) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + BIGNUM *two = NULL, *lg = NULL, *tmp1 = NULL, *tmp2 = NULL; + BN_CTX *ctx = NULL; + + if(!nb_quantities || nb_quantities == 0) goto cleanup; + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp2 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(lg = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(two = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(two,2) == 1); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(tmp1,clsig->lg_exponent-1) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(lg,two,tmp1,ctx)); /* 2le-1 */ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tmp1,clsig->A_rand)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_inverse(tmp1,tmp1,clsig->modulus,ctx)); /* A_rand^-*/ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp(tmp1,tmp1,lg,clsig->modulus,ctx) == 1); /* A_rand^-(2le-1) */ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(tmp1,clsig->Z,tmp1,clsig->modulus,ctx) == 1); /* Z * A_rand^-(2le-1) */ + + for(i=0;ibases[index_bases[i]],clsig->modulus,ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp(tmp2,tmp2,clsig->quantities[index_quantities[i]],clsig->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(tmp1,tmp1,tmp2,clsig->modulus,ctx) == 1); + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(two); + cryptic_release_bn(lg); + cryptic_release_bn(tmp2); + if(rc != CRYPTIC_NO_ERROR){ + cryptic_release_bn(tmp1); + return NULL; + } + return tmp1; + +} + +/** + * cryptic_clsig_run_zkpk_schnorr_round1: + * @shn: CrypticZkpkSchnorr object + * + * Run the first round of a schnorr zkpk to choose randoms of good size. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + **/ + /* IBM: RZ3730 (#99740) 03/19/2009 */ + /* re : lei + l0 + lH */ /* lH = lc = lm*/ + /* rv' : lv + l0 + lH */ + /* rmi : lm + l0 + lH */ + /* Else, in cryptic_zkpk_schnorr_round1() random size is the modulus size. */ + /* This does not match these requirements on random size since lv > ln + l0 + lH + max ( lm+lr+3 , l0+2 ) */ +int +cryptic_clsig_run_zkpk_schnorr_round1(CrypticClsig *clsig, CrypticZkpkSchnorr *shn) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + BIGNUM *randoms[shn->nb_quantities]; + for(i=0;inb_quantities;i++){ + randoms[i] = NULL; + } + + goto_cleanup_if_fail_with_rc_with_warning_openssl(randoms[0] = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(randoms[1] = BN_new()); + int fixed_add_size = clsig->lg_zk_sec_param + clsig->lg_quantities; + cryptic_find_random(randoms[0],clsig->interval_exponent + fixed_add_size); + cryptic_find_random(randoms[1],clsig->lg_blind + fixed_add_size); + for(i=2;inb_quantities;i++){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(randoms[i] = BN_new()); + cryptic_find_random(randoms[i],clsig->lg_quantities + fixed_add_size); + } + + cryptic_check_good_rc(cryptic_zkpk_schnorr_round1_randoms_chosen(shn,randoms)); + + rc = CRYPTIC_NO_ERROR; +cleanup: + for(i=0;inb_quantities;i++){ + cryptic_release_bn(randoms[i]); + } + return rc; +} + +/* Helper functions to extract parameters */ +int +cryptic_clsig_copy_generators_in_tab(BIGNUM **ret, CrypticClsig *clsig) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + for(i=0; inb_bases; i++){ + ret[i] = NULL; + } + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ret[0] = BN_new()); + BN_copy(ret[0],clsig->A_rand); + goto_cleanup_if_fail_with_rc_with_warning_openssl(ret[1] = BN_new()); + BN_copy(ret[1],clsig->S); + for(i=0; inb_bases; i++){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(ret[i+2] = BN_new()); + BN_copy(ret[i+2],clsig->bases[i]); + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + return rc; +} + +int +cryptic_clsig_copy_generators_by_index_in_tab(BIGNUM **ret, CrypticClsig *clsig,int *index,int nb_gen) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + for(i=0; iA_rand); + goto_cleanup_if_fail_with_rc_with_warning_openssl(ret[1] = BN_new()); + BN_copy(ret[1],clsig->S); + for(i=0; ibases[index[i]]); + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + return rc; +} + +int +cryptic_clsig_copy_generators_bulk_from_offset_in_tab(BIGNUM **ret, CrypticClsig *clsig, int offset,int nb_gen) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + for(i=0; iA_rand); + goto_cleanup_if_fail_with_rc_with_warning_openssl(ret[1] = BN_new()); + BN_copy(ret[1],clsig->S); + for(i=0; ibases[i+offset]); + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + return rc; +} + +int +cryptic_clsig_copy_quantities_in_tab(BIGNUM **ret, CrypticClsig *clsig) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + for(i=0; inb_quantities; i++){ + ret[i] = NULL; + } + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ret[0] = BN_new()); + BN_copy(ret[0],clsig->e); + goto_cleanup_if_fail_with_rc_with_warning_openssl(ret[1] = BN_new()); + BN_copy(ret[1],clsig->v_rand); + for(i=0; inb_quantities; i++){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(ret[i+2] = BN_new()); + BN_copy(ret[i+2],clsig->quantities[i]); + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + return rc; +} + +/* Getters */ +BIGNUM* +cryptic_clsig_get_private_composite(CrypticClsig *clsig) +{ + cryptic_return_null_if_fail(clsig->qrg); + return cryptic_qrg_get_p(clsig->qrg); +} + +BIGNUM* +cryptic_clsig_get_order(CrypticClsig *clsig) +{ + cryptic_return_null_if_fail(clsig->qrg); + return cryptic_qrg_get_order(clsig->qrg); +} + +BIGNUM* +cryptic_clsig_get_modulus(CrypticClsig *clsig) +{ + cryptic_return_null_if_fail(clsig->modulus); + return clsig->modulus; +} + +BIGNUM* +cryptic_clsig_get_exponent(CrypticClsig *clsig) +{ + cryptic_return_null_if_fail(clsig->e); + return clsig->e; +} + +BIGNUM* +cryptic_clsig_get_exponent_corrected(CrypticClsig *clsig) +{ + cryptic_return_null_if_fail(clsig->e_corrected); + return clsig->e_corrected; +} + +BIGNUM* +cryptic_clsig_get_private_exponent(CrypticClsig *clsig) +{ + cryptic_return_null_if_fail(clsig->d); + return clsig->d; +} + +BIGNUM* +cryptic_clsig_get_signature(CrypticClsig *clsig) +{ + cryptic_return_null_if_fail(clsig->A); + return clsig->A; +} + +BIGNUM* +cryptic_clsig_get_randomized_signature(CrypticClsig *clsig) +{ + cryptic_return_null_if_fail(clsig->A_rand); + return clsig->A_rand; +} + +BIGNUM* +cryptic_clsig_get_random_for_randomized_signature(CrypticClsig *clsig) +{ + cryptic_return_null_if_fail(clsig->r); + return clsig->r; +} + +BIGNUM* +cryptic_clsig_get_DL_representation(CrypticClsig *clsig) +{ + cryptic_return_null_if_fail(clsig->dlrep); + return clsig->dlrep; +} + +BIGNUM* +cryptic_clsig_get_blind(CrypticClsig *clsig) +{ + cryptic_return_null_if_fail(clsig->v); + return clsig->v; +} + +BIGNUM* +cryptic_clsig_get_random_blind(CrypticClsig *clsig) +{ + cryptic_return_null_if_fail(clsig->v_rand); + return clsig->v_rand; +} + +BIGNUM* +cryptic_clsig_get_S(CrypticClsig *clsig) +{ + cryptic_return_null_if_fail(clsig->S); + return clsig->S; +} + +BIGNUM* +cryptic_clsig_get_Z(CrypticClsig *clsig) +{ + cryptic_return_null_if_fail(clsig->Z); + return clsig->Z; +} + +BIGNUM** +cryptic_clsig_get_bases(CrypticClsig *clsig) +{ + cryptic_return_null_if_fail(clsig->bases); + return clsig->bases; +} + +BIGNUM** +cryptic_clsig_get_quantities(CrypticClsig *clsig) +{ + cryptic_return_null_if_fail(clsig->quantities); + return clsig->quantities; +} + +BIGNUM* +cryptic_clsig_get_i_base(CrypticClsig *clsig, int i) +{ + cryptic_return_null_if_fail(clsig->bases[i]); + return clsig->bases[i]; +} + +BIGNUM* +cryptic_clsig_get_i_quantity(CrypticClsig *clsig, int i) +{ + cryptic_return_null_if_fail(clsig->quantities[i]); + return clsig->quantities[i]; +} + +int +cryptic_clsig_get_nb_quantities(CrypticClsig *clsig) +{ + return clsig->nb_quantities; +} + +int +cryptic_clsig_get_nb_bases(CrypticClsig *clsig) +{ + return clsig->nb_bases; +} + +int +cryptic_clsig_get_lg_quantities(CrypticClsig *clsig) +{ + return clsig->lg_quantities; +} + +int +cryptic_clsig_get_lg_modulus(CrypticClsig *clsig) +{ + return clsig->lg_modulus; +} + +int +cryptic_clsig_get_lg_blind(CrypticClsig *clsig) +{ + return clsig->lg_blind; +} + +int +cryptic_clsig_get_lg_randomize(CrypticClsig *clsig) +{ + return clsig->lg_randomize; +} + +int +cryptic_clsig_get_lg_exponent(CrypticClsig *clsig) +{ + return clsig->lg_exponent; +} + +int +cryptic_clsig_get_interval_exponent(CrypticClsig *clsig) +{ + return clsig->interval_exponent; +} + +int +cryptic_clsig_get_lg_sec_param(CrypticClsig *clsig) +{ + return clsig->lg_sec_param; +} + +int +cryptic_clsig_get_lg_zk_sec_param(CrypticClsig *clsig) +{ + return clsig->lg_zk_sec_param; +} + +int +cryptic_clsig_get_lg_clsig_sec_param(CrypticClsig *clsig) +{ + return clsig->lg_clsig_sec_param; +} diff --git a/cryptic/protocols/clsig/clsig_vrf.c b/cryptic/protocols/clsig/clsig_vrf.c new file mode 100755 index 0000000..138fc23 --- /dev/null +++ b/cryptic/protocols/clsig/clsig_vrf.c @@ -0,0 +1,551 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include + +#include "../../errors.h" +#include "../../utils.h" + +#include "clsig.h" + +/** + * Load certificate should always be used by the prover to check certificate validity + * because these functions rebuild the DL representation. + **/ + +/** + * cryptic_clsig_load_certificate + * @A: Signature value + * @e: RSA exponent + * @v: blind factor + * @quantities: quantities signed + * @nb_quantities: number of quantities + * + * Load a certificate: tuple (A,e,v) and the quantities. + * Compute the DL representation starting using the first base. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + **/ +int +cryptic_clsig_load_certificate(CrypticClsig *clsig, + BIGNUM *A, + BIGNUM *e, + BIGNUM *v, + BIGNUM **quantities, + int nb_quantities, + int sig_checking) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BIGNUM *tmp = NULL, *two = NULL, *lg = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(clsig->init == 1, + CRYPTIC_CLSIG_NOT_CORRECTLY_INITIALIZED); + goto_cleanup_if_fail_with_rc_with_warning(A != NULL, + CRYPTIC_CLSIG_LOADING_CERTIFICATE_MISSING_ELEMENT); + goto_cleanup_if_fail_with_rc_with_warning(e != NULL, + CRYPTIC_CLSIG_LOADING_CERTIFICATE_MISSING_ELEMENT); + goto_cleanup_if_fail_with_rc_with_warning(v != NULL, + CRYPTIC_CLSIG_LOADING_CERTIFICATE_MISSING_ELEMENT); + goto_cleanup_if_fail_with_rc_with_warning(BN_num_bits(e) == clsig->lg_exponent, + CRYPTIC_CLSIG_EXPONENT_BAD_SIZE); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(lg = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(two = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(two,2) == 1); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + /* Take e in [2^le-1, 2^le-1 + 2^lei-1] */ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(lg,clsig->lg_exponent-1) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(tmp,two,lg, ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(lg,clsig->interval_exponent-1) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(lg,two,lg, ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(lg,tmp,lg)); + + goto_cleanup_if_fail_with_rc_with_warning(BN_ucmp(clsig->e,lg) < 0, + CRYPTIC_CLSIG_EXPONENT_BAD_SIZE); + + cryptic_check_good_rc(cryptic_clsig_compute_dlrep_bulk_from_offset(clsig, quantities, 0, nb_quantities)); + + cryptic_release_bn(clsig->A); + cryptic_release_bn(clsig->e); + cryptic_release_bn(clsig->v); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->A = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(clsig->A,A)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->e = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(clsig->e,e)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->v = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(clsig->v,v)); + + clsig->sigloaded = 1; + + if (sig_checking) { + cryptic_check_good_rc(cryptic_clsig_verify_signature_not_randomized(clsig)); + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(two); + cryptic_release_bn(lg); + cryptic_release_bn(tmp); + return rc; +} + +/** + * cryptic_clsig_load_certificate_with_index + * @A: Signature value + * @e: RSA exponent + * @v: blind factor + * @quantities: quantities signed + * @nb_quantities: number of quantities + * @index: indicate the bases of representation + * + * Load a certificate: tuple (A,e,v) and the quantities + * Compute the DL representation using the base given by the index. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + **/ +int +cryptic_clsig_load_certificate_with_index(CrypticClsig *clsig, + BIGNUM *A, + BIGNUM *e, + BIGNUM *v, + BIGNUM **quantities, + int nb_quantities, + int* index, + int sig_checking) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BIGNUM *tmp = NULL, *two = NULL, *lg = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(clsig->init == 1, + CRYPTIC_CLSIG_NOT_CORRECTLY_INITIALIZED); + goto_cleanup_if_fail_with_rc_with_warning(A != NULL, + CRYPTIC_CLSIG_LOADING_CERTIFICATE_MISSING_ELEMENT); + goto_cleanup_if_fail_with_rc_with_warning(e != NULL, + CRYPTIC_CLSIG_LOADING_CERTIFICATE_MISSING_ELEMENT); + goto_cleanup_if_fail_with_rc_with_warning(v != NULL, + CRYPTIC_CLSIG_LOADING_CERTIFICATE_MISSING_ELEMENT); + goto_cleanup_if_fail_with_rc_with_warning(BN_num_bits(e) == clsig->lg_exponent, + CRYPTIC_CLSIG_EXPONENT_BAD_SIZE); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(lg = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(two = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(two,2) == 1); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + /* Take e in [2^le-1, 2^le-1 + 2^lei-1] */ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(lg,clsig->lg_exponent-1) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(tmp,two,lg, ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(lg,clsig->interval_exponent-1) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(lg,two,lg, ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(lg,tmp,lg)); + + goto_cleanup_if_fail_with_rc_with_warning(BN_ucmp(clsig->e,lg) < 0, + CRYPTIC_CLSIG_EXPONENT_BAD_SIZE); + + cryptic_check_good_rc(cryptic_clsig_compute_dlrep_by_index(clsig, quantities, index, nb_quantities)); + + cryptic_release_bn(clsig->A); + cryptic_release_bn(clsig->e); + cryptic_release_bn(clsig->v); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->A = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(clsig->A,A)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->e = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(clsig->e,e)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->v = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(clsig->v,v)); + + clsig->sigloaded = 1; + + if (sig_checking) { + cryptic_check_good_rc(cryptic_clsig_verify_signature_not_randomized(clsig)); + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(two); + cryptic_release_bn(lg); + cryptic_release_bn(tmp); + return rc; +} + +/** + * cryptic_clsig_load_certificate_with_committed_value + * @A: Signature value + * @e: RSA exponent + * @v: blind factor + * @quantities: quantities signed + * @nb_quantities: number of quantities + * @quantities: quantities committed signed + * @nb_quantities: number of quantities committed + * @vprime: blind factor of the quantities committed + * @commitment: Representation of the quantities committed + * + * Load a certificate: tuple (A,e,v) and the quantities + * The bases for the not commited values are taken in order from the first one. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + **/ +int +cryptic_clsig_load_certificate_with_committed_value(CrypticClsig *clsig, + BIGNUM *A, + BIGNUM *e, + BIGNUM *v, + BIGNUM **quantities, int nb_quantities, + BIGNUM **quantitiesC, int nb_quantitiesC, + BIGNUM *commitment, BIGNUM *vprime) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + BIGNUM *tmp = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(clsig->init == 1, + CRYPTIC_CLSIG_NOT_CORRECTLY_INITIALIZED); + goto_cleanup_if_fail_with_rc_with_warning(vprime != NULL, + CRYPTIC_CLSIG_MISSING_SIGN_BLIND_RANDOM); + goto_cleanup_if_fail_with_rc_with_warning(commitment != NULL, + CRYPTIC_CLSIG_MISSING_SIGN_BLIND_COMMITMENT); + goto_cleanup_if_fail_with_rc_with_warning(nb_quantitiesC > 0, + CRYPTIC_CLSIG_NO_VALID_QUANTITIES_NUMBER); + goto_cleanup_if_fail_with_rc_with_warning(quantitiesC != NULL, + CRYPTIC_CLSIG_MISSING_QUANTITIES); + for(i=0;ilg_quantities, + CRYPTIC_CLSIG_QUANTITY_TOO_LARGE); + } + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + cryptic_check_good_rc(cryptic_clsig_load_certificate(clsig, A, e, v, quantities, nb_quantities, 0)); + + /* commitment = committed_dlrep * S^vprime */ + /* commitment * S^-vprime = committed_dlrep */ + /* clsig->dlrep := clsig->dlrep * committed_dlrep */ + /* clsig->v := clsig->v + vprime */ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_inverse(tmp,clsig->S,clsig->modulus,ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp(tmp,tmp,vprime,clsig->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(tmp,tmp,commitment,clsig->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(clsig->dlrep,clsig->dlrep,tmp,clsig->modulus,ctx) == 1); + + clsig->sigloaded = 1; + + for(i=0;iquantities[clsig->nb_quantities+i] = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(clsig->quantities[clsig->nb_quantities+i],quantitiesC[i])); + } + clsig->nb_quantities = clsig->nb_quantities + nb_quantitiesC; + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(clsig->v,clsig->v,vprime)); + + cryptic_check_good_rc(cryptic_clsig_verify_signature_not_randomized(clsig)); + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(tmp); + return rc; +} + +/** + * cryptic_clsig_load_certificate_with_index_with_committed_value + * @A: Signature value + * @e: RSA exponent + * @v: blind factor + * @quantities: quantities signed + * @nb_quantities: number of quantities + * @quantities: quantities committed signed + * @nb_quantities: number of quantities committed + * @vprime: blind factor of the quantities committed + * @commitment: Representation of the quantities committed + * @index: index of the bases used for representation + * + * Load a certificate: tuple (A,e,v) and the quantities + * Compute the DL representation using the base given by the index for the not committed values. + * WARNING: index of the bases used for the not committed to the issuer values + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + **/ +int +cryptic_clsig_load_certificate_with_index_with_committed_value(CrypticClsig *clsig, + BIGNUM *A, + BIGNUM *e, + BIGNUM *v, + BIGNUM **quantities, int nb_quantities, + BIGNUM **quantitiesC, int nb_quantitiesC, + BIGNUM *commitment, BIGNUM *vprime, + int *index) +{ + + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + BIGNUM *tmp = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(clsig->init == 1, + CRYPTIC_CLSIG_NOT_CORRECTLY_INITIALIZED); + goto_cleanup_if_fail_with_rc_with_warning(vprime != NULL, + CRYPTIC_CLSIG_MISSING_SIGN_BLIND_RANDOM); + goto_cleanup_if_fail_with_rc_with_warning(commitment != NULL, + CRYPTIC_CLSIG_MISSING_SIGN_BLIND_COMMITMENT); + goto_cleanup_if_fail_with_rc_with_warning(nb_quantitiesC > 0, + CRYPTIC_CLSIG_NO_VALID_QUANTITIES_NUMBER); + goto_cleanup_if_fail_with_rc_with_warning(quantitiesC != NULL, + CRYPTIC_CLSIG_MISSING_QUANTITIES); + for(i=0;ilg_quantities, + CRYPTIC_CLSIG_QUANTITY_TOO_LARGE); + } + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + cryptic_check_good_rc(cryptic_clsig_load_certificate_with_index(clsig, A, e, v, quantities, nb_quantities, index, 0)); + + /* commitment = committed_dlrep * S^vprime */ + /* commitment * S^-vprime = committed_dlrep */ + /* clsig->dlrep := clsig->dlrep * committed_dlrep */ + /* clsig->v := clsig->v + vprime */ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_inverse(tmp,clsig->S,clsig->modulus,ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp(tmp,tmp,vprime,clsig->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(tmp,tmp,commitment,clsig->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(clsig->dlrep,clsig->dlrep,tmp,clsig->modulus,ctx) == 1); + + clsig->sigloaded = 1; + + for(i=0;iquantities[clsig->nb_quantities+i] = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(clsig->quantities[clsig->nb_quantities+i],quantitiesC[i])); + } + clsig->nb_quantities = clsig->nb_quantities + nb_quantitiesC; + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(clsig->v,clsig->v,vprime)); + + cryptic_check_good_rc(cryptic_clsig_verify_signature_not_randomized(clsig)); + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(tmp); + return rc; +} + +/** + * cryptic_clsig_verify_signature_not_randomized + * + * Verify a signature value not randomized. + * + * Return value: 1 if signature valid, 0 if signature invalid, an error code otherwise. + * + **/ +int +cryptic_clsig_verify_signature_not_randomized(CrypticClsig *clsig) +{ + + int rc = CRYPTIC_ERROR_UNDEFINED; + + int res; + BIGNUM *tmp1 = NULL, *tmp2 = NULL; + BN_CTX *ctx = NULL; + BN_MONT_CTX *mont = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(clsig->init == 1, + CRYPTIC_CLSIG_NOT_CORRECTLY_INITIALIZED); + goto_cleanup_if_fail_with_rc_with_warning(clsig->sigloaded == 1, + CRYPTIC_CLSIG_SIGNATURE_NOT_CORRECTLY_LOADED); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp2 = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(mont=BN_MONT_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_MONT_CTX_set(mont,clsig->modulus,ctx)); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp1,clsig->S,clsig->v,clsig->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(tmp1,tmp1,clsig->dlrep,clsig->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp2,clsig->A,clsig->e,clsig->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(tmp1,tmp1,tmp2,clsig->modulus,ctx) == 1); + + if (BN_ucmp(clsig->Z, tmp1) == 0){ + clsig->sigverified = 1; + res = 1; + } else{ + res = 0; + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_mont(mont); + cryptic_release_bn(tmp2); + cryptic_release_bn(tmp1); + if(rc != CRYPTIC_NO_ERROR) return rc; + return res; +} + +/** + * cryptic_clsig_verify_signature_not_randomized_prover + * + * Verify a signature value randomized. + * + * Return value: 1 if signature valid, 0 if signature invalid, an error code otherwise. + * + **/ +int +cryptic_clsig_verify_signature_randomized(CrypticClsig *clsig) +{ + + int rc = CRYPTIC_ERROR_UNDEFINED; + + int res; + BIGNUM *tmp1 = NULL, *tmp2 = NULL; + BN_CTX *ctx = NULL; + BN_MONT_CTX *mont = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(clsig->sigrandomized == 1, + CRYPTIC_CLSIG_SIGNATURE_NOT_RANDOMIZED); + goto_cleanup_if_fail_with_rc_with_warning(clsig->A_rand != NULL, + CRYPTIC_CLSIG_SIGNATURE_NOT_RANDOMIZED); + goto_cleanup_if_fail_with_rc_with_warning(clsig->e_corrected != NULL, + CRYPTIC_CLSIG_SIGNATURE_NOT_RANDOMIZED); + goto_cleanup_if_fail_with_rc_with_warning(clsig->v_rand != NULL, + CRYPTIC_CLSIG_SIGNATURE_NOT_RANDOMIZED); + goto_cleanup_if_fail_with_rc_with_warning(clsig->S != NULL, + CRYPTIC_CLSIG_SIGNATURE_NOT_RANDOMIZED); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp2 = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(mont=BN_MONT_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_MONT_CTX_set(mont,clsig->modulus,ctx)); + + if(BN_is_negative(clsig->v_rand)){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tmp2,clsig->S)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_inverse(clsig->S,clsig->S,clsig->modulus,ctx)); + } + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp1,clsig->S,clsig->v_rand,clsig->modulus,ctx,mont) == 1); + if(BN_is_negative(clsig->v_rand)) goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(clsig->S,tmp2)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp2,clsig->A_rand,clsig->e,clsig->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(tmp1,tmp1,tmp2,clsig->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(tmp1,tmp1,clsig->dlrep,clsig->modulus,ctx) == 1); + + if (BN_ucmp(clsig->Z, tmp1) == 0){ + res = 1; + } else{ + res = 0; + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_mont(mont); + cryptic_release_bn(tmp2); + cryptic_release_bn(tmp1); + if(rc != CRYPTIC_NO_ERROR) return rc; + return res; +} + +/** + * cryptic_clsig_verify_rsa_param + * + * Check validity of a RSA key pair. + * + * Return value: 1 if signature valid, 0 if signature invalid, an error code otherwise. + * + **/ +int +cryptic_clsig_verify_rsa_param(CrypticClsig *clsig) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BIGNUM *tmp1 = NULL, *tmp2 = NULL; + BN_CTX *ctx = NULL; + RSA *key = RSA_new(); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp2 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(key->n = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(key->e = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(key->d = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(key->p = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(key->q = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(key->dmp1 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(key->dmq1 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(key->iqmp = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(key->n,clsig->modulus)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(key->p,cryptic_qrg_get_p(clsig->qrg))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(key->q,cryptic_qrg_get_q(clsig->qrg))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(key->e,clsig->e)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(key->d,clsig->d)); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(tmp1,cryptic_qrg_get_p(clsig->qrg),BN_value_one())); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod(key->dmp1,key->d,tmp1,ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(tmp1,key->q,BN_value_one())); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod(key->dmq1,key->d,tmp1,ctx)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_inverse(key->iqmp,key->q,key->p,ctx)); + + /*if (r == 1){ + printf("RSA key ok\n"); + } + else if (r == 0){ + printf("RSA key ko\n"); + unsigned long err; + while ((err = ERR_peek_error()) != 0 ){ + printf("RSA key error: %d\n", ERR_reason_error_string(err)); + ERR_get_error(); + } + }*/ + goto_cleanup_if_fail_with_rc_with_warning(RSA_check_key(key) == 1, CRYPTIC_CLSIG_BAD_RSA_KEY_PAIR); + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(tmp2); + cryptic_release_bn(tmp1); + if(key) RSA_free(key); + if(rc == CRYPTIC_NO_ERROR) return 1; + return rc; +} diff --git a/cryptic/protocols/clsig/commit_data_store.c b/cryptic/protocols/clsig/commit_data_store.c new file mode 100644 index 0000000..2080dc9 --- /dev/null +++ b/cryptic/protocols/clsig/commit_data_store.c @@ -0,0 +1,109 @@ +/* X23 -- Certificates tools + * Copyright (C) 2010 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include + +#include "../../errors.h" +#include "../../utils.h" + +#include "commit_data_store.h" + +/*****************************************************************************/ +/* private methods */ +/*****************************************************************************/ + +static GObjectClass *parent_class = NULL; + +/*****************************************************************************/ +/* overridden parent class methods */ +/*****************************************************************************/ + +static void +dispose(GObject *object) +{ + CrypticCommitDataStore *pdc = CRYPTIC_COMMITDATASTORE(object); + + cryptic_release_bn(pdc->dlrep); + cryptic_release_bn(pdc->vprime); + + G_OBJECT_CLASS(parent_class)->dispose(G_OBJECT(pdc)); +} + +/*****************************************************************************/ +/* instance and class init functions */ +/*****************************************************************************/ + +static void +instance_init(CrypticCommitDataStore *pdc) +{ + pdc->dlrep = NULL; + pdc->vprime = NULL; +} + +static void +class_init(CrypticCommitDataStoreClass *klass) +{ + parent_class = g_type_class_peek_parent(klass); + G_OBJECT_CLASS(klass)->dispose = dispose; +} + +/*****************************************************************************/ +/* public methods */ +/*****************************************************************************/ + +GType +cryptic_commit_data_store_get_type() +{ + static GType this_type = 0; + if (!this_type) { + static const GTypeInfo this_info = { + sizeof (CrypticCommitDataStoreClass), + NULL, + NULL, + (GClassInitFunc) class_init, + NULL, + NULL, + sizeof(CrypticCommitDataStore), + 0, + (GInstanceInitFunc) instance_init, + NULL + }; + this_type = g_type_register_static(G_TYPE_OBJECT, + "CrypticCommitDataStore", &this_info, 0); + } + return this_type; +} + +/** + * cryptic_commit_data_store_new + * + * Creates a new #CrypticCommitDataStore. + * + * Return value: a newly created #CrypticCommitDataStore object; or NULL if an error + * occured + **/ +CrypticCommitDataStore* +cryptic_commit_data_store_new() +{ + CrypticCommitDataStore *pdc; + pdc = g_object_new(CRYPTIC_TYPE_COMMITDATASTORE, NULL); + return pdc; +} diff --git a/cryptic/protocols/clsig/commit_data_store.h b/cryptic/protocols/clsig/commit_data_store.h new file mode 100644 index 0000000..eb4aa49 --- /dev/null +++ b/cryptic/protocols/clsig/commit_data_store.h @@ -0,0 +1,75 @@ +/* CRYPTIC -- Certificates tools + * Copyright (C) 2010 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef CRYPTIC_COMMITDATASTORE_H +#define CRYPTIC_COMMITDATASTORE_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/*#ifndef CRYPTIC_SCHNORR_CHALLENGE_MIN_SIZE +#define CRYPTIC_SCHNORR_CHALLENGE_MIN_SIZE 80 +#endif*/ + +#include +#include +#include + +#include "../../export.h" + +#define CRYPTIC_TYPE_COMMITDATASTORE (cryptic_commit_data_store_get_type()) +#define CRYPTIC_COMMITDATASTORE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CRYPTIC_TYPE_COMMITDATASTORE, CrypticCommitDataStore)) +#define CRYPTIC_COMMITDATASTORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), CRYPTIC_TYPE_COMMITDATASTORE, CrypticCommitDataStoreClass)) +#define CRYPTIC_IS_COMMITDATASTORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), CRYPTIC_TYPE_COMMITDATASTORE)) +#define CRYPTIC_IS_COMMITDATASTORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CRYPTIC_TYPE_COMMITDATASTORE)) +#define CRYPTIC_COMMITDATASTORE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CRYPTIC_TYPE_COMMITDATASTORE, CrypticCommitDataStoreClass)) + +typedef struct _CrypticCommitDataStore CrypticCommitDataStore; +typedef struct _CrypticCommitDataStoreClass CrypticCommitDataStoreClass; + +/** + * CrypticCommitDataStore: + * @dlrep: DL representation to prove. + * @vprime: S exponent for commit (roughtly a blind value). + * + * Store to avoid multiple return parameters not easily manageable with bindings. + * + */ +struct _CrypticCommitDataStore { + GObject parent; + + /*< public >*/ + BIGNUM *vprime; + BIGNUM *dlrep; + +}; + +struct _CrypticCommitDataStoreClass { + GObjectClass parent_class; +}; + +CRYPTIC_EXPORT GType cryptic_commit_data_store_get_type(void); + +CRYPTIC_EXPORT CrypticCommitDataStore* cryptic_commit_data_store_new(); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* CRYPTIC_COMMITDATASTORE_H */ diff --git a/cryptic/protocols/pok_schnorr/commitments_utils.c b/cryptic/protocols/pok_schnorr/commitments_utils.c new file mode 100644 index 0000000..1c93fdd --- /dev/null +++ b/cryptic/protocols/pok_schnorr/commitments_utils.c @@ -0,0 +1,138 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include + +#include "../../errors.h" +#include "../../utils.h" + +#include "commitments_utils.h" + +BIGNUM* +cryptic_get_dlrep(int nb_quantities, BIGNUM **quantities,BIGNUM **bases,BIGNUM *modulus) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int j; + BIGNUM *ret = NULL, *tmp = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail(modulus != NULL && quantities != NULL && bases != NULL); + + for(j=0; j + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef CRYPTIC_COMMITMENTS_UTILS_H +#define CRYPTIC_COMMITMENTS_UTILS_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include + +#include "../../export.h" + +CRYPTIC_EXPORT BIGNUM* cryptic_get_dlrep(int nb_quantities, BIGNUM **quantities,BIGNUM **bases,BIGNUM *modulus); +CRYPTIC_EXPORT BIGNUM* cryptic_inv_mod(BIGNUM* value, BIGNUM* modulus); +CRYPTIC_EXPORT int cryptic_cmp_bn(BIGNUM* value1, BIGNUM* value2); +CRYPTIC_EXPORT BIGNUM* cryptic_char_to_bn(char* value); +CRYPTIC_EXPORT BIGNUM* cryptic_int_to_bn(int value); + +//set_int_to_bn +//set_string_to_bn + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* CRYPTIC_PROTOCOLS_POK_SCHNORR_H */ diff --git a/cryptic/protocols/pok_schnorr/hash_for_ni_proofs.c b/cryptic/protocols/pok_schnorr/hash_for_ni_proofs.c new file mode 100644 index 0000000..e29f320 --- /dev/null +++ b/cryptic/protocols/pok_schnorr/hash_for_ni_proofs.c @@ -0,0 +1,614 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2010 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include +#include +#include +#include +#include + +#include "../../errors.h" +#include "../../utils.h" + +#include "hash_for_ni_proofs.h" + +/*****************************************************************************/ +/* private methods */ +/*****************************************************************************/ + +static GObjectClass *parent_class = NULL; + +/*****************************************************************************/ +/* overridden parent class methods */ +/*****************************************************************************/ + +static void +dispose(GObject *object) +{ + CrypticHashForNiProofs *h = CRYPTIC_HASHFORNIPROOFS(object); + + int i; + + if(h->modulus != NULL) { + for(i=0;inb_modulus;i++){ + cryptic_release_bn(h->modulus[i]); + } + } + cryptic_release(h->modulus); + if(h->bases != NULL) { + for(i=0;inb_bases;i++){ + cryptic_release_bn(h->bases[i]); + } + } + cryptic_release(h->bases); + if(h->dlreps != NULL) { + for(i=0;inb_dlreps;i++){ + cryptic_release_bn(h->dlreps[i]); + } + } + cryptic_release(h->dlreps); + if(h->commitments != NULL) { + for(i=0;inb_commitments;i++){ + cryptic_release_bn(h->commitments[i]); + } + } + cryptic_release(h->commitments); + cryptic_release_bn(h->h_value); + + G_OBJECT_CLASS(parent_class)->dispose(G_OBJECT(h)); +} + +/*****************************************************************************/ +/* instance and class init functions */ +/*****************************************************************************/ + +static void +instance_init(CrypticHashForNiProofs *h) +{ + h->modulus = NULL; + h->bases = NULL; + h->dlreps = NULL; + h->commitments = NULL; + h->h_value = NULL; +} + +static void +class_init(CrypticHashForNiProofsClass *klass) +{ + parent_class = g_type_class_peek_parent(klass); + G_OBJECT_CLASS(klass)->dispose = dispose; +} + +/*****************************************************************************/ +/* public methods */ +/*****************************************************************************/ + +GType +cryptic_hash_for_ni_proofs_get_type() +{ + static GType this_type = 0; + if (!this_type) { + static const GTypeInfo this_info = { + sizeof (CrypticHashForNiProofsClass), + NULL, + NULL, + (GClassInitFunc) class_init, + NULL, + NULL, + sizeof(CrypticHashForNiProofs), + 0, + (GInstanceInitFunc) instance_init, + NULL + }; + this_type = g_type_register_static(G_TYPE_OBJECT, + "CrypticHashForNiProofs", &this_info, 0); + } + return this_type; +} + +/** + * cryptic_hash_for_ni_proofs_new: + * @size_hash: Hash size to produce. + * + * Creates a new #CrypticHashForNiProofs. + * + * Return value: a newly created #CrypticHashForNiProofs object; or NULL if an error + * occured + **/ +CrypticHashForNiProofs* +cryptic_hash_for_ni_proofs_new(int size_h) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + CrypticHashForNiProofs *h; + h = g_object_new(CRYPTIC_TYPE_HASHFORNIPROOFS, NULL); + + if((size_h !=256) && (size_h != 512)){ + cryptic_critical("Hash size not supported."); + goto cleanup; + } + + h->size_h = size_h; + + h->nb_modulus = 0; + h->nb_bases = 0; + h->nb_dlreps = 0; + h->nb_commitments = 0; + + cryptic_release_bn(h->h_value); + cryptic_release(h->modulus); + cryptic_release(h->bases); + cryptic_release(h->dlreps); + cryptic_release(h->commitments); + + return h; +cleanup: + cryptic_release_gobject(h); + return NULL; + +} + +/** + * cryptic_hash_for_ni_proofs_add_modulus: + * @modulus: Value to add. + * + * Add a value to the modulus tab. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + **/ +int +cryptic_hash_for_ni_proofs_add_proof(CrypticHashForNiProofs* h, CrypticZkpkSchnorr *shn, BIGNUM *dlrep) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + + goto_cleanup_if_fail_with_rc_with_warning(dlrep != NULL, + CRYPTIC_HASH_NI_PROOFS_NULL_VALUE); + + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_modulus(h,shn->modulus)); + for(i=0;inb_quantities;i++){ + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_base(h,shn->bases[i])); + } + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_dlrep(h,dlrep)); + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_commitment(h,shn->commitment)); + + rc = CRYPTIC_NO_ERROR; +cleanup: + return rc; +} + +int +cryptic_hash_for_ni_proofs_add_proofrange_prover(CrypticHashForNiProofs* h, CrypticProofrangeQrg* pr) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_modulus(h,pr->modulus)); + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_base(h,pr->tabBases[0])); + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_base(h,pr->tabBases[1])); + for(i=0;i<5;i++){ + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_dlrep(h,pr->dlreps[i])); + } + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_commitment(h,pr->pokSqrRoot1->commitment)); + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_commitment(h,pr->pokSqrRoot2->commitment)); + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_commitment(h,pr->pokSqrRoot3->commitment)); + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_commitment(h,pr->pokSqrRoot4->commitment)); + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_commitment(h,pr->pokDelta->commitment)); + + rc = CRYPTIC_NO_ERROR; +cleanup: + return rc; +} + +int +cryptic_hash_for_ni_proofs_add_proofrange_verifier(CrypticHashForNiProofs* h, CrypticProofrangeQrg* pr, BIGNUM** dlreps) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + + goto_cleanup_if_fail_with_rc_with_warning(dlreps != NULL, + CRYPTIC_HASH_NI_PROOFS_NULL_VALUE); + for(i=0;i<5;i++){ + goto_cleanup_if_fail_with_rc_with_warning(dlreps[i] != NULL, + CRYPTIC_HASH_NI_PROOFS_NULL_VALUE); + } + + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_modulus(h,pr->modulus)); + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_base(h,pr->tabBases[0])); + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_base(h,pr->tabBases[1])); + for(i=0;i<5;i++){ + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_dlrep(h,dlreps[i])); + } + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_commitment(h,pr->pokSqrRoot1->commitment)); + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_commitment(h,pr->pokSqrRoot2->commitment)); + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_commitment(h,pr->pokSqrRoot3->commitment)); + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_commitment(h,pr->pokSqrRoot4->commitment)); + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_commitment(h,pr->pokDelta->commitment)); + + rc = CRYPTIC_NO_ERROR; +cleanup: + return rc; +} + +/** + * cryptic_hash_for_ni_proofs_add_modulus: + * @modulus: Value to add. + * + * Add a value to the modulus tab. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + **/ +int +cryptic_hash_for_ni_proofs_add_modulus(CrypticHashForNiProofs* h, BIGNUM* modulus) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + goto_cleanup_if_fail_with_rc_with_warning(modulus != NULL, + CRYPTIC_HASH_NI_PROOFS_NULL_VALUE); + + if(h->nb_modulus == 0) { + cryptic_release(h->modulus); + h->modulus = g_malloc0(sizeof (**h->modulus)); + if(h->modulus == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + }else{ + BIGNUM **tmp = NULL; + tmp = h->modulus; + h->modulus = g_realloc(h->modulus,(h->nb_modulus+1) * sizeof (**h->modulus)); + if(h->modulus == NULL){ + h->modulus = tmp; + tmp = NULL; + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + } + + goto_cleanup_if_fail_with_rc_with_warning_openssl(h->modulus[h->nb_modulus] = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(h->modulus[h->nb_modulus],modulus)); + + h->nb_modulus++; + + rc = CRYPTIC_NO_ERROR; +cleanup: + return rc; +} + +/** + * cryptic_hash_for_ni_proofs_add_base: + * @base: Value to add. + * + * Add a value to the bases tab. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + **/ +int +cryptic_hash_for_ni_proofs_add_base(CrypticHashForNiProofs* h, BIGNUM* base) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + goto_cleanup_if_fail_with_rc_with_warning(base != NULL, + CRYPTIC_HASH_NI_PROOFS_NULL_VALUE); + + if(h->nb_bases == 0) { + cryptic_release(h->bases); + h->bases = g_malloc0(sizeof (**h->bases)); + if(h->bases == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + }else{ + BIGNUM **tmp = NULL; + tmp = h->bases; + h->bases = g_realloc(h->bases,(h->nb_bases+1) * sizeof (**h->bases)); + if(h->bases == NULL){ + h->bases = tmp; + tmp = NULL; + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + } + + goto_cleanup_if_fail_with_rc_with_warning_openssl(h->bases[h->nb_bases] = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(h->bases[h->nb_bases],base)); + + h->nb_bases++; + + rc = CRYPTIC_NO_ERROR; +cleanup: + return rc; +} + +/** + * cryptic_hash_for_ni_proofs_add_dlrep: + * @dlrep: Value to add. + * + * Add a value to the dlreps tab. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + **/ +int +cryptic_hash_for_ni_proofs_add_dlrep(CrypticHashForNiProofs* h, BIGNUM* dlrep) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + goto_cleanup_if_fail_with_rc_with_warning(dlrep != NULL, + CRYPTIC_HASH_NI_PROOFS_NULL_VALUE); + if(h->nb_dlreps == 0) { + cryptic_release(h->dlreps); + h->dlreps = g_malloc0(sizeof (**h->dlreps)); + if(h->dlreps == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + }else{ + BIGNUM **tmp = NULL; + tmp = h->dlreps; + h->dlreps = g_realloc(h->dlreps,(h->nb_dlreps+1) * sizeof (**h->dlreps)); + if(h->dlreps == NULL){ + h->dlreps = tmp; + tmp = NULL; + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + } + + goto_cleanup_if_fail_with_rc_with_warning_openssl(h->dlreps[h->nb_dlreps] = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(h->dlreps[h->nb_dlreps],dlrep)); + + h->nb_dlreps++; + + rc = CRYPTIC_NO_ERROR; +cleanup: + return rc; +} + +/** + * cryptic_hash_for_ni_proofs_add_commitment: + * @commitment: Value to add. + * + * Add a value to the commitments tab. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + **/ +int +cryptic_hash_for_ni_proofs_add_commitment(CrypticHashForNiProofs* h, BIGNUM* commitment) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + goto_cleanup_if_fail_with_rc_with_warning(commitment != NULL, + CRYPTIC_HASH_NI_PROOFS_NULL_VALUE); + + if(h->nb_commitments == 0) { + cryptic_release(h->commitments); + h->commitments = g_malloc0(sizeof (**h->commitments)); + if(h->commitments == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + }else{ + BIGNUM **tmp = NULL; + tmp = h->commitments; + h->commitments = g_realloc(h->commitments,(h->nb_commitments+1) * sizeof (**h->commitments)); + if(h->commitments == NULL){ + h->commitments = tmp; + tmp = NULL; + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + } + + goto_cleanup_if_fail_with_rc_with_warning_openssl(h->commitments[h->nb_commitments] = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(h->commitments[h->nb_commitments],commitment)); + + h->nb_commitments++; + + rc = CRYPTIC_NO_ERROR; +cleanup: + return rc; +} + +/** + * cryptic_hash_for_ni_proofs_add_commitment: + * + * Compute the hash. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + * + **/ +int +cryptic_hash_for_ni_proofs_compute_hash(CrypticHashForNiProofs* h) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + char *concat = NULL, *tmp = NULL; + cryptic_release_string(concat); + cryptic_release_string(tmp); + + int i,j; + int s = 0; + int size = 0; + int local_size; + + if(h->modulus) { + for(i=0;inb_modulus;i++){ + if(BN_num_bits(h->modulus[i])%8 != 0) s++; + s += BN_num_bits(h->modulus[i])/8; + } + } + if(h->bases) { + for(i=0;inb_bases;i++){ + if(BN_num_bits(h->bases[i])%8 != 0) s++; + s += BN_num_bits(h->bases[i])/8; + } + } + if(h->dlreps) { + for(i=0;inb_dlreps;i++){ + if(BN_num_bits(h->dlreps[i])%8 != 0) s++; + s += BN_num_bits(h->dlreps[i])/8; + } + } + if(h->commitments) { + for(i=0;inb_commitments;i++){ + if(BN_num_bits(h->commitments[i])%8 != 0) s++; + s += BN_num_bits(h->commitments[i])/8; + } + } + + concat = g_malloc0(s * sizeof (char)); + if(concat == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + + if(h->modulus) { + for(i=0;inb_modulus;i++){ + local_size = 0; + if(BN_num_bits(h->modulus[i])%8 != 0) local_size++; + local_size += BN_num_bits(h->modulus[i])/8; + tmp = g_malloc0(local_size * sizeof (char)); + if(tmp == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_bn2bin(h->modulus[i],tmp)); + for(j=0;j<=local_size;j++){ + concat[j+size]=tmp[j]; + } + size += local_size; + cryptic_release_string(tmp); + } + } + if(h->bases) { + for(i=0;inb_bases;i++){ + local_size = 0; + if(BN_num_bits(h->bases[i])%8 != 0) local_size++; + local_size += BN_num_bits(h->bases[i])/8; + tmp = g_malloc0(local_size * sizeof (char)); + if(tmp == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_bn2bin(h->bases[i],tmp)); + for(j=0;j<=local_size;j++){ + concat[j+size]=tmp[j]; + } + size += local_size; + cryptic_release_string(tmp); + } + } + if(h->dlreps) { + for(i=0;inb_dlreps;i++){ + local_size = 0; + if(BN_num_bits(h->dlreps[i])%8 != 0) local_size++; + local_size += BN_num_bits(h->dlreps[i])/8; + tmp = g_malloc0(local_size * sizeof (char)); + if(tmp == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_bn2bin(h->dlreps[i],tmp)); + for(j=0;j<=local_size;j++){ + concat[j+size]=tmp[j]; + } + size += local_size; + cryptic_release_string(tmp); + } + } + if(h->commitments) { + for(i=0;inb_commitments;i++){ + local_size = 0; + if(BN_num_bits(h->commitments[i])%8 != 0) local_size++; + local_size += BN_num_bits(h->commitments[i])/8; + tmp = g_malloc0(local_size * sizeof (char)); + if(tmp == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_bn2bin(h->commitments[i],tmp)); + for(j=0;j<=local_size;j++){ + concat[j+size]=tmp[j]; + } + size += local_size; + cryptic_release_string(tmp); + } + } + + goto_cleanup_if_fail_with_rc_with_warning(concat != NULL && concat[0] != 0, + CRYPTIC_HASH_NI_PROOFS_ERROR_COMPUTATION); + goto_cleanup_if_fail_with_rc_with_warning(s == size, + CRYPTIC_HASH_NI_PROOFS_ERROR_COMPUTATION); + + tmp = g_malloc0((h->size_h/8) * sizeof (char)); + if(tmp == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + + if(h->size_h == 256){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(EVP_Digest (concat,size,tmp,NULL,EVP_sha256(),NULL)); + /*SHA256_CTX *c; + c = g_malloc0(sizeof (SHA256_CTX)); + SHA256_Init(c); + SHA256_Update(c, concat, size); + SHA256_Final(tmp,c); + cryptic_release(c);*/ + }else{ + goto_cleanup_if_fail_with_rc_with_warning_openssl(EVP_Digest (concat,size,tmp,NULL,EVP_sha512(),NULL)); + /*SHA512_CTX *c; + c = g_malloc0(sizeof (SHA512_CTX)); + SHA512_Init(c); + SHA512_Update(c, concat, size); + SHA512_Final(tmp,c); + cryptic_release(c);*/ + } + + goto_cleanup_if_fail_with_rc_with_warning(tmp != NULL, + CRYPTIC_HASH_NI_PROOFS_ERROR_COMPUTATION); + + cryptic_release_bn(h->h_value); + h->h_value = BN_bin2bn(tmp,h->size_h/8,NULL); + + goto_cleanup_if_fail_with_rc_with_warning(h->h_value != NULL, + CRYPTIC_HASH_NI_PROOFS_ERROR_COMPUTATION); + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_string(tmp); + cryptic_release_string(concat); + return rc; +} + +BIGNUM* +cryptic_hash_for_ni_proofs_get_hash(CrypticHashForNiProofs* h) +{ + cryptic_return_null_if_fail(h->h_value); + return h->h_value; +} + diff --git a/cryptic/protocols/pok_schnorr/hash_for_ni_proofs.h b/cryptic/protocols/pok_schnorr/hash_for_ni_proofs.h new file mode 100644 index 0000000..c5fdedd --- /dev/null +++ b/cryptic/protocols/pok_schnorr/hash_for_ni_proofs.h @@ -0,0 +1,95 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef CRYPTIC_HASH_FOR_NI_PROOFS_H +#define CRYPTIC_HASH_FOR_NI_PROOFS_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include + +#include "../../export.h" + +#include "schnorr_zkpk.h" +#include "../proof_range/proof_range_in_qrg.h" + +#define CRYPTIC_TYPE_HASHFORNIPROOFS (cryptic_hash_for_ni_proofs_get_type()) +#define CRYPTIC_HASHFORNIPROOFS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CRYPTIC_TYPE_HASHFORNIPROOFS, CrypticHashForNiProofs)) +#define CRYPTIC_HASHFORNIPROOFS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), CRYPTIC_TYPE_HASHFORNIPROOFS, CrypticHashForNiProofsClass)) +#define CRYPTIC_IS_HASHFORNIPROOFS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), CRYPTIC_TYPE_HASHFORNIPROOFS)) +#define CRYPTIC_IS_HASHFORNIPROOFS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CRYPTIC_TYPE_HASHFORNIPROOFS)) +#define CRYPTIC_HASHFORNIPROOFS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CRYPTIC_TYPE_HASHFORNIPROOFS, CrypticHashForNiProofsClass)) + +typedef struct _CrypticHashForNiProofs CrypticHashForNiProofs; +typedef struct _CrypticHashForNiProofsClass CrypticHashForNiProofsClass; + +/** + * CrypticHashForNiProofs: + * @size_h: hash size + * + * Result in @h_value. + * Concatenate modulus || bases || dlrep || Commitment and produce a hash. + * + */ +struct _CrypticHashForNiProofs{ + GObject parent; + + /*< public >*/ + int size_h; + int nb_modulus; + int nb_bases; + int nb_dlreps; + int nb_commitments; + BIGNUM *h_value; + BIGNUM **modulus; + BIGNUM **bases; + BIGNUM **dlreps; + BIGNUM **commitments; +}; + +struct _CrypticHashForNiProofsClass { + GObjectClass parent_class; +}; + + +CRYPTIC_EXPORT GType cryptic_hash_for_ni_proofs_get_type(void); + +CRYPTIC_EXPORT CrypticHashForNiProofs* cryptic_hash_for_ni_proofs_new(int size_h); + +CRYPTIC_EXPORT int cryptic_hash_for_ni_proofs_add_proof(CrypticHashForNiProofs* h, CrypticZkpkSchnorr *shn, BIGNUM *dlrep); +CRYPTIC_EXPORT int cryptic_hash_for_ni_proofs_add_proofrange_prover(CrypticHashForNiProofs* h, CrypticProofrangeQrg* pr); +CRYPTIC_EXPORT int cryptic_hash_for_ni_proofs_add_proofrange_verifier(CrypticHashForNiProofs* h, CrypticProofrangeQrg* pr, BIGNUM **dlreps); + +CRYPTIC_EXPORT int cryptic_hash_for_ni_proofs_add_modulus(CrypticHashForNiProofs* h, BIGNUM* modulus); +CRYPTIC_EXPORT int cryptic_hash_for_ni_proofs_add_base(CrypticHashForNiProofs* h, BIGNUM* base); +CRYPTIC_EXPORT int cryptic_hash_for_ni_proofs_add_dlrep(CrypticHashForNiProofs* h, BIGNUM* dlrep); +CRYPTIC_EXPORT int cryptic_hash_for_ni_proofs_add_commitment(CrypticHashForNiProofs* h, BIGNUM* commitment); + +CRYPTIC_EXPORT int cryptic_hash_for_ni_proofs_compute_hash(CrypticHashForNiProofs* h); + +/* Accessors */ +CRYPTIC_EXPORT BIGNUM* cryptic_hash_for_ni_proofs_get_hash(CrypticHashForNiProofs* h); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* CRYPTIC_HASH_FOR_NI_PROOFS_H */ diff --git a/cryptic/protocols/pok_schnorr/schnorr_zkpk.c b/cryptic/protocols/pok_schnorr/schnorr_zkpk.c new file mode 100644 index 0000000..19d6623 --- /dev/null +++ b/cryptic/protocols/pok_schnorr/schnorr_zkpk.c @@ -0,0 +1,745 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include + +#include +#include +#include +#include + +#include "../../errors.h" +#include "../../utils.h" + +#include "schnorr_zkpk.h" + +/*****************************************************************************/ +/* private methods */ +/*****************************************************************************/ + +static GObjectClass *parent_class = NULL; + +/*****************************************************************************/ +/* overridden parent class methods */ +/*****************************************************************************/ + +static void +dispose(GObject *object) +{ + CrypticZkpkSchnorr *shn = CRYPTIC_ZKPKSCHNORR(object); + + int i = shn->nb_quantities-1; + cryptic_release_bn(shn->modulus); + cryptic_release_bn(shn->commitment); + while (i >= 0) { + if (shn->bases) { + cryptic_release_bn(shn->bases[i]); + } + if (shn->randoms) { + cryptic_release_bn(shn->randoms[i]); + } + if (shn->responses) { + cryptic_release_bn(shn->responses[i]); + } + i--; + } + cryptic_release(shn->bases); + cryptic_release(shn->randoms); + cryptic_release(shn->responses); + + G_OBJECT_CLASS(parent_class)->dispose(G_OBJECT(shn)); +} + +/*****************************************************************************/ +/* instance and class init functions */ +/*****************************************************************************/ + +static void +instance_init(CrypticZkpkSchnorr *shn) +{ + shn->modulus = NULL; + shn->commitment = NULL; + shn->bases = NULL; + shn->randoms = NULL; + shn->responses = NULL; +} + +static void +class_init(CrypticZkpkSchnorrClass *klass) +{ + parent_class = g_type_class_peek_parent(klass); + G_OBJECT_CLASS(klass)->dispose = dispose; +} + +/*****************************************************************************/ +/* public methods */ +/*****************************************************************************/ + +GType +cryptic_zkpk_schnorr_get_type() +{ + static GType this_type = 0; + if (!this_type) { + static const GTypeInfo this_info = { + sizeof (CrypticZkpkSchnorrClass), + NULL, + NULL, + (GClassInitFunc) class_init, + NULL, + NULL, + sizeof(CrypticZkpkSchnorr), + 0, + (GInstanceInitFunc) instance_init, + NULL + }; + this_type = g_type_register_static(G_TYPE_OBJECT, + "CrypticZkpkSchnorr", &this_info, 0); + } + return this_type; +} + +/** + * cryptic_zkpk_schnorr_new + * @bases: bases of the DL representation. + * @nb_quantities: number of quantities in the DL representation. + * @dlrep: DL representation to prove. + * @modulus: modulus of the group. + * + * Creates a new #CrypticZkpkSchnorr. + * The non-interactive version is a signature scheme secure under the so-called + * random oracle model due to Fiat-Shamir, in practice the hash function is the oracle function. + * + * Return value: a newly created #CrypticZkpkSchnorr object; or NULL if an error + * occured + **/ +CrypticZkpkSchnorr* +cryptic_zkpk_schnorr_new(BIGNUM **bases, int nb_quantities, BIGNUM *modulus) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + CrypticZkpkSchnorr *shn; + shn = g_object_new(CRYPTIC_TYPE_ZKPKSCHNORR, NULL); + + int i; + + goto_cleanup_if_fail_with_rc_with_warning(nb_quantities > 0, + CRYPTIC_PROOF_GENERIC_NB_QUANTITIES_NULL); + goto_cleanup_if_fail_with_rc_with_warning(bases != NULL, + CRYPTIC_PROOF_GENERIC_BASES_MISSING); + for(i=0;inb_quantities;i++){ + goto_cleanup_if_fail_with_rc_with_warning(bases[i] != NULL, + CRYPTIC_PROOF_GENERIC_BASES_MISSING); + } + goto_cleanup_if_fail_with_rc_with_warning(modulus != NULL, + CRYPTIC_PROOF_GENERIC_MODULUS_MISSING); + + shn->nb_quantities = nb_quantities; + + cryptic_release_bn(shn->modulus); + goto_cleanup_if_fail_with_rc_with_warning_openssl(shn->modulus = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(shn->modulus, modulus)); + + cryptic_release(shn->bases); + shn->bases = g_malloc0(nb_quantities * sizeof (**shn->bases)); + if(shn->bases == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + + for(i=0;ibases[i] = NULL; + goto_cleanup_if_fail_with_rc_with_warning_openssl(shn->bases[i] = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(shn->bases[i], bases[i])); + } + + return shn; +cleanup: + cryptic_release_gobject(shn); + return NULL; +} + +/** + * cryptic_zkpk_schnorr_round1: + * @shn: a #CrypticZkpkSchnorr object + * + * Compute the commitment of the proof. + * All randoms are picked into this function. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + */ +/* +To work with each bit of the commitment: + + cryptic_release(shn->randoms); + shn->randoms = g_malloc0((shn->nb_quantities*size_hash) * sizeof (**shn->randoms)); + + /* commitment = MUL bases[i]^rij */ + /* i quantities in the DL representation */ + /* j is the number of bit of the hash * + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(shn->commitment = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(shn->commitment,1) == 1); + for(j=0;jnb_quantities;i++){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(shn->randoms[i+(j*shn->nb_quantities)] = BN_new()); + if( (rc = cryptic_find_random_with_range_value(shn->randoms[i+(j*shn->nb_quantities)],shn->modulus)) < 0) + goto cleanup; + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp(tmp1,shn->bases[i],shn->randoms[i+(j*shn->nb_quantities)],shn->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(shn->commitment,shn->commitment,tmp1,shn->modulus,ctx) == 1); + } + } + + [...] + + cryptic_release(shn->responses); + shn->responses = g_malloc0((shn->nb_quantities*size_hash) * sizeof (**shn->responses)); + + /* commitment = MUL bases[i]^rij */ + /* sij = rij + ci xi -> ij responses -> e.g. 256 * 4)*/ + /* ci = (ith bit) * 2^i */ + /* j is the number of bit of the hash * + BIGNUM *c,*two,*exp,*count; + goto_cleanup_if_fail_with_rc_with_warning_openssl(c = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(two = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(exp = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(count = BN_new()); + BN_set_word(two,2); + int t,z,k,y; + for(j=0;j<(size_hash/8);j++){ + t=(int)*(hash+((size_hash/8)-j-1)); + for(z=0;z<8;z++){ + k=1<nb_quantities;i++){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(shn->responses[(((j*8)+z)*shn->nb_quantities+i)] = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(tmp1,quantities[i],c,order,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_add(shn->responses[ (((j*8)+z)*shn->nb_quantities+i) ],shn->randoms[ (((j*8)+z)*shn->nb_quantities+i) ],tmp1,order,ctx) == 1); + } + }else{ //ci = 0 -> sij = rij + for(i=0;inb_quantities;i++){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(shn->responses[(((j*8)+z)*shn->nb_quantities+i)] = BN_new()); + BN_copy(shn->responses[ (((j*8)+z)*shn->nb_quantities+i) ],shn->randoms[ (((j*8)+z)*shn->nb_quantities+i) ]); + } + } + } + } + +*/ + + +int cryptic_zkpk_schnorr_round1(CrypticZkpkSchnorr *shn) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + + BIGNUM *tmp1 = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(shn->modulus != NULL, + CRYPTIC_PROOF_GENERIC_STRUCTURE_NOT_INIT); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + cryptic_release(shn->randoms); + shn->randoms = g_malloc0((shn->nb_quantities) * sizeof (**shn->randoms)); + if(shn->randoms == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + + cryptic_release_bn(shn->commitment); + goto_cleanup_if_fail_with_rc_with_warning_openssl(shn->commitment = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(shn->commitment,1) == 1); + + for(i=0;inb_quantities;i++){ + shn->randoms[i] = NULL; + goto_cleanup_if_fail_with_rc_with_warning_openssl(shn->randoms[i] = BN_new()); + cryptic_check_good_rc(cryptic_find_random_with_range_value(shn->randoms[i],shn->modulus)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp(tmp1,shn->bases[i],shn->randoms[i],shn->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(shn->commitment,shn->commitment,tmp1,shn->modulus,ctx) == 1); + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(tmp1); + return rc; +} + +/** + * cryptic_zkpk_schnorr_round1_one_random_chosen: + * @shn: a #CrypticZkpkSchnorr object + * @random: random value + * @position: index of the base where use the random. Start at 0. + * + * Compute the proof. + * All randoms but one are picked into this function. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + */ +int cryptic_zkpk_schnorr_round1_one_random_chosen(CrypticZkpkSchnorr *shn, + BIGNUM *random, int position) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + BIGNUM *tmp1 = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(shn->modulus != NULL, + CRYPTIC_PROOF_GENERIC_STRUCTURE_NOT_INIT); + goto_cleanup_if_fail_with_rc_with_warning(random != NULL, + CRYPTIC_PROOF_GENERIC_RANDOMS_MISSING); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + cryptic_release(shn->randoms); + shn->randoms = g_malloc0((shn->nb_quantities) * sizeof (**shn->randoms)); + if(shn->randoms == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + + cryptic_release_bn(shn->commitment); + goto_cleanup_if_fail_with_rc_with_warning_openssl(shn->commitment = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(shn->commitment,1) == 1); + + for(i=0;inb_quantities;i++){ + shn->randoms[i] = NULL; + goto_cleanup_if_fail_with_rc_with_warning_openssl(shn->randoms[i] = BN_new()); + if(i != position){ + cryptic_check_good_rc(cryptic_find_random_with_range_value(shn->randoms[i],shn->modulus)); + }else{ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(shn->randoms[i],random)); + } + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp(tmp1,shn->bases[i],shn->randoms[i],shn->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(shn->commitment,shn->commitment,tmp1,shn->modulus,ctx) == 1); + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(tmp1); + return rc; +} + +/** + * cryptic_zkpk_schnorr_round1_randoms_chosen: + * @shn: a #CrypticZkpkSchnorr object + * @randoms: random value + * + * Compute the proof. + * All randoms are picked out of this function. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + */ +int cryptic_zkpk_schnorr_round1_randoms_chosen(CrypticZkpkSchnorr *shn, + BIGNUM **randoms) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + BIGNUM *tmp1 = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(shn->modulus != NULL, + CRYPTIC_PROOF_GENERIC_STRUCTURE_NOT_INIT); + goto_cleanup_if_fail_with_rc_with_warning(randoms != NULL, + CRYPTIC_PROOF_GENERIC_RANDOMS_MISSING); + for(i=0;i<(shn->nb_quantities);i++){ + goto_cleanup_if_fail_with_rc_with_warning(randoms[i] != NULL, + CRYPTIC_PROOF_GENERIC_RANDOMS_MISSING); + } + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + cryptic_release_bn(shn->commitment); + goto_cleanup_if_fail_with_rc_with_warning_openssl(shn->commitment = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(shn->commitment,1) == 1); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + cryptic_release(shn->randoms); + shn->randoms = g_malloc0((shn->nb_quantities) * sizeof (**shn->randoms)); + if(shn->randoms == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + + for(i=0;inb_quantities;i++){ + shn->randoms[i] = NULL; + goto_cleanup_if_fail_with_rc_with_warning_openssl(shn->randoms[i] = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(shn->randoms[i],randoms[i])); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp(tmp1,shn->bases[i],shn->randoms[i],shn->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(shn->commitment,shn->commitment,tmp1,shn->modulus,ctx) == 1); + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(tmp1); + return rc; +} + +/** + * cryptic_zkpk_schnorr_round2: + * @shn: a #CrypticZkpkSchnorr object + * @order: group order used as the modulus when computing responses + * @quantities: quantities to prove + * @hash: hash value + * + * Compute the responses for the proof. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + */ +int cryptic_zkpk_schnorr_round2(CrypticZkpkSchnorr *shn, + BIGNUM *order, BIGNUM *challenge, BIGNUM **quantities) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + BIGNUM *tmp1 = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(shn->randoms != NULL, + CRYPTIC_PROOF_GENERIC_ROUND1_NOT_DONE); + goto_cleanup_if_fail_with_rc_with_warning(challenge != NULL, + CRYPTIC_PROOF_GENERIC_HASH_OR_CHALLENGE_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(order != NULL, + CRYPTIC_PROOF_GENERIC_ORDER_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(BN_num_bits(challenge) >= CRYPTIC_SCHNORR_CHALLENGE_MIN_SIZE, + CRYPTIC_PROOF_GENERIC_CHALLENGE_SIZE_NOT_VALID); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + cryptic_release(shn->responses); + shn->responses = g_malloc0((shn->nb_quantities) * sizeof (**shn->responses)); + if(shn->responses == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + + for(i=0;inb_quantities;i++){ + shn->responses[i] = NULL; + goto_cleanup_if_fail_with_rc_with_warning_openssl(shn->responses[i] = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(tmp1,quantities[i],challenge,order,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_add(shn->responses[i],shn->randoms[i],tmp1,order,ctx) == 1); + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(tmp1); + return rc; +} + +/** + * cryptic_zkpk_schnorr_round2_without_order: + * @shn: a #CrypticZkpkSchnorr object + * @quantities: quantities to prove + * @hash: hash value + * + * Compute the responses for the proof. + * The responses are not computed using the group order as modulus. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + */ +int cryptic_zkpk_schnorr_round2_without_order(CrypticZkpkSchnorr *shn, + BIGNUM *challenge, BIGNUM **quantities) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + BIGNUM *tmp1 = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(shn->randoms != NULL, + CRYPTIC_PROOF_GENERIC_ROUND1_NOT_DONE); + goto_cleanup_if_fail_with_rc_with_warning(challenge != NULL, + CRYPTIC_PROOF_GENERIC_HASH_OR_CHALLENGE_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(BN_num_bits(challenge) >= CRYPTIC_SCHNORR_CHALLENGE_MIN_SIZE, + CRYPTIC_PROOF_GENERIC_CHALLENGE_SIZE_NOT_VALID); + goto_cleanup_if_fail_with_rc_with_warning(quantities != NULL, + CRYPTIC_PROOF_GENERIC_QUANTITY_MISSING); + for(i=0;inb_quantities;i++){ + goto_cleanup_if_fail_with_rc_with_warning(quantities[i] != NULL, + CRYPTIC_PROOF_GENERIC_QUANTITY_MISSING); + } + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + cryptic_release(shn->responses); + shn->responses = g_malloc0((shn->nb_quantities) * sizeof (**shn->responses)); + if(shn->responses == NULL){ + rc = CRYPTIC_MEMORY_ALLOCATION_FAILURE; + goto cleanup; + } + + for(i=0;inb_quantities;i++){ + shn->responses[i] = NULL; + goto_cleanup_if_fail_with_rc_with_warning_openssl(shn->responses[i] = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mul(tmp1,quantities[i],challenge,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(shn->responses[i],shn->randoms[i],tmp1) == 1); + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(tmp1); + return rc; +} + +/** + * cryptic_zkpk_schnorr_verify_noninteractive_proof: + * @shn: a #CrypticZkpkSchnorr object + * @hash: hash received + * @responses:(array length=shn->nb_quantities): responses + * + * Compute the commitment of the proof. + * It will then be used to computed the hash. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + */ +/* +To work with each bit of the commitment: + + for(j=0;jnb_quantities;i++){ + if(BN_is_negative(responses[i+(j*shn->nb_quantities)])){ + BN_copy(tmp2,shn->bases[i]); + shn->bases[i] = BN_mod_inverse(NULL,shn->bases[i],shn->modulus,ctx); + } + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp(tmp1,shn->bases[i],responses[i+(j*shn->nb_quantities)],shn->modulus,ctx) == 1); + if(BN_is_negative(responses[i+(j*shn->nb_quantities)])) BN_copy(shn->bases[i],tmp2); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(check,check,tmp1,shn->modulus,ctx) == 1); + } + } + +*/ +int +cryptic_zkpk_schnorr_verify_noninteractive_proof(CrypticZkpkSchnorr *shn, BIGNUM *dlrep, BIGNUM *hash, BIGNUM **responses) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + BIGNUM *tmp1 = NULL, *tmp2 = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(dlrep != NULL, + CRYPTIC_PROOF_GENERIC_DLREP_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(hash != NULL, + CRYPTIC_PROOF_GENERIC_CHALLENGE_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses != NULL, + CRYPTIC_PROOF_GENERIC_RESPONSES_MISSING); + for(i=0;i<(shn->nb_quantities);i++){ + goto_cleanup_if_fail_with_rc_with_warning(responses[i] != NULL, + CRYPTIC_PROOF_GENERIC_RESPONSES_MISSING); + } + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp2 = BN_new()); + cryptic_release_bn(shn->commitment); + goto_cleanup_if_fail_with_rc_with_warning_openssl(shn->commitment = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + /* s = r + cx */ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_inverse(tmp1,dlrep,shn->modulus,ctx)); /* Comment for s = r - cx */ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp(shn->commitment,tmp1,hash,shn->modulus,ctx) == 1); + + for(i=0;inb_quantities;i++){ + /* WARNING */ + /* The exponentiation with a negative nb does not its sign into account */ + /* So when the exponent is negative, it is enough to inverse the base */ + if(BN_is_negative(responses[i])){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_inverse(tmp1,shn->bases[i],shn->modulus,ctx)); + }else{ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tmp1,shn->bases[i])); + } + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp(tmp1,tmp1,responses[i],shn->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(shn->commitment,shn->commitment,tmp1,shn->modulus,ctx) == 1); + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(tmp1); + cryptic_release_bn(tmp2); + return rc; +} + +/** + * cryptic_zkpk_schnorr_verify_interactive_proof: + * @shn: a #CrypticZkpkSchnorr object + * @hash: hash received + * @responses:(array length=shn->nb_quantities): responses + * + * Compute the commitment of the proof. + * + * Return value: 1 if interactive proof successful, 0 if the proof is bas, an error code otherwise. + */ +int +cryptic_zkpk_schnorr_verify_interactive_proof(CrypticZkpkSchnorr *shn, BIGNUM *dlrep, BIGNUM *commitment, BIGNUM *challenge, BIGNUM **responses) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + int res; + BIGNUM *tmp1 = NULL, *tmp2 = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(dlrep != NULL, + CRYPTIC_PROOF_GENERIC_DLREP_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(challenge != NULL, + CRYPTIC_PROOF_GENERIC_CHALLENGE_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses != NULL, + CRYPTIC_PROOF_GENERIC_RESPONSES_MISSING); + for(i=0;i<(shn->nb_quantities);i++){ + goto_cleanup_if_fail_with_rc_with_warning(responses[i] != NULL, + CRYPTIC_PROOF_GENERIC_RESPONSES_MISSING); + } + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp2 = BN_new()); + cryptic_release_bn(shn->commitment); + goto_cleanup_if_fail_with_rc_with_warning_openssl(shn->commitment = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + /* s = r + cx */ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_inverse(tmp1,dlrep,shn->modulus,ctx)); /* Comment for s = r - cx */ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp(shn->commitment,tmp1,challenge,shn->modulus,ctx) == 1); + + for(i=0;inb_quantities;i++){ + /* WARNING */ + /* The exponentiation with a negative nb does not its sign into account */ + /* So when the exponent is negative, it is enough to inverse the base */ + if(BN_is_negative(responses[i])){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_inverse(tmp1,shn->bases[i],shn->modulus,ctx)); + }else{ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tmp1,shn->bases[i])); + } + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp(tmp1,tmp1,responses[i],shn->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(shn->commitment,shn->commitment,tmp1,shn->modulus,ctx) == 1); + } + + if(BN_ucmp(shn->commitment,commitment) == 0) + res= 1; + else + res = 0; + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(tmp1); + cryptic_release_bn(tmp2); + if(rc != CRYPTIC_NO_ERROR) return rc; + return res; +} + +/** + * cryptic_zkpk_schnorr_get_randoms: + * @shn: a #CrypticZkpkSchnorr object + * + * Getter. + * + * Return value: BIGNUM** randoms + */ +BIGNUM** +cryptic_zkpk_schnorr_get_randoms(CrypticZkpkSchnorr *shn) +{ + cryptic_return_null_if_fail(shn->randoms); + return shn->randoms; +} + +/** + * cryptic_zkpk_schnorr_get_i_random: + * @shn: a #CrypticZkpkSchnorr object + * + * Getter of the random at the index given. + * + * Return value: BIGNUM* randoms[i] + */ +BIGNUM* +cryptic_zkpk_schnorr_get_i_random(CrypticZkpkSchnorr *shn, int i) +{ + if (shn->randoms && i < shn->nb_quantities){ + if (shn->randoms[i]) return shn->randoms[i]; + } + return NULL; +} + +/** + * cryptic_zkpk_schnorr_get_commitment: + * @shn: a #CrypticZkpkSchnorr object + * + * Getter. + * + * Return value: BIGNUM* commitment + */ +BIGNUM* +cryptic_zkpk_schnorr_get_commitment(CrypticZkpkSchnorr *shn) +{ + cryptic_return_null_if_fail(shn->commitment); + return shn->commitment; +} + +/** + * cryptic_zkpk_schnorr_get_responses: + * @shn: a #CrypticZkpkSchnorr object + * + * Getter. + * + * Return value: BIGNUM** responses + */ +BIGNUM** +cryptic_zkpk_schnorr_get_responses(CrypticZkpkSchnorr *shn) +{ + cryptic_return_null_if_fail(shn->responses); + return shn->responses; +} + +/** + * cryptic_zkpk_schnorr_get_i_response: + * @shn: a #CrypticZkpkSchnorr object + * + * Getter of the response at the index given. + * + * Return value: BIGNUM* responses[i] + */ +BIGNUM* +cryptic_zkpk_schnorr_get_i_response(CrypticZkpkSchnorr *shn, int i) +{ + if (shn->responses && i < shn->nb_quantities){ + if (shn->responses[i]) return shn->responses[i]; + } + return NULL; +} diff --git a/cryptic/protocols/pok_schnorr/schnorr_zkpk.h b/cryptic/protocols/pok_schnorr/schnorr_zkpk.h new file mode 100644 index 0000000..a8d0d01 --- /dev/null +++ b/cryptic/protocols/pok_schnorr/schnorr_zkpk.h @@ -0,0 +1,114 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef CRYPTIC_PROTOCOLS_POK_SCHNORR_H +#define CRYPTIC_PROTOCOLS_POK_SCHNORR_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#define CRYPTIC_SCHNORR_CHALLENGE_MIN_SIZE 80 + +#include +#include +#include + +#include "../../export.h" + +#define CRYPTIC_TYPE_ZKPKSCHNORR (cryptic_zkpk_schnorr_get_type()) +#define CRYPTIC_ZKPKSCHNORR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CRYPTIC_TYPE_ZKPKSCHNORR, CrypticZkpkSchnorr)) +#define CRYPTIC_ZKPKSCHNORR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), CRYPTIC_TYPE_ZKPKSCHNORR, CrypticZkpkSchnorrClass)) +#define CRYPTIC_IS_ZKPKSCHNORR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), CRYPTIC_TYPE_ZKPKSCHNORR)) +#define CRYPTIC_IS_ZKPKSCHNORR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CRYPTIC_TYPE_ZKPKSCHNORR)) +#define CRYPTIC_ZKPKSCHNORR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CRYPTIC_TYPE_ZKPKSCHNORR, CrypticZkpkSchnorrClass)) + +typedef struct _CrypticZkpkSchnorr CrypticZkpkSchnorr; +typedef struct _CrypticZkpkSchnorrClass CrypticZkpkSchnorrClass; + +/** + * CrypticZkpkSchnorr: + * @nb_quantities: Nb of quantities in the DL representation to prove. + * @bases: base for the DL representation. + * @dlrep: DL representation to prove. + * @modulus: modulus of the group. + * @randoms: Randoms used for the commitment. + * @commitment: The commitment. + * @response: responses computed with the challenge. + * + * Schnorr zero knowledge proof of knowledge protocol for interactive and non interactive proofs. + * + * The chellange used for interactive proof is a hash for non-interactive proofs. + * The Fiat-Shamir heuristic introduced a hash function as an oracle. + * + */ +struct _CrypticZkpkSchnorr { + GObject parent; + + /*< public >*/ + BIGNUM **randoms; + BIGNUM *commitment; + BIGNUM **responses; + BIGNUM *modulus; + BIGNUM **bases; + int nb_quantities; +}; + +struct _CrypticZkpkSchnorrClass { + GObjectClass parent_class; +}; + +CRYPTIC_EXPORT GType cryptic_zkpk_schnorr_get_type(void); + +CRYPTIC_EXPORT CrypticZkpkSchnorr* cryptic_zkpk_schnorr_new(BIGNUM **bases, + int nb_quantities, BIGNUM *modulus); + + +/* Prover */ +CRYPTIC_EXPORT int cryptic_zkpk_schnorr_round1(CrypticZkpkSchnorr *shn); + +CRYPTIC_EXPORT int cryptic_zkpk_schnorr_round1_one_random_chosen(CrypticZkpkSchnorr *shn, + BIGNUM *random, int position); + +CRYPTIC_EXPORT int cryptic_zkpk_schnorr_round1_randoms_chosen(CrypticZkpkSchnorr *shn, + BIGNUM **randoms); + +CRYPTIC_EXPORT int cryptic_zkpk_schnorr_round2(CrypticZkpkSchnorr *shn, + BIGNUM *order, BIGNUM *challenge, BIGNUM **quantities); + +CRYPTIC_EXPORT int cryptic_zkpk_schnorr_round2_without_order(CrypticZkpkSchnorr *shn, + BIGNUM *challenge, BIGNUM **quantities); + +/* Verifier */ +CRYPTIC_EXPORT int cryptic_zkpk_schnorr_verify_noninteractive_proof(CrypticZkpkSchnorr *shn, BIGNUM *dlrep, BIGNUM *hash, BIGNUM **responses); + +CRYPTIC_EXPORT int cryptic_zkpk_schnorr_verify_interactive_proof(CrypticZkpkSchnorr *shn, BIGNUM *dlrep, BIGNUM *commitment, BIGNUM *challenge, BIGNUM **responses); + +/* Accessors */ +CRYPTIC_EXPORT BIGNUM** cryptic_zkpk_schnorr_get_randoms(CrypticZkpkSchnorr *shn); +CRYPTIC_EXPORT BIGNUM* cryptic_zkpk_schnorr_get_i_random(CrypticZkpkSchnorr *shn, int i); +CRYPTIC_EXPORT BIGNUM* cryptic_zkpk_schnorr_get_commitment(CrypticZkpkSchnorr *shn); +CRYPTIC_EXPORT BIGNUM** cryptic_zkpk_schnorr_get_responses(CrypticZkpkSchnorr *shn); +CRYPTIC_EXPORT BIGNUM* cryptic_zkpk_schnorr_get_i_response(CrypticZkpkSchnorr *shn, int i); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* CRYPTIC_PROTOCOLS_POK_SCHNORR_H */ diff --git a/cryptic/protocols/proof_range/proof_range_in_qrg.c b/cryptic/protocols/proof_range/proof_range_in_qrg.c new file mode 100644 index 0000000..3ee41de --- /dev/null +++ b/cryptic/protocols/proof_range/proof_range_in_qrg.c @@ -0,0 +1,934 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2010 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include +#include +#include +#include + +#include "../../errors.h" +#include "../../utils.h" + +#include "../pok_schnorr/schnorr_zkpk.h" +#include "../proof_range/proof_range_in_qrg.h" + +/*****************************************************************************/ +/* private methods */ +/*****************************************************************************/ + +static GObjectClass *parent_class = NULL; + +/*****************************************************************************/ +/* overridden parent class methods */ +/*****************************************************************************/ + +static void +dispose(GObject *object) +{ + CrypticProofrangeQrg *pr = CRYPTIC_PROOFRANGEQRG(object); + + int i; + + cryptic_release_bn(pr->modulus); + cryptic_release_bn(pr->m); + cryptic_release_bn(pr->b); + cryptic_release_bn(pr->delta); + cryptic_release_bn(pr->randDLRepDelta); + cryptic_release_bn(pr->randQ); + cryptic_release_bn(pr->Q); + cryptic_release_bn(pr->challenge); + if(pr->tabBases){ + for(i=0;i<2;i++){ + cryptic_release_bn(pr->tabBases[i]); + } + } + if(pr->tabRandDLRepSqrRoot){ + for(i=0;i<4;i++){ + cryptic_release_bn(pr->tabRandDLRepSqrRoot[i]); + } + } + if(pr->dlreps){ + for(i=0;i<5;i++){ + cryptic_release_bn(pr->dlreps[i]); + } + } + if(pr->commitments){ + for(i=0;i<6;i++){ + cryptic_release_bn(pr->commitments[i]); + } + } + if(pr->responses){ + for(i=0;i<11;i++){ + cryptic_release_bn(pr->responses[i]); + } + } + cryptic_release(pr->tabBases); + cryptic_release(pr->tabRandDLRepSqrRoot); + cryptic_release(pr->dlreps); + cryptic_release(pr->commitments); + cryptic_release(pr->responses); + + cryptic_release_gobject(pr->pokSqrRoot1); + cryptic_release_gobject(pr->pokSqrRoot2); + cryptic_release_gobject(pr->pokSqrRoot3); + cryptic_release_gobject(pr->pokSqrRoot4); + cryptic_release_gobject(pr->pokDelta); + + cryptic_release_gobject(pr->di); + + G_OBJECT_CLASS(parent_class)->dispose(G_OBJECT(pr)); +} + +/*****************************************************************************/ +/* instance and class init functions */ +/*****************************************************************************/ + +static void +instance_init(CrypticProofrangeQrg *pr) +{ + pr->modulus = NULL; + pr->m = NULL; + pr->b = NULL; + pr->delta = NULL; + pr->randDLRepDelta = NULL; + pr->randQ = NULL; + pr->Q = NULL; + pr->challenge = NULL; + pr->tabBases = NULL; + pr->tabRandDLRepSqrRoot = NULL; + pr->dlreps = NULL; + pr->commitments = NULL; + pr->responses = NULL; + pr->pokSqrRoot1 = NULL; + pr->pokSqrRoot2 = NULL; + pr->pokSqrRoot3 = NULL; + pr->pokSqrRoot4 = NULL; + pr->pokDelta = NULL; + pr->di = NULL; +} + +static void +class_init(CrypticProofrangeQrgClass *klass) +{ + parent_class = g_type_class_peek_parent(klass); + G_OBJECT_CLASS(klass)->dispose = dispose; +} + +/*****************************************************************************/ +/* public methods */ +/*****************************************************************************/ + +GType +cryptic_proofrange_qrg_get_type() +{ + static GType this_type = 0; + if (!this_type) { + static const GTypeInfo this_info = { + sizeof (CrypticProofrangeQrgClass), + NULL, + NULL, + (GClassInitFunc) class_init, + NULL, + NULL, + sizeof(CrypticProofrangeQrg), + 0, + (GInstanceInitFunc) instance_init, + NULL + }; + this_type = g_type_register_static(G_TYPE_OBJECT, + "CrypticProofrangeQrg", &this_info, 0); + } + return this_type; +} + +/** + * cryptic_proofrange_qrg_new: + * @base1: First base used for the DL representation. + * @base2: Second base used for the DL representation. + * @modulus: Modulus of the group. + * + * Creates a new #CrypticProofrangeQrg. + * + * Return value: a newly created #CrypticProofrangeQrg object; or NULL if an error + * occured + **/ +CrypticProofrangeQrg* +cryptic_proofrange_qrg_new(BIGNUM *base1, BIGNUM *base2, BIGNUM *modulus) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + CrypticProofrangeQrg *pr; + pr = g_object_new(CRYPTIC_TYPE_PROOFRANGEQRG, NULL); + + int i; + + cryptic_release(pr->tabBases); + pr->tabBases = g_malloc0(2 * sizeof (**pr->tabBases)); + for(i=0; i<2; i++){ + pr->tabBases[i] = NULL; + } + cryptic_release(pr->tabRandDLRepSqrRoot); + pr->tabRandDLRepSqrRoot = g_malloc0(4 * sizeof (**pr->tabRandDLRepSqrRoot)); + for(i=0; i<4; i++){ + pr->tabRandDLRepSqrRoot[i] = NULL; + } + cryptic_release(pr->dlreps); + pr->dlreps = g_malloc0(5 * sizeof (**pr->dlreps)); + for(i=0; i<5; i++){ + pr->dlreps[i] = NULL; + } + cryptic_release(pr->commitments); + pr->commitments = g_malloc0(6 * sizeof (**pr->commitments)); + for(i=0; i<6; i++){ + pr->commitments[i] = NULL; + } + cryptic_release(pr->responses); + pr->responses = g_malloc0(11 * sizeof (**pr->responses)); + for(i=0; i<11; i++){ + pr->responses[i] = NULL; + } + + goto_cleanup_if_fail_with_rc_with_warning_openssl(pr->tabBases[0] = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->tabBases[0],base1)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(pr->tabBases[1] = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->tabBases[1],base2)); + + cryptic_release_bn(pr->modulus); + goto_cleanup_if_fail_with_rc_with_warning_openssl(pr->modulus = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->modulus, modulus)); + + return pr; +cleanup: + cryptic_release_gobject(pr); + return NULL; + +} + +/** + * cryptic_proofrange_qrg_round1: + * @rel: inequality to prove. + * @m: quantity on which the range proof is led. + * @b: quantity of comparison. + * @random_m: Random for m. + * @rand1: size of the random for proof of the first square. + * @rand2: size of the random for proof of the second square. + * @rand3: size of the random for proof of the third square. + * @rand4: size of the random for proof of the forth square. + * + * Lead a range proof relying on the interactive Schnorr ZKPK. Round1 for committing. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + */ +int +cryptic_proofrange_qrg_round1(CrypticProofrangeQrg *pr, int rel, BIGNUM *m, BIGNUM *b, BIGNUM *random_m, int lg_sec_param, int lg_zk_sec_param, int lg_challenge) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + int neg = 0; + BIGNUM *tmp = NULL; + BIGNUM *tab_rand[2]; + tab_rand[0] = NULL; + tab_rand[1] = NULL; + BN_CTX *ctx = NULL; + BN_MONT_CTX *mont = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(pr->modulus != NULL, + CRYPTIC_PROOF_RANGE_STRUCTURE_NOT_INIT); + goto_cleanup_if_fail_with_rc_with_warning(m != NULL, + CRYPTIC_PROOF_RANGE_STRUCTURE_NOT_INIT); + goto_cleanup_if_fail_with_rc_with_warning(b != NULL, + CRYPTIC_PROOF_RANGE_NO_BOUND); + + if(lg_sec_param= CRYPTIC_PROOF_RANGE_TEST_CHALLENGE_MIN_SIZE, + CRYPTIC_PROOF_GENERIC_CHALLENGE_SIZE_NOT_VALID); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tab_rand[0] = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tab_rand[1] = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(mont=BN_MONT_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_MONT_CTX_set(mont,pr->modulus,ctx)); + + /***************************** + * Compute delta + ******************************/ + + goto_cleanup_if_fail_with_rc_with_warning_openssl(pr->delta = BN_new()); + + switch (rel) { + case CRYPTIC_PROOF_RANGE_LTE: + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(pr->delta,b,m) == 1); // b-m + neg = 1; + break; + case CRYPTIC_PROOF_RANGE_LT: + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(pr->delta,b,m) == 1); // b-m-1 + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(pr->delta,pr->delta,BN_value_one()) == 1); + neg = 1; + break; + case CRYPTIC_PROOF_RANGE_GTE: + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(pr->delta,m,b) == 1); // m-b + break; + case CRYPTIC_PROOF_RANGE_GT: + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(pr->delta,m,b) == 1); // m-b-1 + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(pr->delta,pr->delta,BN_value_one()) == 1); + break; + default: + rc = CRYPTIC_PROOF_RANGE_RELATION_UNKNOWN; + goto cleanup; + } + + goto_cleanup_if_fail_with_rc_with_warning(!BN_is_negative(pr->delta), + CRYPTIC_PROOF_RANGE_DELTA_NEGATIVE); + + /***************************** + * Decomposition + ******************************/ + + cryptic_release_bn(pr->m); + goto_cleanup_if_fail_with_rc_with_warning_openssl(pr->m = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->m,m)); + cryptic_release_bn(pr->b); + goto_cleanup_if_fail_with_rc_with_warning_openssl(pr->b = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->b,b)); + + pr->di = cryptic_decompose_integer_new(pr->delta); + + goto_cleanup_if_fail_with_rc_with_warning(pr->di >= 0 && cryptic_decompose_integer_verify_decomposition(pr->di,pr->delta) == 1, + CRYPTIC_PROOF_RANGE_DECOMPOSITION_FAILED); + + /* IBM: RZ3730 (#99740) 03/19/2009 */ + /* rdelta, ri : rand1 = ln + l_zk_sec_param */ + /* qi : rand2 = lm + l_challenge + l_zk_sec_param */ + /* zdelta, zi : rand3 = lm + l_challenge + 2*l_zk_sec_param */ + /* rrho : rand4 = ln + lm + 2*l_sec_param + 2*l_zk_sec_param + 3 */ + + int lg_modulus = BN_num_bits(pr->modulus); + int lg_quantity = lg_challenge; + + int rand1 = lg_modulus + lg_zk_sec_param; + int rand2 = lg_quantity + lg_challenge + lg_zk_sec_param; + int rand3 = lg_quantity + lg_challenge + 2*lg_zk_sec_param; + int rand4 = lg_modulus + lg_quantity + 2*lg_sec_param + 2*lg_zk_sec_param + 3; + + /***************************** + * Build dlrep + ******************************/ + + for(i=0;i<4;i++){ + cryptic_release_bn(pr->tabRandDLRepSqrRoot[i]); + cryptic_release_bn(pr->dlreps[i]); + goto_cleanup_if_fail_with_rc_with_warning_openssl(pr->tabRandDLRepSqrRoot[i] = BN_new()); //random to dlrep the square roots of Delta + goto_cleanup_if_fail_with_rc_with_warning_openssl(pr->dlreps[i] = BN_new()); //dlrep of the square roots of Delta (Ti) + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_find_random(pr->tabRandDLRepSqrRoot[i],rand1) == 0); + switch (i){ + case 0: goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(pr->dlreps[i],pr->tabBases[0],cryptic_getSqrRoot1(pr->di),pr->modulus,ctx,mont) == 1); break; + case 1: goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(pr->dlreps[i],pr->tabBases[0],cryptic_getSqrRoot2(pr->di),pr->modulus,ctx,mont) == 1); break; + case 2: goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(pr->dlreps[i],pr->tabBases[0],cryptic_getSqrRoot3(pr->di),pr->modulus,ctx,mont) == 1); break; + case 3: goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(pr->dlreps[i],pr->tabBases[0],cryptic_getSqrRoot4(pr->di),pr->modulus,ctx,mont) == 1); break; + } + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp,pr->tabBases[1],pr->tabRandDLRepSqrRoot[i],pr->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(pr->dlreps[i],pr->dlreps[i],tmp,pr->modulus,ctx) == 1); + } + + cryptic_release_bn(pr->randDLRepDelta); + cryptic_release_bn(pr->dlreps[4]); + goto_cleanup_if_fail_with_rc_with_warning_openssl(pr->randDLRepDelta = BN_new()); //random to dlrep Delta + goto_cleanup_if_fail_with_rc_with_warning_openssl(pr->dlreps[4] = BN_new()); //dlrep Delta (Td) + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_find_random(pr->randDLRepDelta,rand1) == 0); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(pr->dlreps[4],pr->tabBases[0],pr->delta,pr->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp,pr->tabBases[1],pr->randDLRepDelta,pr->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(pr->dlreps[4],pr->dlreps[4],tmp,pr->modulus,ctx) == 1); + + /***************************** + * Compute commitments + ******************************/ + + pr->pokSqrRoot1 = cryptic_zkpk_schnorr_new(pr->tabBases, 2, pr->modulus); + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_find_random(tab_rand[0],rand2) == 0); + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_find_random(tab_rand[1],rand3) == 0); + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_zkpk_schnorr_round1_randoms_chosen(pr->pokSqrRoot1,tab_rand) == 0); + + pr->pokSqrRoot2 = cryptic_zkpk_schnorr_new(pr->tabBases, 2, pr->modulus); + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_find_random(tab_rand[0],rand2) == 0); + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_find_random(tab_rand[1],rand3) == 0); + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_zkpk_schnorr_round1_randoms_chosen(pr->pokSqrRoot2,tab_rand) == 0); + + pr->pokSqrRoot3 = cryptic_zkpk_schnorr_new(pr->tabBases, 2, pr->modulus); + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_find_random(tab_rand[0],rand2) == 0); + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_find_random(tab_rand[1],rand3) == 0); + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_zkpk_schnorr_round1_randoms_chosen(pr->pokSqrRoot3,tab_rand) == 0); + + pr->pokSqrRoot4 = cryptic_zkpk_schnorr_new(pr->tabBases, 2, pr->modulus); + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_find_random(tab_rand[0],rand2) == 0); + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_find_random(tab_rand[1],rand3) == 0); + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_zkpk_schnorr_round1_randoms_chosen(pr->pokSqrRoot4,tab_rand) == 0); + + if(neg){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tmp,pr->tabBases[1])); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_inverse(pr->tabBases[1],pr->tabBases[1],pr->modulus,ctx)); + } + + pr->pokDelta = cryptic_zkpk_schnorr_new(pr->tabBases, 2, pr->modulus); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_rand[0],random_m)); //r_m + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_find_random(tab_rand[1],rand3) == 0); //z_delta + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_zkpk_schnorr_round1_randoms_chosen(pr->pokDelta,tab_rand) == 0); + if(neg) goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->tabBases[1],tmp)); + + /***************************** + * Compute Q + ******************************/ + + cryptic_release_bn(pr->randQ); + goto_cleanup_if_fail_with_rc_with_warning_openssl(pr->randQ = BN_new()); + cryptic_check_good_rc(cryptic_find_random(pr->randQ,rand4)); //r_rho + + goto_cleanup_if_fail_with_rc_with_warning_openssl(pr->Q = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(pr->Q,pr->dlreps[0],cryptic_zkpk_schnorr_get_i_random(pr->pokSqrRoot1, 0),pr->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp,pr->dlreps[1],cryptic_zkpk_schnorr_get_i_random(pr->pokSqrRoot2, 0),pr->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(pr->Q,pr->Q,tmp,pr->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp,pr->dlreps[2],cryptic_zkpk_schnorr_get_i_random(pr->pokSqrRoot3, 0),pr->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(pr->Q,pr->Q,tmp,pr->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp,pr->dlreps[3],cryptic_zkpk_schnorr_get_i_random(pr->pokSqrRoot4, 0),pr->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(pr->Q,pr->Q,tmp,pr->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp,pr->tabBases[1],pr->randQ,pr->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(pr->Q,pr->Q,tmp,pr->modulus,ctx) == 1); + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_mont(mont); + cryptic_release_bn(tab_rand[1]); + cryptic_release_bn(tab_rand[0]); + cryptic_release_bn(tmp); + return rc; +} + +/** + * cryptic_proofrange_qrg_round1: + * @challenge: challenge for interactive, hash for non interactive proofs. + * + * Round2 for response. + * + * Return value: #CRYPTIC_NO_ERROR if successful, an error code otherwise. + */ +int +cryptic_proofrange_qrg_round2(CrypticProofrangeQrg *pr, BIGNUM *challenge) +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + BIGNUM *tmp = NULL; + BIGNUM *tab_qty[2]; + tab_qty[0] = NULL; + tab_qty[1] = NULL; + BN_CTX *ctx = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(pr->modulus != NULL, + CRYPTIC_PROOF_RANGE_STRUCTURE_NOT_INIT); + goto_cleanup_if_fail_with_rc_with_warning(pr->Q != NULL, + CRYPTIC_PROOF_RANGE_INTERACTIVE_ROUND_1_UNCOMPLETE); + goto_cleanup_if_fail_with_rc_with_warning(challenge != NULL, + CRYPTIC_PROOF_RANGE_INTERACTIVE_ROUND_2_NO_CHALLENGE); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(pr->challenge = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->challenge,challenge)); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tab_qty[0] = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tab_qty[1] = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + + /***************************** + * Compute responses + ******************************/ + + /* S_u_1 = pr->pokSqrRoot1->random[0] + c.u_1 */ + /* S_r_1 = pr->pokSqrRoot1->random[1] + c.r_1 */ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_qty[0],cryptic_getSqrRoot1(pr->di))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_qty[1],pr->tabRandDLRepSqrRoot[0])); + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_zkpk_schnorr_round2_without_order(pr->pokSqrRoot1,pr->challenge,tab_qty) == 0); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_qty[0],cryptic_getSqrRoot2(pr->di))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_qty[1],pr->tabRandDLRepSqrRoot[1])); + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_zkpk_schnorr_round2_without_order(pr->pokSqrRoot2,pr->challenge,tab_qty) == 0); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_qty[0],cryptic_getSqrRoot3(pr->di))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_qty[1],pr->tabRandDLRepSqrRoot[2])); + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_zkpk_schnorr_round2_without_order(pr->pokSqrRoot3,pr->challenge,tab_qty) == 0); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_qty[0],cryptic_getSqrRoot4(pr->di))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_qty[1],pr->tabRandDLRepSqrRoot[3])); + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_zkpk_schnorr_round2_without_order(pr->pokSqrRoot4,pr->challenge,tab_qty) == 0); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_qty[0],pr->m)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_qty[1],pr->randDLRepDelta)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_zkpk_schnorr_round2_without_order(pr->pokDelta,pr->challenge,tab_qty) == 0); + + cryptic_release_bn(pr->responserho); + goto_cleanup_if_fail_with_rc_with_warning_openssl(pr->responserho = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mul(tmp,cryptic_getSqrRoot1(pr->di),pr->tabRandDLRepSqrRoot[0],ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mul(pr->responserho,cryptic_getSqrRoot2(pr->di),pr->tabRandDLRepSqrRoot[1],ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(pr->responserho,tmp,pr->responserho) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mul(tmp,cryptic_getSqrRoot3(pr->di),pr->tabRandDLRepSqrRoot[2],ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(pr->responserho,tmp,pr->responserho) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mul(tmp,cryptic_getSqrRoot4(pr->di),pr->tabRandDLRepSqrRoot[3],ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(pr->responserho,tmp,pr->responserho) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(pr->responserho,pr->randDLRepDelta,pr->responserho) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mul(pr->responserho,pr->responserho,pr->challenge,ctx) == 1); + /* s = r - cx */ + //goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(pr->responserho,pr->randQ,pr->responserho) == 1); + /* s = r + cx */ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(pr->responserho,pr->randQ,pr->responserho) == 1); + + int i; + for(i=0;i<11;i++){ + cryptic_release_bn(pr->responses[i]); + goto_cleanup_if_fail_with_rc_with_warning_openssl(pr->responses[i] = BN_new()); + } + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->responses[0],cryptic_zkpk_schnorr_get_i_response(pr->pokSqrRoot1,0))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->responses[1],cryptic_zkpk_schnorr_get_i_response(pr->pokSqrRoot1,1))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->responses[2],cryptic_zkpk_schnorr_get_i_response(pr->pokSqrRoot2,0))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->responses[3],cryptic_zkpk_schnorr_get_i_response(pr->pokSqrRoot2,1))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->responses[4],cryptic_zkpk_schnorr_get_i_response(pr->pokSqrRoot3,0))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->responses[5],cryptic_zkpk_schnorr_get_i_response(pr->pokSqrRoot3,1))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->responses[6],cryptic_zkpk_schnorr_get_i_response(pr->pokSqrRoot4,0))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->responses[7],cryptic_zkpk_schnorr_get_i_response(pr->pokSqrRoot4,1))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->responses[8],cryptic_zkpk_schnorr_get_i_response(pr->pokDelta,0))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->responses[9],cryptic_zkpk_schnorr_get_i_response(pr->pokDelta,1))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->responses[10],pr->responserho)); + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_bn(tmp); + if(tab_qty){ + int i; + for(i=0;i<2;i++){ + cryptic_release_bn(tab_qty[i]); + } + } + return rc; +} + +/** + * cryptic_proofrange_qrg_verify_interactive_proof: + * @rel: inequality to prove. + * @b: quantity of comparison. + * @dlreps: Representation proved. + * @commitments: Commitments. + * @challenge: Challenge. + * @responses: Responses of the proof. + * + * Verify a range proof relying on the interactive Schnorr ZKPK. + * + * Return value: 1 if proof is successful, an error code otherwise. + */ +int +cryptic_proofrange_qrg_verify_interactive_proof(CrypticProofrangeQrg *pr, + int rel, + BIGNUM *b, + BIGNUM **dlreps, //T1, T2, T3, T4, T5, Tdelta + BIGNUM **commitments, //t1, t2, t3, t4, t5, tdelta, tQ + BIGNUM *challenge, //c + BIGNUM **responses) //su1, zu1, su2, zu2, su3, zu3, su4, zu4, srho +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + int neg = 0; + BIGNUM *tmp = NULL; + BN_CTX *ctx = NULL; + BN_MONT_CTX *mont = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(pr->modulus != NULL, + CRYPTIC_PROOF_RANGE_STRUCTURE_NOT_INIT); + goto_cleanup_if_fail_with_rc_with_warning(b != NULL, + CRYPTIC_PROOF_RANGE_NO_BOUND); + + cryptic_release_bn(pr->delta); + goto_cleanup_if_fail_with_rc_with_warning_openssl(pr->delta = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(mont=BN_MONT_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_MONT_CTX_set(mont,pr->modulus,ctx)); + + /***************************** + * Compute delta + ******************************/ + + switch (rel) { + case CRYPTIC_PROOF_RANGE_LTE: + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->delta,b)); + neg = 1; + break; + case CRYPTIC_PROOF_RANGE_LT: + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->delta,b)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(pr->delta,pr->delta,BN_value_one()) == 1); + neg = 1; + break; + case CRYPTIC_PROOF_RANGE_GTE: + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->delta,b)); + break; + case CRYPTIC_PROOF_RANGE_GT: + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->delta,b)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(pr->delta,pr->delta,BN_value_one()) == 1); + break; + default: + rc = CRYPTIC_PROOF_RANGE_RELATION_UNKNOWN; + goto cleanup; + } + + goto_cleanup_if_fail_with_rc_with_warning(!BN_is_negative(pr->delta), + CRYPTIC_PROOF_RANGE_DELTA_NEGATIVE); + goto_cleanup_if_fail_with_rc_with_warning(dlreps != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_TAB_DLREPS_EMPTY); + goto_cleanup_if_fail_with_rc_with_warning(dlreps[0] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_DLREP_FIRST_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(dlreps[1] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_DLREP_SECOND_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(dlreps[2] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_DLREP_THIRD_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(dlreps[3] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_DLREP_FORTH_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(dlreps[4] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_DLREP_DELTA_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(commitments != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_TAB_COMMITMENTS_EMPTY); + goto_cleanup_if_fail_with_rc_with_warning(commitments[0] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_COMMIT_FIRST_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(commitments[1] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_COMMIT_SECOND_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(commitments[2] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_COMMIT_THIRD_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(commitments[3] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_COMMIT_FORTH_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(commitments[4] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_COMMIT_DELTA_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(commitments[5] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_COMMIT_Q_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(challenge != NULL, + CRYPTIC_PROOF_GENERIC_CHALLENGE_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_TAB_RESPONSES_EMPTY); + goto_cleanup_if_fail_with_rc_with_warning(responses[0] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_FIRST_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses[1] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_FIRST_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses[2] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_SECOND_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses[3] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_SECOND_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses[4] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_THIRD_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses[5] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_THIRD_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses[6] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_FORTH_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses[7] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_FORTH_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses[8] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_DELTA_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses[9] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_DELTA_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses[10] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_RHO_MISSING); + + pr->pokSqrRoot1 = cryptic_zkpk_schnorr_new(pr->tabBases, 2, pr->modulus); + goto_cleanup_if_fail_with_rc_with_warning( + cryptic_zkpk_schnorr_verify_interactive_proof(pr->pokSqrRoot1, dlreps[0], commitments[0], challenge, responses) == 1, + CRYPTIC_PROOF_RANGE_VERIFICATION_FAILURE); + pr->pokSqrRoot2 = cryptic_zkpk_schnorr_new(pr->tabBases, 2, pr->modulus); + goto_cleanup_if_fail_with_rc_with_warning( + cryptic_zkpk_schnorr_verify_interactive_proof(pr->pokSqrRoot2, dlreps[1], commitments[1], challenge, responses+2) == 1, + CRYPTIC_PROOF_RANGE_VERIFICATION_FAILURE); + pr->pokSqrRoot3 = cryptic_zkpk_schnorr_new(pr->tabBases, 2, pr->modulus); + goto_cleanup_if_fail_with_rc_with_warning( + cryptic_zkpk_schnorr_verify_interactive_proof(pr->pokSqrRoot3, dlreps[2], commitments[2], challenge, responses+4) == 1, + CRYPTIC_PROOF_RANGE_VERIFICATION_FAILURE); + pr->pokSqrRoot4 = cryptic_zkpk_schnorr_new(pr->tabBases, 2,pr->modulus); + goto_cleanup_if_fail_with_rc_with_warning( + cryptic_zkpk_schnorr_verify_interactive_proof(pr->pokSqrRoot4, dlreps[3], commitments[3], challenge, responses+6) == 1, + CRYPTIC_PROOF_RANGE_VERIFICATION_FAILURE); + + cryptic_release_bn(pr->dlreps[4]); + goto_cleanup_if_fail_with_rc_with_warning_openssl(pr->dlreps[4] = BN_new()); + if(neg){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_inverse(pr->dlreps[4],dlreps[4],pr->modulus,ctx)); + }else{ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->dlreps[4],dlreps[4])); + } + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp,pr->tabBases[0],pr->delta,pr->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(pr->dlreps[4],pr->dlreps[4],tmp,pr->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp,pr->dlreps[4],challenge,pr->modulus,ctx,mont) == 1); + + if(neg){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tmp,pr->tabBases[1])); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_inverse(pr->tabBases[1],pr->tabBases[1],pr->modulus,ctx)); + } + pr->pokDelta = cryptic_zkpk_schnorr_new(pr->tabBases, 2, pr->modulus); + goto_cleanup_if_fail_with_rc_with_warning( + cryptic_zkpk_schnorr_verify_interactive_proof(pr->pokDelta,pr->dlreps[4], commitments[4],challenge,responses+8) == 1, + CRYPTIC_PROOF_RANGE_VERIFICATION_FAILURE); + + if(neg) goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->tabBases[1],tmp)); + + cryptic_release_bn(pr->Q); + goto_cleanup_if_fail_with_rc_with_warning_openssl(pr->Q = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_inverse(tmp,dlreps[4],pr->modulus,ctx)); /* Comment for s = r - cx */ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(pr->Q,tmp,challenge,pr->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp,dlreps[0],responses[0],pr->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(pr->Q,pr->Q,tmp,pr->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp,dlreps[1],responses[2],pr->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(pr->Q,pr->Q,tmp,pr->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp,dlreps[2],responses[4],pr->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(pr->Q,pr->Q,tmp,pr->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp,dlreps[3],responses[6],pr->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(pr->Q,pr->Q,tmp,pr->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp,pr->tabBases[1],responses[10],pr->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(pr->Q,pr->Q,tmp,pr->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning(BN_ucmp(pr->Q,commitments[5]) == 0, + CRYPTIC_PROOF_RANGE_VERIFICATION_FAILURE); + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_mont(mont); + cryptic_release_bn(tmp); + if(rc == CRYPTIC_NO_ERROR) return 1; + return rc; +} + +/** + * cryptic_proofrange_qrg_verify_noninteractive_proof: + * @rel: inequality to prove. + * @b: quantity of comparison. + * @dlreps: Representation proved. + * @hash: hash. + * @responses: Responses of the proof. + * + * Verify a range proof relying on the interactive Schnorr ZKPK. + * + * Return value: 1 if proof is successful, an error code otherwise. + */ +int +cryptic_proofrange_qrg_verify_noninteractive_proof(CrypticProofrangeQrg *pr, + int rel, + BIGNUM *b, + BIGNUM **dlreps, //T1, T2, T3, T4, T5, Tdelta + BIGNUM *hash, //hash + BIGNUM **responses) //su1, zu1, su2, zu2, su3, zu3, su4, zu4, srho +{ + int rc = CRYPTIC_ERROR_UNDEFINED; + + int i; + int neg = 0; + BIGNUM *tmp = NULL; + BN_CTX *ctx = NULL; + BN_MONT_CTX *mont = NULL; + + goto_cleanup_if_fail_with_rc_with_warning(pr->modulus != NULL, + CRYPTIC_PROOF_RANGE_STRUCTURE_NOT_INIT); + goto_cleanup_if_fail_with_rc_with_warning(b != NULL, + CRYPTIC_PROOF_RANGE_NO_BOUND); + + cryptic_release_bn(pr->delta); + goto_cleanup_if_fail_with_rc_with_warning_openssl(pr->delta = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp = BN_new()); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(mont=BN_MONT_CTX_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_MONT_CTX_set(mont,pr->modulus,ctx)); + + /***************************** + * Compute delta + ******************************/ + + switch (rel) { + case CRYPTIC_PROOF_RANGE_LTE: + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->delta,b)); + neg = 1; + break; + case CRYPTIC_PROOF_RANGE_LT: + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->delta,b)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_sub(pr->delta,pr->delta,BN_value_one()) == 1); + neg = 1; + break; + case CRYPTIC_PROOF_RANGE_GTE: + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->delta,b)); + break; + case CRYPTIC_PROOF_RANGE_GT: + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->delta,b)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(pr->delta,pr->delta,BN_value_one()) == 1); + break; + default: + rc = CRYPTIC_PROOF_RANGE_RELATION_UNKNOWN; + goto cleanup; + } + + goto_cleanup_if_fail_with_rc_with_warning(!BN_is_negative(pr->delta), + CRYPTIC_PROOF_RANGE_DELTA_NEGATIVE); + goto_cleanup_if_fail_with_rc_with_warning(dlreps != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_TAB_DLREPS_EMPTY); + goto_cleanup_if_fail_with_rc_with_warning(dlreps[0] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_DLREP_FIRST_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(dlreps[1] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_DLREP_SECOND_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(dlreps[2] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_DLREP_THIRD_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(dlreps[3] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_DLREP_FORTH_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(dlreps[4] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_DLREP_DELTA_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(hash != NULL, + CRYPTIC_PROOF_GENERIC_CHALLENGE_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_TAB_RESPONSES_EMPTY); + goto_cleanup_if_fail_with_rc_with_warning(responses[0] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_FIRST_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses[1] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_FIRST_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses[2] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_SECOND_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses[3] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_SECOND_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses[4] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_THIRD_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses[5] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_THIRD_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses[6] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_FORTH_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses[7] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_FORTH_SQRROOT_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses[8] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_DELTA_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses[9] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_DELTA_MISSING); + goto_cleanup_if_fail_with_rc_with_warning(responses[10] != NULL, + CRYPTIC_PROOF_RANGE_VERIFY_RESPONSES_RHO_MISSING); + + pr->pokSqrRoot1 = cryptic_zkpk_schnorr_new(pr->tabBases, 2, pr->modulus); + cryptic_check_good_rc(cryptic_zkpk_schnorr_verify_noninteractive_proof(pr->pokSqrRoot1,dlreps[0],hash,responses)); + pr->pokSqrRoot2 = cryptic_zkpk_schnorr_new(pr->tabBases, 2, pr->modulus); + cryptic_check_good_rc(cryptic_zkpk_schnorr_verify_noninteractive_proof(pr->pokSqrRoot2,dlreps[1],hash,responses+2)); + pr->pokSqrRoot3 = cryptic_zkpk_schnorr_new(pr->tabBases, 2, pr->modulus); + cryptic_check_good_rc(cryptic_zkpk_schnorr_verify_noninteractive_proof(pr->pokSqrRoot3,dlreps[2],hash,responses+4)); + pr->pokSqrRoot4 = cryptic_zkpk_schnorr_new(pr->tabBases, 2, pr->modulus); + cryptic_check_good_rc(cryptic_zkpk_schnorr_verify_noninteractive_proof(pr->pokSqrRoot4,dlreps[3],hash,responses+6)); + + cryptic_release_bn(pr->dlreps[4]); + goto_cleanup_if_fail_with_rc_with_warning_openssl(pr->dlreps[4] = BN_new()); + if(neg){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_inverse(pr->dlreps[4],dlreps[4],pr->modulus,ctx)); + }else{ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->dlreps[4],dlreps[4])); + } + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp,pr->tabBases[0],pr->delta,pr->modulus,ctx,mont) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(pr->dlreps[4],pr->dlreps[4],tmp,pr->modulus,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp,pr->dlreps[4],hash,pr->modulus,ctx,mont) == 1); + + if(neg){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tmp,pr->tabBases[1])); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_inverse(pr->tabBases[1],pr->tabBases[1],pr->modulus,ctx)); + } + pr->pokDelta = cryptic_zkpk_schnorr_new(pr->tabBases, 2, pr->modulus); + goto_cleanup_if_fail(cryptic_zkpk_schnorr_verify_noninteractive_proof(pr->pokDelta,pr->dlreps[4],hash,responses+8) == 0); + if(neg) goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(pr->tabBases[1],tmp)); + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_mont(mont); + cryptic_release_bn(tmp); + return rc; +} + +/* Getters */ +BIGNUM* +cryptic_proofrange_qrg_get_modulus(CrypticProofrangeQrg *pr) +{ + if(pr->modulus) {return(pr->modulus);} + else {return(NULL);} +} + +BIGNUM** +cryptic_proofrange_qrg_get_dlreps(CrypticProofrangeQrg *pr) +{ + if(pr->dlreps){ + //concat avec delta + return(pr->dlreps); + } + else{ + return(NULL); + } +} + +BIGNUM** +cryptic_proofrange_qrg_get_commitments(CrypticProofrangeQrg *pr) +{ + if(pr->pokSqrRoot1 && pr->pokSqrRoot2 && pr->pokSqrRoot3 && pr->pokSqrRoot4 && pr->pokDelta){ + int i; + for(i=0;i<6;i++){ + if(!(pr->commitments[i] = BN_new())) return NULL; + } + if(!BN_copy(pr->commitments[0],cryptic_zkpk_schnorr_get_commitment(pr->pokSqrRoot1))) return NULL; + if(!BN_copy(pr->commitments[1],cryptic_zkpk_schnorr_get_commitment(pr->pokSqrRoot2))) return NULL; + if(!BN_copy(pr->commitments[2],cryptic_zkpk_schnorr_get_commitment(pr->pokSqrRoot3))) return NULL; + if(!BN_copy(pr->commitments[3],cryptic_zkpk_schnorr_get_commitment(pr->pokSqrRoot4))) return NULL; + if(!BN_copy(pr->commitments[4],cryptic_zkpk_schnorr_get_commitment(pr->pokDelta))) return NULL; + if(!BN_copy(pr->commitments[5],pr->Q)) return NULL; + return(pr->commitments); + } + else { + return(NULL); + } +} + +BIGNUM** +cryptic_proofrange_qrg_get_responses(CrypticProofrangeQrg *pr) +{ + if(pr->pokSqrRoot1 && pr->pokSqrRoot2 && pr->pokSqrRoot3 && pr->pokSqrRoot4 && pr->pokDelta){ + return(pr->responses); + } + else { + return(NULL); + } +} + +BIGNUM** +cryptic_proofrange_qrg_get_tabRandDLRepSqrRoot(CrypticProofrangeQrg *pr) +{ + if(pr->tabRandDLRepSqrRoot){ + //concat avec delta + return(pr->tabRandDLRepSqrRoot); + } + else{ + return(NULL); + } +} diff --git a/cryptic/protocols/proof_range/proof_range_in_qrg.h b/cryptic/protocols/proof_range/proof_range_in_qrg.h new file mode 100644 index 0000000..66c67f9 --- /dev/null +++ b/cryptic/protocols/proof_range/proof_range_in_qrg.h @@ -0,0 +1,184 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef CRYPTIC_PROOF_RANGE_H +#define CRYPTIC_PROOF_RANGE_H + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +#define CRYPTIC_PROOF_RANGE_GT 1 +#define CRYPTIC_PROOF_RANGE_GTE 2 +#define CRYPTIC_PROOF_RANGE_LT 3 +#define CRYPTIC_PROOF_RANGE_LTE 4 + +#define CRYPTIC_PROOF_RANGE_ZK_SEC_PARAM 80 //l0 +#define CRYPTIC_PROOF_RANGE_SEC_PARAM 160 //lk +#define CRYPTIC_PROOF_RANGE_CHALLENGE_MIN_SIZE 160 //lc + +#define CRYPTIC_PROOF_RANGE_TEST_ZK_SEC_PARAM 40 //l0 +#define CRYPTIC_PROOF_RANGE_TEST_SEC_PARAM 80 //lk +#define CRYPTIC_PROOF_RANGE_TEST_CHALLENGE_MIN_SIZE 80 //lc + +#include +#include +#include + +#include "../../export.h" + +#include "../pok_schnorr/schnorr_zkpk.h" +#include "../../maths/decompose_integer.h" + +#define CRYPTIC_TYPE_PROOFRANGEQRG (cryptic_proofrange_qrg_get_type()) +#define CRYPTIC_PROOFRANGEQRG(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CRYPTIC_TYPE_PROOFRANGEQRG, CrypticProofrangeQrg)) +#define CRYPTIC_PROOFRANGEQRG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), CRYPTIC_TYPE_PROOFRANGEQRG, CrypticProofrangeQrgClass)) +#define CRYPTIC_IS_PROOFRANGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), CRYPTIC_TYPE_PROOFRANGEQRG)) +#define CRYPTIC_IS_PROOFRANGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CRYPTIC_TYPE_PROOFRANGEQRG)) +#define CRYPTIC_PROOFRANGEQRG_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CRYPTIC_TYPE_PROOFRANGEQRG, CrypticProofrangeQrgClass)) + +typedef struct _CrypticProofrangeQrg CrypticProofrangeQrg; +typedef struct _CrypticProofrangeQrgClass CrypticProofrangeQrgClass; + +/** + * CrypticProofrangeQrg: + * @rel: inequality to prove + * @m: quantity on which the range proof is led + * @b: quantity of comparison + * @delta: Absolute value of the difference of b - m (-1) + * @di: decomposition in squares of delta + * @randDLRepDelta: + * @dLRepDelta: dlrep Delta (Td) + * @tabRandDLRepSqrRoot: random to dlrep the square roots of Delta + * @tabDLRepSqrRoot: dlrep of the square roots of Delta (Ti) + * @randQ: + * @Q: + * @challenge: + * @tabBases: e.g. S and Z for CLSIG + * @responserho: + * @dlreps: T1, T2, T3, T4, T5, Tdelta + * @commitments: t1, t2, t3, t4, t5, tdelta, tQ + * @responses: su1, zu1, su2, zu2, su3, zu3, su4, zu4, srho + * @modulus: + * @pokSqrRoot1: Proof of T1 = -/+ Z^u1.S^randDLRepSqrRoot[0] + * @pokSqrRoot2: Proof of T2 = -/+ Z^u2.S^randDLRepSqrRoot[1] + * @pokSqrRoot3: Proof of T3 = -/+ Z^u3.S^randDLRepSqrRoot[2] + * @pokSqrRoot4:Proof of T3 = -/+ Z^u4.S^randDLRepSqrRoot[3] + * @pokDelta: Proof of Td = T1^u1.T2^u2.T3^u3.T4^u4.S^(randDLRepDelta - (u1r1 + u2r2 + u3r3 + u4r4)) + * + * This class is used to lead a proof of an inequality statement on a value in a DL representation. + * The quantity m can be proved >, >=, < or <= to b. + * + * WARNING: This proof is for commitments and proofs led in a composite group. + * Consists in prooving that a value is positive (e.g. delta = b-m to prove that m < b). + * The prover does not know the order and thus cannot make compute the proof for negative values. + * Boudot, Efficient proofs that a committed number lies in an interval, 2000, divide the proof into two positivity proofs. + * Decomposition in four squares for this purpose introduced by Lipmaa: + * Helger Lipmaa, Statistical zero-knowledge proofs from diophantine equations, 2001. + * Decomposition is due to Lagrange's four square theorem (1770) also know as Bachet's conjecture. + * Algorithm of decomposition due to Rabin and Shalit, Randomized algorithms in number theory, 1986. + * + */ +struct _CrypticProofrangeQrg{ + GObject parent; + + /*< public >*/ + int rel; + + int lg_sec_param; /* lk */ + int lg_zk_sec_param; /* l0 */ + int lg_challenge; /* lc */ + + BIGNUM *m; + BIGNUM *b; + BIGNUM *delta; + BIGNUM *randDLRepDelta; + BIGNUM **tabRandDLRepSqrRoot; + BIGNUM *randQ; + BIGNUM *Q; + BIGNUM *challenge; + BIGNUM **tabBases; + BIGNUM *responserho; + BIGNUM **dlreps; + BIGNUM **commitments; + BIGNUM **responses; + BIGNUM *modulus; + + CrypticZkpkSchnorr *pokSqrRoot1; + CrypticZkpkSchnorr *pokSqrRoot2; + CrypticZkpkSchnorr *pokSqrRoot3; + CrypticZkpkSchnorr *pokSqrRoot4; + CrypticZkpkSchnorr *pokDelta; + + CrypticDecomposeInteger *di; +}; + +struct _CrypticProofrangeQrgClass { + GObjectClass parent_class; +}; + + +CRYPTIC_EXPORT GType cryptic_proofrange_qrg_get_type(void); + +CRYPTIC_EXPORT CrypticProofrangeQrg* cryptic_proofrange_qrg_new(BIGNUM *base1, BIGNUM *base2, BIGNUM *modulus); + + +/* Prover */ +CRYPTIC_EXPORT int cryptic_proofrange_qrg_round1(CrypticProofrangeQrg *pr, + int rel, + BIGNUM *m, + BIGNUM *b, + BIGNUM *random_m, + int lg_sec_param, + int lg_zk_sec_param, + int lg_challenge); + +CRYPTIC_EXPORT int cryptic_proofrange_qrg_round2(CrypticProofrangeQrg *pr, BIGNUM *challenge); + + +/* Verifier */ +CRYPTIC_EXPORT int cryptic_proofrange_qrg_verify_interactive_proof(CrypticProofrangeQrg *pr, + int rel, + BIGNUM *b, + BIGNUM **dlreps, + BIGNUM **commitments, + BIGNUM *challenge, + BIGNUM **responses); + +CRYPTIC_EXPORT int cryptic_proofrange_qrg_verify_noninteractive_proof(CrypticProofrangeQrg *pr, + int rel, + BIGNUM *b, + BIGNUM **dlreps, + BIGNUM *hash, + BIGNUM **responses); + +/* Accessors */ +CRYPTIC_EXPORT BIGNUM* cryptic_proofrange_qrg_get_modulus(CrypticProofrangeQrg *pr); +CRYPTIC_EXPORT BIGNUM** cryptic_proofrange_qrg_get_dlreps(CrypticProofrangeQrg *pr); +CRYPTIC_EXPORT BIGNUM** cryptic_proofrange_qrg_get_commitments(CrypticProofrangeQrg *pr); +CRYPTIC_EXPORT BIGNUM** cryptic_proofrange_qrg_get_responses(CrypticProofrangeQrg *pr); +CRYPTIC_EXPORT BIGNUM** cryptic_proofrange_qrg_get_tabRandDLRepSqrRoot(CrypticProofrangeQrg *pr); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* CRYPTIC_PROOF_RANGE_H */ diff --git a/cryptic/utils.h b/cryptic/utils.h new file mode 100644 index 0000000..b59e61c --- /dev/null +++ b/cryptic/utils.h @@ -0,0 +1,533 @@ + +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef CRYPTIC_UTILS_H +#define CRYPTIC_UTILS_H + +#include +#include + +#define cryptic_critical(message, args...) \ + g_log("cryptic", G_LOG_LEVEL_CRITICAL, message, ## args) + +#define cryptic_warning(message, args...) \ + g_log("cryptic", G_LOG_LEVEL_WARNING, message, ## args) + +#define cryptic_message(message, args...) \ + g_log("cryptic", G_LOG_LEVEL_MESSAGE, message, ## args) + +/** + * cryptic_ref: + * @object: an object whose reference count must be incremented. + * + * Increment the reference count of an object, do not emit warning if it is NULL. + * + * Return value: the @object. + */ +#define cryptic_ref(object) ((object) != NULL ? (g_object_ref(object), object) : NULL) + +/** + * cryptic_unref: + * @object: an object whose reference count must be decremented. + * + * Decrement the reference count of an object, do not emit warnings if it is NULL. + * + * Return value: the @object. + */ +#define cryptic_unref(object) ((object) != NULL ? (g_object_unref(object), object) : NULL) + +/* Freeing */ + +/* + * cryptic_release_xxx are macros which ensure you do not get 'double free' errors, they first check + * that the variable is not NULL before calling the deallocation function, and after deallocation + * they reset the variable to NULL, preventing 'double free'. + */ +#define cryptic_release(dest) \ + { \ + if (dest) { \ + g_free(dest); dest = NULL; \ + } \ + } + +#define cryptic_release_bn(bn) \ + { \ + BIGNUM **__tmp = &(bn); \ + if (*__tmp) { \ + BN_clear_free(*__tmp); \ + *__tmp = NULL; \ + } \ + } + +//BN_CTX_end(ctx) produce a seg fault; +#define cryptic_release_ctx(ctx) \ + { \ + if (ctx) { \ + BN_CTX_free(ctx); \ + } \ + } + +#define cryptic_release_mont(mont) \ + { \ + if (mont != NULL) { \ + BN_MONT_CTX_free(mont); \ + } \ + } + +#define cryptic_release_full(dest, free_function) \ + { \ + if (dest) { \ + free_function(dest); dest = NULL; \ + } \ + } + +#define cryptic_release_full2(dest, free_function, type) \ + { \ + cryptic_check_type_equality(dest, type); \ + if (dest) { \ + free_function(dest); dest = NULL; \ + } \ + } + +#define cryptic_release_gobject(dest) \ + { \ + if (G_IS_OBJECT(dest) || dest == NULL) { \ + cryptic_release_full(dest, g_object_unref); \ + } else { \ + g_critical("Trying to unref a non GObject pointer file=%s:%u pointerbybname=%s pointer=%p", __FILE__, __LINE__, #dest, dest); \ + } \ + } + +#define cryptic_release_string(dest) \ + cryptic_release_full(dest, g_free) + +#define cryptic_release_list(dest) \ + cryptic_release_full2(dest, g_list_free, GList*) + +#define cryptic_release_list_of_full(dest, free_function) \ + { \ + GList **__tmp = &(dest); \ + if (*__tmp) { \ + g_list_foreach(*__tmp, (GFunc)free_function, NULL); \ + cryptic_release_list(*__tmp); \ + } \ + } + +#define cryptic_release_list_of_strings(dest) \ + cryptic_release_list_of_full(dest, g_free) + +#define cryptic_release_list_of_gobjects(dest) \ + cryptic_release_list_of_full(dest, g_object_unref) + +#define cryptic_release_ghashtable(dest) \ + cryptic_release_full(dest, g_hash_table_destroy) + +#define cryptic_release_gstring(dest, b) \ + { \ + GString **__tmp = &(dest); \ + if (*__tmp) {\ + g_string_free(*__tmp, (b)); \ + *__tmp = NULL; \ + } \ + } + +/* Assignment and list appending */ +/* + * cryptic_assign_xxx macros ensure that you dot leak previous value of assigned things, they use + * cryptic_release_xxx macros to deallocate, they also ensure proper reference counting on passed by + * references values and proper copying on passed by value values. + */ +#define cryptic_assign_string(dest,src) \ + { \ + char *__tmp = g_strdup(src);\ + cryptic_release_string(dest); \ + dest = __tmp; \ + } + +#define cryptic_assign_new_string(dest,src) \ + { \ + char *__tmp = src; \ + if (dest != __tmp) \ + cryptic_release_string(dest); \ + dest = __tmp; \ + } + +#define cryptic_assign_gobject(dest,src) \ + { \ + GObject *__tmp = G_OBJECT(src); \ + if (__tmp) \ + g_object_ref(__tmp); \ + cryptic_release_gobject(dest); \ + dest = (void*)(__tmp); \ + } + +#define cryptic_assign_new_gobject(dest,src) \ + { \ + GObject *__tmp = G_OBJECT(src); \ + if (dest != (void*)__tmp) \ + cryptic_release_gobject(dest); \ + dest = (void*)(__tmp); \ + } + +#define cryptic_assign_list(dest, src) \ + { \ + GList **__tmp = &(dest); \ + if (*__tmp) \ + g_list_free(*__tmp); \ + *__tmp = g_list_copy((src)); \ + } + +#define cryptic_assign_new_list_of_gobjects(dest, src) \ + { \ + GList *__tmp = (src); \ + cryptic_release_list_of_gobjects(dest); \ + dest = (GList*)__tmp; \ + } + +#define cryptic_assign_new_list_of_strings(dest, src) \ + { \ + GList *__tmp = (src); \ + cryptic_release_list_of_strings(dest); \ + dest = (GList*)__tmp; \ + } + +#define cryptic_assign_list_of_gobjects(dest, src) \ + { \ + GList *__tmp = (src); \ + cryptic_release_list_of_gobjects(dest); \ + dest = g_list_copy(__tmp); \ + for (;__tmp != NULL; __tmp = g_list_next(__tmp)) { \ + if (G_IS_OBJECT(__tmp->data)) { \ + g_object_ref(__tmp->data); \ + } \ + } \ + } + +#define cryptic_assign_list_of_strings(dest, src) \ + { \ + GList *__tmp = src; \ + GList *__iter_dest; \ + cryptic_release_list_of_strings(dest); \ + dest = g_list_copy(__tmp); \ + for (__iter_dest = dest ; __iter_dest != NULL ; __iter_dest = g_list_next(__iter_dest)) { \ + __iter_dest->data = g_strdup(__iter_dest->data); \ + } \ + } + +/* List appending */ + +/* cryptic_list_add_xxx macros, simplify code around list manipulation (g_list_append needs to be + * used like this 'l = g_list_appen(l, value)' ) and ensure proper reference count or copying of + * values. + */ +#define cryptic_list_add(dest, src) \ + { \ + cryptic_check_type_equality((src), void*); \ + dest = g_list_append(dest, (src)); \ + } + +#define cryptic_list_add_non_null(dest, src) \ + { \ + void *__tmp_non_null_src = (src); \ + if (__tmp_non_null_src != NULL) { \ + dest = g_list_append(dest, __tmp_non_null_src); \ + } else { \ + g_critical("Adding a NULL value to a non-NULL content list: dest=%s src=%s", #dest, #src); \ + } \ + } + +#define cryptic_list_add_string(dest, src) \ + { \ + cryptic_list_add_non_null(dest, g_strdup(src));\ + } + +#define cryptic_list_add_new_string(dest, src) \ + { \ + gchar *__tmp = src; \ + cryptic_list_add_non_null(dest, __tmp); \ + } + +#define cryptic_list_add_gobject(dest, src) \ + { \ + void *__tmp_src = (src); \ + if (G_IS_OBJECT(__tmp_src)) { \ + dest = g_list_append(dest, g_object_ref(__tmp_src)); \ + } else { \ + g_critical("Trying to add to a GList* a non GObject pointer dest=%s src=%s", #dest, #src); \ + } \ + } + +#define cryptic_list_add_new_gobject(dest, src) \ + { \ + void *__tmp_src = (src); \ + if (G_IS_OBJECT(__tmp_src)) { \ + dest = g_list_append(dest, __tmp_src); \ + } else { \ + g_critical("Trying to add to a GList* a non GObject pointer dest=%s src=%s", #dest, #src); \ + } \ + } + +#define cryptic_list_add_gstrv(dest, src) \ + { \ + GList **__tmp_dest = &(dest); \ + const char **__iter = (const char**)(src); \ + while (__iter && *__iter) { \ + cryptic_list_add_string(*__tmp_dest, *__iter); \ + } \ + } + +/* List element removal */ +#define cryptic_list_remove_gobject(list, gobject) \ + do { void *__tmp = gobject; GList **__tmp_list = &(list); \ + *__tmp_list = g_list_remove(*__tmp_list, __tmp); \ + cryptic_unref(__tmp); } while(0) + +/* Pointer ownership transfer */ + +/* cryptic_transfer_xxx macros are like cryptic_assign_xxx but they do not increment reference count or + * copy the source value, instead they steal the value (and set the source to NULL, preventing stale + * references). + */ +#define cryptic_transfer_full(dest, src, kind) \ + {\ + cryptic_release_##kind((dest)); \ + cryptic_check_type_equality(dest, src); \ + (dest) = (void*)(src); \ + (src) = NULL; \ + } + +#define cryptic_transfer_xpath_object(dest, src) \ + cryptic_transfer_full(dest, src, xpath_object) + +#define cryptic_transfer_string(dest, src) \ + cryptic_transfer_full(dest, src, string) + +#define cryptic_transfer_gobject(dest, src) \ + cryptic_transfer_full(dest, src, gobject) + +/* Node extraction */ +#define cryptic_extract_node_or_fail(to, from, kind, error) \ + {\ + void *__tmp = (from); \ + if (CRYPTIC_IS_##kind(__tmp)) { \ + to = CRYPTIC_##kind(__tmp); \ + } else { \ + rc = error; \ + goto cleanup; \ + }\ + } + +/* Bad param handling */ +#define cryptic_return_val_if_invalid_param(kind, name, val) \ + g_return_val_if_fail(CRYPTIC_IS_##kind(name), val) + +#define cryptic_bad_param(kind, name) \ + cryptic_return_val_if_invalid_param(kind, name, \ + CRYPTIC_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); + +#define cryptic_null_param(name) \ + g_return_val_if_fail(name != NULL, CRYPTIC_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); + +inline static gboolean +cryptic_is_empty_string(const char *str) { + return ((str) == NULL || (str)[0] == '\0'); +} + +/** + * cryptic_check_non_empty_string: + * @str: a char pointer + * + * Check that @str is non-NULL and not empty, otherwise jump to cleanup and return + * CRYPTIC_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ. + */ +#define cryptic_check_non_empty_string(str) \ + goto_cleanup_if_fail_with_rc(! cryptic_is_empty_string(str), \ + CRYPTIC_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); + +/* + * We extensively use goto operator but in a formalized way, i.e. only for error checking code + * paths. + * + * The next macros goto_cleanup_xxxx encapsulate idioms used in cryptic, like checking for a condition + * or setting the return code which must be called 'rc' and be of an 'int' type. + */ + +/* + * The following macros are made to create some formalism for function's cleanup code. + * + * The exit label should be called 'cleanup'. And for functions returning an integer error code, the + * error code should be named 'rc' and 'return rc;' should be the last statement of the function. + */ + +/** + * goto_cleanup_with_rc: + * @rc_value: integer return value + * + * This macro jump to the 'cleanup' label and set the return value to @rc_value. + * + */ +#define goto_cleanup_with_rc(rc_value) \ + do {\ + rc = (rc_value); \ + goto cleanup; \ + } while(0); + +/** + * goto_cleanup_if_fail: + * @condition: a boolean condition + * + * Jump to the 'cleanup' label if the @condition is FALSE. + * + */ +#define goto_cleanup_if_fail(condition) \ + {\ + if (! (condition) ) {\ + goto cleanup; \ + } \ + } + +/** + * goto_cleanup_if_fail_with_rc: + * @condition: a boolean condition + * @rc_value: integer return value + * + * Jump to the 'cleanup' label if the @condition is FALSE and set the return value to + * @rc_value. + * + */ +#define goto_cleanup_if_fail_with_rc(condition, rc_value) \ + {\ + if (! (condition) ) {\ + rc = (rc_value); \ + goto cleanup; \ + } \ + } + +/** + * goto_cleanup_if_fail_with_rc_with_warning: + * @condition: a boolean condition + * @rc_value: integer return value + * + * Jump to the 'cleanup' label if the @condition is FALSE and set the return value to + * @rc_value. Also emit a warning, showing the condition and the return value. + * + */ +#define goto_cleanup_if_fail_with_rc_with_warning(condition, rc_value) \ + {\ + if (! (condition) ) {\ + g_warning("%s failed, returning %s", #condition, #rc_value);\ + rc = (rc_value); \ + goto cleanup; \ + } \ + } + +#define goto_cleanup_if_fail_with_warning(condition) \ + {\ + if (! (condition) ) {\ + g_warning("%s failed", #condition);\ + goto cleanup; \ + } \ + } + +#define goto_cleanup_if_fail_with_rc_with_warning_openssl(condition) \ + {\ + if (! (condition) ) {\ + g_warning("%s failed, returning CRYPTIC_ERROR_SSL", #condition);\ + rc = (CRYPTIC_ERROR_SSL); \ + goto cleanup; \ + } \ + } + +/** + * check_good_rc: + * @what: a call to a function returning a cryptic error code + * + * Check if return code is 0, if not store it in rc and jump to cleanup label. + */ +#define cryptic_check_good_rc(what) \ + { \ + int __rc = (what);\ + goto_cleanup_if_fail_with_rc(__rc == 0, __rc); \ + } + +#define cryptic_mem_debug(who, what, where) \ + { \ + if (cryptic_flag_memory_debug) \ + fprintf(stderr, " freeing %s/%s (at %p)\n", who, what, (void*)where); \ + } + +/** + * cryptic_foreach: + * @_iter: a #GList variable, which will server to traverse @_list + * @_list: a #GList value, which we will traverse + * + * Traverse a #GList list using 'for' construct. It must be followed by a block or a statement. + */ +#define cryptic_foreach(_iter, _list) \ + for (_iter = (_list); _iter; _iter = g_list_next(_iter)) + +/** + * cryptic_foreach_full_begin: + * @_type: the type of the variable @_data + * @_data: the name of the variable to define to store data values + * @_iter: the name of the variable to define to store the iterator + * @_list: the GList* to iterate + * + * Traverse a GList* @_list, using @_iter as iteration variable extract data field to variable + * @_data of type @_type. + */ +#define cryptic_foreach_full_begin(_type, _data, _iter, _list) \ + { \ + _type _data = NULL; \ + GList *_iter = NULL; \ + for (_iter = (_list); _iter && ((_data = _iter->data), 1); _iter = g_list_next(_iter)) \ + { + +#define cryptic_foreach_full_end() \ + } } + +/** + * cryptic_list_get_first_child: + * @list:(allowed-none): a #GList node or NULL. + * + * Return the first child in a list, or NULL. + */ +#define cryptic_list_get_first_child(list) \ + ((list) ? (list)->data : NULL) + +/* + * Simplify simple accessors argument checking. + * + */ +#define cryptic_return_val_if_fail(assertion, value) \ + if (!(assertion)) return (value); + +#define cryptic_return_null_if_fail(assertion) \ + cryptic_return_val_if_fail(assertion, NULL) + +#define cryptic_return_if_fail(assertion) \ + if (!(assertion)) return; + +#define cryptic_trace(args...) \ + if (cryptic_flag_memory_debug) { \ + fprintf(stderr, ## args); \ + } + + +#endif /* CRYPTIC_UTILS_H */ diff --git a/cryptic/utils/print.c b/cryptic/utils/print.c new file mode 100644 index 0000000..05b8fe5 --- /dev/null +++ b/cryptic/utils/print.c @@ -0,0 +1,92 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include +#include +#include + +//#include "../cryptic.h" +#include "../protocols/clsig/clsig.h" +#include "../errors.h" +#include "print.h" + +int +cryptic_print_bn(char *prefix, BIGNUM *bn) +{ + char *hex = NULL; + hex = BN_bn2hex(bn); + printf("%s%s\n", prefix, hex); + OPENSSL_free(hex); + return CRYPTIC_NO_ERROR; +} + +int +cryptic_print_private_CLSIG_parameters(CrypticClsig *clsig) +{ + printf("SIGNER PRIVATE DATA\n"); + if(clsig->qrg){ + if (cryptic_qrg_get_q(clsig->qrg)) cryptic_print_bn("----> \tq\t",cryptic_qrg_get_q(clsig->qrg)); + if (cryptic_qrg_get_qq(clsig->qrg)) cryptic_print_bn("----> \tqq\t",cryptic_qrg_get_qq(clsig->qrg)); + if (cryptic_qrg_get_p(clsig->qrg)) cryptic_print_bn("----> \tp\t",cryptic_qrg_get_p(clsig->qrg)); + if (cryptic_qrg_get_pp(clsig->qrg)) cryptic_print_bn("----> \tpp\t",cryptic_qrg_get_pp(clsig->qrg)); + if (cryptic_qrg_get_order(clsig->qrg)) cryptic_print_bn("----> \torder\t",cryptic_qrg_get_order(clsig->qrg)); + if (cryptic_qrg_get_phi(clsig->qrg)) cryptic_print_bn("----> \tphi\t",cryptic_qrg_get_phi(clsig->qrg)); + } + if (clsig->d) cryptic_print_bn("----> \td\t",clsig->d); + + return CRYPTIC_NO_ERROR; +} + +int +cryptic_print_public_CLSIG_parameters(CrypticClsig *clsig) +{ + + printf("SIGNER PUBLIC DATA\n"); + if (clsig->modulus) cryptic_print_bn("----> \tn\t",clsig->modulus); + if (clsig->S) cryptic_print_bn("----> \tS\t",clsig->S); + if (clsig->Z) cryptic_print_bn("----> \tZ\t",clsig->Z); + int i; + for(i=0;inb_bases;i++){ + if (clsig->bases[i]){ + printf("----> \tR%d",i); + cryptic_print_bn("\t",clsig->bases[i]); + } + } + if (clsig->e) cryptic_print_bn("----> \te\t",clsig->e); + + return CRYPTIC_NO_ERROR; +} + +int +cryptic_print_CLSIG_lengths(CrypticClsig *clsig) +{ + printf("Bit lengths of the clsig system:\n"); + printf("lg_modulus:\t\t%d\n",clsig->lg_modulus); + printf("lg_exponent:\t\t%d\n",clsig->lg_exponent); + printf("interval_exponent:\t%d\n",clsig->interval_exponent); + printf("lg_blind:\t\t%d\n",clsig->lg_blind); + printf("lg_randomize:\t\t%d\n",clsig->lg_randomize); + printf("lg_sec_param:\t\t%d\n",clsig->lg_sec_param); + printf("lg_zk_sec_param:\t%d\n",clsig->lg_zk_sec_param); + printf("lg_clsig_sec_param:\t%d\n",clsig->lg_clsig_sec_param); + printf("nb_bases:\t\t%d\n",clsig->nb_bases); + + return CRYPTIC_NO_ERROR; +} diff --git a/cryptic/utils/print.h b/cryptic/utils/print.h new file mode 100644 index 0000000..31bbc59 --- /dev/null +++ b/cryptic/utils/print.h @@ -0,0 +1,32 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef CRYPTIC_UTILS_PRINT_H +#define CRYPTIC_UTILS_PRINT_H + +#include +#include "../protocols/clsig/clsig.h" + +#include "../export.h" + +CRYPTIC_EXPORT int cryptic_print_bn(char *prefix, BIGNUM *bn); +int cryptic_print_private_CLSIG_parameters(CrypticClsig* clsig); +int cryptic_print_public_CLSIG_parameters(CrypticClsig* clsig); +int cryptic_print_CLSIG_lengths(CrypticClsig* clsig); + +#endif diff --git a/gtk-doc.make b/gtk-doc.make new file mode 120000 index 0000000..3ee6bad --- /dev/null +++ b/gtk-doc.make @@ -0,0 +1 @@ +/usr/share/gtk-doc/data/gtk-doc.notmpl.make \ No newline at end of file diff --git a/m4/ac_check_class.m4 b/m4/ac_check_class.m4 new file mode 100644 index 0000000..264ba4d --- /dev/null +++ b/m4/ac_check_class.m4 @@ -0,0 +1,147 @@ +##### http://autoconf-archive.cryp.to/ac_check_class.html +# +# SYNOPSIS +# +# AC_CHECK_CLASS +# +# DESCRIPTION +# +# AC_CHECK_CLASS tests the existence of a given Java class, either in +# a jar or in a '.class' file. +# +# *Warning*: its success or failure can depend on a proper setting of +# the CLASSPATH env. variable. +# +# Note: This is part of the set of autoconf M4 macros for Java +# programs. It is VERY IMPORTANT that you download the whole set, +# some macros depend on other. Unfortunately, the autoconf archive +# does not support the concept of set of macros, so I had to break it +# for submission. The general documentation, as well as the sample +# configure.in, is included in the AC_PROG_JAVA macro. +# +# LAST MODIFICATION +# +# 2000-07-19 +# +# COPYLEFT +# +# Copyright (c) 2000 Stephane Bortzmeyer +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. +# +# As a special exception, the respective Autoconf Macro's copyright +# owner gives unlimited permission to copy, distribute and modify the +# configure scripts that are the output of Autoconf when processing +# the Macro. You need not follow the terms of the GNU General Public +# License when using or distributing such scripts, even though +# portions of the text of the Macro appear in them. The GNU General +# Public License (GPL) does govern all other use of the material that +# constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the +# Autoconf Macro released by the Autoconf Macro Archive. When you +# make and distribute a modified version of the Autoconf Macro, you +# may extend this special exception to the GPL to apply to your +# modified version as well. + +AC_DEFUN([AC_CHECK_CLASS],[ +AC_REQUIRE([AC_PROG_JAVA]) +ac_var_name=`echo $1 | sed 's/\./_/g'` +dnl Normaly I'd use a AC_CACHE_CHECK here but since the variable name is +dnl dynamic I need an extra level of extraction +AC_MSG_CHECKING([for $1 class]) +AC_CACHE_VAL(ac_cv_class_$ac_var_name, [ +if test x$ac_cv_prog_uudecode_base64 = xyes; then +dnl /** +dnl * Test.java: used to test dynamicaly if a class exists. +dnl */ +dnl public class Test +dnl { +dnl +dnl public static void +dnl main( String[] argv ) +dnl { +dnl Class lib; +dnl if (argv.length < 1) +dnl { +dnl System.err.println ("Missing argument"); +dnl System.exit (77); +dnl } +dnl try +dnl { +dnl lib = Class.forName (argv[0]); +dnl } +dnl catch (ClassNotFoundException e) +dnl { +dnl System.exit (1); +dnl } +dnl lib = null; +dnl System.exit (0); +dnl } +dnl +dnl } +cat << \EOF > Test.uue +begin-base64 644 Test.class +yv66vgADAC0AKQcAAgEABFRlc3QHAAQBABBqYXZhL2xhbmcvT2JqZWN0AQAE +bWFpbgEAFihbTGphdmEvbGFuZy9TdHJpbmc7KVYBAARDb2RlAQAPTGluZU51 +bWJlclRhYmxlDAAKAAsBAANlcnIBABVMamF2YS9pby9QcmludFN0cmVhbTsJ +AA0ACQcADgEAEGphdmEvbGFuZy9TeXN0ZW0IABABABBNaXNzaW5nIGFyZ3Vt +ZW50DAASABMBAAdwcmludGxuAQAVKExqYXZhL2xhbmcvU3RyaW5nOylWCgAV +ABEHABYBABNqYXZhL2lvL1ByaW50U3RyZWFtDAAYABkBAARleGl0AQAEKEkp +VgoADQAXDAAcAB0BAAdmb3JOYW1lAQAlKExqYXZhL2xhbmcvU3RyaW5nOylM +amF2YS9sYW5nL0NsYXNzOwoAHwAbBwAgAQAPamF2YS9sYW5nL0NsYXNzBwAi +AQAgamF2YS9sYW5nL0NsYXNzTm90Rm91bmRFeGNlcHRpb24BAAY8aW5pdD4B +AAMoKVYMACMAJAoAAwAlAQAKU291cmNlRmlsZQEACVRlc3QuamF2YQAhAAEA +AwAAAAAAAgAJAAUABgABAAcAAABtAAMAAwAAACkqvgSiABCyAAwSD7YAFBBN +uAAaKgMyuAAeTKcACE0EuAAaAUwDuAAasQABABMAGgAdACEAAQAIAAAAKgAK +AAAACgAAAAsABgANAA4ADgATABAAEwASAB4AFgAiABgAJAAZACgAGgABACMA +JAABAAcAAAAhAAEAAQAAAAUqtwAmsQAAAAEACAAAAAoAAgAAAAQABAAEAAEA +JwAAAAIAKA== +==== +EOF + if uudecode$EXEEXT Test.uue; then + : + else + echo "configure: __oline__: uudecode had trouble decoding base 64 file 'Test.uue'" >&AC_FD_CC + echo "configure: failed file was:" >&AC_FD_CC + cat Test.uue >&AC_FD_CC + ac_cv_prog_uudecode_base64=no + fi + rm -f Test.uue + if AC_TRY_COMMAND($JAVA $JAVAFLAGS Test $1) >/dev/null 2>&1; then + eval "ac_cv_class_$ac_var_name=yes" + else + eval "ac_cv_class_$ac_var_name=no" + fi + rm -f Test.class +else + AC_TRY_COMPILE_JAVA([$1], , [eval "ac_cv_class_$ac_var_name=yes"], + [eval "ac_cv_class_$ac_var_name=no"]) +fi +eval "ac_var_val=$`eval echo ac_cv_class_$ac_var_name`" +eval "HAVE_$ac_var_name=$`echo ac_cv_class_$ac_var_val`" +HAVE_LAST_CLASS=$ac_var_val +if test x$ac_var_val = xyes; then + ifelse([$2], , :, [$2]) +else + ifelse([$3], , :, [$3]) +fi +]) +dnl for some reason the above statment didn't fall though here? +dnl do scripts have variable scoping? +eval "ac_var_val=$`eval echo ac_cv_class_$ac_var_name`" +AC_MSG_RESULT($ac_var_val) +]) diff --git a/m4/ac_check_classpath.m4 b/m4/ac_check_classpath.m4 new file mode 100644 index 0000000..bfbdda4 --- /dev/null +++ b/m4/ac_check_classpath.m4 @@ -0,0 +1,63 @@ +##### http://autoconf-archive.cryp.to/ac_check_classpath.html +# +# SYNOPSIS +# +# AC_CHECK_CLASSPATH +# +# DESCRIPTION +# +# AC_CHECK_CLASSPATH just displays the CLASSPATH, for the edification +# of the user. +# +# Note: This is part of the set of autoconf M4 macros for Java +# programs. It is VERY IMPORTANT that you download the whole set, +# some macros depend on other. Unfortunately, the autoconf archive +# does not support the concept of set of macros, so I had to break it +# for submission. The general documentation, as well as the sample +# configure.in, is included in the AC_PROG_JAVA macro. +# +# LAST MODIFICATION +# +# 2000-07-19 +# +# COPYLEFT +# +# Copyright (c) 2000 Stephane Bortzmeyer +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. +# +# As a special exception, the respective Autoconf Macro's copyright +# owner gives unlimited permission to copy, distribute and modify the +# configure scripts that are the output of Autoconf when processing +# the Macro. You need not follow the terms of the GNU General Public +# License when using or distributing such scripts, even though +# portions of the text of the Macro appear in them. The GNU General +# Public License (GPL) does govern all other use of the material that +# constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the +# Autoconf Macro released by the Autoconf Macro Archive. When you +# make and distribute a modified version of the Autoconf Macro, you +# may extend this special exception to the GPL to apply to your +# modified version as well. + +AC_DEFUN([AC_CHECK_CLASSPATH],[ +if test "x$CLASSPATH" = x; then + echo "You have no CLASSPATH, I hope it is good" +else + echo "You have CLASSPATH $CLASSPATH, hope it is correct" +fi +]) diff --git a/m4/ac_check_java_home.m4 b/m4/ac_check_java_home.m4 new file mode 100644 index 0000000..88bfbd1 --- /dev/null +++ b/m4/ac_check_java_home.m4 @@ -0,0 +1,62 @@ +##### http://autoconf-archive.cryp.to/ac_check_java_home.html +# +# SYNOPSIS +# +# AC_CHECK_JAVA_HOME +# +# DESCRIPTION +# +# Check for Sun Java (JDK / JRE) installation, where the 'java' VM is +# in. If found, set environment variable JAVA_HOME = Java +# installation home, else left JAVA_HOME untouch, which in most case +# means JAVA_HOME is empty. +# +# LAST MODIFICATION +# +# 2002-10-10 +# +# COPYLEFT +# +# Copyright (c) 2002 Gleen Salmon +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. +# +# As a special exception, the respective Autoconf Macro's copyright +# owner gives unlimited permission to copy, distribute and modify the +# configure scripts that are the output of Autoconf when processing +# the Macro. You need not follow the terms of the GNU General Public +# License when using or distributing such scripts, even though +# portions of the text of the Macro appear in them. The GNU General +# Public License (GPL) does govern all other use of the material that +# constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the +# Autoconf Macro released by the Autoconf Macro Archive. When you +# make and distribute a modified version of the Autoconf Macro, you +# may extend this special exception to the GPL to apply to your +# modified version as well. + +AC_DEFUN([AC_CHECK_JAVA_HOME],[ +AC_REQUIRE([AC_EXEEXT])dnl +TRY_JAVA_HOME=`ls -dr /usr/java/* 2> /dev/null | head -n 1` +if test x$TRY_JAVA_HOME != x; then + PATH=$PATH:$TRY_JAVA_HOME/bin +fi +AC_PATH_PROG(JAVA_PATH_NAME, java$EXEEXT) +if test x$JAVA_PATH_NAME != x; then + JAVA_HOME=`echo $JAVA_PATH_NAME | sed "s/\(.*\)[[/]]bin[[/]]java$EXEEXT$/\1/"` +fi;dnl +]) diff --git a/m4/ac_check_junit.m4 b/m4/ac_check_junit.m4 new file mode 100644 index 0000000..3214335 --- /dev/null +++ b/m4/ac_check_junit.m4 @@ -0,0 +1,69 @@ +##### http://autoconf-archive.cryp.to/ac_check_junit.html +# +# SYNOPSIS +# +# AC_CHECK_JUNIT +# +# DESCRIPTION +# +# AC_CHECK_JUNIT tests the availability of the Junit testing +# framework, and set some variables for conditional compilation of +# the test suite by automake. +# +# If available, JUNIT is set to a command launching the text based +# user interface of Junit, @JAVA_JUNIT@ is set to $JAVA_JUNIT and +# @TESTS_JUNIT@ is set to $TESTS_JUNIT, otherwise they are set to +# empty values. +# +# You can use these variables in your Makefile.am file like this : +# +# # Some of the following classes are built only if junit is available +# JAVA_JUNIT = Class1Test.java Class2Test.java AllJunitTests.java +# +# noinst_JAVA = Example1.java Example2.java @JAVA_JUNIT@ +# +# EXTRA_JAVA = $(JAVA_JUNIT) +# +# TESTS_JUNIT = AllJunitTests +# +# TESTS = StandaloneTest1 StandaloneTest2 @TESTS_JUNIT@ +# +# EXTRA_TESTS = $(TESTS_JUNIT) +# +# AllJunitTests : +# echo "#! /bin/sh" > $@ +# echo "exec @JUNIT@ my.package.name.AllJunitTests" >> $@ +# chmod +x $@ +# +# LAST MODIFICATION +# +# 2001-03-02 +# +# COPYLEFT +# +# Copyright (c) 2001 Luc Maisonobe +# +# Copying and distribution of this file, with or without +# modification, are permitted in any medium without royalty provided +# the copyright notice and this notice are preserved. + +AC_DEFUN([AC_CHECK_JUNIT],[ +AC_CACHE_VAL(ac_cv_prog_JUNIT,[ +AC_CHECK_CLASS(junit.textui.TestRunner) +if test x"`eval 'echo $ac_cv_class_junit_textui_TestRunner'`" != xno ; then + ac_cv_prog_JUNIT='$(CLASSPATH_ENV) $(JAVA) $(JAVAFLAGS) junit.textui.TestRunner' +fi]) +AC_MSG_CHECKING([for junit]) +if test x"`eval 'echo $ac_cv_prog_JUNIT'`" != x ; then + JUNIT="$ac_cv_prog_JUNIT" + JAVA_JUNIT='$(JAVA_JUNIT)' + TESTS_JUNIT='$(TESTS_JUNIT)' +else + JUNIT= + JAVA_JUNIT= + TESTS_JUNIT= +fi +AC_MSG_RESULT($JUNIT) +AC_SUBST(JUNIT) +AC_SUBST(JAVA_JUNIT) +AC_SUBST(TESTS_JUNIT)]) diff --git a/m4/ac_check_rqrd_class.m4 b/m4/ac_check_rqrd_class.m4 new file mode 100644 index 0000000..fb13fff --- /dev/null +++ b/m4/ac_check_rqrd_class.m4 @@ -0,0 +1,65 @@ +##### http://autoconf-archive.cryp.to/ac_check_rqrd_class.html +# +# SYNOPSIS +# +# AC_CHECK_RQRD_CLASS +# +# DESCRIPTION +# +# AC_CHECK_RQRD_CLASS tests the existence of a given Java class, +# either in a jar or in a '.class' file and fails if it doesn't +# exist. Its success or failure can depend on a proper setting of the +# CLASSPATH env. variable. +# +# Note: This is part of the set of autoconf M4 macros for Java +# programs. It is VERY IMPORTANT that you download the whole set, +# some macros depend on other. Unfortunately, the autoconf archive +# does not support the concept of set of macros, so I had to break it +# for submission. The general documentation, as well as the sample +# configure.in, is included in the AC_PROG_JAVA macro. +# +# LAST MODIFICATION +# +# 2000-07-19 +# +# COPYLEFT +# +# Copyright (c) 2000 Stephane Bortzmeyer +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. +# +# As a special exception, the respective Autoconf Macro's copyright +# owner gives unlimited permission to copy, distribute and modify the +# configure scripts that are the output of Autoconf when processing +# the Macro. You need not follow the terms of the GNU General Public +# License when using or distributing such scripts, even though +# portions of the text of the Macro appear in them. The GNU General +# Public License (GPL) does govern all other use of the material that +# constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the +# Autoconf Macro released by the Autoconf Macro Archive. When you +# make and distribute a modified version of the Autoconf Macro, you +# may extend this special exception to the GPL to apply to your +# modified version as well. + +AC_DEFUN([AC_CHECK_RQRD_CLASS],[ +CLASS=`echo $1|sed 's/\./_/g'` +AC_CHECK_CLASS($1) +if test "$HAVE_LAST_CLASS" = "no"; then +true +fi +]) diff --git a/m4/ac_java_options.m4 b/m4/ac_java_options.m4 new file mode 100644 index 0000000..290406e --- /dev/null +++ b/m4/ac_java_options.m4 @@ -0,0 +1,46 @@ +##### http://autoconf-archive.cryp.to/ac_java_options.html +# +# SYNOPSIS +# +# AC_JAVA_OPTIONS +# +# DESCRIPTION +# +# AC_JAVA_OPTIONS adds configure command line options used for Java +# m4 macros. This Macro is optional. +# +# Note: This is part of the set of autoconf M4 macros for Java +# programs. It is VERY IMPORTANT that you download the whole set, +# some macros depend on other. Unfortunately, the autoconf archive +# does not support the concept of set of macros, so I had to break it +# for submission. The general documentation, as well as the sample +# configure.in, is included in the AC_PROG_JAVA macro. +# +# LAST MODIFICATION +# +# 2000-07-19 +# +# COPYLEFT +# +# Copyright (c) 2000 Devin Weaver +# +# Copying and distribution of this file, with or without +# modification, are permitted in any medium without royalty provided +# the copyright notice and this notice are preserved. + +AC_DEFUN([AC_JAVA_OPTIONS],[ +AC_ARG_WITH(java-prefix, + [ --with-java-prefix=PFX prefix where Java runtime is installed (optional)]) +AC_ARG_WITH(javac-flags, + [ --with-javac-flags=FLAGS flags to pass to the Java compiler (optional)]) +AC_ARG_WITH(java-flags, + [ --with-java-flags=FLAGS flags to pass to the Java VM (optional)]) +JAVAPREFIX=$with_java_prefix +JAVACFLAGS=$with_javac_flags +JAVAFLAGS=$with_java_flags +AC_SUBST(JAVAPREFIX)dnl +AC_SUBST(JAVACFLAGS)dnl +AC_SUBST(JAVAFLAGS)dnl +AC_SUBST(JAVA)dnl +AC_SUBST(JAVAC)dnl +]) diff --git a/m4/ac_prog_jar.m4 b/m4/ac_prog_jar.m4 new file mode 100644 index 0000000..266d310 --- /dev/null +++ b/m4/ac_prog_jar.m4 @@ -0,0 +1,52 @@ +##### http://autoconf-archive.cryp.to/ac_prog_jar.html +# +# SYNOPSIS +# +# AC_PROG_JAR +# +# DESCRIPTION +# +# AC_PROG_JAR tests for an existing jar program. It uses the +# environment variable JAR then tests in sequence various common jar +# programs. +# +# If you want to force a specific compiler: +# +# - at the configure.in level, set JAR=yourcompiler before calling +# AC_PROG_JAR +# +# - at the configure level, setenv JAR +# +# You can use the JAR variable in your Makefile.in, with @JAR@. +# +# Note: This macro depends on the autoconf M4 macros for Java +# programs. It is VERY IMPORTANT that you download that whole set, +# some macros depend on other. Unfortunately, the autoconf archive +# does not support the concept of set of macros, so I had to break it +# for submission. +# +# The general documentation of those macros, as well as the sample +# configure.in, is included in the AC_PROG_JAVA macro. +# +# LAST MODIFICATION +# +# 2000-07-19 +# +# COPYLEFT +# +# Copyright (c) 2000 Egon Willighagen +# +# Copying and distribution of this file, with or without +# modification, are permitted in any medium without royalty provided +# the copyright notice and this notice are preserved. + +AC_DEFUN([AC_PROG_JAR],[ +AC_REQUIRE([AC_EXEEXT])dnl +if test "x$JAVAPREFIX" = x; then + test "x$JAR" = x && AC_CHECK_PROGS(JAR, jar$EXEEXT) +else + test "x$JAR" = x && AC_CHECK_PROGS(JAR, jar, $JAVAPREFIX) +fi +true +AC_PROVIDE([$0])dnl +]) diff --git a/m4/ac_prog_java.m4 b/m4/ac_prog_java.m4 new file mode 100644 index 0000000..af2b6cb --- /dev/null +++ b/m4/ac_prog_java.m4 @@ -0,0 +1,122 @@ +##### http://autoconf-archive.cryp.to/ac_prog_java.html +# +# SYNOPSIS +# +# AC_PROG_JAVA +# +# DESCRIPTION +# +# Here is a summary of the main macros: +# +# AC_PROG_JAVAC: finds a Java compiler. +# +# AC_PROG_JAVA: finds a Java virtual machine. +# +# AC_CHECK_CLASS: finds if we have the given class (beware of +# CLASSPATH!). +# +# AC_CHECK_RQRD_CLASS: finds if we have the given class and stops +# otherwise. +# +# AC_TRY_COMPILE_JAVA: attempt to compile user given source. +# +# AC_TRY_RUN_JAVA: attempt to compile and run user given source. +# +# AC_JAVA_OPTIONS: adds Java configure options. +# +# AC_PROG_JAVA tests an existing Java virtual machine. It uses the +# environment variable JAVA then tests in sequence various common +# Java virtual machines. For political reasons, it starts with the +# free ones. You *must* call [AC_PROG_JAVAC] before. +# +# If you want to force a specific VM: +# +# - at the configure.in level, set JAVA=yourvm before calling +# AC_PROG_JAVA +# +# (but after AC_INIT) +# +# - at the configure level, setenv JAVA +# +# You can use the JAVA variable in your Makefile.in, with @JAVA@. +# +# *Warning*: its success or failure can depend on a proper setting of +# the CLASSPATH env. variable. +# +# TODO: allow to exclude virtual machines (rationale: most Java +# programs cannot run with some VM like kaffe). +# +# Note: This is part of the set of autoconf M4 macros for Java +# programs. It is VERY IMPORTANT that you download the whole set, +# some macros depend on other. Unfortunately, the autoconf archive +# does not support the concept of set of macros, so I had to break it +# for submission. +# +# A Web page, with a link to the latest CVS snapshot is at +# . +# +# This is a sample configure.in Process this file with autoconf to +# produce a configure script. +# +# AC_INIT(UnTag.java) +# +# dnl Checks for programs. +# AC_CHECK_CLASSPATH +# AC_PROG_JAVAC +# AC_PROG_JAVA +# +# dnl Checks for classes +# AC_CHECK_RQRD_CLASS(org.xml.sax.Parser) +# AC_CHECK_RQRD_CLASS(com.jclark.xml.sax.Driver) +# +# AC_OUTPUT(Makefile) +# +# LAST MODIFICATION +# +# 2000-07-19 +# +# COPYLEFT +# +# Copyright (c) 2000 Stephane Bortzmeyer +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. +# +# As a special exception, the respective Autoconf Macro's copyright +# owner gives unlimited permission to copy, distribute and modify the +# configure scripts that are the output of Autoconf when processing +# the Macro. You need not follow the terms of the GNU General Public +# License when using or distributing such scripts, even though +# portions of the text of the Macro appear in them. The GNU General +# Public License (GPL) does govern all other use of the material that +# constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the +# Autoconf Macro released by the Autoconf Macro Archive. When you +# make and distribute a modified version of the Autoconf Macro, you +# may extend this special exception to the GPL to apply to your +# modified version as well. + +AC_DEFUN([AC_PROG_JAVA],[ +AC_REQUIRE([AC_EXEEXT])dnl +if test x$JAVAPREFIX = x; then + test x$JAVA = x && AC_CHECK_PROGS(JAVA, kaffe$EXEEXT java$EXEEXT) +else + test x$JAVA = x && AC_CHECK_PROGS(JAVA, kaffe$EXEEXT java$EXEEXT, $JAVAPREFIX) +fi +true +AC_PROG_JAVA_WORKS +AC_PROVIDE([$0])dnl +]) diff --git a/m4/ac_prog_java_cc.m4 b/m4/ac_prog_java_cc.m4 new file mode 100644 index 0000000..df12785 --- /dev/null +++ b/m4/ac_prog_java_cc.m4 @@ -0,0 +1,107 @@ +##### http://autoconf-archive.cryp.to/ac_prog_java_cc.html +# +# SYNOPSIS +# +# AC_PROG_JAVA_CC +# +# DESCRIPTION +# +# Finds the appropriate java compiler on your path. By preference the +# java compiler is gcj, then jikes then javac. +# +# The macro can take one argument specifying a space separated list +# of java compiler names. +# +# For example: +# +# AC_PROG_JAVA_CC(javac, gcj) +# +# The macro also sets the compiler options variable: JAVA_CC_OPTS to +# something sensible: +# +# - for GCJ it sets it to: @GCJ_OPTS@ +# (if GCJ_OPTS is not yet defined then it is set to "-C") +# +# - no other compiler has applicable options yet +# +# Here's an example configure.in: +# +# AC_INIT(Makefile.in) +# AC_PROG_JAVA_CC() +# AC_OUTPUT(Makefile) +# dnl End. +# +# And here's the start of the Makefile.in: +# +# PROJECT_ROOT := @srcdir@ +# # Tool definitions. +# JAVAC := @JAVA_CC@ +# JAVAC_OPTS := @JAVA_CC_OPTS@ +# JAR_TOOL := @jar_tool@ +# +# LAST MODIFICATION +# +# 2002-03-04 +# +# COPYLEFT +# +# Copyright (c) 2002 Nic Ferrier +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. +# +# As a special exception, the respective Autoconf Macro's copyright +# owner gives unlimited permission to copy, distribute and modify the +# configure scripts that are the output of Autoconf when processing +# the Macro. You need not follow the terms of the GNU General Public +# License when using or distributing such scripts, even though +# portions of the text of the Macro appear in them. The GNU General +# Public License (GPL) does govern all other use of the material that +# constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the +# Autoconf Macro released by the Autoconf Macro Archive. When you +# make and distribute a modified version of the Autoconf Macro, you +# may extend this special exception to the GPL to apply to your +# modified version as well. + +# AC_PROG_JAVA_CC([COMPILER ...]) +# -------------------------- +# COMPILER ... is a space separated list of java compilers to search for. +# This just gives the user an opportunity to specify an alternative +# search list for the java compiler. +AC_DEFUN([AC_PROG_JAVA_CC], +[AC_ARG_VAR([JAVA_CC], [java compiler command])dnl +AC_ARG_VAR([JAVA_CC_FLAGS], [java compiler flags])dnl +m4_ifval([$1], + [AC_CHECK_TOOLS(JAVA_CC, [$1])], +[AC_CHECK_TOOL(JAVA_CC, gcj) +if test -z "$JAVA_CC"; then + AC_CHECK_TOOL(JAVA_CC, javac) +fi +if test -z "$JAVA_CC"; then + AC_CHECK_TOOL(JAVA_CC, jikes) +fi +]) + +if test "$JAVA_CC" = "gcj"; then + if test "$GCJ_OPTS" = ""; then + AC_SUBST(GCJ_OPTS,-C) + fi + AC_SUBST(JAVA_CC_OPTS, @GCJ_OPTS@, + [Define the compilation options for GCJ]) +fi +true +])# AC_PROG_JAVA_CC diff --git a/m4/ac_prog_java_works.m4 b/m4/ac_prog_java_works.m4 new file mode 100644 index 0000000..e450c6c --- /dev/null +++ b/m4/ac_prog_java_works.m4 @@ -0,0 +1,137 @@ +##### http://autoconf-archive.cryp.to/ac_prog_java_works.html +# +# SYNOPSIS +# +# AC_PROG_JAVA_WORKS +# +# DESCRIPTION +# +# Internal use ONLY. +# +# Note: This is part of the set of autoconf M4 macros for Java +# programs. It is VERY IMPORTANT that you download the whole set, +# some macros depend on other. Unfortunately, the autoconf archive +# does not support the concept of set of macros, so I had to break it +# for submission. The general documentation, as well as the sample +# configure.in, is included in the AC_PROG_JAVA macro. +# +# LAST MODIFICATION +# +# 2000-07-19 +# +# COPYLEFT +# +# Copyright (c) 2000 Stephane Bortzmeyer +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. +# +# As a special exception, the respective Autoconf Macro's copyright +# owner gives unlimited permission to copy, distribute and modify the +# configure scripts that are the output of Autoconf when processing +# the Macro. You need not follow the terms of the GNU General Public +# License when using or distributing such scripts, even though +# portions of the text of the Macro appear in them. The GNU General +# Public License (GPL) does govern all other use of the material that +# constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the +# Autoconf Macro released by the Autoconf Macro Archive. When you +# make and distribute a modified version of the Autoconf Macro, you +# may extend this special exception to the GPL to apply to your +# modified version as well. + +AC_DEFUN([AC_PROG_JAVA_WORKS], [ +AC_CHECK_PROG(uudecode, uudecode$EXEEXT, yes) +if test x$uudecode = xyes; then +AC_CACHE_CHECK([if uudecode can decode base 64 file], ac_cv_prog_uudecode_base64, [ +dnl /** +dnl * Test.java: used to test if java compiler works. +dnl */ +dnl public class Test +dnl { +dnl +dnl public static void +dnl main( String[] argv ) +dnl { +dnl System.exit (0); +dnl } +dnl +dnl } +cat << \EOF > Test.uue +begin-base64 644 Test.class +yv66vgADAC0AFQcAAgEABFRlc3QHAAQBABBqYXZhL2xhbmcvT2JqZWN0AQAE +bWFpbgEAFihbTGphdmEvbGFuZy9TdHJpbmc7KVYBAARDb2RlAQAPTGluZU51 +bWJlclRhYmxlDAAKAAsBAARleGl0AQAEKEkpVgoADQAJBwAOAQAQamF2YS9s +YW5nL1N5c3RlbQEABjxpbml0PgEAAygpVgwADwAQCgADABEBAApTb3VyY2VG +aWxlAQAJVGVzdC5qYXZhACEAAQADAAAAAAACAAkABQAGAAEABwAAACEAAQAB +AAAABQO4AAyxAAAAAQAIAAAACgACAAAACgAEAAsAAQAPABAAAQAHAAAAIQAB +AAEAAAAFKrcAErEAAAABAAgAAAAKAAIAAAAEAAQABAABABMAAAACABQ= +==== +EOF +if uudecode$EXEEXT Test.uue; then + ac_cv_prog_uudecode_base64=yes +else + echo "configure: __oline__: uudecode had trouble decoding base 64 file 'Test.uue'" >&AC_FD_CC + echo "configure: failed file was:" >&AC_FD_CC + cat Test.uue >&AC_FD_CC + ac_cv_prog_uudecode_base64=no +fi +rm -f Test.uue]) +fi +if test x$ac_cv_prog_uudecode_base64 != xyes; then + rm -f Test.class + AC_MSG_WARN([I have to compile Test.class from scratch]) + if test x$ac_cv_prog_javac_works = xno; then +true + fi + if test x$ac_cv_prog_javac_works = x; then + AC_PROG_JAVAC + fi +fi +AC_CACHE_CHECK(if $JAVA works, ac_cv_prog_java_works, [ +JAVA_TEST=Test.java +CLASS_TEST=Test.class +TEST=Test +changequote(, )dnl +cat << \EOF > $JAVA_TEST +/* [#]line __oline__ "configure" */ +public class Test { +public static void main (String args[]) { + System.exit (0); +} } +EOF +changequote([, ])dnl +if test x$ac_cv_prog_uudecode_base64 != xyes; then + if AC_TRY_COMMAND($JAVAC $JAVACFLAGS $JAVA_TEST) && test -s $CLASS_TEST; then + : + else + echo "configure: failed program was:" >&AC_FD_CC + cat $JAVA_TEST >&AC_FD_CC +true + fi +fi +if AC_TRY_COMMAND($JAVA $JAVAFLAGS $TEST) >/dev/null 2>&1; then + ac_cv_prog_java_works=yes +else + echo "configure: failed program was:" >&AC_FD_CC + cat $JAVA_TEST >&AC_FD_CC +true +fi +rm -fr $JAVA_TEST $CLASS_TEST Test.uue +]) +AC_PROVIDE([$0])dnl +] +) diff --git a/m4/ac_prog_javac.m4 b/m4/ac_prog_javac.m4 new file mode 100644 index 0000000..630c3cf --- /dev/null +++ b/m4/ac_prog_javac.m4 @@ -0,0 +1,84 @@ +##### http://autoconf-archive.cryp.to/ac_prog_javac.html +# +# SYNOPSIS +# +# AC_PROG_JAVAC +# +# DESCRIPTION +# +# AC_PROG_JAVAC tests an existing Java compiler. It uses the +# environment variable JAVAC then tests in sequence various common +# Java compilers. For political reasons, it starts with the free +# ones. +# +# If you want to force a specific compiler: +# +# - at the configure.in level, set JAVAC=yourcompiler before calling +# AC_PROG_JAVAC +# +# - at the configure level, setenv JAVAC +# +# You can use the JAVAC variable in your Makefile.in, with @JAVAC@. +# +# *Warning*: its success or failure can depend on a proper setting of +# the CLASSPATH env. variable. +# +# TODO: allow to exclude compilers (rationale: most Java programs +# cannot compile with some compilers like guavac). +# +# Note: This is part of the set of autoconf M4 macros for Java +# programs. It is VERY IMPORTANT that you download the whole set, +# some macros depend on other. Unfortunately, the autoconf archive +# does not support the concept of set of macros, so I had to break it +# for submission. The general documentation, as well as the sample +# configure.in, is included in the AC_PROG_JAVA macro. +# +# LAST MODIFICATION +# +# 2000-07-19 +# +# COPYLEFT +# +# Copyright (c) 2000 Stephane Bortzmeyer +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. +# +# As a special exception, the respective Autoconf Macro's copyright +# owner gives unlimited permission to copy, distribute and modify the +# configure scripts that are the output of Autoconf when processing +# the Macro. You need not follow the terms of the GNU General Public +# License when using or distributing such scripts, even though +# portions of the text of the Macro appear in them. The GNU General +# Public License (GPL) does govern all other use of the material that +# constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the +# Autoconf Macro released by the Autoconf Macro Archive. When you +# make and distribute a modified version of the Autoconf Macro, you +# may extend this special exception to the GPL to apply to your +# modified version as well. + +AC_DEFUN([AC_PROG_JAVAC],[ +AC_REQUIRE([AC_EXEEXT])dnl +if test "x$JAVAPREFIX" = x; then + test "x$JAVAC" = x && AC_CHECK_PROGS(JAVAC, "gcj$EXEEXT -C" jikes$EXEEXT guavac$EXEEXT javac$EXEEXT) +else + test "x$JAVAC" = x && AC_CHECK_PROGS(JAVAC, "gcj$EXEEXT -C" jikes$EXEEXT guavac$EXEEXT javac$EXEEXT, $JAVAPREFIX) +fi +true +AC_PROG_JAVAC_WORKS +AC_PROVIDE([$0])dnl +]) diff --git a/m4/ac_prog_javac_works.m4 b/m4/ac_prog_javac_works.m4 new file mode 100644 index 0000000..d3ceb5c --- /dev/null +++ b/m4/ac_prog_javac_works.m4 @@ -0,0 +1,75 @@ +##### http://autoconf-archive.cryp.to/ac_prog_javac_works.html +# +# SYNOPSIS +# +# AC_PROG_JAVAC_WORKS +# +# DESCRIPTION +# +# Internal use ONLY. +# +# Note: This is part of the set of autoconf M4 macros for Java +# programs. It is VERY IMPORTANT that you download the whole set, +# some macros depend on other. Unfortunately, the autoconf archive +# does not support the concept of set of macros, so I had to break it +# for submission. The general documentation, as well as the sample +# configure.in, is included in the AC_PROG_JAVA macro. +# +# LAST MODIFICATION +# +# 2000-07-19 +# +# COPYLEFT +# +# Copyright (c) 2000 Stephane Bortzmeyer +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. +# +# As a special exception, the respective Autoconf Macro's copyright +# owner gives unlimited permission to copy, distribute and modify the +# configure scripts that are the output of Autoconf when processing +# the Macro. You need not follow the terms of the GNU General Public +# License when using or distributing such scripts, even though +# portions of the text of the Macro appear in them. The GNU General +# Public License (GPL) does govern all other use of the material that +# constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the +# Autoconf Macro released by the Autoconf Macro Archive. When you +# make and distribute a modified version of the Autoconf Macro, you +# may extend this special exception to the GPL to apply to your +# modified version as well. + +AC_DEFUN([AC_PROG_JAVAC_WORKS],[ +AC_CACHE_CHECK([if $JAVAC works], ac_cv_prog_javac_works, [ +JAVA_TEST=Test.java +CLASS_TEST=Test.class +cat << \EOF > $JAVA_TEST +/* [#]line __oline__ "configure" */ +public class Test { +} +EOF +if AC_TRY_COMMAND($JAVAC $JAVACFLAGS $JAVA_TEST) >/dev/null 2>&1; then + ac_cv_prog_javac_works=yes +else +true + echo "configure: failed program was:" >&AC_FD_CC + cat $JAVA_TEST >&AC_FD_CC +fi +rm -f $JAVA_TEST $CLASS_TEST +]) +AC_PROVIDE([$0])dnl +]) diff --git a/m4/ac_prog_javadoc.m4 b/m4/ac_prog_javadoc.m4 new file mode 100644 index 0000000..0920c55 --- /dev/null +++ b/m4/ac_prog_javadoc.m4 @@ -0,0 +1,53 @@ +##### http://autoconf-archive.cryp.to/ac_prog_javadoc.html +# +# SYNOPSIS +# +# AC_PROG_JAVADOC +# +# DESCRIPTION +# +# AC_PROG_JAVADOC tests for an existing javadoc generator. It uses +# the environment variable JAVADOC then tests in sequence various +# common javadoc generator. +# +# If you want to force a specific compiler: +# +# - at the configure.in level, set JAVADOC=yourgenerator before +# calling AC_PROG_JAVADOC +# +# - at the configure level, setenv JAVADOC +# +# You can use the JAVADOC variable in your Makefile.in, with +# @JAVADOC@. +# +# Note: This macro depends on the autoconf M4 macros for Java +# programs. It is VERY IMPORTANT that you download that whole set, +# some macros depend on other. Unfortunately, the autoconf archive +# does not support the concept of set of macros, so I had to break it +# for submission. +# +# The general documentation of those macros, as well as the sample +# configure.in, is included in the AC_PROG_JAVA macro. +# +# LAST MODIFICATION +# +# 2000-07-19 +# +# COPYLEFT +# +# Copyright (c) 2000 Egon Willighagen +# +# Copying and distribution of this file, with or without +# modification, are permitted in any medium without royalty provided +# the copyright notice and this notice are preserved. + +AC_DEFUN([AC_PROG_JAVADOC],[ +AC_REQUIRE([AC_EXEEXT])dnl +if test "x$JAVAPREFIX" = x; then + test "x$JAVADOC" = x && AC_CHECK_PROGS(JAVADOC, javadoc$EXEEXT) +else + test "x$JAVADOC" = x && AC_CHECK_PROGS(JAVADOC, javadoc, $JAVAPREFIX) +fi +true +AC_PROVIDE([$0])dnl +]) diff --git a/m4/ac_prog_javah.m4 b/m4/ac_prog_javah.m4 new file mode 100644 index 0000000..6da7784 --- /dev/null +++ b/m4/ac_prog_javah.m4 @@ -0,0 +1,43 @@ +##### http://autoconf-archive.cryp.to/ac_prog_javah.html +# +# SYNOPSIS +# +# AC_PROG_JAVAH +# +# DESCRIPTION +# +# AC_PROG_JAVAH tests the availability of the javah header generator +# and looks for the jni.h header file. If available, JAVAH is set to +# the full path of javah and CPPFLAGS is updated accordingly. +# +# LAST MODIFICATION +# +# 2002-03-25 +# +# COPYLEFT +# +# Copyright (c) 2002 Luc Maisonobe +# +# Copying and distribution of this file, with or without +# modification, are permitted in any medium without royalty provided +# the copyright notice and this notice are preserved. + +AC_DEFUN([AC_PROG_JAVAH],[ +AC_REQUIRE([AC_CANONICAL_SYSTEM])dnl +AC_REQUIRE([AC_PROG_CPP])dnl +test "x$JAVAH" = x && AC_CHECK_PROGS(JAVAH,gjavah gcjh javah) +if test "x$JAVAH" != x ; then + AC_TRY_CPP([#include ],,[ + ac_save_CPPFLAGS="$CPPFLAGS" +changequote(, )dnl + ac_dir=`echo $ac_cv_path_JAVAH | sed 's,\(.*\)/[^/]*/[^/]*$,\1/include,'` + ac_machdep=`echo $build_os | sed 's,[-0-9].*,,' | sed 's,cygwin,win32,'` +changequote([, ])dnl + CPPFLAGS="$ac_save_CPPFLAGS -I$ac_dir -I$ac_dir/$ac_machdep" + AC_TRY_CPP([#include ], + ac_save_CPPFLAGS="$CPPFLAGS", + AC_MSG_WARN([unable to include ])) + CPPFLAGS="$ac_save_CPPFLAGS"]) +else +true +fi]) diff --git a/m4/ac_try_compile_java.m4 b/m4/ac_try_compile_java.m4 new file mode 100644 index 0000000..ab49aae --- /dev/null +++ b/m4/ac_try_compile_java.m4 @@ -0,0 +1,53 @@ +##### http://autoconf-archive.cryp.to/ac_try_compile_java.html +# +# SYNOPSIS +# +# AC_TRY_COMPILE_JAVA +# +# DESCRIPTION +# +# AC_TRY_COMPILE_JAVA attempt to compile user given source. +# +# *Warning*: its success or failure can depend on a proper setting of +# the CLASSPATH env. variable. +# +# Note: This is part of the set of autoconf M4 macros for Java +# programs. It is VERY IMPORTANT that you download the whole set, +# some macros depend on other. Unfortunately, the autoconf archive +# does not support the concept of set of macros, so I had to break it +# for submission. The general documentation, as well as the sample +# configure.in, is included in the AC_PROG_JAVA macro. +# +# LAST MODIFICATION +# +# 2000-07-19 +# +# COPYLEFT +# +# Copyright (c) 2000 Devin Weaver +# +# Copying and distribution of this file, with or without +# modification, are permitted in any medium without royalty provided +# the copyright notice and this notice are preserved. + +AC_DEFUN([AC_TRY_COMPILE_JAVA],[ +AC_REQUIRE([AC_PROG_JAVAC])dnl +cat << \EOF > Test.java +/* [#]line __oline__ "configure" */ +ifelse([$1], , , [import $1;]) +public class Test { +[$2] +} +EOF +if AC_TRY_COMMAND($JAVAC $JAVACFLAGS Test.java) && test -s Test.class +then +dnl Don't remove the temporary files here, so they can be examined. + ifelse([$3], , :, [$3]) +else + echo "configure: failed program was:" >&AC_FD_CC + cat Test.java >&AC_FD_CC +ifelse([$4], , , [ rm -fr Test* + $4 +])dnl +fi +rm -fr Test*]) diff --git a/m4/ac_try_run_javac.m4 b/m4/ac_try_run_javac.m4 new file mode 100644 index 0000000..188c414 --- /dev/null +++ b/m4/ac_try_run_javac.m4 @@ -0,0 +1,54 @@ +##### http://autoconf-archive.cryp.to/ac_try_run_javac.html +# +# SYNOPSIS +# +# AC_TRY_RUN_JAVA +# +# DESCRIPTION +# +# AC_TRY_RUN_JAVA attempt to compile and run user given source. +# +# *Warning*: its success or failure can depend on a proper setting of +# the CLASSPATH env. variable. +# +# Note: This is part of the set of autoconf M4 macros for Java +# programs. It is VERY IMPORTANT that you download the whole set, +# some macros depend on other. Unfortunately, the autoconf archive +# does not support the concept of set of macros, so I had to break it +# for submission. The general documentation, as well as the sample +# configure.in, is included in the AC_PROG_JAVA macro. +# +# LAST MODIFICATION +# +# 2000-07-19 +# +# COPYLEFT +# +# Copyright (c) 2000 Devin Weaver +# +# Copying and distribution of this file, with or without +# modification, are permitted in any medium without royalty provided +# the copyright notice and this notice are preserved. + +AC_DEFUN([AC_TRY_RUN_JAVA],[ +AC_REQUIRE([AC_PROG_JAVAC])dnl +AC_REQUIRE([AC_PROG_JAVA])dnl +cat << \EOF > Test.java +/* [#]line __oline__ "configure" */ +ifelse([$1], , , [include $1;]) +public class Test { +[$2] +} +EOF +if AC_TRY_COMMAND($JAVAC $JAVACFLAGS Test.java) && test -s Test.class && ($JAVA $JAVAFLAGS Test; exit) 2>/dev/null +then +dnl Don't remove the temporary files here, so they can be examined. + ifelse([$3], , :, [$3]) +else + echo "configure: failed program was:" >&AC_FD_CC + cat Test.java >&AC_FD_CC +ifelse([$4], , , [ rm -fr Test* + $4 +])dnl +fi +rm -fr Test*]) diff --git a/m4/as-compiler-flag.m4 b/m4/as-compiler-flag.m4 new file mode 100644 index 0000000..0f660cf --- /dev/null +++ b/m4/as-compiler-flag.m4 @@ -0,0 +1,62 @@ +dnl as-compiler-flag.m4 0.1.0 + +dnl autostars m4 macro for detection of compiler flags + +dnl David Schleef + +dnl $Id: as-compiler-flag.m4,v 1.1 2005/12/15 23:35:19 ds Exp $ + +dnl AS_COMPILER_FLAG(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED]) +dnl Tries to compile with the given CFLAGS. +dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags, +dnl and ACTION-IF-NOT-ACCEPTED otherwise. + +AC_DEFUN([AS_COMPILER_FLAG], +[ + AC_MSG_CHECKING([to see if compiler understands $1]) + + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $1" + + AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no]) + CFLAGS="$save_CFLAGS" + + if test "X$flag_ok" = Xyes ; then + m4_ifvaln([$2],[$2]) + true + else + m4_ifvaln([$3],[$3]) + true + fi + AC_MSG_RESULT([$flag_ok]) +]) + +dnl AS_COMPILER_FLAGS(VAR, FLAGS) +dnl Tries to compile with the given CFLAGS. + +AC_DEFUN([AS_COMPILER_FLAGS], +[ + list=$2 + flags_supported="" + flags_unsupported="" + AC_MSG_CHECKING([for supported compiler flags]) + for each in $list + do + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $each" + AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no]) + CFLAGS="$save_CFLAGS" + + if test "X$flag_ok" = Xyes ; then + flags_supported="$flags_supported $each" + else + flags_unsupported="$flags_unsupported $each" + fi + done + AC_MSG_RESULT([$flags_supported]) + if test "X$flags_unsupported" != X ; then + AC_MSG_WARN([unsupported compiler flags: $flags_unsupported]) + fi + $1="$$1 $flags_supported" +]) + diff --git a/m4/check.m4 b/m4/check.m4 new file mode 100644 index 0000000..a2e0812 --- /dev/null +++ b/m4/check.m4 @@ -0,0 +1,133 @@ +dnl AM_PATH_CHECK([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) +dnl Test for check, and define CHECK_CFLAGS and CHECK_LIBS +dnl + +AC_DEFUN([AM_PATH_CHECK], +[ + AC_ARG_WITH(check, + [ --with-check=PATH prefix where check is installed [default=auto]]) + + min_check_version=ifelse([$1], ,0.8.2,$1) + + AC_MSG_CHECKING(for check - version >= $min_check_version) + + if test x$with_check = xno; then + AC_MSG_RESULT(disabled) + ifelse([$3], , AC_MSG_ERROR([disabling check is not supported]), [$3]) + else + if test "x$with_check" != x; then + CHECK_CFLAGS="-I$with_check/include" + CHECK_LIBS="-L$with_check/lib -lcheck" + else + CHECK_CFLAGS="" + CHECK_LIBS="-lcheck" + fi + + ac_save_CFLAGS="$CFLAGS" + ac_save_LIBS="$LIBS" + + CFLAGS="$CFLAGS $CHECK_CFLAGS" + LIBS="$CHECK_LIBS $LIBS" + + rm -f conf.check-test + AC_TRY_RUN([ +#include +#include + +#include + +int main () +{ + int major, minor, micro; + char *tmp_version; + + system ("touch conf.check-test"); + + /* HP/UX 9 (%@#!) writes to sscanf strings */ + tmp_version = strdup("$min_check_version"); + if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) { + printf("%s, bad version string\n", "$min_check_version"); + return 1; + } + + if ((CHECK_MAJOR_VERSION != check_major_version) || + (CHECK_MINOR_VERSION != check_minor_version) || + (CHECK_MICRO_VERSION != check_micro_version)) + { + printf("\n*** The check header file (version %d.%d.%d) does not match\n", + CHECK_MAJOR_VERSION, CHECK_MINOR_VERSION, CHECK_MICRO_VERSION); + printf("*** the check library (version %d.%d.%d).\n", + check_major_version, check_minor_version, check_micro_version); + return 1; + } + + if ((check_major_version > major) || + ((check_major_version == major) && (check_minor_version > minor)) || + ((check_major_version == major) && (check_minor_version == minor) && (check_micro_version >= micro))) + { + return 0; + } + else + { + printf("\n*** An old version of check (%d.%d.%d) was found.\n", + check_major_version, check_minor_version, check_micro_version); + printf("*** You need a version of check being at least %d.%d.%d.\n", major, minor, micro); + printf("***\n"); + printf("*** If you have already installed a sufficiently new version, this error\n"); + printf("*** probably means that the wrong copy of the check library and header\n"); + printf("*** file is being found. Rerun configure with the --with-check=PATH option\n"); + printf("*** to specify the prefix where the correct version was installed.\n"); + } + + return 1; +} +],, no_check=yes, [echo $ac_n "cross compiling; assumed OK... $ac_c"]) + + CFLAGS="$ac_save_CFLAGS" + LIBS="$ac_save_LIBS" + + if test "x$no_check" = x ; then + AC_MSG_RESULT(yes) + ifelse([$2], , :, [$2]) + else + AC_MSG_RESULT(no) + if test -f conf.check-test ; then + : + else + echo "*** Could not run check test program, checking why..." + CFLAGS="$CFLAGS $CHECK_CFLAGS" + LIBS="$CHECK_LIBS $LIBS" + AC_TRY_LINK([ +#include +#include + +#include +], , [ echo "*** The test program compiled, but did not run. This usually means" + echo "*** that the run-time linker is not finding check. You'll need to set your" + echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point" + echo "*** to the installed location Also, make sure you have run ldconfig if that" + echo "*** is required on your system" + echo "***" + echo "*** If you have an old version installed, it is best to remove it, although" + echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"], + [ echo "*** The test program failed to compile or link. See the file config.log for" + echo "*** the exact error that occured." ]) + + CFLAGS="$ac_save_CFLAGS" + LIBS="$ac_save_LIBS" + fi + + CHECK_CFLAGS="" + CHECK_LIBS="" + + rm -f conf.check-test + ifelse([$3], , AC_MSG_ERROR([check not found]), [$3]) + fi + + AC_SUBST(CHECK_CFLAGS) + AC_SUBST(CHECK_LIBS) + + rm -f conf.check-test + + fi +]) diff --git a/m4/dps_java_check_class.m4 b/m4/dps_java_check_class.m4 new file mode 100644 index 0000000..a86d641 --- /dev/null +++ b/m4/dps_java_check_class.m4 @@ -0,0 +1,89 @@ +##### http://autoconf-archive.cryp.to/dps_java_check_class.html +# +# SYNOPSIS +# +# DPS_JAVA_CHECK_CLASS(,,) +# +# DESCRIPTION +# +# Test if a Java class is available. Based on AC_PROG_JAVAC_WORKS. +# This version uses a cache variable which is both compiler, options +# and classpath dependent (so if you switch from javac to gcj it +# correctly notices and redoes the test). +# +# The macro tries to compile a minimal program importing . +# Some newer compilers moan about the failure to use this but fail or +# produce a class file anyway. All moaing is sunk to /dev/null since +# I only wanted to know if the class could be imported. This is a +# recommended followup to DPS_CHECK_JAVA_PLUGIN with classpath +# appropriately adjusted. +# +# LAST MODIFICATION +# +# 2008-01-28 +# +# COPYLEFT +# +# Copyright (c) 2008 Duncan Simpson +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. +# +# As a special exception, the respective Autoconf Macro's copyright +# owner gives unlimited permission to copy, distribute and modify the +# configure scripts that are the output of Autoconf when processing +# the Macro. You need not follow the terms of the GNU General Public +# License when using or distributing such scripts, even though +# portions of the text of the Macro appear in them. The GNU General +# Public License (GPL) does govern all other use of the material that +# constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the +# Autoconf Macro released by the Autoconf Macro Archive. When you +# make and distribute a modified version of the Autoconf Macro, you +# may extend this special exception to the GPL to apply to your +# modified version as well. + +AC_DEFUN([DPS_JAVA_CHECK_CLASS],[ +m4_define([cache_val],[m4_translit(dps_cv_have_java_class_$1, " ." ,"__")]) +if test "x$CLASSPATH" != "x"; then +xtra=" with classpath ${CLASSPATH}" +xopts=`echo ${CLASSPATH} | ${SED} 's/^ *://'` +xopts="-classpath $xopts" +else xtra=""; xopts=""; fi +cache_var="cache_val"AS_TR_SH([_Jc_${JAVAC}_Cp_${CLASSPATH}]) +AC_CACHE_CHECK([if the $1 class is available$xtra], [$cache_var], [ +JAVA_TEST=Testing.java +CLASS_TEST=Testing.class +cat << \EOF > $JAVA_TEST +/* [#]xline __oline__ "configure" */ +import $1; +public class Testing { +} +EOF +if AC_TRY_COMMAND($JAVAC $JAVACFLAGS $xopts $JAVA_TEST) >/dev/null 2>&1; then + eval "${cache_var}=yes" +else + eval "${cache_var}=no" + echo "configure: failed program was:" >&AC_FD_CC + cat $JAVA_TEST >&AC_FD_CC +fi +rm -f $JAVA_TEST $CLASS_TEST +]) +if eval 'test "x$'${cache_var}'" = "xyes"'; then +$2 +true; else +$3 +false; fi]) diff --git a/m4/dps_libgcj_jar.m4 b/m4/dps_libgcj_jar.m4 new file mode 100644 index 0000000..777cd5c --- /dev/null +++ b/m4/dps_libgcj_jar.m4 @@ -0,0 +1,86 @@ +##### http://autoconf-archive.cryp.to/dps_libgcj_jar.html +# +# SYNOPSIS +# +# DPS_LIBGCJ_JAR +# +# DESCRIPTION +# +# Locate libgcj.jar so you can place it before everything else when +# using gcj. +# +# LAST MODIFICATION +# +# 2008-01-28 +# +# COPYLEFT +# +# Copyright (c) 2008 Duncan Simpson +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. +# +# As a special exception, the respective Autoconf Macro's copyright +# owner gives unlimited permission to copy, distribute and modify the +# configure scripts that are the output of Autoconf when processing +# the Macro. You need not follow the terms of the GNU General Public +# License when using or distributing such scripts, even though +# portions of the text of the Macro appear in them. The GNU General +# Public License (GPL) does govern all other use of the material that +# constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the +# Autoconf Macro released by the Autoconf Macro Archive. When you +# make and distribute a modified version of the Autoconf Macro, you +# may extend this special exception to the GPL to apply to your +# modified version as well. + +AC_DEFUN([DPS_LIBGCJ_JAR], +[ +AC_REQUIRE([AC_EXEEXT]) +AC_REQUIRE([AC_PROG_JAVAC]) +AC_REQUIRE([AC_PROG_FGREP]) +AC_CHECK_PROG(SED, sed) +if test "x$SED" = "x"; then +AC_MSG_WARN([sed not avaiable, so libgcj.jar test skipped]) +else +AC_MSG_CHECKING([if $JAVAC is gcj]); +jc=`eval "[echo x$JAVAC | $SED 's/^x.*\\/\\([^/]*\\)\$/x\\1/;s/^ *\\([^ ]*\\) .*$/\\1/;s/"$EXEEXT"$//']"` +if test "x$jc" != "xxgcj"; then +AC_MSG_RESULT(no) +else +AC_MSG_RESULT(yes) +AC_MSG_CHECKING([libgcj.jar location]) +save_cp="$CLASSPATH"; +unset CLASSPATH; +AC_MSG_CHECKING([gcj default classpath]) +cat << \EOF > Test.java +/* [#]line __oline__ "configure" */ +public class Test { +} +EOF +lgcj=`eval "[$JAVAC -v -C Test.java 2>&1 | $FGREP \\(system\\) | $SED 's/^ *\\([^ ]*\\) .*$/\\1/;s/\\.jar\\//.jar/']"`; +if test -f Test.class && test "x$lgcj" != "x"; then +AC_MSG_RESULT($lgcj) +$1="$lgcj:" +else +AC_MSG_RESULT(failed) +$1="" +fi +if test "x$save_cp" != "x"; then CLASSPATH="$save_cp"; fi +rm -f Test.java Test.class +fi +fi +]) diff --git a/m4/dps_xtra_classpath.m4 b/m4/dps_xtra_classpath.m4 new file mode 100644 index 0000000..83cc37e --- /dev/null +++ b/m4/dps_xtra_classpath.m4 @@ -0,0 +1,71 @@ +##### http://autoconf-archive.cryp.to/dps_xtra_classpath.html +# +# SYNOPSIS +# +# DPS_XTRA_CLASSPATH(,,,,) +# +# DESCRIPTION +# +# Set $1 to extra classpath components required for class $2 found in +# a jar file in $3. If the class is found do $4 and otherwise do $5. +# Uses DPS_JAVA_CHECK_CLASS for testing whether a class is avialable +# +# LAST MODIFICATION +# +# 2008-01-28 +# +# COPYLEFT +# +# Copyright (c) 2008 Duncan Simpson +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. +# +# As a special exception, the respective Autoconf Macro's copyright +# owner gives unlimited permission to copy, distribute and modify the +# configure scripts that are the output of Autoconf when processing +# the Macro. You need not follow the terms of the GNU General Public +# License when using or distributing such scripts, even though +# portions of the text of the Macro appear in them. The GNU General +# Public License (GPL) does govern all other use of the material that +# constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the +# Autoconf Macro released by the Autoconf Macro Archive. When you +# make and distribute a modified version of the Autoconf Macro, you +# may extend this special exception to the GPL to apply to your +# modified version as well. + +AC_DEFUN([DPS_XTRA_CLASSPATH],[ +AC_CHECK_PROG(SED, sed) +DPS_JAVA_CHECK_CLASS([$2],[got="yes"],[got="no"]) +cpxtra=""; saved_cp="${CLASSPATH}"; +for jhome in `ls -dr /usr/share/java /usr/java/* /usr/local/java/* 2> /dev/null`; do +for jdir in lib jre/lib . ; do +for jfile in $3; do +if test "x$got" != "xyes" && test -f "$jhome/$jdir/$jfile"; then +CLASSPATH="${saved_cp}:$jhome/$jdir/$jfile" +DPS_JAVA_CHECK_CLASS([$2],[got="yes"; cpxtra="$jhome/$jdir/$jfile:"],[got="no"]) +fi; done; done; done +if test "x${saved_cp}" != "x"; then +CLASSPATH="${saved_cp}" +else unset CLASSPATH; fi +if test "x$got" = "xyes"; then +$1="$cpxtra" +$4 +true; else +$5 +false; fi +]) diff --git a/m4/gtk-doc.m4 b/m4/gtk-doc.m4 new file mode 120000 index 0000000..d214c6a --- /dev/null +++ b/m4/gtk-doc.m4 @@ -0,0 +1 @@ +/usr/share/aclocal/gtk-doc.m4 \ No newline at end of file diff --git a/m4/libtool.m4 b/m4/libtool.m4 new file mode 100644 index 0000000..a3fee53 --- /dev/null +++ b/m4/libtool.m4 @@ -0,0 +1,7377 @@ +# libtool.m4 - Configure libtool for the host system. -*-Autoconf-*- +# +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, +# 2006, 2007, 2008 Free Software Foundation, Inc. +# Written by Gordon Matzigkeit, 1996 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +m4_define([_LT_COPYING], [dnl +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, +# 2006, 2007, 2008 Free Software Foundation, Inc. +# Written by Gordon Matzigkeit, 1996 +# +# This file is part of GNU Libtool. +# +# GNU Libtool is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# As a special exception to the GNU General Public License, +# if you distribute this file as part of a program or library that +# is built using GNU Libtool, you may include this file under the +# same distribution terms that you use for the rest of that program. +# +# GNU Libtool is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Libtool; see the file COPYING. If not, a copy +# can be downloaded from http://www.gnu.org/licenses/gpl.html, or +# obtained by writing to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +]) + +# serial 56 LT_INIT + + +# LT_PREREQ(VERSION) +# ------------------ +# Complain and exit if this libtool version is less that VERSION. +m4_defun([LT_PREREQ], +[m4_if(m4_version_compare(m4_defn([LT_PACKAGE_VERSION]), [$1]), -1, + [m4_default([$3], + [m4_fatal([Libtool version $1 or higher is required], + 63)])], + [$2])]) + + +# _LT_CHECK_BUILDDIR +# ------------------ +# Complain if the absolute build directory name contains unusual characters +m4_defun([_LT_CHECK_BUILDDIR], +[case `pwd` in + *\ * | *\ *) + AC_MSG_WARN([Libtool does not cope well with whitespace in `pwd`]) ;; +esac +]) + + +# LT_INIT([OPTIONS]) +# ------------------ +AC_DEFUN([LT_INIT], +[AC_PREREQ([2.58])dnl We use AC_INCLUDES_DEFAULT +AC_BEFORE([$0], [LT_LANG])dnl +AC_BEFORE([$0], [LT_OUTPUT])dnl +AC_BEFORE([$0], [LTDL_INIT])dnl +m4_require([_LT_CHECK_BUILDDIR])dnl + +dnl Autoconf doesn't catch unexpanded LT_ macros by default: +m4_pattern_forbid([^_?LT_[A-Z_]+$])dnl +m4_pattern_allow([^(_LT_EOF|LT_DLGLOBAL|LT_DLLAZY_OR_NOW|LT_MULTI_MODULE)$])dnl +dnl aclocal doesn't pull ltoptions.m4, ltsugar.m4, or ltversion.m4 +dnl unless we require an AC_DEFUNed macro: +AC_REQUIRE([LTOPTIONS_VERSION])dnl +AC_REQUIRE([LTSUGAR_VERSION])dnl +AC_REQUIRE([LTVERSION_VERSION])dnl +AC_REQUIRE([LTOBSOLETE_VERSION])dnl +m4_require([_LT_PROG_LTMAIN])dnl + +dnl Parse OPTIONS +_LT_SET_OPTIONS([$0], [$1]) + +# This can be used to rebuild libtool when needed +LIBTOOL_DEPS="$ltmain" + +# Always use our own libtool. +LIBTOOL='$(SHELL) $(top_builddir)/libtool' +AC_SUBST(LIBTOOL)dnl + +_LT_SETUP + +# Only expand once: +m4_define([LT_INIT]) +])# LT_INIT + +# Old names: +AU_ALIAS([AC_PROG_LIBTOOL], [LT_INIT]) +AU_ALIAS([AM_PROG_LIBTOOL], [LT_INIT]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_PROG_LIBTOOL], []) +dnl AC_DEFUN([AM_PROG_LIBTOOL], []) + + +# _LT_CC_BASENAME(CC) +# ------------------- +# Calculate cc_basename. Skip known compiler wrappers and cross-prefix. +m4_defun([_LT_CC_BASENAME], +[for cc_temp in $1""; do + case $cc_temp in + compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;; + distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;; + \-*) ;; + *) break;; + esac +done +cc_basename=`$ECHO "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"` +]) + + +# _LT_FILEUTILS_DEFAULTS +# ---------------------- +# It is okay to use these file commands and assume they have been set +# sensibly after `m4_require([_LT_FILEUTILS_DEFAULTS])'. +m4_defun([_LT_FILEUTILS_DEFAULTS], +[: ${CP="cp -f"} +: ${MV="mv -f"} +: ${RM="rm -f"} +])# _LT_FILEUTILS_DEFAULTS + + +# _LT_SETUP +# --------- +m4_defun([_LT_SETUP], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_CANONICAL_BUILD])dnl +_LT_DECL([], [host_alias], [0], [The host system])dnl +_LT_DECL([], [host], [0])dnl +_LT_DECL([], [host_os], [0])dnl +dnl +_LT_DECL([], [build_alias], [0], [The build system])dnl +_LT_DECL([], [build], [0])dnl +_LT_DECL([], [build_os], [0])dnl +dnl +AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([LT_PATH_LD])dnl +AC_REQUIRE([LT_PATH_NM])dnl +dnl +AC_REQUIRE([AC_PROG_LN_S])dnl +test -z "$LN_S" && LN_S="ln -s" +_LT_DECL([], [LN_S], [1], [Whether we need soft or hard links])dnl +dnl +AC_REQUIRE([LT_CMD_MAX_LEN])dnl +_LT_DECL([objext], [ac_objext], [0], [Object file suffix (normally "o")])dnl +_LT_DECL([], [exeext], [0], [Executable file suffix (normally "")])dnl +dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_CHECK_SHELL_FEATURES])dnl +m4_require([_LT_CMD_RELOAD])dnl +m4_require([_LT_CHECK_MAGIC_METHOD])dnl +m4_require([_LT_CMD_OLD_ARCHIVE])dnl +m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl + +_LT_CONFIG_LIBTOOL_INIT([ +# See if we are running on zsh, and set the options which allow our +# commands through without removal of \ escapes INIT. +if test -n "\${ZSH_VERSION+set}" ; then + setopt NO_GLOB_SUBST +fi +]) +if test -n "${ZSH_VERSION+set}" ; then + setopt NO_GLOB_SUBST +fi + +_LT_CHECK_OBJDIR + +m4_require([_LT_TAG_COMPILER])dnl +_LT_PROG_ECHO_BACKSLASH + +case $host_os in +aix3*) + # AIX sometimes has problems with the GCC collect2 program. For some + # reason, if we set the COLLECT_NAMES environment variable, the problems + # vanish in a puff of smoke. + if test "X${COLLECT_NAMES+set}" != Xset; then + COLLECT_NAMES= + export COLLECT_NAMES + fi + ;; +esac + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +sed_quote_subst='s/\([["`$\\]]\)/\\\1/g' + +# Same as above, but do not quote variable references. +double_quote_subst='s/\([["`\\]]\)/\\\1/g' + +# Sed substitution to delay expansion of an escaped shell variable in a +# double_quote_subst'ed string. +delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g' + +# Sed substitution to delay expansion of an escaped single quote. +delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g' + +# Sed substitution to avoid accidental globbing in evaled expressions +no_glob_subst='s/\*/\\\*/g' + +# Global variables: +ofile=libtool +can_build_shared=yes + +# All known linkers require a `.a' archive for static linking (except MSVC, +# which needs '.lib'). +libext=a + +with_gnu_ld="$lt_cv_prog_gnu_ld" + +old_CC="$CC" +old_CFLAGS="$CFLAGS" + +# Set sane defaults for various variables +test -z "$CC" && CC=cc +test -z "$LTCC" && LTCC=$CC +test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS +test -z "$LD" && LD=ld +test -z "$ac_objext" && ac_objext=o + +_LT_CC_BASENAME([$compiler]) + +# Only perform the check for file, if the check method requires it +test -z "$MAGIC_CMD" && MAGIC_CMD=file +case $deplibs_check_method in +file_magic*) + if test "$file_magic_cmd" = '$MAGIC_CMD'; then + _LT_PATH_MAGIC + fi + ;; +esac + +# Use C for the default configuration in the libtool script +LT_SUPPORTED_TAG([CC]) +_LT_LANG_C_CONFIG +_LT_LANG_DEFAULT_CONFIG +_LT_CONFIG_COMMANDS +])# _LT_SETUP + + +# _LT_PROG_LTMAIN +# --------------- +# Note that this code is called both from `configure', and `config.status' +# now that we use AC_CONFIG_COMMANDS to generate libtool. Notably, +# `config.status' has no value for ac_aux_dir unless we are using Automake, +# so we pass a copy along to make sure it has a sensible value anyway. +m4_defun([_LT_PROG_LTMAIN], +[m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([ltmain.sh])])dnl +_LT_CONFIG_LIBTOOL_INIT([ac_aux_dir='$ac_aux_dir']) +ltmain="$ac_aux_dir/ltmain.sh" +])# _LT_PROG_LTMAIN + + +## ------------------------------------- ## +## Accumulate code for creating libtool. ## +## ------------------------------------- ## + +# So that we can recreate a full libtool script including additional +# tags, we accumulate the chunks of code to send to AC_CONFIG_COMMANDS +# in macros and then make a single call at the end using the `libtool' +# label. + + +# _LT_CONFIG_LIBTOOL_INIT([INIT-COMMANDS]) +# ---------------------------------------- +# Register INIT-COMMANDS to be passed to AC_CONFIG_COMMANDS later. +m4_define([_LT_CONFIG_LIBTOOL_INIT], +[m4_ifval([$1], + [m4_append([_LT_OUTPUT_LIBTOOL_INIT], + [$1 +])])]) + +# Initialize. +m4_define([_LT_OUTPUT_LIBTOOL_INIT]) + + +# _LT_CONFIG_LIBTOOL([COMMANDS]) +# ------------------------------ +# Register COMMANDS to be passed to AC_CONFIG_COMMANDS later. +m4_define([_LT_CONFIG_LIBTOOL], +[m4_ifval([$1], + [m4_append([_LT_OUTPUT_LIBTOOL_COMMANDS], + [$1 +])])]) + +# Initialize. +m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS]) + + +# _LT_CONFIG_SAVE_COMMANDS([COMMANDS], [INIT_COMMANDS]) +# ----------------------------------------------------- +m4_defun([_LT_CONFIG_SAVE_COMMANDS], +[_LT_CONFIG_LIBTOOL([$1]) +_LT_CONFIG_LIBTOOL_INIT([$2]) +]) + + +# _LT_FORMAT_COMMENT([COMMENT]) +# ----------------------------- +# Add leading comment marks to the start of each line, and a trailing +# full-stop to the whole comment if one is not present already. +m4_define([_LT_FORMAT_COMMENT], +[m4_ifval([$1], [ +m4_bpatsubst([m4_bpatsubst([$1], [^ *], [# ])], + [['`$\]], [\\\&])]m4_bmatch([$1], [[!?.]$], [], [.]) +)]) + + + +## ------------------------ ## +## FIXME: Eliminate VARNAME ## +## ------------------------ ## + + +# _LT_DECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION], [IS-TAGGED?]) +# ------------------------------------------------------------------- +# CONFIGNAME is the name given to the value in the libtool script. +# VARNAME is the (base) name used in the configure script. +# VALUE may be 0, 1 or 2 for a computed quote escaped value based on +# VARNAME. Any other value will be used directly. +m4_define([_LT_DECL], +[lt_if_append_uniq([lt_decl_varnames], [$2], [, ], + [lt_dict_add_subkey([lt_decl_dict], [$2], [libtool_name], + [m4_ifval([$1], [$1], [$2])]) + lt_dict_add_subkey([lt_decl_dict], [$2], [value], [$3]) + m4_ifval([$4], + [lt_dict_add_subkey([lt_decl_dict], [$2], [description], [$4])]) + lt_dict_add_subkey([lt_decl_dict], [$2], + [tagged?], [m4_ifval([$5], [yes], [no])])]) +]) + + +# _LT_TAGDECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION]) +# -------------------------------------------------------- +m4_define([_LT_TAGDECL], [_LT_DECL([$1], [$2], [$3], [$4], [yes])]) + + +# lt_decl_tag_varnames([SEPARATOR], [VARNAME1...]) +# ------------------------------------------------ +m4_define([lt_decl_tag_varnames], +[_lt_decl_filter([tagged?], [yes], $@)]) + + +# _lt_decl_filter(SUBKEY, VALUE, [SEPARATOR], [VARNAME1..]) +# --------------------------------------------------------- +m4_define([_lt_decl_filter], +[m4_case([$#], + [0], [m4_fatal([$0: too few arguments: $#])], + [1], [m4_fatal([$0: too few arguments: $#: $1])], + [2], [lt_dict_filter([lt_decl_dict], [$1], [$2], [], lt_decl_varnames)], + [3], [lt_dict_filter([lt_decl_dict], [$1], [$2], [$3], lt_decl_varnames)], + [lt_dict_filter([lt_decl_dict], $@)])[]dnl +]) + + +# lt_decl_quote_varnames([SEPARATOR], [VARNAME1...]) +# -------------------------------------------------- +m4_define([lt_decl_quote_varnames], +[_lt_decl_filter([value], [1], $@)]) + + +# lt_decl_dquote_varnames([SEPARATOR], [VARNAME1...]) +# --------------------------------------------------- +m4_define([lt_decl_dquote_varnames], +[_lt_decl_filter([value], [2], $@)]) + + +# lt_decl_varnames_tagged([SEPARATOR], [VARNAME1...]) +# --------------------------------------------------- +m4_define([lt_decl_varnames_tagged], +[m4_assert([$# <= 2])dnl +_$0(m4_quote(m4_default([$1], [[, ]])), + m4_ifval([$2], [[$2]], [m4_dquote(lt_decl_tag_varnames)]), + m4_split(m4_normalize(m4_quote(_LT_TAGS)), [ ]))]) +m4_define([_lt_decl_varnames_tagged], +[m4_ifval([$3], [lt_combine([$1], [$2], [_], $3)])]) + + +# lt_decl_all_varnames([SEPARATOR], [VARNAME1...]) +# ------------------------------------------------ +m4_define([lt_decl_all_varnames], +[_$0(m4_quote(m4_default([$1], [[, ]])), + m4_if([$2], [], + m4_quote(lt_decl_varnames), + m4_quote(m4_shift($@))))[]dnl +]) +m4_define([_lt_decl_all_varnames], +[lt_join($@, lt_decl_varnames_tagged([$1], + lt_decl_tag_varnames([[, ]], m4_shift($@))))dnl +]) + + +# _LT_CONFIG_STATUS_DECLARE([VARNAME]) +# ------------------------------------ +# Quote a variable value, and forward it to `config.status' so that its +# declaration there will have the same value as in `configure'. VARNAME +# must have a single quote delimited value for this to work. +m4_define([_LT_CONFIG_STATUS_DECLARE], +[$1='`$ECHO "X$][$1" | $Xsed -e "$delay_single_quote_subst"`']) + + +# _LT_CONFIG_STATUS_DECLARATIONS +# ------------------------------ +# We delimit libtool config variables with single quotes, so when +# we write them to config.status, we have to be sure to quote all +# embedded single quotes properly. In configure, this macro expands +# each variable declared with _LT_DECL (and _LT_TAGDECL) into: +# +# ='`$ECHO "X$" | $Xsed -e "$delay_single_quote_subst"`' +m4_defun([_LT_CONFIG_STATUS_DECLARATIONS], +[m4_foreach([_lt_var], m4_quote(lt_decl_all_varnames), + [m4_n([_LT_CONFIG_STATUS_DECLARE(_lt_var)])])]) + + +# _LT_LIBTOOL_TAGS +# ---------------- +# Output comment and list of tags supported by the script +m4_defun([_LT_LIBTOOL_TAGS], +[_LT_FORMAT_COMMENT([The names of the tagged configurations supported by this script])dnl +available_tags="_LT_TAGS"dnl +]) + + +# _LT_LIBTOOL_DECLARE(VARNAME, [TAG]) +# ----------------------------------- +# Extract the dictionary values for VARNAME (optionally with TAG) and +# expand to a commented shell variable setting: +# +# # Some comment about what VAR is for. +# visible_name=$lt_internal_name +m4_define([_LT_LIBTOOL_DECLARE], +[_LT_FORMAT_COMMENT(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], + [description])))[]dnl +m4_pushdef([_libtool_name], + m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [libtool_name])))[]dnl +m4_case(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [value])), + [0], [_libtool_name=[$]$1], + [1], [_libtool_name=$lt_[]$1], + [2], [_libtool_name=$lt_[]$1], + [_libtool_name=lt_dict_fetch([lt_decl_dict], [$1], [value])])[]dnl +m4_ifval([$2], [_$2])[]m4_popdef([_libtool_name])[]dnl +]) + + +# _LT_LIBTOOL_CONFIG_VARS +# ----------------------- +# Produce commented declarations of non-tagged libtool config variables +# suitable for insertion in the LIBTOOL CONFIG section of the `libtool' +# script. Tagged libtool config variables (even for the LIBTOOL CONFIG +# section) are produced by _LT_LIBTOOL_TAG_VARS. +m4_defun([_LT_LIBTOOL_CONFIG_VARS], +[m4_foreach([_lt_var], + m4_quote(_lt_decl_filter([tagged?], [no], [], lt_decl_varnames)), + [m4_n([_LT_LIBTOOL_DECLARE(_lt_var)])])]) + + +# _LT_LIBTOOL_TAG_VARS(TAG) +# ------------------------- +m4_define([_LT_LIBTOOL_TAG_VARS], +[m4_foreach([_lt_var], m4_quote(lt_decl_tag_varnames), + [m4_n([_LT_LIBTOOL_DECLARE(_lt_var, [$1])])])]) + + +# _LT_TAGVAR(VARNAME, [TAGNAME]) +# ------------------------------ +m4_define([_LT_TAGVAR], [m4_ifval([$2], [$1_$2], [$1])]) + + +# _LT_CONFIG_COMMANDS +# ------------------- +# Send accumulated output to $CONFIG_STATUS. Thanks to the lists of +# variables for single and double quote escaping we saved from calls +# to _LT_DECL, we can put quote escaped variables declarations +# into `config.status', and then the shell code to quote escape them in +# for loops in `config.status'. Finally, any additional code accumulated +# from calls to _LT_CONFIG_LIBTOOL_INIT is expanded. +m4_defun([_LT_CONFIG_COMMANDS], +[AC_PROVIDE_IFELSE([LT_OUTPUT], + dnl If the libtool generation code has been placed in $CONFIG_LT, + dnl instead of duplicating it all over again into config.status, + dnl then we will have config.status run $CONFIG_LT later, so it + dnl needs to know what name is stored there: + [AC_CONFIG_COMMANDS([libtool], + [$SHELL $CONFIG_LT || AS_EXIT(1)], [CONFIG_LT='$CONFIG_LT'])], + dnl If the libtool generation code is destined for config.status, + dnl expand the accumulated commands and init code now: + [AC_CONFIG_COMMANDS([libtool], + [_LT_OUTPUT_LIBTOOL_COMMANDS], [_LT_OUTPUT_LIBTOOL_COMMANDS_INIT])]) +])#_LT_CONFIG_COMMANDS + + +# Initialize. +m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS_INIT], +[ + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +sed_quote_subst='$sed_quote_subst' +double_quote_subst='$double_quote_subst' +delay_variable_subst='$delay_variable_subst' +_LT_CONFIG_STATUS_DECLARATIONS +LTCC='$LTCC' +LTCFLAGS='$LTCFLAGS' +compiler='$compiler_DEFAULT' + +# Quote evaled strings. +for var in lt_decl_all_varnames([[ \ +]], lt_decl_quote_varnames); do + case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in + *[[\\\\\\\`\\"\\\$]]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$sed_quote_subst\\"\\\`\\\\\\"" + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +# Double-quote double-evaled strings. +for var in lt_decl_all_varnames([[ \ +]], lt_decl_dquote_varnames); do + case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in + *[[\\\\\\\`\\"\\\$]]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\"" + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +# Fix-up fallback echo if it was mangled by the above quoting rules. +case \$lt_ECHO in +*'\\\[$]0 --fallback-echo"')dnl " + lt_ECHO=\`\$ECHO "X\$lt_ECHO" | \$Xsed -e 's/\\\\\\\\\\\\\\\[$]0 --fallback-echo"\[$]/\[$]0 --fallback-echo"/'\` + ;; +esac + +_LT_OUTPUT_LIBTOOL_INIT +]) + + +# LT_OUTPUT +# --------- +# This macro allows early generation of the libtool script (before +# AC_OUTPUT is called), incase it is used in configure for compilation +# tests. +AC_DEFUN([LT_OUTPUT], +[: ${CONFIG_LT=./config.lt} +AC_MSG_NOTICE([creating $CONFIG_LT]) +cat >"$CONFIG_LT" <<_LTEOF +#! $SHELL +# Generated by $as_me. +# Run this file to recreate a libtool stub with the current configuration. + +lt_cl_silent=false +SHELL=\${CONFIG_SHELL-$SHELL} +_LTEOF + +cat >>"$CONFIG_LT" <<\_LTEOF +AS_SHELL_SANITIZE +_AS_PREPARE + +exec AS_MESSAGE_FD>&1 +exec AS_MESSAGE_LOG_FD>>config.log +{ + echo + AS_BOX([Running $as_me.]) +} >&AS_MESSAGE_LOG_FD + +lt_cl_help="\ +\`$as_me' creates a local libtool stub from the current configuration, +for use in further configure time tests before the real libtool is +generated. + +Usage: $[0] [[OPTIONS]] + + -h, --help print this help, then exit + -V, --version print version number, then exit + -q, --quiet do not print progress messages + -d, --debug don't remove temporary files + +Report bugs to ." + +lt_cl_version="\ +m4_ifset([AC_PACKAGE_NAME], [AC_PACKAGE_NAME ])config.lt[]dnl +m4_ifset([AC_PACKAGE_VERSION], [ AC_PACKAGE_VERSION]) +configured by $[0], generated by m4_PACKAGE_STRING. + +Copyright (C) 2008 Free Software Foundation, Inc. +This config.lt script is free software; the Free Software Foundation +gives unlimited permision to copy, distribute and modify it." + +while test $[#] != 0 +do + case $[1] in + --version | --v* | -V ) + echo "$lt_cl_version"; exit 0 ;; + --help | --h* | -h ) + echo "$lt_cl_help"; exit 0 ;; + --debug | --d* | -d ) + debug=: ;; + --quiet | --q* | --silent | --s* | -q ) + lt_cl_silent=: ;; + + -*) AC_MSG_ERROR([unrecognized option: $[1] +Try \`$[0] --help' for more information.]) ;; + + *) AC_MSG_ERROR([unrecognized argument: $[1] +Try \`$[0] --help' for more information.]) ;; + esac + shift +done + +if $lt_cl_silent; then + exec AS_MESSAGE_FD>/dev/null +fi +_LTEOF + +cat >>"$CONFIG_LT" <<_LTEOF +_LT_OUTPUT_LIBTOOL_COMMANDS_INIT +_LTEOF + +cat >>"$CONFIG_LT" <<\_LTEOF +AC_MSG_NOTICE([creating $ofile]) +_LT_OUTPUT_LIBTOOL_COMMANDS +AS_EXIT(0) +_LTEOF +chmod +x "$CONFIG_LT" + +# configure is writing to config.log, but config.lt does its own redirection, +# appending to config.log, which fails on DOS, as config.log is still kept +# open by configure. Here we exec the FD to /dev/null, effectively closing +# config.log, so it can be properly (re)opened and appended to by config.lt. +if test "$no_create" != yes; then + lt_cl_success=: + test "$silent" = yes && + lt_config_lt_args="$lt_config_lt_args --quiet" + exec AS_MESSAGE_LOG_FD>/dev/null + $SHELL "$CONFIG_LT" $lt_config_lt_args || lt_cl_success=false + exec AS_MESSAGE_LOG_FD>>config.log + $lt_cl_success || AS_EXIT(1) +fi +])# LT_OUTPUT + + +# _LT_CONFIG(TAG) +# --------------- +# If TAG is the built-in tag, create an initial libtool script with a +# default configuration from the untagged config vars. Otherwise add code +# to config.status for appending the configuration named by TAG from the +# matching tagged config vars. +m4_defun([_LT_CONFIG], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +_LT_CONFIG_SAVE_COMMANDS([ + m4_define([_LT_TAG], m4_if([$1], [], [C], [$1]))dnl + m4_if(_LT_TAG, [C], [ + # See if we are running on zsh, and set the options which allow our + # commands through without removal of \ escapes. + if test -n "${ZSH_VERSION+set}" ; then + setopt NO_GLOB_SUBST + fi + + cfgfile="${ofile}T" + trap "$RM \"$cfgfile\"; exit 1" 1 2 15 + $RM "$cfgfile" + + cat <<_LT_EOF >> "$cfgfile" +#! $SHELL + +# `$ECHO "$ofile" | sed 's%^.*/%%'` - Provide generalized library-building support services. +# Generated automatically by $as_me ($PACKAGE$TIMESTAMP) $VERSION +# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: +# NOTE: Changes made to this file will be lost: look at ltmain.sh. +# +_LT_COPYING +_LT_LIBTOOL_TAGS + +# ### BEGIN LIBTOOL CONFIG +_LT_LIBTOOL_CONFIG_VARS +_LT_LIBTOOL_TAG_VARS +# ### END LIBTOOL CONFIG + +_LT_EOF + + case $host_os in + aix3*) + cat <<\_LT_EOF >> "$cfgfile" +# AIX sometimes has problems with the GCC collect2 program. For some +# reason, if we set the COLLECT_NAMES environment variable, the problems +# vanish in a puff of smoke. +if test "X${COLLECT_NAMES+set}" != Xset; then + COLLECT_NAMES= + export COLLECT_NAMES +fi +_LT_EOF + ;; + esac + + _LT_PROG_LTMAIN + + # We use sed instead of cat because bash on DJGPP gets confused if + # if finds mixed CR/LF and LF-only lines. Since sed operates in + # text mode, it properly converts lines to CR/LF. This bash problem + # is reportedly fixed, but why not run on old versions too? + sed '/^# Generated shell functions inserted here/q' "$ltmain" >> "$cfgfile" \ + || (rm -f "$cfgfile"; exit 1) + + _LT_PROG_XSI_SHELLFNS + + sed -n '/^# Generated shell functions inserted here/,$p' "$ltmain" >> "$cfgfile" \ + || (rm -f "$cfgfile"; exit 1) + + mv -f "$cfgfile" "$ofile" || + (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile") + chmod +x "$ofile" +], +[cat <<_LT_EOF >> "$ofile" + +dnl Unfortunately we have to use $1 here, since _LT_TAG is not expanded +dnl in a comment (ie after a #). +# ### BEGIN LIBTOOL TAG CONFIG: $1 +_LT_LIBTOOL_TAG_VARS(_LT_TAG) +# ### END LIBTOOL TAG CONFIG: $1 +_LT_EOF +])dnl /m4_if +], +[m4_if([$1], [], [ + PACKAGE='$PACKAGE' + VERSION='$VERSION' + TIMESTAMP='$TIMESTAMP' + RM='$RM' + ofile='$ofile'], []) +])dnl /_LT_CONFIG_SAVE_COMMANDS +])# _LT_CONFIG + + +# LT_SUPPORTED_TAG(TAG) +# --------------------- +# Trace this macro to discover what tags are supported by the libtool +# --tag option, using: +# autoconf --trace 'LT_SUPPORTED_TAG:$1' +AC_DEFUN([LT_SUPPORTED_TAG], []) + + +# C support is built-in for now +m4_define([_LT_LANG_C_enabled], []) +m4_define([_LT_TAGS], []) + + +# LT_LANG(LANG) +# ------------- +# Enable libtool support for the given language if not already enabled. +AC_DEFUN([LT_LANG], +[AC_BEFORE([$0], [LT_OUTPUT])dnl +m4_case([$1], + [C], [_LT_LANG(C)], + [C++], [_LT_LANG(CXX)], + [Java], [_LT_LANG(GCJ)], + [Fortran 77], [_LT_LANG(F77)], + [Fortran], [_LT_LANG(FC)], + [Windows Resource], [_LT_LANG(RC)], + [m4_ifdef([_LT_LANG_]$1[_CONFIG], + [_LT_LANG($1)], + [m4_fatal([$0: unsupported language: "$1"])])])dnl +])# LT_LANG + + +# _LT_LANG(LANGNAME) +# ------------------ +m4_defun([_LT_LANG], +[m4_ifdef([_LT_LANG_]$1[_enabled], [], + [LT_SUPPORTED_TAG([$1])dnl + m4_append([_LT_TAGS], [$1 ])dnl + m4_define([_LT_LANG_]$1[_enabled], [])dnl + _LT_LANG_$1_CONFIG($1)])dnl +])# _LT_LANG + + +# _LT_LANG_DEFAULT_CONFIG +# ----------------------- +m4_defun([_LT_LANG_DEFAULT_CONFIG], +[AC_PROVIDE_IFELSE([AC_PROG_CXX], + [LT_LANG(CXX)], + [m4_define([AC_PROG_CXX], defn([AC_PROG_CXX])[LT_LANG(CXX)])]) + +AC_PROVIDE_IFELSE([AC_PROG_F77], + [LT_LANG(F77)], + [m4_define([AC_PROG_F77], defn([AC_PROG_F77])[LT_LANG(F77)])]) + +AC_PROVIDE_IFELSE([AC_PROG_FC], + [LT_LANG(FC)], + [m4_define([AC_PROG_FC], defn([AC_PROG_FC])[LT_LANG(FC)])]) + +dnl The call to [A][M_PROG_GCJ] is quoted like that to stop aclocal +dnl pulling things in needlessly. +AC_PROVIDE_IFELSE([AC_PROG_GCJ], + [LT_LANG(GCJ)], + [AC_PROVIDE_IFELSE([A][M_PROG_GCJ], + [LT_LANG(GCJ)], + [AC_PROVIDE_IFELSE([LT_PROG_GCJ], + [LT_LANG(GCJ)], + [m4_ifdef([AC_PROG_GCJ], + [m4_define([AC_PROG_GCJ], defn([AC_PROG_GCJ])[LT_LANG(GCJ)])]) + m4_ifdef([A][M_PROG_GCJ], + [m4_define([A][M_PROG_GCJ], defn([A][M_PROG_GCJ])[LT_LANG(GCJ)])]) + m4_ifdef([LT_PROG_GCJ], + [m4_define([LT_PROG_GCJ], defn([LT_PROG_GCJ])[LT_LANG(GCJ)])])])])]) + +AC_PROVIDE_IFELSE([LT_PROG_RC], + [LT_LANG(RC)], + [m4_define([LT_PROG_RC], defn([LT_PROG_RC])[LT_LANG(RC)])]) +])# _LT_LANG_DEFAULT_CONFIG + +# Obsolete macros: +AU_DEFUN([AC_LIBTOOL_CXX], [LT_LANG(C++)]) +AU_DEFUN([AC_LIBTOOL_F77], [LT_LANG(Fortran 77)]) +AU_DEFUN([AC_LIBTOOL_FC], [LT_LANG(Fortran)]) +AU_DEFUN([AC_LIBTOOL_GCJ], [LT_LANG(Java)]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_CXX], []) +dnl AC_DEFUN([AC_LIBTOOL_F77], []) +dnl AC_DEFUN([AC_LIBTOOL_FC], []) +dnl AC_DEFUN([AC_LIBTOOL_GCJ], []) + + +# _LT_TAG_COMPILER +# ---------------- +m4_defun([_LT_TAG_COMPILER], +[AC_REQUIRE([AC_PROG_CC])dnl + +_LT_DECL([LTCC], [CC], [1], [A C compiler])dnl +_LT_DECL([LTCFLAGS], [CFLAGS], [1], [LTCC compiler flags])dnl +_LT_TAGDECL([CC], [compiler], [1], [A language specific compiler])dnl +_LT_TAGDECL([with_gcc], [GCC], [0], [Is the compiler the GNU compiler?])dnl + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC +])# _LT_TAG_COMPILER + + +# _LT_COMPILER_BOILERPLATE +# ------------------------ +# Check for compiler boilerplate output or warnings with +# the simple compiler test code. +m4_defun([_LT_COMPILER_BOILERPLATE], +[m4_require([_LT_DECL_SED])dnl +ac_outfile=conftest.$ac_objext +echo "$lt_simple_compile_test_code" >conftest.$ac_ext +eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_compiler_boilerplate=`cat conftest.err` +$RM conftest* +])# _LT_COMPILER_BOILERPLATE + + +# _LT_LINKER_BOILERPLATE +# ---------------------- +# Check for linker boilerplate output or warnings with +# the simple link test code. +m4_defun([_LT_LINKER_BOILERPLATE], +[m4_require([_LT_DECL_SED])dnl +ac_outfile=conftest.$ac_objext +echo "$lt_simple_link_test_code" >conftest.$ac_ext +eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_linker_boilerplate=`cat conftest.err` +$RM -r conftest* +])# _LT_LINKER_BOILERPLATE + +# _LT_REQUIRED_DARWIN_CHECKS +# ------------------------- +m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[ + case $host_os in + rhapsody* | darwin*) + AC_CHECK_TOOL([DSYMUTIL], [dsymutil], [:]) + AC_CHECK_TOOL([NMEDIT], [nmedit], [:]) + AC_CHECK_TOOL([LIPO], [lipo], [:]) + AC_CHECK_TOOL([OTOOL], [otool], [:]) + AC_CHECK_TOOL([OTOOL64], [otool64], [:]) + _LT_DECL([], [DSYMUTIL], [1], + [Tool to manipulate archived DWARF debug symbol files on Mac OS X]) + _LT_DECL([], [NMEDIT], [1], + [Tool to change global to local symbols on Mac OS X]) + _LT_DECL([], [LIPO], [1], + [Tool to manipulate fat objects and archives on Mac OS X]) + _LT_DECL([], [OTOOL], [1], + [ldd/readelf like tool for Mach-O binaries on Mac OS X]) + _LT_DECL([], [OTOOL64], [1], + [ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4]) + + AC_CACHE_CHECK([for -single_module linker flag],[lt_cv_apple_cc_single_mod], + [lt_cv_apple_cc_single_mod=no + if test -z "${LT_MULTI_MODULE}"; then + # By default we will add the -single_module flag. You can override + # by either setting the environment variable LT_MULTI_MODULE + # non-empty at configure time, or by adding -multi_module to the + # link flags. + rm -rf libconftest.dylib* + echo "int foo(void){return 1;}" > conftest.c + echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ +-dynamiclib -Wl,-single_module conftest.c" >&AS_MESSAGE_LOG_FD + $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ + -dynamiclib -Wl,-single_module conftest.c 2>conftest.err + _lt_result=$? + if test -f libconftest.dylib && test ! -s conftest.err && test $_lt_result = 0; then + lt_cv_apple_cc_single_mod=yes + else + cat conftest.err >&AS_MESSAGE_LOG_FD + fi + rm -rf libconftest.dylib* + rm -f conftest.* + fi]) + AC_CACHE_CHECK([for -exported_symbols_list linker flag], + [lt_cv_ld_exported_symbols_list], + [lt_cv_ld_exported_symbols_list=no + save_LDFLAGS=$LDFLAGS + echo "_main" > conftest.sym + LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym" + AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], + [lt_cv_ld_exported_symbols_list=yes], + [lt_cv_ld_exported_symbols_list=no]) + LDFLAGS="$save_LDFLAGS" + ]) + case $host_os in + rhapsody* | darwin1.[[012]]) + _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;; + darwin1.*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; + darwin*) # darwin 5.x on + # if running on 10.5 or later, the deployment target defaults + # to the OS version, if on x86, and 10.4, the deployment + # target defaults to 10.4. Don't you love it? + case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in + 10.0,*86*-darwin8*|10.0,*-darwin[[91]]*) + _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; + 10.[[012]]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; + 10.*) + _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; + esac + ;; + esac + if test "$lt_cv_apple_cc_single_mod" = "yes"; then + _lt_dar_single_mod='$single_module' + fi + if test "$lt_cv_ld_exported_symbols_list" = "yes"; then + _lt_dar_export_syms=' ${wl}-exported_symbols_list,$output_objdir/${libname}-symbols.expsym' + else + _lt_dar_export_syms='~$NMEDIT -s $output_objdir/${libname}-symbols.expsym ${lib}' + fi + if test "$DSYMUTIL" != ":"; then + _lt_dsymutil='~$DSYMUTIL $lib || :' + else + _lt_dsymutil= + fi + ;; + esac +]) + + +# _LT_DARWIN_LINKER_FEATURES +# -------------------------- +# Checks for linker and compiler features on darwin +m4_defun([_LT_DARWIN_LINKER_FEATURES], +[ + m4_require([_LT_REQUIRED_DARWIN_CHECKS]) + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_automatic, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported + _LT_TAGVAR(whole_archive_flag_spec, $1)='' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(allow_undefined_flag, $1)="$_lt_dar_allow_undefined" + case $cc_basename in + ifort*) _lt_dar_can_shared=yes ;; + *) _lt_dar_can_shared=$GCC ;; + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=echo + _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" + _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" + _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" + _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + m4_if([$1], [CXX], +[ if test "$lt_cv_apple_cc_single_mod" != "yes"; then + _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" + _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi +],[]) + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi +]) + +# _LT_SYS_MODULE_PATH_AIX +# ----------------------- +# Links a minimal program and checks the executable +# for the system default hardcoded library path. In most cases, +# this is /usr/lib:/lib, but when the MPI compilers are used +# the location of the communication and MPI libs are included too. +# If we don't find anything, use the default library path according +# to the aix ld manual. +m4_defun([_LT_SYS_MODULE_PATH_AIX], +[m4_require([_LT_DECL_SED])dnl +AC_LINK_IFELSE(AC_LANG_PROGRAM,[ +lt_aix_libpath_sed=' + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\(.*\)$/\1/ + p + } + }' +aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` +# Check for a 64-bit object if we didn't find anything. +if test -z "$aix_libpath"; then + aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` +fi],[]) +if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi +])# _LT_SYS_MODULE_PATH_AIX + + +# _LT_SHELL_INIT(ARG) +# ------------------- +m4_define([_LT_SHELL_INIT], +[ifdef([AC_DIVERSION_NOTICE], + [AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)], + [AC_DIVERT_PUSH(NOTICE)]) +$1 +AC_DIVERT_POP +])# _LT_SHELL_INIT + + +# _LT_PROG_ECHO_BACKSLASH +# ----------------------- +# Add some code to the start of the generated configure script which +# will find an echo command which doesn't interpret backslashes. +m4_defun([_LT_PROG_ECHO_BACKSLASH], +[_LT_SHELL_INIT([ +# Check that we are running under the correct shell. +SHELL=${CONFIG_SHELL-/bin/sh} + +case X$lt_ECHO in +X*--fallback-echo) + # Remove one level of quotation (which was required for Make). + ECHO=`echo "$lt_ECHO" | sed 's,\\\\\[$]\\[$]0,'[$]0','` + ;; +esac + +ECHO=${lt_ECHO-echo} +if test "X[$]1" = X--no-reexec; then + # Discard the --no-reexec flag, and continue. + shift +elif test "X[$]1" = X--fallback-echo; then + # Avoid inline document here, it may be left over + : +elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' ; then + # Yippee, $ECHO works! + : +else + # Restart under the correct shell. + exec $SHELL "[$]0" --no-reexec ${1+"[$]@"} +fi + +if test "X[$]1" = X--fallback-echo; then + # used as fallback echo + shift + cat <<_LT_EOF +[$]* +_LT_EOF + exit 0 +fi + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +if test -z "$lt_ECHO"; then + if test "X${echo_test_string+set}" != Xset; then + # find a string as large as possible, as long as the shell can cope with it + for cmd in 'sed 50q "[$]0"' 'sed 20q "[$]0"' 'sed 10q "[$]0"' 'sed 2q "[$]0"' 'echo test'; do + # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ... + if { echo_test_string=`eval $cmd`; } 2>/dev/null && + { test "X$echo_test_string" = "X$echo_test_string"; } 2>/dev/null + then + break + fi + done + fi + + if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' && + echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + : + else + # The Solaris, AIX, and Digital Unix default echo programs unquote + # backslashes. This makes it impossible to quote backslashes using + # echo "$something" | sed 's/\\/\\\\/g' + # + # So, first we look for a working echo in the user's PATH. + + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for dir in $PATH /usr/ucb; do + IFS="$lt_save_ifs" + if (test -f $dir/echo || test -f $dir/echo$ac_exeext) && + test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' && + echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + ECHO="$dir/echo" + break + fi + done + IFS="$lt_save_ifs" + + if test "X$ECHO" = Xecho; then + # We didn't find a better echo, so look for alternatives. + if test "X`{ print -r '\t'; } 2>/dev/null`" = 'X\t' && + echo_testing_string=`{ print -r "$echo_test_string"; } 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + # This shell has a builtin print -r that does the trick. + ECHO='print -r' + elif { test -f /bin/ksh || test -f /bin/ksh$ac_exeext; } && + test "X$CONFIG_SHELL" != X/bin/ksh; then + # If we have ksh, try running configure again with it. + ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh} + export ORIGINAL_CONFIG_SHELL + CONFIG_SHELL=/bin/ksh + export CONFIG_SHELL + exec $CONFIG_SHELL "[$]0" --no-reexec ${1+"[$]@"} + else + # Try using printf. + ECHO='printf %s\n' + if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' && + echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + # Cool, printf works + : + elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` && + test "X$echo_testing_string" = 'X\t' && + echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL + export CONFIG_SHELL + SHELL="$CONFIG_SHELL" + export SHELL + ECHO="$CONFIG_SHELL [$]0 --fallback-echo" + elif echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` && + test "X$echo_testing_string" = 'X\t' && + echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + ECHO="$CONFIG_SHELL [$]0 --fallback-echo" + else + # maybe with a smaller string... + prev=: + + for cmd in 'echo test' 'sed 2q "[$]0"' 'sed 10q "[$]0"' 'sed 20q "[$]0"' 'sed 50q "[$]0"'; do + if { test "X$echo_test_string" = "X`eval $cmd`"; } 2>/dev/null + then + break + fi + prev="$cmd" + done + + if test "$prev" != 'sed 50q "[$]0"'; then + echo_test_string=`eval $prev` + export echo_test_string + exec ${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}} "[$]0" ${1+"[$]@"} + else + # Oops. We lost completely, so just stick with echo. + ECHO=echo + fi + fi + fi + fi + fi +fi + +# Copy echo and quote the copy suitably for passing to libtool from +# the Makefile, instead of quoting the original, which is used later. +lt_ECHO=$ECHO +if test "X$lt_ECHO" = "X$CONFIG_SHELL [$]0 --fallback-echo"; then + lt_ECHO="$CONFIG_SHELL \\\$\[$]0 --fallback-echo" +fi + +AC_SUBST(lt_ECHO) +]) +_LT_DECL([], [SHELL], [1], [Shell to use when invoking shell scripts]) +_LT_DECL([], [ECHO], [1], + [An echo program that does not interpret backslashes]) +])# _LT_PROG_ECHO_BACKSLASH + + +# _LT_ENABLE_LOCK +# --------------- +m4_defun([_LT_ENABLE_LOCK], +[AC_ARG_ENABLE([libtool-lock], + [AS_HELP_STRING([--disable-libtool-lock], + [avoid locking (might break parallel builds)])]) +test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes + +# Some flags need to be propagated to the compiler or linker for good +# libtool support. +case $host in +ia64-*-hpux*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.$ac_objext` in + *ELF-32*) + HPUX_IA64_MODE="32" + ;; + *ELF-64*) + HPUX_IA64_MODE="64" + ;; + esac + fi + rm -rf conftest* + ;; +*-*-irix6*) + # Find out which ABI we are using. + echo '[#]line __oline__ "configure"' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + if test "$lt_cv_prog_gnu_ld" = yes; then + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -melf32bsmip" + ;; + *N32*) + LD="${LD-ld} -melf32bmipn32" + ;; + *64-bit*) + LD="${LD-ld} -melf64bmip" + ;; + esac + else + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -32" + ;; + *N32*) + LD="${LD-ld} -n32" + ;; + *64-bit*) + LD="${LD-ld} -64" + ;; + esac + fi + fi + rm -rf conftest* + ;; + +x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \ +s390*-*linux*|s390*-*tpf*|sparc*-*linux*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.o` in + *32-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_i386_fbsd" + ;; + x86_64-*linux*) + LD="${LD-ld} -m elf_i386" + ;; + ppc64-*linux*|powerpc64-*linux*) + LD="${LD-ld} -m elf32ppclinux" + ;; + s390x-*linux*) + LD="${LD-ld} -m elf_s390" + ;; + sparc64-*linux*) + LD="${LD-ld} -m elf32_sparc" + ;; + esac + ;; + *64-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_x86_64_fbsd" + ;; + x86_64-*linux*) + LD="${LD-ld} -m elf_x86_64" + ;; + ppc*-*linux*|powerpc*-*linux*) + LD="${LD-ld} -m elf64ppc" + ;; + s390*-*linux*|s390*-*tpf*) + LD="${LD-ld} -m elf64_s390" + ;; + sparc*-*linux*) + LD="${LD-ld} -m elf64_sparc" + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; + +*-*-sco3.2v5*) + # On SCO OpenServer 5, we need -belf to get full-featured binaries. + SAVE_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -belf" + AC_CACHE_CHECK([whether the C compiler needs -belf], lt_cv_cc_needs_belf, + [AC_LANG_PUSH(C) + AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no]) + AC_LANG_POP]) + if test x"$lt_cv_cc_needs_belf" != x"yes"; then + # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf + CFLAGS="$SAVE_CFLAGS" + fi + ;; +sparc*-*solaris*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.o` in + *64-bit*) + case $lt_cv_prog_gnu_ld in + yes*) LD="${LD-ld} -m elf64_sparc" ;; + *) + if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then + LD="${LD-ld} -64" + fi + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; +esac + +need_locks="$enable_libtool_lock" +])# _LT_ENABLE_LOCK + + +# _LT_CMD_OLD_ARCHIVE +# ------------------- +m4_defun([_LT_CMD_OLD_ARCHIVE], +[AC_CHECK_TOOL(AR, ar, false) +test -z "$AR" && AR=ar +test -z "$AR_FLAGS" && AR_FLAGS=cru +_LT_DECL([], [AR], [1], [The archiver]) +_LT_DECL([], [AR_FLAGS], [1]) + +AC_CHECK_TOOL(STRIP, strip, :) +test -z "$STRIP" && STRIP=: +_LT_DECL([], [STRIP], [1], [A symbol stripping program]) + +AC_CHECK_TOOL(RANLIB, ranlib, :) +test -z "$RANLIB" && RANLIB=: +_LT_DECL([], [RANLIB], [1], + [Commands used to install an old-style archive]) + +# Determine commands to create old-style static archives. +old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs' +old_postinstall_cmds='chmod 644 $oldlib' +old_postuninstall_cmds= + +if test -n "$RANLIB"; then + case $host_os in + openbsd*) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$oldlib" + ;; + *) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$oldlib" + ;; + esac + old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib" +fi +_LT_DECL([], [old_postinstall_cmds], [2]) +_LT_DECL([], [old_postuninstall_cmds], [2]) +_LT_TAGDECL([], [old_archive_cmds], [2], + [Commands used to build an old-style archive]) +])# _LT_CMD_OLD_ARCHIVE + + +# _LT_COMPILER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, +# [OUTPUT-FILE], [ACTION-SUCCESS], [ACTION-FAILURE]) +# ---------------------------------------------------------------- +# Check whether the given compiler option works +AC_DEFUN([_LT_COMPILER_OPTION], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_SED])dnl +AC_CACHE_CHECK([$1], [$2], + [$2=no + m4_if([$4], , [ac_outfile=conftest.$ac_objext], [ac_outfile=$4]) + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="$3" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&AS_MESSAGE_LOG_FD + echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + $2=yes + fi + fi + $RM conftest* +]) + +if test x"[$]$2" = xyes; then + m4_if([$5], , :, [$5]) +else + m4_if([$6], , :, [$6]) +fi +])# _LT_COMPILER_OPTION + +# Old name: +AU_ALIAS([AC_LIBTOOL_COMPILER_OPTION], [_LT_COMPILER_OPTION]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_COMPILER_OPTION], []) + + +# _LT_LINKER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, +# [ACTION-SUCCESS], [ACTION-FAILURE]) +# ---------------------------------------------------- +# Check whether the given linker option works +AC_DEFUN([_LT_LINKER_OPTION], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_SED])dnl +AC_CACHE_CHECK([$1], [$2], + [$2=no + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS $3" + echo "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&AS_MESSAGE_LOG_FD + $ECHO "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + $2=yes + fi + else + $2=yes + fi + fi + $RM -r conftest* + LDFLAGS="$save_LDFLAGS" +]) + +if test x"[$]$2" = xyes; then + m4_if([$4], , :, [$4]) +else + m4_if([$5], , :, [$5]) +fi +])# _LT_LINKER_OPTION + +# Old name: +AU_ALIAS([AC_LIBTOOL_LINKER_OPTION], [_LT_LINKER_OPTION]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_LINKER_OPTION], []) + + +# LT_CMD_MAX_LEN +#--------------- +AC_DEFUN([LT_CMD_MAX_LEN], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +# find the maximum length of command line arguments +AC_MSG_CHECKING([the maximum length of command line arguments]) +AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl + i=0 + teststring="ABCD" + + case $build_os in + msdosdjgpp*) + # On DJGPP, this test can blow up pretty badly due to problems in libc + # (any single argument exceeding 2000 bytes causes a buffer overrun + # during glob expansion). Even if it were fixed, the result of this + # check would be larger than it should be. + lt_cv_sys_max_cmd_len=12288; # 12K is about right + ;; + + gnu*) + # Under GNU Hurd, this test is not required because there is + # no limit to the length of command line arguments. + # Libtool will interpret -1 as no limit whatsoever + lt_cv_sys_max_cmd_len=-1; + ;; + + cygwin* | mingw* | cegcc*) + # On Win9x/ME, this test blows up -- it succeeds, but takes + # about 5 minutes as the teststring grows exponentially. + # Worse, since 9x/ME are not pre-emptively multitasking, + # you end up with a "frozen" computer, even though with patience + # the test eventually succeeds (with a max line length of 256k). + # Instead, let's just punt: use the minimum linelength reported by + # all of the supported platforms: 8192 (on NT/2K/XP). + lt_cv_sys_max_cmd_len=8192; + ;; + + amigaos*) + # On AmigaOS with pdksh, this test takes hours, literally. + # So we just punt and use a minimum line length of 8192. + lt_cv_sys_max_cmd_len=8192; + ;; + + netbsd* | freebsd* | openbsd* | darwin* | dragonfly*) + # This has been around since 386BSD, at least. Likely further. + if test -x /sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` + elif test -x /usr/sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax` + else + lt_cv_sys_max_cmd_len=65536 # usable default for all BSDs + fi + # And add a safety zone + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + ;; + + interix*) + # We know the value 262144 and hardcode it with a safety zone (like BSD) + lt_cv_sys_max_cmd_len=196608 + ;; + + osf*) + # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure + # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not + # nice to cause kernel panics so lets avoid the loop below. + # First set a reasonable default. + lt_cv_sys_max_cmd_len=16384 + # + if test -x /sbin/sysconfig; then + case `/sbin/sysconfig -q proc exec_disable_arg_limit` in + *1*) lt_cv_sys_max_cmd_len=-1 ;; + esac + fi + ;; + sco3.2v5*) + lt_cv_sys_max_cmd_len=102400 + ;; + sysv5* | sco5v6* | sysv4.2uw2*) + kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null` + if test -n "$kargmax"; then + lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[[ ]]//'` + else + lt_cv_sys_max_cmd_len=32768 + fi + ;; + *) + lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null` + if test -n "$lt_cv_sys_max_cmd_len"; then + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + else + # Make teststring a little bigger before we do anything with it. + # a 1K string should be a reasonable start. + for i in 1 2 3 4 5 6 7 8 ; do + teststring=$teststring$teststring + done + SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}} + # If test is not a shell built-in, we'll probably end up computing a + # maximum length that is only half of the actual maximum length, but + # we can't tell. + while { test "X"`$SHELL [$]0 --fallback-echo "X$teststring$teststring" 2>/dev/null` \ + = "XX$teststring$teststring"; } >/dev/null 2>&1 && + test $i != 17 # 1/2 MB should be enough + do + i=`expr $i + 1` + teststring=$teststring$teststring + done + # Only check the string length outside the loop. + lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1` + teststring= + # Add a significant safety factor because C++ compilers can tack on + # massive amounts of additional arguments before passing them to the + # linker. It appears as though 1/2 is a usable value. + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2` + fi + ;; + esac +]) +if test -n $lt_cv_sys_max_cmd_len ; then + AC_MSG_RESULT($lt_cv_sys_max_cmd_len) +else + AC_MSG_RESULT(none) +fi +max_cmd_len=$lt_cv_sys_max_cmd_len +_LT_DECL([], [max_cmd_len], [0], + [What is the maximum length of a command?]) +])# LT_CMD_MAX_LEN + +# Old name: +AU_ALIAS([AC_LIBTOOL_SYS_MAX_CMD_LEN], [LT_CMD_MAX_LEN]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN], []) + + +# _LT_HEADER_DLFCN +# ---------------- +m4_defun([_LT_HEADER_DLFCN], +[AC_CHECK_HEADERS([dlfcn.h], [], [], [AC_INCLUDES_DEFAULT])dnl +])# _LT_HEADER_DLFCN + + +# _LT_TRY_DLOPEN_SELF (ACTION-IF-TRUE, ACTION-IF-TRUE-W-USCORE, +# ACTION-IF-FALSE, ACTION-IF-CROSS-COMPILING) +# ---------------------------------------------------------------- +m4_defun([_LT_TRY_DLOPEN_SELF], +[m4_require([_LT_HEADER_DLFCN])dnl +if test "$cross_compiling" = yes; then : + [$4] +else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +[#line __oline__ "configure" +#include "confdefs.h" + +#if HAVE_DLFCN_H +#include +#endif + +#include + +#ifdef RTLD_GLOBAL +# define LT_DLGLOBAL RTLD_GLOBAL +#else +# ifdef DL_GLOBAL +# define LT_DLGLOBAL DL_GLOBAL +# else +# define LT_DLGLOBAL 0 +# endif +#endif + +/* We may have to define LT_DLLAZY_OR_NOW in the command line if we + find out it does not work in some platform. */ +#ifndef LT_DLLAZY_OR_NOW +# ifdef RTLD_LAZY +# define LT_DLLAZY_OR_NOW RTLD_LAZY +# else +# ifdef DL_LAZY +# define LT_DLLAZY_OR_NOW DL_LAZY +# else +# ifdef RTLD_NOW +# define LT_DLLAZY_OR_NOW RTLD_NOW +# else +# ifdef DL_NOW +# define LT_DLLAZY_OR_NOW DL_NOW +# else +# define LT_DLLAZY_OR_NOW 0 +# endif +# endif +# endif +# endif +#endif + +void fnord() { int i=42;} +int main () +{ + void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); + int status = $lt_dlunknown; + + if (self) + { + if (dlsym (self,"fnord")) status = $lt_dlno_uscore; + else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; + /* dlclose (self); */ + } + else + puts (dlerror ()); + + return status; +}] +_LT_EOF + if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext} 2>/dev/null; then + (./conftest; exit; ) >&AS_MESSAGE_LOG_FD 2>/dev/null + lt_status=$? + case x$lt_status in + x$lt_dlno_uscore) $1 ;; + x$lt_dlneed_uscore) $2 ;; + x$lt_dlunknown|x*) $3 ;; + esac + else : + # compilation failed + $3 + fi +fi +rm -fr conftest* +])# _LT_TRY_DLOPEN_SELF + + +# LT_SYS_DLOPEN_SELF +# ------------------ +AC_DEFUN([LT_SYS_DLOPEN_SELF], +[m4_require([_LT_HEADER_DLFCN])dnl +if test "x$enable_dlopen" != xyes; then + enable_dlopen=unknown + enable_dlopen_self=unknown + enable_dlopen_self_static=unknown +else + lt_cv_dlopen=no + lt_cv_dlopen_libs= + + case $host_os in + beos*) + lt_cv_dlopen="load_add_on" + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ;; + + mingw* | pw32* | cegcc*) + lt_cv_dlopen="LoadLibrary" + lt_cv_dlopen_libs= + ;; + + cygwin*) + lt_cv_dlopen="dlopen" + lt_cv_dlopen_libs= + ;; + + darwin*) + # if libdl is installed we need to link against it + AC_CHECK_LIB([dl], [dlopen], + [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],[ + lt_cv_dlopen="dyld" + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ]) + ;; + + *) + AC_CHECK_FUNC([shl_load], + [lt_cv_dlopen="shl_load"], + [AC_CHECK_LIB([dld], [shl_load], + [lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld"], + [AC_CHECK_FUNC([dlopen], + [lt_cv_dlopen="dlopen"], + [AC_CHECK_LIB([dl], [dlopen], + [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"], + [AC_CHECK_LIB([svld], [dlopen], + [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"], + [AC_CHECK_LIB([dld], [dld_link], + [lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld"]) + ]) + ]) + ]) + ]) + ]) + ;; + esac + + if test "x$lt_cv_dlopen" != xno; then + enable_dlopen=yes + else + enable_dlopen=no + fi + + case $lt_cv_dlopen in + dlopen) + save_CPPFLAGS="$CPPFLAGS" + test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H" + + save_LDFLAGS="$LDFLAGS" + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\" + + save_LIBS="$LIBS" + LIBS="$lt_cv_dlopen_libs $LIBS" + + AC_CACHE_CHECK([whether a program can dlopen itself], + lt_cv_dlopen_self, [dnl + _LT_TRY_DLOPEN_SELF( + lt_cv_dlopen_self=yes, lt_cv_dlopen_self=yes, + lt_cv_dlopen_self=no, lt_cv_dlopen_self=cross) + ]) + + if test "x$lt_cv_dlopen_self" = xyes; then + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\" + AC_CACHE_CHECK([whether a statically linked program can dlopen itself], + lt_cv_dlopen_self_static, [dnl + _LT_TRY_DLOPEN_SELF( + lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=yes, + lt_cv_dlopen_self_static=no, lt_cv_dlopen_self_static=cross) + ]) + fi + + CPPFLAGS="$save_CPPFLAGS" + LDFLAGS="$save_LDFLAGS" + LIBS="$save_LIBS" + ;; + esac + + case $lt_cv_dlopen_self in + yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;; + *) enable_dlopen_self=unknown ;; + esac + + case $lt_cv_dlopen_self_static in + yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;; + *) enable_dlopen_self_static=unknown ;; + esac +fi +_LT_DECL([dlopen_support], [enable_dlopen], [0], + [Whether dlopen is supported]) +_LT_DECL([dlopen_self], [enable_dlopen_self], [0], + [Whether dlopen of programs is supported]) +_LT_DECL([dlopen_self_static], [enable_dlopen_self_static], [0], + [Whether dlopen of statically linked programs is supported]) +])# LT_SYS_DLOPEN_SELF + +# Old name: +AU_ALIAS([AC_LIBTOOL_DLOPEN_SELF], [LT_SYS_DLOPEN_SELF]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_DLOPEN_SELF], []) + + +# _LT_COMPILER_C_O([TAGNAME]) +# --------------------------- +# Check to see if options -c and -o are simultaneously supported by compiler. +# This macro does not hard code the compiler like AC_PROG_CC_C_O. +m4_defun([_LT_COMPILER_C_O], +[m4_require([_LT_DECL_SED])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_TAG_COMPILER])dnl +AC_CACHE_CHECK([if $compiler supports -c -o file.$ac_objext], + [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)], + [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&AS_MESSAGE_LOG_FD + echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + _LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes + fi + fi + chmod u+w . 2>&AS_MESSAGE_LOG_FD + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* +]) +_LT_TAGDECL([compiler_c_o], [lt_cv_prog_compiler_c_o], [1], + [Does compiler simultaneously support -c and -o options?]) +])# _LT_COMPILER_C_O + + +# _LT_COMPILER_FILE_LOCKS([TAGNAME]) +# ---------------------------------- +# Check to see if we can do hard links to lock some files if needed +m4_defun([_LT_COMPILER_FILE_LOCKS], +[m4_require([_LT_ENABLE_LOCK])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +_LT_COMPILER_C_O([$1]) + +hard_links="nottested" +if test "$_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)" = no && test "$need_locks" != no; then + # do not overwrite the value of need_locks provided by the user + AC_MSG_CHECKING([if we can lock with hard links]) + hard_links=yes + $RM conftest* + ln conftest.a conftest.b 2>/dev/null && hard_links=no + touch conftest.a + ln conftest.a conftest.b 2>&5 || hard_links=no + ln conftest.a conftest.b 2>/dev/null && hard_links=no + AC_MSG_RESULT([$hard_links]) + if test "$hard_links" = no; then + AC_MSG_WARN([`$CC' does not support `-c -o', so `make -j' may be unsafe]) + need_locks=warn + fi +else + need_locks=no +fi +_LT_DECL([], [need_locks], [1], [Must we lock files when doing compilation?]) +])# _LT_COMPILER_FILE_LOCKS + + +# _LT_CHECK_OBJDIR +# ---------------- +m4_defun([_LT_CHECK_OBJDIR], +[AC_CACHE_CHECK([for objdir], [lt_cv_objdir], +[rm -f .libs 2>/dev/null +mkdir .libs 2>/dev/null +if test -d .libs; then + lt_cv_objdir=.libs +else + # MS-DOS does not allow filenames that begin with a dot. + lt_cv_objdir=_libs +fi +rmdir .libs 2>/dev/null]) +objdir=$lt_cv_objdir +_LT_DECL([], [objdir], [0], + [The name of the directory that contains temporary libtool files])dnl +m4_pattern_allow([LT_OBJDIR])dnl +AC_DEFINE_UNQUOTED(LT_OBJDIR, "$lt_cv_objdir/", + [Define to the sub-directory in which libtool stores uninstalled libraries.]) +])# _LT_CHECK_OBJDIR + + +# _LT_LINKER_HARDCODE_LIBPATH([TAGNAME]) +# -------------------------------------- +# Check hardcoding attributes. +m4_defun([_LT_LINKER_HARDCODE_LIBPATH], +[AC_MSG_CHECKING([how to hardcode library paths into programs]) +_LT_TAGVAR(hardcode_action, $1)= +if test -n "$_LT_TAGVAR(hardcode_libdir_flag_spec, $1)" || + test -n "$_LT_TAGVAR(runpath_var, $1)" || + test "X$_LT_TAGVAR(hardcode_automatic, $1)" = "Xyes" ; then + + # We can hardcode non-existent directories. + if test "$_LT_TAGVAR(hardcode_direct, $1)" != no && + # If the only mechanism to avoid hardcoding is shlibpath_var, we + # have to relink, otherwise we might link with an installed library + # when we should be linking with a yet-to-be-installed one + ## test "$_LT_TAGVAR(hardcode_shlibpath_var, $1)" != no && + test "$_LT_TAGVAR(hardcode_minus_L, $1)" != no; then + # Linking always hardcodes the temporary library directory. + _LT_TAGVAR(hardcode_action, $1)=relink + else + # We can link without hardcoding, and we can hardcode nonexisting dirs. + _LT_TAGVAR(hardcode_action, $1)=immediate + fi +else + # We cannot hardcode anything, or else we can only hardcode existing + # directories. + _LT_TAGVAR(hardcode_action, $1)=unsupported +fi +AC_MSG_RESULT([$_LT_TAGVAR(hardcode_action, $1)]) + +if test "$_LT_TAGVAR(hardcode_action, $1)" = relink || + test "$_LT_TAGVAR(inherit_rpath, $1)" = yes; then + # Fast installation is not supported + enable_fast_install=no +elif test "$shlibpath_overrides_runpath" = yes || + test "$enable_shared" = no; then + # Fast installation is not necessary + enable_fast_install=needless +fi +_LT_TAGDECL([], [hardcode_action], [0], + [How to hardcode a shared library path into an executable]) +])# _LT_LINKER_HARDCODE_LIBPATH + + +# _LT_CMD_STRIPLIB +# ---------------- +m4_defun([_LT_CMD_STRIPLIB], +[m4_require([_LT_DECL_EGREP]) +striplib= +old_striplib= +AC_MSG_CHECKING([whether stripping libraries is possible]) +if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then + test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" + test -z "$striplib" && striplib="$STRIP --strip-unneeded" + AC_MSG_RESULT([yes]) +else +# FIXME - insert some real tests, host_os isn't really good enough + case $host_os in + darwin*) + if test -n "$STRIP" ; then + striplib="$STRIP -x" + old_striplib="$STRIP -S" + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + fi + ;; + *) + AC_MSG_RESULT([no]) + ;; + esac +fi +_LT_DECL([], [old_striplib], [1], [Commands to strip libraries]) +_LT_DECL([], [striplib], [1]) +])# _LT_CMD_STRIPLIB + + +# _LT_SYS_DYNAMIC_LINKER([TAG]) +# ----------------------------- +# PORTME Fill in your ld.so characteristics +m4_defun([_LT_SYS_DYNAMIC_LINKER], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_OBJDUMP])dnl +m4_require([_LT_DECL_SED])dnl +AC_MSG_CHECKING([dynamic linker characteristics]) +m4_if([$1], + [], [ +if test "$GCC" = yes; then + case $host_os in + darwin*) lt_awk_arg="/^libraries:/,/LR/" ;; + *) lt_awk_arg="/^libraries:/" ;; + esac + lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e "s,=/,/,g"` + if $ECHO "$lt_search_path_spec" | $GREP ';' >/dev/null ; then + # if the path contains ";" then we assume it to be the separator + # otherwise default to the standard path separator (i.e. ":") - it is + # assumed that no part of a normal pathname contains ";" but that should + # okay in the real world where ";" in dirpaths is itself problematic. + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED -e 's/;/ /g'` + else + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + # Ok, now we have the path, separated by spaces, we can step through it + # and add multilib dir if necessary. + lt_tmp_lt_search_path_spec= + lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null` + for lt_sys_path in $lt_search_path_spec; do + if test -d "$lt_sys_path/$lt_multi_os_dir"; then + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir" + else + test -d "$lt_sys_path" && \ + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path" + fi + done + lt_search_path_spec=`$ECHO $lt_tmp_lt_search_path_spec | awk ' +BEGIN {RS=" "; FS="/|\n";} { + lt_foo=""; + lt_count=0; + for (lt_i = NF; lt_i > 0; lt_i--) { + if ($lt_i != "" && $lt_i != ".") { + if ($lt_i == "..") { + lt_count++; + } else { + if (lt_count == 0) { + lt_foo="/" $lt_i lt_foo; + } else { + lt_count--; + } + } + } + } + if (lt_foo != "") { lt_freq[[lt_foo]]++; } + if (lt_freq[[lt_foo]] == 1) { print lt_foo; } +}'` + sys_lib_search_path_spec=`$ECHO $lt_search_path_spec` +else + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" +fi]) +library_names_spec= +libname_spec='lib$name' +soname_spec= +shrext_cmds=".so" +postinstall_cmds= +postuninstall_cmds= +finish_cmds= +finish_eval= +shlibpath_var= +shlibpath_overrides_runpath=unknown +version_type=none +dynamic_linker="$host_os ld.so" +sys_lib_dlsearch_path_spec="/lib /usr/lib" +need_lib_prefix=unknown +hardcode_into_libs=no + +# when you set need_version to no, make sure it does not cause -set_version +# flags to be left without arguments +need_version=unknown + +case $host_os in +aix3*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a' + shlibpath_var=LIBPATH + + # AIX 3 has no versioning support, so we append a major version to the name. + soname_spec='${libname}${release}${shared_ext}$major' + ;; + +aix[[4-9]]*) + version_type=linux + need_lib_prefix=no + need_version=no + hardcode_into_libs=yes + if test "$host_cpu" = ia64; then + # AIX 5 supports IA64 + library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + else + # With GCC up to 2.95.x, collect2 would create an import file + # for dependence libraries. The import file would start with + # the line `#! .'. This would cause the generated library to + # depend on `.', always an invalid library. This was fixed in + # development snapshots of GCC prior to 3.0. + case $host_os in + aix4 | aix4.[[01]] | aix4.[[01]].*) + if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' + echo ' yes ' + echo '#endif'; } | ${CC} -E - | $GREP yes > /dev/null; then + : + else + can_build_shared=no + fi + ;; + esac + # AIX (on Power*) has no versioning support, so currently we can not hardcode correct + # soname into executable. Probably we can add versioning support to + # collect2, so additional links can be useful in future. + if test "$aix_use_runtimelinking" = yes; then + # If using run time linking (on AIX 4.2 or later) use lib.so + # instead of lib.a to let people know that these are not + # typical AIX shared libraries. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + else + # We preserve .a as extension for shared libraries through AIX4.2 + # and later when we are not doing run time linking. + library_names_spec='${libname}${release}.a $libname.a' + soname_spec='${libname}${release}${shared_ext}$major' + fi + shlibpath_var=LIBPATH + fi + ;; + +amigaos*) + case $host_cpu in + powerpc) + # Since July 2007 AmigaOS4 officially supports .so libraries. + # When compiling the executable, add -use-dynld -Lsobjs: to the compileline. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + ;; + m68k) + library_names_spec='$libname.ixlibrary $libname.a' + # Create ${libname}_ixlibrary.a entries in /sys/libs. + finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$ECHO "X$lib" | $Xsed -e '\''s%^.*/\([[^/]]*\)\.ixlibrary$%\1%'\''`; test $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' + ;; + esac + ;; + +beos*) + library_names_spec='${libname}${shared_ext}' + dynamic_linker="$host_os ld.so" + shlibpath_var=LIBRARY_PATH + ;; + +bsdi[[45]]*) + version_type=linux + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" + sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" + # the default ld.so.conf also contains /usr/contrib/lib and + # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow + # libtool to hard-code these into programs + ;; + +cygwin* | mingw* | pw32* | cegcc*) + version_type=windows + shrext_cmds=".dll" + need_version=no + need_lib_prefix=no + + case $GCC,$host_os in + yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*) + library_names_spec='$libname.dll.a' + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \${file}`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + + case $host_os in + cygwin*) + # Cygwin DLLs use 'cyg' prefix rather than 'lib' + soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' + sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib" + ;; + mingw* | cegcc*) + # MinGW DLLs use traditional 'lib' prefix + soname_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' + sys_lib_search_path_spec=`$CC -print-search-dirs | $GREP "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"` + if $ECHO "$sys_lib_search_path_spec" | [$GREP ';[c-zC-Z]:/' >/dev/null]; then + # It is most probably a Windows format PATH printed by + # mingw gcc, but we are running on Cygwin. Gcc prints its search + # path with ; separators, and with drive letters. We can handle the + # drive letters (cygwin fileutils understands them), so leave them, + # especially as we might pass files found there to a mingw objdump, + # which wouldn't understand a cygwinified path. Ahh. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + ;; + pw32*) + # pw32 DLLs use 'pw' prefix rather than 'lib' + library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' + ;; + esac + ;; + + *) + library_names_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext} $libname.lib' + ;; + esac + dynamic_linker='Win32 ld.exe' + # FIXME: first we should search . and the directory the executable is in + shlibpath_var=PATH + ;; + +darwin* | rhapsody*) + dynamic_linker="$host_os dyld" + version_type=darwin + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${major}$shared_ext ${libname}$shared_ext' + soname_spec='${libname}${release}${major}$shared_ext' + shlibpath_overrides_runpath=yes + shlibpath_var=DYLD_LIBRARY_PATH + shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' +m4_if([$1], [],[ + sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"]) + sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' + ;; + +dgux*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +freebsd1*) + dynamic_linker=no + ;; + +freebsd* | dragonfly*) + # DragonFly does not have aout. When/if they implement a new + # versioning mechanism, adjust this. + if test -x /usr/bin/objformat; then + objformat=`/usr/bin/objformat` + else + case $host_os in + freebsd[[123]]*) objformat=aout ;; + *) objformat=elf ;; + esac + fi + version_type=freebsd-$objformat + case $version_type in + freebsd-elf*) + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' + need_version=no + need_lib_prefix=no + ;; + freebsd-*) + library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix' + need_version=yes + ;; + esac + shlibpath_var=LD_LIBRARY_PATH + case $host_os in + freebsd2*) + shlibpath_overrides_runpath=yes + ;; + freebsd3.[[01]]* | freebsdelf3.[[01]]*) + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + freebsd3.[[2-9]]* | freebsdelf3.[[2-9]]* | \ + freebsd4.[[0-5]] | freebsdelf4.[[0-5]] | freebsd4.1.1 | freebsdelf4.1.1) + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + *) # from 4.6 on, and DragonFly + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + esac + ;; + +gnu*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + hardcode_into_libs=yes + ;; + +hpux9* | hpux10* | hpux11*) + # Give a soname corresponding to the major version so that dld.sl refuses to + # link against other versions. + version_type=sunos + need_lib_prefix=no + need_version=no + case $host_cpu in + ia64*) + shrext_cmds='.so' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.so" + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + if test "X$HPUX_IA64_MODE" = X32; then + sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" + else + sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" + fi + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + hppa*64*) + shrext_cmds='.sl' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.sl" + shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + *) + shrext_cmds='.sl' + dynamic_linker="$host_os dld.sl" + shlibpath_var=SHLIB_PATH + shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + ;; + esac + # HP-UX runs *really* slowly unless shared libraries are mode 555. + postinstall_cmds='chmod 555 $lib' + ;; + +interix[[3-9]]*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +irix5* | irix6* | nonstopux*) + case $host_os in + nonstopux*) version_type=nonstopux ;; + *) + if test "$lt_cv_prog_gnu_ld" = yes; then + version_type=linux + else + version_type=irix + fi ;; + esac + need_lib_prefix=no + need_version=no + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}' + case $host_os in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in # libtool.m4 will add one of these switches to LD + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") + libsuff= shlibsuff= libmagic=32-bit;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") + libsuff=32 shlibsuff=N32 libmagic=N32;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") + libsuff=64 shlibsuff=64 libmagic=64-bit;; + *) libsuff= shlibsuff= libmagic=never-match;; + esac + ;; + esac + shlibpath_var=LD_LIBRARY${shlibsuff}_PATH + shlibpath_overrides_runpath=no + sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}" + sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}" + hardcode_into_libs=yes + ;; + +# No shared lib support for Linux oldld, aout, or coff. +linux*oldld* | linux*aout* | linux*coff*) + dynamic_linker=no + ;; + +# This must be Linux ELF. +linux* | k*bsd*-gnu | kopensolaris*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + # Some binutils ld are patched to set DT_RUNPATH + save_LDFLAGS=$LDFLAGS + save_libdir=$libdir + eval "libdir=/foo; wl=\"$_LT_TAGVAR(lt_prog_compiler_wl, $1)\"; \ + LDFLAGS=\"\$LDFLAGS $_LT_TAGVAR(hardcode_libdir_flag_spec, $1)\"" + AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], + [AS_IF([ ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null], + [shlibpath_overrides_runpath=yes])]) + LDFLAGS=$save_LDFLAGS + libdir=$save_libdir + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + # Append ld.so.conf contents to the search path + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '` + sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on + # powerpc, because MkLinux only supported shared libraries with the + # GNU dynamic linker. Since this was broken with cross compilers, + # most powerpc-linux boxes support dynamic linking these days and + # people can always --disable-shared, the test was removed, and we + # assume the GNU/Linux dynamic linker is in use. + dynamic_linker='GNU/Linux ld.so' + ;; + +netbsdelf*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='NetBSD ld.elf_so' + ;; + +netbsd*) + version_type=sunos + need_lib_prefix=no + need_version=no + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + dynamic_linker='NetBSD (a.out) ld.so' + else + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + dynamic_linker='NetBSD ld.elf_so' + fi + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + +newsos6) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +*nto* | *qnx*) + version_type=qnx + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='ldqnx.so' + ;; + +openbsd*) + version_type=sunos + sys_lib_dlsearch_path_spec="/usr/lib" + need_lib_prefix=no + # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs. + case $host_os in + openbsd3.3 | openbsd3.3.*) need_version=yes ;; + *) need_version=no ;; + esac + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + shlibpath_var=LD_LIBRARY_PATH + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + case $host_os in + openbsd2.[[89]] | openbsd2.[[89]].*) + shlibpath_overrides_runpath=no + ;; + *) + shlibpath_overrides_runpath=yes + ;; + esac + else + shlibpath_overrides_runpath=yes + fi + ;; + +os2*) + libname_spec='$name' + shrext_cmds=".dll" + need_lib_prefix=no + library_names_spec='$libname${shared_ext} $libname.a' + dynamic_linker='OS/2 ld.exe' + shlibpath_var=LIBPATH + ;; + +osf3* | osf4* | osf5*) + version_type=osf + need_lib_prefix=no + need_version=no + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" + sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec" + ;; + +rdos*) + dynamic_linker=no + ;; + +solaris*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + # ldd complains unless libraries are executable + postinstall_cmds='chmod +x $lib' + ;; + +sunos4*) + version_type=sunos + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + if test "$with_gnu_ld" = yes; then + need_lib_prefix=no + fi + need_version=yes + ;; + +sysv4 | sysv4.3*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + case $host_vendor in + sni) + shlibpath_overrides_runpath=no + need_lib_prefix=no + runpath_var=LD_RUN_PATH + ;; + siemens) + need_lib_prefix=no + ;; + motorola) + need_lib_prefix=no + need_version=no + shlibpath_overrides_runpath=no + sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' + ;; + esac + ;; + +sysv4*MP*) + if test -d /usr/nec ;then + version_type=linux + library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}' + soname_spec='$libname${shared_ext}.$major' + shlibpath_var=LD_LIBRARY_PATH + fi + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + version_type=freebsd-elf + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + if test "$with_gnu_ld" = yes; then + sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' + else + sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' + case $host_os in + sco3.2v5*) + sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" + ;; + esac + fi + sys_lib_dlsearch_path_spec='/usr/lib' + ;; + +tpf*) + # TPF is a cross-target only. Preferred cross-host = GNU/Linux. + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +uts4*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +*) + dynamic_linker=no + ;; +esac +AC_MSG_RESULT([$dynamic_linker]) +test "$dynamic_linker" = no && can_build_shared=no + +variables_saved_for_relink="PATH $shlibpath_var $runpath_var" +if test "$GCC" = yes; then + variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" +fi + +if test "${lt_cv_sys_lib_search_path_spec+set}" = set; then + sys_lib_search_path_spec="$lt_cv_sys_lib_search_path_spec" +fi +if test "${lt_cv_sys_lib_dlsearch_path_spec+set}" = set; then + sys_lib_dlsearch_path_spec="$lt_cv_sys_lib_dlsearch_path_spec" +fi + +_LT_DECL([], [variables_saved_for_relink], [1], + [Variables whose values should be saved in libtool wrapper scripts and + restored at link time]) +_LT_DECL([], [need_lib_prefix], [0], + [Do we need the "lib" prefix for modules?]) +_LT_DECL([], [need_version], [0], [Do we need a version for libraries?]) +_LT_DECL([], [version_type], [0], [Library versioning type]) +_LT_DECL([], [runpath_var], [0], [Shared library runtime path variable]) +_LT_DECL([], [shlibpath_var], [0],[Shared library path variable]) +_LT_DECL([], [shlibpath_overrides_runpath], [0], + [Is shlibpath searched before the hard-coded library search path?]) +_LT_DECL([], [libname_spec], [1], [Format of library name prefix]) +_LT_DECL([], [library_names_spec], [1], + [[List of archive names. First name is the real one, the rest are links. + The last name is the one that the linker finds with -lNAME]]) +_LT_DECL([], [soname_spec], [1], + [[The coded name of the library, if different from the real name]]) +_LT_DECL([], [postinstall_cmds], [2], + [Command to use after installation of a shared archive]) +_LT_DECL([], [postuninstall_cmds], [2], + [Command to use after uninstallation of a shared archive]) +_LT_DECL([], [finish_cmds], [2], + [Commands used to finish a libtool library installation in a directory]) +_LT_DECL([], [finish_eval], [1], + [[As "finish_cmds", except a single script fragment to be evaled but + not shown]]) +_LT_DECL([], [hardcode_into_libs], [0], + [Whether we should hardcode library paths into libraries]) +_LT_DECL([], [sys_lib_search_path_spec], [2], + [Compile-time system search path for libraries]) +_LT_DECL([], [sys_lib_dlsearch_path_spec], [2], + [Run-time system search path for libraries]) +])# _LT_SYS_DYNAMIC_LINKER + + +# _LT_PATH_TOOL_PREFIX(TOOL) +# -------------------------- +# find a file program which can recognize shared library +AC_DEFUN([_LT_PATH_TOOL_PREFIX], +[m4_require([_LT_DECL_EGREP])dnl +AC_MSG_CHECKING([for $1]) +AC_CACHE_VAL(lt_cv_path_MAGIC_CMD, +[case $MAGIC_CMD in +[[\\/*] | ?:[\\/]*]) + lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path. + ;; +*) + lt_save_MAGIC_CMD="$MAGIC_CMD" + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR +dnl $ac_dummy forces splitting on constant user-supplied paths. +dnl POSIX.2 word splitting is done only on the output of word expansions, +dnl not every word. This closes a longstanding sh security hole. + ac_dummy="m4_if([$2], , $PATH, [$2])" + for ac_dir in $ac_dummy; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + if test -f $ac_dir/$1; then + lt_cv_path_MAGIC_CMD="$ac_dir/$1" + if test -n "$file_magic_test_file"; then + case $deplibs_check_method in + "file_magic "*) + file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` + MAGIC_CMD="$lt_cv_path_MAGIC_CMD" + if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | + $EGREP "$file_magic_regex" > /dev/null; then + : + else + cat <<_LT_EOF 1>&2 + +*** Warning: the command libtool uses to detect shared libraries, +*** $file_magic_cmd, produces output that libtool cannot recognize. +*** The result is that libtool may fail to recognize shared libraries +*** as such. This will affect the creation of libtool libraries that +*** depend on shared libraries, but programs linked with such libtool +*** libraries will work regardless of this problem. Nevertheless, you +*** may want to report the problem to your system manager and/or to +*** bug-libtool@gnu.org + +_LT_EOF + fi ;; + esac + fi + break + fi + done + IFS="$lt_save_ifs" + MAGIC_CMD="$lt_save_MAGIC_CMD" + ;; +esac]) +MAGIC_CMD="$lt_cv_path_MAGIC_CMD" +if test -n "$MAGIC_CMD"; then + AC_MSG_RESULT($MAGIC_CMD) +else + AC_MSG_RESULT(no) +fi +_LT_DECL([], [MAGIC_CMD], [0], + [Used to examine libraries when file_magic_cmd begins with "file"])dnl +])# _LT_PATH_TOOL_PREFIX + +# Old name: +AU_ALIAS([AC_PATH_TOOL_PREFIX], [_LT_PATH_TOOL_PREFIX]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_PATH_TOOL_PREFIX], []) + + +# _LT_PATH_MAGIC +# -------------- +# find a file program which can recognize a shared library +m4_defun([_LT_PATH_MAGIC], +[_LT_PATH_TOOL_PREFIX(${ac_tool_prefix}file, /usr/bin$PATH_SEPARATOR$PATH) +if test -z "$lt_cv_path_MAGIC_CMD"; then + if test -n "$ac_tool_prefix"; then + _LT_PATH_TOOL_PREFIX(file, /usr/bin$PATH_SEPARATOR$PATH) + else + MAGIC_CMD=: + fi +fi +])# _LT_PATH_MAGIC + + +# LT_PATH_LD +# ---------- +# find the pathname to the GNU or non-GNU linker +AC_DEFUN([LT_PATH_LD], +[AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_CANONICAL_BUILD])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_DECL_EGREP])dnl + +AC_ARG_WITH([gnu-ld], + [AS_HELP_STRING([--with-gnu-ld], + [assume the C compiler uses GNU ld @<:@default=no@:>@])], + [test "$withval" = no || with_gnu_ld=yes], + [with_gnu_ld=no])dnl + +ac_prog=ld +if test "$GCC" = yes; then + # Check if gcc -print-prog-name=ld gives a path. + AC_MSG_CHECKING([for ld used by $CC]) + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [[\\/]]* | ?:[[\\/]]*) + re_direlt='/[[^/]][[^/]]*/\.\./' + # Canonicalize the pathname of ld + ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'` + while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do + ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"` + done + test -z "$LD" && LD="$ac_prog" + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test "$with_gnu_ld" = yes; then + AC_MSG_CHECKING([for GNU ld]) +else + AC_MSG_CHECKING([for non-GNU ld]) +fi +AC_CACHE_VAL(lt_cv_path_LD, +[if test -z "$LD"; then + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for ac_dir in $PATH; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + lt_cv_path_LD="$ac_dir/$ac_prog" + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some variants of GNU ld only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$lt_cv_path_LD" -v 2>&1 &1 /dev/null 2>&1; then + lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' + lt_cv_file_magic_cmd='func_win32_libid' + else + lt_cv_deplibs_check_method='file_magic file format pei*-i386(.*architecture: i386)?' + lt_cv_file_magic_cmd='$OBJDUMP -f' + fi + ;; + +cegcc) + # use the weaker test based on 'objdump'. See mingw*. + lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?' + lt_cv_file_magic_cmd='$OBJDUMP -f' + ;; + +darwin* | rhapsody*) + lt_cv_deplibs_check_method=pass_all + ;; + +freebsd* | dragonfly*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + case $host_cpu in + i*86 ) + # Not sure whether the presence of OpenBSD here was a mistake. + # Let's accept both of them until this is cleared up. + lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[[3-9]]86 (compact )?demand paged shared library' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*` + ;; + esac + else + lt_cv_deplibs_check_method=pass_all + fi + ;; + +gnu*) + lt_cv_deplibs_check_method=pass_all + ;; + +hpux10.20* | hpux11*) + lt_cv_file_magic_cmd=/usr/bin/file + case $host_cpu in + ia64*) + lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|ELF-[[0-9]][[0-9]]) shared object file - IA64' + lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so + ;; + hppa*64*) + [lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - PA-RISC [0-9].[0-9]'] + lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl + ;; + *) + lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|PA-RISC[[0-9]].[[0-9]]) shared library' + lt_cv_file_magic_test_file=/usr/lib/libc.sl + ;; + esac + ;; + +interix[[3-9]]*) + # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|\.a)$' + ;; + +irix5* | irix6* | nonstopux*) + case $LD in + *-32|*"-32 ") libmagic=32-bit;; + *-n32|*"-n32 ") libmagic=N32;; + *-64|*"-64 ") libmagic=64-bit;; + *) libmagic=never-match;; + esac + lt_cv_deplibs_check_method=pass_all + ;; + +# This must be Linux ELF. +linux* | k*bsd*-gnu | kopensolaris*-gnu) + lt_cv_deplibs_check_method=pass_all + ;; + +netbsd* | netbsdelf*-gnu) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|_pic\.a)$' + fi + ;; + +newos6*) + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (executable|dynamic lib)' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=/usr/lib/libnls.so + ;; + +*nto* | *qnx*) + lt_cv_deplibs_check_method=pass_all + ;; + +openbsd*) + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|\.so|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' + fi + ;; + +osf3* | osf4* | osf5*) + lt_cv_deplibs_check_method=pass_all + ;; + +rdos*) + lt_cv_deplibs_check_method=pass_all + ;; + +solaris*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv4 | sysv4.3*) + case $host_vendor in + motorola) + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib) M[[0-9]][[0-9]]* Version [[0-9]]' + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*` + ;; + ncr) + lt_cv_deplibs_check_method=pass_all + ;; + sequent) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )' + ;; + sni) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method="file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB dynamic lib" + lt_cv_file_magic_test_file=/lib/libc.so + ;; + siemens) + lt_cv_deplibs_check_method=pass_all + ;; + pc) + lt_cv_deplibs_check_method=pass_all + ;; + esac + ;; + +tpf*) + lt_cv_deplibs_check_method=pass_all + ;; +esac +]) +file_magic_cmd=$lt_cv_file_magic_cmd +deplibs_check_method=$lt_cv_deplibs_check_method +test -z "$deplibs_check_method" && deplibs_check_method=unknown + +_LT_DECL([], [deplibs_check_method], [1], + [Method to check whether dependent libraries are shared objects]) +_LT_DECL([], [file_magic_cmd], [1], + [Command to use when deplibs_check_method == "file_magic"]) +])# _LT_CHECK_MAGIC_METHOD + + +# LT_PATH_NM +# ---------- +# find the pathname to a BSD- or MS-compatible name lister +AC_DEFUN([LT_PATH_NM], +[AC_REQUIRE([AC_PROG_CC])dnl +AC_CACHE_CHECK([for BSD- or MS-compatible name lister (nm)], lt_cv_path_NM, +[if test -n "$NM"; then + # Let the user override the test. + lt_cv_path_NM="$NM" +else + lt_nm_to_check="${ac_tool_prefix}nm" + if test -n "$ac_tool_prefix" && test "$build" = "$host"; then + lt_nm_to_check="$lt_nm_to_check nm" + fi + for lt_tmp_nm in $lt_nm_to_check; do + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + tmp_nm="$ac_dir/$lt_tmp_nm" + if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then + # Check to see if the nm accepts a BSD-compat flag. + # Adding the `sed 1q' prevents false positives on HP-UX, which says: + # nm: unknown option "B" ignored + # Tru64's nm complains that /dev/null is an invalid object file + case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in + */dev/null* | *'Invalid file or object type'*) + lt_cv_path_NM="$tmp_nm -B" + break + ;; + *) + case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in + */dev/null*) + lt_cv_path_NM="$tmp_nm -p" + break + ;; + *) + lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but + continue # so that we can try to find one that supports BSD flags + ;; + esac + ;; + esac + fi + done + IFS="$lt_save_ifs" + done + : ${lt_cv_path_NM=no} +fi]) +if test "$lt_cv_path_NM" != "no"; then + NM="$lt_cv_path_NM" +else + # Didn't find any BSD compatible name lister, look for dumpbin. + AC_CHECK_TOOLS(DUMPBIN, ["dumpbin -symbols" "link -dump -symbols"], :) + AC_SUBST([DUMPBIN]) + if test "$DUMPBIN" != ":"; then + NM="$DUMPBIN" + fi +fi +test -z "$NM" && NM=nm +AC_SUBST([NM]) +_LT_DECL([], [NM], [1], [A BSD- or MS-compatible name lister])dnl + +AC_CACHE_CHECK([the name lister ($NM) interface], [lt_cv_nm_interface], + [lt_cv_nm_interface="BSD nm" + echo "int some_variable = 0;" > conftest.$ac_ext + (eval echo "\"\$as_me:__oline__: $ac_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$ac_compile" 2>conftest.err) + cat conftest.err >&AS_MESSAGE_LOG_FD + (eval echo "\"\$as_me:__oline__: $NM \\\"conftest.$ac_objext\\\"\"" >&AS_MESSAGE_LOG_FD) + (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) + cat conftest.err >&AS_MESSAGE_LOG_FD + (eval echo "\"\$as_me:__oline__: output\"" >&AS_MESSAGE_LOG_FD) + cat conftest.out >&AS_MESSAGE_LOG_FD + if $GREP 'External.*some_variable' conftest.out > /dev/null; then + lt_cv_nm_interface="MS dumpbin" + fi + rm -f conftest*]) +])# LT_PATH_NM + +# Old names: +AU_ALIAS([AM_PROG_NM], [LT_PATH_NM]) +AU_ALIAS([AC_PROG_NM], [LT_PATH_NM]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AM_PROG_NM], []) +dnl AC_DEFUN([AC_PROG_NM], []) + + +# LT_LIB_M +# -------- +# check for math library +AC_DEFUN([LT_LIB_M], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +LIBM= +case $host in +*-*-beos* | *-*-cygwin* | *-*-pw32* | *-*-darwin*) + # These system don't have libm, or don't need it + ;; +*-ncr-sysv4.3*) + AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw") + AC_CHECK_LIB(m, cos, LIBM="$LIBM -lm") + ;; +*) + AC_CHECK_LIB(m, cos, LIBM="-lm") + ;; +esac +AC_SUBST([LIBM]) +])# LT_LIB_M + +# Old name: +AU_ALIAS([AC_CHECK_LIBM], [LT_LIB_M]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_CHECK_LIBM], []) + + +# _LT_COMPILER_NO_RTTI([TAGNAME]) +# ------------------------------- +m4_defun([_LT_COMPILER_NO_RTTI], +[m4_require([_LT_TAG_COMPILER])dnl + +_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= + +if test "$GCC" = yes; then + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' + + _LT_COMPILER_OPTION([if $compiler supports -fno-rtti -fno-exceptions], + lt_cv_prog_compiler_rtti_exceptions, + [-fno-rtti -fno-exceptions], [], + [_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)="$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) -fno-rtti -fno-exceptions"]) +fi +_LT_TAGDECL([no_builtin_flag], [lt_prog_compiler_no_builtin_flag], [1], + [Compiler flag to turn off builtin functions]) +])# _LT_COMPILER_NO_RTTI + + +# _LT_CMD_GLOBAL_SYMBOLS +# ---------------------- +m4_defun([_LT_CMD_GLOBAL_SYMBOLS], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([LT_PATH_NM])dnl +AC_REQUIRE([LT_PATH_LD])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_TAG_COMPILER])dnl + +# Check for command to grab the raw symbol name followed by C symbol from nm. +AC_MSG_CHECKING([command to parse $NM output from $compiler object]) +AC_CACHE_VAL([lt_cv_sys_global_symbol_pipe], +[ +# These are sane defaults that work on at least a few old systems. +# [They come from Ultrix. What could be older than Ultrix?!! ;)] + +# Character class describing NM global symbol codes. +symcode='[[BCDEGRST]]' + +# Regexp to match symbols that can be accessed directly from C. +sympat='\([[_A-Za-z]][[_A-Za-z0-9]]*\)' + +# Define system-specific variables. +case $host_os in +aix*) + symcode='[[BCDT]]' + ;; +cygwin* | mingw* | pw32* | cegcc*) + symcode='[[ABCDGISTW]]' + ;; +hpux*) + if test "$host_cpu" = ia64; then + symcode='[[ABCDEGRST]]' + fi + ;; +irix* | nonstopux*) + symcode='[[BCDEGRST]]' + ;; +osf*) + symcode='[[BCDEGQRST]]' + ;; +solaris*) + symcode='[[BDRT]]' + ;; +sco3.2v5*) + symcode='[[DT]]' + ;; +sysv4.2uw2*) + symcode='[[DT]]' + ;; +sysv5* | sco5v6* | unixware* | OpenUNIX*) + symcode='[[ABDT]]' + ;; +sysv4) + symcode='[[DFNSTU]]' + ;; +esac + +# If we're using GNU nm, then use its standard symbol codes. +case `$NM -V 2>&1` in +*GNU* | *'with BFD'*) + symcode='[[ABCDGIRSTW]]' ;; +esac + +# Transform an extracted symbol line into a proper C declaration. +# Some systems (esp. on ia64) link data and code symbols differently, +# so use this general approach. +lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'" + +# Transform an extracted symbol line into symbol name and symbol address +lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/ {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/ {\"\2\", (void *) \&\2},/p'" +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n -e 's/^: \([[^ ]]*\) $/ {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \(lib[[^ ]]*\)$/ {\"\2\", (void *) \&\2},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/ {\"lib\2\", (void *) \&\2},/p'" + +# Handle CRLF in mingw tool chain +opt_cr= +case $build_os in +mingw*) + opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp + ;; +esac + +# Try without a prefix underscore, then with it. +for ac_symprfx in "" "_"; do + + # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol. + symxfrm="\\1 $ac_symprfx\\2 \\2" + + # Write the raw and C identifiers. + if test "$lt_cv_nm_interface" = "MS dumpbin"; then + # Fake it for dumpbin and say T for any non-static function + # and D for any global variable. + # Also find C++ and __fastcall symbols from MSVC++, + # which start with @ or ?. + lt_cv_sys_global_symbol_pipe="$AWK ['"\ +" {last_section=section; section=\$ 3};"\ +" /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\ +" \$ 0!~/External *\|/{next};"\ +" / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\ +" {if(hide[section]) next};"\ +" {f=0}; \$ 0~/\(\).*\|/{f=1}; {printf f ? \"T \" : \"D \"};"\ +" {split(\$ 0, a, /\||\r/); split(a[2], s)};"\ +" s[1]~/^[@?]/{print s[1], s[1]; next};"\ +" s[1]~prfx {split(s[1],t,\"@\"); print t[1], substr(t[1],length(prfx))}"\ +" ' prfx=^$ac_symprfx]" + else + lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[[ ]]\($symcode$symcode*\)[[ ]][[ ]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" + fi + + # Check to see that the pipe works correctly. + pipe_works=no + + rm -f conftest* + cat > conftest.$ac_ext <<_LT_EOF +#ifdef __cplusplus +extern "C" { +#endif +char nm_test_var; +void nm_test_func(void); +void nm_test_func(void){} +#ifdef __cplusplus +} +#endif +int main(){nm_test_var='a';nm_test_func();return(0);} +_LT_EOF + + if AC_TRY_EVAL(ac_compile); then + # Now try to grab the symbols. + nlist=conftest.nm + if AC_TRY_EVAL(NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist) && test -s "$nlist"; then + # Try sorting and uniquifying the output. + if sort "$nlist" | uniq > "$nlist"T; then + mv -f "$nlist"T "$nlist" + else + rm -f "$nlist"T + fi + + # Make sure that we snagged all the symbols we need. + if $GREP ' nm_test_var$' "$nlist" >/dev/null; then + if $GREP ' nm_test_func$' "$nlist" >/dev/null; then + cat <<_LT_EOF > conftest.$ac_ext +#ifdef __cplusplus +extern "C" { +#endif + +_LT_EOF + # Now generate the symbol file. + eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext' + + cat <<_LT_EOF >> conftest.$ac_ext + +/* The mapping between symbol names and symbols. */ +const struct { + const char *name; + void *address; +} +lt__PROGRAM__LTX_preloaded_symbols[[]] = +{ + { "@PROGRAM@", (void *) 0 }, +_LT_EOF + $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/ {\"\2\", (void *) \&\2},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext + cat <<\_LT_EOF >> conftest.$ac_ext + {0, (void *) 0} +}; + +/* This works around a problem in FreeBSD linker */ +#ifdef FREEBSD_WORKAROUND +static const void *lt_preloaded_setup() { + return lt__PROGRAM__LTX_preloaded_symbols; +} +#endif + +#ifdef __cplusplus +} +#endif +_LT_EOF + # Now try linking the two files. + mv conftest.$ac_objext conftstm.$ac_objext + lt_save_LIBS="$LIBS" + lt_save_CFLAGS="$CFLAGS" + LIBS="conftstm.$ac_objext" + CFLAGS="$CFLAGS$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)" + if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext}; then + pipe_works=yes + fi + LIBS="$lt_save_LIBS" + CFLAGS="$lt_save_CFLAGS" + else + echo "cannot find nm_test_func in $nlist" >&AS_MESSAGE_LOG_FD + fi + else + echo "cannot find nm_test_var in $nlist" >&AS_MESSAGE_LOG_FD + fi + else + echo "cannot run $lt_cv_sys_global_symbol_pipe" >&AS_MESSAGE_LOG_FD + fi + else + echo "$progname: failed program was:" >&AS_MESSAGE_LOG_FD + cat conftest.$ac_ext >&5 + fi + rm -rf conftest* conftst* + + # Do not use the global_symbol_pipe unless it works. + if test "$pipe_works" = yes; then + break + else + lt_cv_sys_global_symbol_pipe= + fi +done +]) +if test -z "$lt_cv_sys_global_symbol_pipe"; then + lt_cv_sys_global_symbol_to_cdecl= +fi +if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then + AC_MSG_RESULT(failed) +else + AC_MSG_RESULT(ok) +fi + +_LT_DECL([global_symbol_pipe], [lt_cv_sys_global_symbol_pipe], [1], + [Take the output of nm and produce a listing of raw symbols and C names]) +_LT_DECL([global_symbol_to_cdecl], [lt_cv_sys_global_symbol_to_cdecl], [1], + [Transform the output of nm in a proper C declaration]) +_LT_DECL([global_symbol_to_c_name_address], + [lt_cv_sys_global_symbol_to_c_name_address], [1], + [Transform the output of nm in a C name address pair]) +_LT_DECL([global_symbol_to_c_name_address_lib_prefix], + [lt_cv_sys_global_symbol_to_c_name_address_lib_prefix], [1], + [Transform the output of nm in a C name address pair when lib prefix is needed]) +]) # _LT_CMD_GLOBAL_SYMBOLS + + +# _LT_COMPILER_PIC([TAGNAME]) +# --------------------------- +m4_defun([_LT_COMPILER_PIC], +[m4_require([_LT_TAG_COMPILER])dnl +_LT_TAGVAR(lt_prog_compiler_wl, $1)= +_LT_TAGVAR(lt_prog_compiler_pic, $1)= +_LT_TAGVAR(lt_prog_compiler_static, $1)= + +AC_MSG_CHECKING([for $compiler option to produce PIC]) +m4_if([$1], [CXX], [ + # C++ specific cases for pic, static, wl, etc. + if test "$GXX" = yes; then + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + m68k) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the `-m68020' flag to GCC prevents building anything better, + # like `-m68040'. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' + ;; + esac + ;; + + beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + mingw* | cygwin* | os2* | pw32* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + ;; + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' + ;; + *djgpp*) + # DJGPP does not support shared libraries at all + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + ;; + interix[[3-9]]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic + fi + ;; + hpux*) + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + case $host_cpu in + hppa*64*) + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + ;; + *qnx* | *nto*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + else + case $host_os in + aix[[4-9]]*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + else + _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' + fi + ;; + chorus*) + case $cc_basename in + cxch68*) + # Green Hills C++ Compiler + # _LT_TAGVAR(lt_prog_compiler_static, $1)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a" + ;; + esac + ;; + dgux*) + case $cc_basename in + ec++*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + ;; + ghcx*) + # Green Hills C++ Compiler + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + *) + ;; + esac + ;; + freebsd* | dragonfly*) + # FreeBSD uses GNU C++ + ;; + hpux9* | hpux10* | hpux11*) + case $cc_basename in + CC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive' + if test "$host_cpu" != ia64; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + fi + ;; + aCC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive' + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + ;; + esac + ;; + *) + ;; + esac + ;; + interix*) + # This is c89, which is MS Visual C++ (no shared libs) + # Anyone wants to do a port? + ;; + irix5* | irix6* | nonstopux*) + case $cc_basename in + CC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + # CC pic flag -KPIC is the default. + ;; + *) + ;; + esac + ;; + linux* | k*bsd*-gnu | kopensolaris*-gnu) + case $cc_basename in + KCC*) + # KAI C++ Compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + ecpc* ) + # old Intel C++ for x86_64 which still supported -KPIC. + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + icpc* ) + # Intel C++, used to be incompatible with GCC. + # ICC 10 doesn't accept -KPIC any more. + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + pgCC* | pgcpp*) + # Portland Group C++ compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + cxx*) + # Compaq C++ + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + xlc* | xlC*) + # IBM XL 8.0 on PPC + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + ;; + esac + ;; + esac + ;; + lynxos*) + ;; + m88k*) + ;; + mvs*) + case $cc_basename in + cxx*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-W c,exportall' + ;; + *) + ;; + esac + ;; + netbsd* | netbsdelf*-gnu) + ;; + *qnx* | *nto*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' + ;; + RCC*) + # Rational C++ 2.4.1 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + cxx*) + # Digital/Compaq C++ + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + *) + ;; + esac + ;; + psos*) + ;; + solaris*) + case $cc_basename in + CC*) + # Sun C++ 4.2, 5.x and Centerline C++ + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + ;; + gcx*) + # Green Hills C++ Compiler + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + ;; + *) + ;; + esac + ;; + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + lcc*) + # Lucid + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + *) + ;; + esac + ;; + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + case $cc_basename in + CC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + esac + ;; + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + ;; + *) + ;; + esac + ;; + vxworks*) + ;; + *) + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + esac + fi +], +[ + if test "$GCC" = yes; then + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + m68k) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the `-m68020' flag to GCC prevents building anything better, + # like `-m68040'. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' + ;; + esac + ;; + + beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' + ;; + + hpux*) + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + case $host_cpu in + hppa*64*) + # +Z the default + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + ;; + + interix[[3-9]]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + + msdosdjgpp*) + # Just because we use GCC doesn't mean we suddenly get shared libraries + # on systems that don't support them. + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + enable_shared=no + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic + fi + ;; + + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + else + # PORTME Check for flag to pass linker flags through the system compiler. + case $host_os in + aix*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + else + _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' + fi + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + ;; + + hpux9* | hpux10* | hpux11*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + ;; + esac + # Is there a better lt_prog_compiler_static that works with the bundled CC? + _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive' + ;; + + irix5* | irix6* | nonstopux*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # PIC (with -KPIC) is the default. + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + linux* | k*bsd*-gnu | kopensolaris*-gnu) + case $cc_basename in + # old Intel for x86_64 which still supported -KPIC. + ecc*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + # icc used to be incompatible with GCC. + # ICC 10 doesn't accept -KPIC any more. + icc* | ifort*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + # Lahey Fortran 8.1. + lf95*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='--shared' + _LT_TAGVAR(lt_prog_compiler_static, $1)='--static' + ;; + pgcc* | pgf77* | pgf90* | pgf95*) + # Portland Group compilers (*not* the Pentium gcc compiler, + # which looks to be a dead project) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + ccc*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # All Alpha code is PIC. + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + xl*) + # IBM XL C 8.0/Fortran 10.1 on PPC + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C 5.9 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + ;; + *Sun\ F*) + # Sun Fortran 8.3 passes all unrecognized flags to the linker + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='' + ;; + esac + ;; + esac + ;; + + newsos6) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + + osf3* | osf4* | osf5*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # All OSF/1 code is PIC. + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + rdos*) + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + solaris*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + case $cc_basename in + f77* | f90* | f95*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ';; + *) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,';; + esac + ;; + + sunos4*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + sysv4 | sysv4.2uw2* | sysv4.3*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + sysv4*MP*) + if test -d /usr/nec ;then + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-Kconform_pic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + ;; + + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + unicos*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + + uts4*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + *) + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + esac + fi +]) +case $host_os in + # For platforms which do not support PIC, -DPIC is meaningless: + *djgpp*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)="$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])" + ;; +esac +AC_MSG_RESULT([$_LT_TAGVAR(lt_prog_compiler_pic, $1)]) +_LT_TAGDECL([wl], [lt_prog_compiler_wl], [1], + [How to pass a linker flag through the compiler]) + +# +# Check to make sure the PIC flag actually works. +# +if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then + _LT_COMPILER_OPTION([if $compiler PIC flag $_LT_TAGVAR(lt_prog_compiler_pic, $1) works], + [_LT_TAGVAR(lt_cv_prog_compiler_pic_works, $1)], + [$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])], [], + [case $_LT_TAGVAR(lt_prog_compiler_pic, $1) in + "" | " "*) ;; + *) _LT_TAGVAR(lt_prog_compiler_pic, $1)=" $_LT_TAGVAR(lt_prog_compiler_pic, $1)" ;; + esac], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no]) +fi +_LT_TAGDECL([pic_flag], [lt_prog_compiler_pic], [1], + [Additional compiler flags for building library objects]) + +# +# Check to make sure the static flag actually works. +# +wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) eval lt_tmp_static_flag=\"$_LT_TAGVAR(lt_prog_compiler_static, $1)\" +_LT_LINKER_OPTION([if $compiler static flag $lt_tmp_static_flag works], + _LT_TAGVAR(lt_cv_prog_compiler_static_works, $1), + $lt_tmp_static_flag, + [], + [_LT_TAGVAR(lt_prog_compiler_static, $1)=]) +_LT_TAGDECL([link_static_flag], [lt_prog_compiler_static], [1], + [Compiler flag to prevent dynamic linking]) +])# _LT_COMPILER_PIC + + +# _LT_LINKER_SHLIBS([TAGNAME]) +# ---------------------------- +# See if the linker supports building shared libraries. +m4_defun([_LT_LINKER_SHLIBS], +[AC_REQUIRE([LT_PATH_LD])dnl +AC_REQUIRE([LT_PATH_NM])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl +m4_require([_LT_TAG_COMPILER])dnl +AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) +m4_if([$1], [CXX], [ + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + case $host_os in + aix[[4-9]]*) + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to AIX nm, but means don't demangle with GNU nm + if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then + _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' + else + _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' + fi + ;; + pw32*) + _LT_TAGVAR(export_symbols_cmds, $1)="$ltdll_cmds" + ;; + cygwin* | mingw* | cegcc*) + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;/^.*[[ ]]__nm__/s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols' + ;; + linux* | k*bsd*-gnu) + _LT_TAGVAR(link_all_deplibs, $1)=no + ;; + *) + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + ;; + esac + _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'] +], [ + runpath_var= + _LT_TAGVAR(allow_undefined_flag, $1)= + _LT_TAGVAR(always_export_symbols, $1)=no + _LT_TAGVAR(archive_cmds, $1)= + _LT_TAGVAR(archive_expsym_cmds, $1)= + _LT_TAGVAR(compiler_needs_object, $1)=no + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + _LT_TAGVAR(export_dynamic_flag_spec, $1)= + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + _LT_TAGVAR(hardcode_automatic, $1)=no + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= + _LT_TAGVAR(hardcode_libdir_separator, $1)= + _LT_TAGVAR(hardcode_minus_L, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported + _LT_TAGVAR(inherit_rpath, $1)=no + _LT_TAGVAR(link_all_deplibs, $1)=unknown + _LT_TAGVAR(module_cmds, $1)= + _LT_TAGVAR(module_expsym_cmds, $1)= + _LT_TAGVAR(old_archive_from_new_cmds, $1)= + _LT_TAGVAR(old_archive_from_expsyms_cmds, $1)= + _LT_TAGVAR(thread_safe_flag_spec, $1)= + _LT_TAGVAR(whole_archive_flag_spec, $1)= + # include_expsyms should be a list of space-separated symbols to be *always* + # included in the symbol list + _LT_TAGVAR(include_expsyms, $1)= + # exclude_expsyms can be an extended regexp of symbols to exclude + # it will be wrapped by ` (' and `)$', so one must not match beginning or + # end of line. Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc', + # as well as any symbol that contains `d'. + _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'] + # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out + # platforms (ab)use it in PIC code, but their linkers get confused if + # the symbol is explicitly referenced. Since portable code cannot + # rely on this symbol name, it's probably fine to never include it in + # preloaded symbol tables. + # Exclude shared library initialization/finalization symbols. +dnl Note also adjust exclude_expsyms for C++ above. + extract_expsyms_cmds= + + case $host_os in + cygwin* | mingw* | pw32* | cegcc*) + # FIXME: the MSVC++ port hasn't been tested in a loooong time + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + if test "$GCC" != yes; then + with_gnu_ld=no + fi + ;; + interix*) + # we just hope/assume this is gcc and not c89 (= MSVC++) + with_gnu_ld=yes + ;; + openbsd*) + with_gnu_ld=no + ;; + linux* | k*bsd*-gnu) + _LT_TAGVAR(link_all_deplibs, $1)=no + ;; + esac + + _LT_TAGVAR(ld_shlibs, $1)=yes + if test "$with_gnu_ld" = yes; then + # If archive_cmds runs LD, not CC, wlarc should be empty + wlarc='${wl}' + + # Set some defaults for GNU ld with shared library support. These + # are reset later if shared libraries are not supported. Putting them + # here allows them to be overridden if necessary. + runpath_var=LD_RUN_PATH + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + # ancient GNU ld didn't support --whole-archive et. al. + if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then + _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + else + _LT_TAGVAR(whole_archive_flag_spec, $1)= + fi + supports_anon_versioning=no + case `$LD -v 2>&1` in + *GNU\ gold*) supports_anon_versioning=yes ;; + *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.10.*) ;; # catch versions < 2.11 + *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... + *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ... + *\ 2.11.*) ;; # other 2.11 versions + *) supports_anon_versioning=yes ;; + esac + + # See if GNU ld supports shared libraries. + case $host_os in + aix[[3-9]]*) + # On AIX/PPC, the GNU linker is very broken + if test "$host_cpu" != ia64; then + _LT_TAGVAR(ld_shlibs, $1)=no + cat <<_LT_EOF 1>&2 + +*** Warning: the GNU linker, at least up to release 2.9.1, is reported +*** to be unable to reliably create shared libraries on AIX. +*** Therefore, libtool is disabling shared libraries support. If you +*** really care for shared libraries, you may want to modify your PATH +*** so that a non-GNU linker is found, and then restart. + +_LT_EOF + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='' + ;; + m68k) + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + ;; + + beos*) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, + # as there is no search path for DLLs. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=no + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/'\'' | $SED -e '\''/^[[AITW]][[ ]]/s/.*[[ ]]//'\'' | sort | uniq > $export_symbols' + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file (1st line + # is EXPORTS), use it as is; otherwise, prepend... + _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + interix[[3-9]]*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + + gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu) + tmp_diet=no + if test "$host_os" = linux-dietlibc; then + case $cc_basename in + diet\ *) tmp_diet=yes;; # linux-dietlibc with static linking (!diet-dyn) + esac + fi + if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \ + && test "$tmp_diet" = no + then + tmp_addflag= + tmp_sharedflag='-shared' + case $cc_basename,$host_cpu in + pgcc*) # Portland Group C compiler + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + tmp_addflag=' $pic_flag' + ;; + pgf77* | pgf90* | pgf95*) # Portland Group f77 and f90 compilers + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + tmp_addflag=' $pic_flag -Mnomain' ;; + ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64 + tmp_addflag=' -i_dynamic' ;; + efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64 + tmp_addflag=' -i_dynamic -nofor_main' ;; + ifc* | ifort*) # Intel Fortran compiler + tmp_addflag=' -nofor_main' ;; + lf95*) # Lahey Fortran 8.1 + _LT_TAGVAR(whole_archive_flag_spec, $1)= + tmp_sharedflag='--shared' ;; + xl[[cC]]*) # IBM XL C 8.0 on PPC (deal with xlf below) + tmp_sharedflag='-qmkshrobj' + tmp_addflag= ;; + esac + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) # Sun C 5.9 + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + _LT_TAGVAR(compiler_needs_object, $1)=yes + tmp_sharedflag='-G' ;; + *Sun\ F*) # Sun Fortran 8.3 + tmp_sharedflag='-G' ;; + esac + _LT_TAGVAR(archive_cmds, $1)='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + + if test "x$supports_anon_versioning" = xyes; then + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib' + fi + + case $cc_basename in + xlf*) + # IBM XL Fortran 10.1 on PPC cannot create shared libs itself + _LT_TAGVAR(whole_archive_flag_spec, $1)='--whole-archive$convenience --no-whole-archive' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='-rpath $libdir' + _LT_TAGVAR(archive_cmds, $1)='$LD -shared $libobjs $deplibs $compiler_flags -soname $soname -o $lib' + if test "x$supports_anon_versioning" = xyes; then + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $LD -shared $libobjs $deplibs $compiler_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib' + fi + ;; + esac + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + netbsd* | netbsdelf*-gnu) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' + wlarc= + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + fi + ;; + + solaris*) + if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then + _LT_TAGVAR(ld_shlibs, $1)=no + cat <<_LT_EOF 1>&2 + +*** Warning: The releases 2.8.* of the GNU linker cannot reliably +*** create shared libraries on Solaris systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.9.1 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) + case `$LD -v 2>&1` in + *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.1[[0-5]].*) + _LT_TAGVAR(ld_shlibs, $1)=no + cat <<_LT_EOF 1>&2 + +*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not +*** reliably create shared libraries on SCO systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.16.91.0.3 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + ;; + *) + # For security reasons, it is highly recommended that you always + # use absolute paths for naming shared libraries, and exclude the + # DT_RUNPATH tag from executables and libraries. But doing so + # requires that you compile everything twice, which is a pain. + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + sunos4*) + _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags' + wlarc= + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + + if test "$_LT_TAGVAR(ld_shlibs, $1)" = no; then + runpath_var= + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_TAGVAR(export_dynamic_flag_spec, $1)= + _LT_TAGVAR(whole_archive_flag_spec, $1)= + fi + else + # PORTME fill in a description of your system's linker (not GNU ld) + case $host_os in + aix3*) + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=yes + _LT_TAGVAR(archive_expsym_cmds, $1)='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname' + # Note: this linker hardcodes the directories in LIBPATH if there + # are no directories specified by -L. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then + # Neither direct hardcoding nor static linking is supported with a + # broken collect2. + _LT_TAGVAR(hardcode_direct, $1)=unsupported + fi + ;; + + aix[[4-9]]*) + if test "$host_cpu" = ia64; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag="" + else + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to AIX nm, but means don't demangle with GNU nm + if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then + _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' + else + _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' + fi + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # need to do runtime linking. + case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*) + for ld_flag in $LDFLAGS; do + if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then + aix_use_runtimelinking=yes + break + fi + done + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + _LT_TAGVAR(archive_cmds, $1)='' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='${wl}-f,' + + if test "$GCC" = yes; then + case $host_os in aix4.[[012]]|aix4.[[012]].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`${CC} -print-prog-name=collect2` + if test -f "$collect2name" && + strings "$collect2name" | $GREP resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + _LT_TAGVAR(hardcode_direct, $1)=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)= + fi + ;; + esac + shared_flag='-shared' + if test "$aix_use_runtimelinking" = yes; then + shared_flag="$shared_flag "'${wl}-G' + fi + _LT_TAGVAR(link_all_deplibs, $1)=no + else + # not using gcc + if test "$host_cpu" = ia64; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test "$aix_use_runtimelinking" = yes; then + shared_flag='${wl}-G' + else + shared_flag='${wl}-bM:SRE' + fi + fi + fi + + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall' + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to export. + _LT_TAGVAR(always_export_symbols, $1)=yes + if test "$aix_use_runtimelinking" = yes; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(allow_undefined_flag, $1)='-berok' + # Determine the default libpath from the value encoded in an + # empty executable. + _LT_SYS_MODULE_PATH_AIX + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag" + else + if test "$host_cpu" = ia64; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib' + _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs" + _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an + # empty executable. + _LT_SYS_MODULE_PATH_AIX + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok' + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok' + # Exported symbols can be pulled into shared objects from archives + _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience' + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + # This is similar to how AIX traditionally builds its shared libraries. + _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' + fi + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='' + ;; + m68k) + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + ;; + + bsdi[[45]]*) + _LT_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=".dll" + # FIXME: Setting linknames here is a bad hack. + _LT_TAGVAR(archive_cmds, $1)='$CC -o $lib $libobjs $compiler_flags `$ECHO "X$deplibs" | $Xsed -e '\''s/ -lc$//'\''` -link -dll~linknames=' + # The linker will automatically build a .lib file if we build a DLL. + _LT_TAGVAR(old_archive_from_new_cmds, $1)='true' + # FIXME: Should let the user specify the lib program. + _LT_TAGVAR(old_archive_cmds, $1)='lib -OUT:$oldlib$oldobjs$old_deplibs' + _LT_TAGVAR(fix_srcfile_path, $1)='`cygpath -w "$srcfile"`' + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + ;; + + darwin* | rhapsody*) + _LT_DARWIN_LINKER_FEATURES($1) + ;; + + dgux*) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + freebsd1*) + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor + # support. Future versions do this automatically, but an explicit c++rt0.o + # does not break anything, and helps significantly (at the cost of a little + # extra space). + freebsd2.2*) + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + # Unfortunately, older versions of FreeBSD 2 do not have this feature. + freebsd2*) + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + # FreeBSD 3 and greater uses gcc -shared to do shared libraries. + freebsd* | dragonfly*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + hpux9*) + if test "$GCC" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + else + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(hardcode_direct, $1)=yes + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + ;; + + hpux10*) + if test "$GCC" = yes -a "$with_gnu_ld" = no; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' + fi + if test "$with_gnu_ld" = no; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='+b $libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + fi + ;; + + hpux11*) + if test "$GCC" = yes -a "$with_gnu_ld" = no; then + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + else + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + fi + if test "$with_gnu_ld" = no; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + case $host_cpu in + hppa*64*|ia64*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + *) + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + fi + ;; + + irix5* | irix6* | nonstopux*) + if test "$GCC" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + # Try to use the -exported_symbol ld option, if it does not + # work, assume that -exports_file does not work either and + # implicitly export all symbols. + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS -shared ${wl}-exported_symbol ${wl}foo ${wl}-update_registry ${wl}/dev/null" + AC_LINK_IFELSE(int foo(void) {}, + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations ${wl}-exports_file ${wl}$export_symbols -o $lib' + ) + LDFLAGS="$save_LDFLAGS" + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -exports_file $export_symbols -o $lib' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)='no' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(inherit_rpath, $1)=yes + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + + netbsd* | netbsdelf*-gnu) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out + else + _LT_TAGVAR(archive_cmds, $1)='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + newsos6) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *nto* | *qnx*) + ;; + + openbsd*) + if test -f /usr/libexec/ld.so; then + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + else + case $host_os in + openbsd[[01]].* | openbsd2.[[0-7]] | openbsd2.[[0-7]].*) + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + ;; + esac + fi + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + os2*) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$ECHO DATA >> $output_objdir/$libname.def~$ECHO " SINGLE NONSHARED" >> $output_objdir/$libname.def~$ECHO EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def' + _LT_TAGVAR(old_archive_from_new_cmds, $1)='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def' + ;; + + osf3*) + if test "$GCC" = yes; then + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + else + _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)='no' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + ;; + + osf4* | osf5*) # as osf3* with the addition of -msym flag + if test "$GCC" = yes; then + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + else + _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~ + $CC -shared${allow_undefined_flag} ${wl}-input ${wl}$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~$RM $lib.exp' + + # Both c and cxx compiler support -rpath directly + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)='no' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + ;; + + solaris*) + _LT_TAGVAR(no_undefined_flag, $1)=' -z defs' + if test "$GCC" = yes; then + wlarc='${wl}' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-z ${wl}text ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -shared ${wl}-z ${wl}text ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + else + case `$CC -V 2>&1` in + *"Compilers 5.0"*) + wlarc='' + _LT_TAGVAR(archive_cmds, $1)='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp' + ;; + *) + wlarc='${wl}' + _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + ;; + esac + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + # The compiler driver will combine and reorder linker options, + # but understands `-z linker_flag'. GCC discards it without `$wl', + # but is careful enough not to reorder. + # Supported since Solaris 2.6 (maybe 2.5.1?) + if test "$GCC" = yes; then + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract' + else + _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' + fi + ;; + esac + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + + sunos4*) + if test "x$host_vendor" = xsequent; then + # Use $CC to link under sequent, because it throws in some extra .o + # files that make .init and .fini sections work. + _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags' + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + sysv4) + case $host_vendor in + sni) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=yes # is this really true??? + ;; + siemens) + ## LD is ld it makes a PLAMLIB + ## CC just makes a GrossModule. + _LT_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(reload_cmds, $1)='$CC -r -o $output$reload_objs' + _LT_TAGVAR(hardcode_direct, $1)=no + ;; + motorola) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=no #Motorola manual says yes, but my tests say they lie + ;; + esac + runpath_var='LD_RUN_PATH' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + sysv4.3*) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(export_dynamic_flag_spec, $1)='-Bexport' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var=LD_RUN_PATH + hardcode_runpath_var=yes + _LT_TAGVAR(ld_shlibs, $1)=yes + fi + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*) + _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var='LD_RUN_PATH' + + if test "$GCC" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We can NOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' + _LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport' + runpath_var='LD_RUN_PATH' + + if test "$GCC" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + uts4*) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *) + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + + if test x$host_vendor = xsni; then + case $host in + sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Blargedynsym' + ;; + esac + fi + fi +]) +AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)]) +test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no + +_LT_TAGVAR(with_gnu_ld, $1)=$with_gnu_ld + +_LT_DECL([], [libext], [0], [Old archive suffix (normally "a")])dnl +_LT_DECL([], [shrext_cmds], [1], [Shared library suffix (normally ".so")])dnl +_LT_DECL([], [extract_expsyms_cmds], [2], + [The commands to extract the exported symbol list from a shared archive]) + +# +# Do we need to explicitly link libc? +# +case "x$_LT_TAGVAR(archive_cmds_need_lc, $1)" in +x|xyes) + # Assume -lc should be added + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + + if test "$enable_shared" = yes && test "$GCC" = yes; then + case $_LT_TAGVAR(archive_cmds, $1) in + *'~'*) + # FIXME: we may have to deal with multi-command sequences. + ;; + '$CC '*) + # Test whether the compiler implicitly links with -lc since on some + # systems, -lgcc has to come before -lc. If gcc already passes -lc + # to ld, don't add -lc before -lgcc. + AC_MSG_CHECKING([whether -lc should be explicitly linked in]) + $RM conftest* + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + if AC_TRY_EVAL(ac_compile) 2>conftest.err; then + soname=conftest + lib=conftest + libobjs=conftest.$ac_objext + deplibs= + wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) + pic_flag=$_LT_TAGVAR(lt_prog_compiler_pic, $1) + compiler_flags=-v + linker_flags=-v + verstring= + output_objdir=. + libname=conftest + lt_save_allow_undefined_flag=$_LT_TAGVAR(allow_undefined_flag, $1) + _LT_TAGVAR(allow_undefined_flag, $1)= + if AC_TRY_EVAL(_LT_TAGVAR(archive_cmds, $1) 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) + then + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + else + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + fi + _LT_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag + else + cat conftest.err 1>&5 + fi + $RM conftest* + AC_MSG_RESULT([$_LT_TAGVAR(archive_cmds_need_lc, $1)]) + ;; + esac + fi + ;; +esac + +_LT_TAGDECL([build_libtool_need_lc], [archive_cmds_need_lc], [0], + [Whether or not to add -lc for building shared libraries]) +_LT_TAGDECL([allow_libtool_libs_with_static_runtimes], + [enable_shared_with_static_runtimes], [0], + [Whether or not to disallow shared libs when runtime libs are static]) +_LT_TAGDECL([], [export_dynamic_flag_spec], [1], + [Compiler flag to allow reflexive dlopens]) +_LT_TAGDECL([], [whole_archive_flag_spec], [1], + [Compiler flag to generate shared objects directly from archives]) +_LT_TAGDECL([], [compiler_needs_object], [1], + [Whether the compiler copes with passing no objects directly]) +_LT_TAGDECL([], [old_archive_from_new_cmds], [2], + [Create an old-style archive from a shared archive]) +_LT_TAGDECL([], [old_archive_from_expsyms_cmds], [2], + [Create a temporary old-style archive to link instead of a shared archive]) +_LT_TAGDECL([], [archive_cmds], [2], [Commands used to build a shared archive]) +_LT_TAGDECL([], [archive_expsym_cmds], [2]) +_LT_TAGDECL([], [module_cmds], [2], + [Commands used to build a loadable module if different from building + a shared archive.]) +_LT_TAGDECL([], [module_expsym_cmds], [2]) +_LT_TAGDECL([], [with_gnu_ld], [1], + [Whether we are building with GNU ld or not]) +_LT_TAGDECL([], [allow_undefined_flag], [1], + [Flag that allows shared libraries with undefined symbols to be built]) +_LT_TAGDECL([], [no_undefined_flag], [1], + [Flag that enforces no undefined symbols]) +_LT_TAGDECL([], [hardcode_libdir_flag_spec], [1], + [Flag to hardcode $libdir into a binary during linking. + This must work even if $libdir does not exist]) +_LT_TAGDECL([], [hardcode_libdir_flag_spec_ld], [1], + [[If ld is used when linking, flag to hardcode $libdir into a binary + during linking. This must work even if $libdir does not exist]]) +_LT_TAGDECL([], [hardcode_libdir_separator], [1], + [Whether we need a single "-rpath" flag with a separated argument]) +_LT_TAGDECL([], [hardcode_direct], [0], + [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes + DIR into the resulting binary]) +_LT_TAGDECL([], [hardcode_direct_absolute], [0], + [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes + DIR into the resulting binary and the resulting library dependency is + "absolute", i.e impossible to change by setting ${shlibpath_var} if the + library is relocated]) +_LT_TAGDECL([], [hardcode_minus_L], [0], + [Set to "yes" if using the -LDIR flag during linking hardcodes DIR + into the resulting binary]) +_LT_TAGDECL([], [hardcode_shlibpath_var], [0], + [Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR + into the resulting binary]) +_LT_TAGDECL([], [hardcode_automatic], [0], + [Set to "yes" if building a shared library automatically hardcodes DIR + into the library and all subsequent libraries and executables linked + against it]) +_LT_TAGDECL([], [inherit_rpath], [0], + [Set to yes if linker adds runtime paths of dependent libraries + to runtime path list]) +_LT_TAGDECL([], [link_all_deplibs], [0], + [Whether libtool must link a program against all its dependency libraries]) +_LT_TAGDECL([], [fix_srcfile_path], [1], + [Fix the shell variable $srcfile for the compiler]) +_LT_TAGDECL([], [always_export_symbols], [0], + [Set to "yes" if exported symbols are required]) +_LT_TAGDECL([], [export_symbols_cmds], [2], + [The commands to list exported symbols]) +_LT_TAGDECL([], [exclude_expsyms], [1], + [Symbols that should not be listed in the preloaded symbols]) +_LT_TAGDECL([], [include_expsyms], [1], + [Symbols that must always be exported]) +_LT_TAGDECL([], [prelink_cmds], [2], + [Commands necessary for linking programs (against libraries) with templates]) +_LT_TAGDECL([], [file_list_spec], [1], + [Specify filename containing input files]) +dnl FIXME: Not yet implemented +dnl _LT_TAGDECL([], [thread_safe_flag_spec], [1], +dnl [Compiler flag to generate thread safe objects]) +])# _LT_LINKER_SHLIBS + + +# _LT_LANG_C_CONFIG([TAG]) +# ------------------------ +# Ensure that the configuration variables for a C compiler are suitably +# defined. These variables are subsequently used by _LT_CONFIG to write +# the compiler configuration to `libtool'. +m4_defun([_LT_LANG_C_CONFIG], +[m4_require([_LT_DECL_EGREP])dnl +lt_save_CC="$CC" +AC_LANG_PUSH(C) + +# Source file extension for C test sources. +ac_ext=c + +# Object file extension for compiled C test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="int some_variable = 0;" + +# Code to be used in simple link tests +lt_simple_link_test_code='int main(){return(0);}' + +_LT_TAG_COMPILER +# Save the default compiler, since it gets overwritten when the other +# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP. +compiler_DEFAULT=$CC + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +## CAVEAT EMPTOR: +## There is no encapsulation within the following macros, do not change +## the running order or otherwise move them around unless you know exactly +## what you are doing... +if test -n "$compiler"; then + _LT_COMPILER_NO_RTTI($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + LT_SYS_DLOPEN_SELF + _LT_CMD_STRIPLIB + + # Report which library types will actually be built + AC_MSG_CHECKING([if libtool supports shared libraries]) + AC_MSG_RESULT([$can_build_shared]) + + AC_MSG_CHECKING([whether to build shared libraries]) + test "$can_build_shared" = "no" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test "$enable_shared" = yes && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + + aix[[4-9]]*) + if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then + test "$enable_shared" = yes && enable_static=no + fi + ;; + esac + AC_MSG_RESULT([$enable_shared]) + + AC_MSG_CHECKING([whether to build static libraries]) + # Make sure either enable_shared or enable_static is yes. + test "$enable_shared" = yes || enable_static=yes + AC_MSG_RESULT([$enable_static]) + + _LT_CONFIG($1) +fi +AC_LANG_POP +CC="$lt_save_CC" +])# _LT_LANG_C_CONFIG + + +# _LT_PROG_CXX +# ------------ +# Since AC_PROG_CXX is broken, in that it returns g++ if there is no c++ +# compiler, we have our own version here. +m4_defun([_LT_PROG_CXX], +[ +pushdef([AC_MSG_ERROR], [_lt_caught_CXX_error=yes]) +AC_PROG_CXX +if test -n "$CXX" && ( test "X$CXX" != "Xno" && + ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) || + (test "X$CXX" != "Xg++"))) ; then + AC_PROG_CXXCPP +else + _lt_caught_CXX_error=yes +fi +popdef([AC_MSG_ERROR]) +])# _LT_PROG_CXX + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([_LT_PROG_CXX], []) + + +# _LT_LANG_CXX_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for a C++ compiler are suitably +# defined. These variables are subsequently used by _LT_CONFIG to write +# the compiler configuration to `libtool'. +m4_defun([_LT_LANG_CXX_CONFIG], +[AC_REQUIRE([_LT_PROG_CXX])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_EGREP])dnl + +AC_LANG_PUSH(C++) +_LT_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_TAGVAR(allow_undefined_flag, $1)= +_LT_TAGVAR(always_export_symbols, $1)=no +_LT_TAGVAR(archive_expsym_cmds, $1)= +_LT_TAGVAR(compiler_needs_object, $1)=no +_LT_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_TAGVAR(hardcode_direct, $1)=no +_LT_TAGVAR(hardcode_direct_absolute, $1)=no +_LT_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= +_LT_TAGVAR(hardcode_libdir_separator, $1)= +_LT_TAGVAR(hardcode_minus_L, $1)=no +_LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported +_LT_TAGVAR(hardcode_automatic, $1)=no +_LT_TAGVAR(inherit_rpath, $1)=no +_LT_TAGVAR(module_cmds, $1)= +_LT_TAGVAR(module_expsym_cmds, $1)= +_LT_TAGVAR(link_all_deplibs, $1)=unknown +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(no_undefined_flag, $1)= +_LT_TAGVAR(whole_archive_flag_spec, $1)= +_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Source file extension for C++ test sources. +ac_ext=cpp + +# Object file extension for compiled C++ test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# No sense in running all these tests if we already determined that +# the CXX compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test "$_lt_caught_CXX_error" != yes; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="int some_variable = 0;" + + # Code to be used in simple link tests + lt_simple_link_test_code='int main(int, char *[[]]) { return(0); }' + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + _LT_TAG_COMPILER + + # save warnings/boilerplate of simple test code + _LT_COMPILER_BOILERPLATE + _LT_LINKER_BOILERPLATE + + # Allow CC to be a program name with arguments. + lt_save_CC=$CC + lt_save_LD=$LD + lt_save_GCC=$GCC + GCC=$GXX + lt_save_with_gnu_ld=$with_gnu_ld + lt_save_path_LD=$lt_cv_path_LD + if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then + lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx + else + $as_unset lt_cv_prog_gnu_ld + fi + if test -n "${lt_cv_path_LDCXX+set}"; then + lt_cv_path_LD=$lt_cv_path_LDCXX + else + $as_unset lt_cv_path_LD + fi + test -z "${LDCXX+set}" || LD=$LDCXX + CC=${CXX-"c++"} + compiler=$CC + _LT_TAGVAR(compiler, $1)=$CC + _LT_CC_BASENAME([$compiler]) + + if test -n "$compiler"; then + # We don't want -fno-exception when compiling C++ code, so set the + # no_builtin_flag separately + if test "$GXX" = yes; then + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' + else + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= + fi + + if test "$GXX" = yes; then + # Set up default GNU C++ configuration + + LT_PATH_LD + + # Check if GNU C++ uses GNU ld as the underlying linker, since the + # archiving commands below assume that GNU ld is being used. + if test "$with_gnu_ld" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + + # If archive_cmds runs LD, not CC, wlarc should be empty + # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to + # investigate it a little bit more. (MM) + wlarc='${wl}' + + # ancient GNU ld didn't support --whole-archive et. al. + if eval "`$CC -print-prog-name=ld` --help 2>&1" | + $GREP 'no-whole-archive' > /dev/null; then + _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + else + _LT_TAGVAR(whole_archive_flag_spec, $1)= + fi + else + with_gnu_ld=no + wlarc= + + # A generic and very simple default shared library creation + # command for GNU C++ for the case where it uses the native + # linker, instead of GNU ld. If possible, this setting should + # overridden to take advantage of the native linker features on + # the platform it is being used on. + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + fi + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"' + + else + GXX=no + with_gnu_ld=no + wlarc= + fi + + # PORTME: fill in a description of your system's C++ link characteristics + AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) + _LT_TAGVAR(ld_shlibs, $1)=yes + case $host_os in + aix3*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + aix[[4-9]]*) + if test "$host_cpu" = ia64; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag="" + else + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # need to do runtime linking. + case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*) + for ld_flag in $LDFLAGS; do + case $ld_flag in + *-brtl*) + aix_use_runtimelinking=yes + break + ;; + esac + done + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + _LT_TAGVAR(archive_cmds, $1)='' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='${wl}-f,' + + if test "$GXX" = yes; then + case $host_os in aix4.[[012]]|aix4.[[012]].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`${CC} -print-prog-name=collect2` + if test -f "$collect2name" && + strings "$collect2name" | $GREP resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + _LT_TAGVAR(hardcode_direct, $1)=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)= + fi + esac + shared_flag='-shared' + if test "$aix_use_runtimelinking" = yes; then + shared_flag="$shared_flag "'${wl}-G' + fi + else + # not using gcc + if test "$host_cpu" = ia64; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test "$aix_use_runtimelinking" = yes; then + shared_flag='${wl}-G' + else + shared_flag='${wl}-bM:SRE' + fi + fi + fi + + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall' + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to + # export. + _LT_TAGVAR(always_export_symbols, $1)=yes + if test "$aix_use_runtimelinking" = yes; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(allow_undefined_flag, $1)='-berok' + # Determine the default libpath from the value encoded in an empty + # executable. + _LT_SYS_MODULE_PATH_AIX + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag" + else + if test "$host_cpu" = ia64; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib' + _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs" + _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an + # empty executable. + _LT_SYS_MODULE_PATH_AIX + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok' + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok' + # Exported symbols can be pulled into shared objects from archives + _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience' + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + # This is similar to how AIX traditionally builds its shared + # libraries. + _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' + fi + fi + ;; + + beos*) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + chorus*) + case $cc_basename in + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, + # as there is no search path for DLLs. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=no + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file (1st line + # is EXPORTS), use it as is; otherwise, prepend... + _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + darwin* | rhapsody*) + _LT_DARWIN_LINKER_FEATURES($1) + ;; + + dgux*) + case $cc_basename in + ec++*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + ghcx*) + # Green Hills C++ Compiler + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + freebsd[[12]]*) + # C++ shared libraries reported to be fairly broken before + # switch to ELF + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + freebsd-elf*) + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + ;; + + freebsd* | dragonfly*) + # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF + # conventions + _LT_TAGVAR(ld_shlibs, $1)=yes + ;; + + gnu*) + ;; + + hpux9*) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, + # but as the default + # location of the library. + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + aCC*) + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -b ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' + ;; + *) + if test "$GXX" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -nostdlib -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + else + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + hpux10*|hpux11*) + if test $with_gnu_ld = no; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + case $host_cpu in + hppa*64*|ia64*) + ;; + *) + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + ;; + esac + fi + case $host_cpu in + hppa*64*|ia64*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + *) + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, + # but as the default + # location of the library. + ;; + esac + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + aCC*) + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' + ;; + *) + if test "$GXX" = yes; then + if test $with_gnu_ld = no; then + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + fi + else + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + interix[[3-9]]*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + irix5* | irix6*) + case $cc_basename in + CC*) + # SGI C++ + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + + # Archives containing C++ object files must be created using + # "CC -ar", where "CC" is the IRIX C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -ar -WR,-u -o $oldlib $oldobjs' + ;; + *) + if test "$GXX" = yes; then + if test "$with_gnu_ld" = no; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` -o $lib' + fi + fi + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + esac + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(inherit_rpath, $1)=yes + ;; + + linux* | k*bsd*-gnu | kopensolaris*-gnu) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib ${wl}-retain-symbols-file,$export_symbols; mv \$templib $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | $GREP "ld"`; rm -f libconftest$shared_ext; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + + # Archives containing C++ object files must be created using + # "CC -Bstatic", where "CC" is the KAI C++ compiler. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' + ;; + icpc* | ecpc* ) + # Intel C++ + with_gnu_ld=yes + # version 8.0 and above of icpc choke on multiply defined symbols + # if we add $predep_objects and $postdep_objects, however 7.1 and + # earlier do not add the objects themselves. + case `$CC -V 2>&1` in + *"Version 7."*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + ;; + *) # Version 8.0 or newer + tmp_idyn= + case $host_cpu in + ia64*) tmp_idyn=' -i_dynamic';; + esac + _LT_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + ;; + esac + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive' + ;; + pgCC* | pgcpp*) + # Portland Group C++ compiler + case `$CC -V` in + *pgCC\ [[1-5]]* | *pgcpp\ [[1-5]]*) + _LT_TAGVAR(prelink_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~ + compile_command="$compile_command `find $tpldir -name \*.o | $NL2SP`"' + _LT_TAGVAR(old_archive_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~ + $AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | $NL2SP`~ + $RANLIB $oldlib' + _LT_TAGVAR(archive_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ + $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ + $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib' + ;; + *) # Version 6 will use weak symbols + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib' + ;; + esac + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + ;; + cxx*) + # Compaq C++ + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib ${wl}-retain-symbols-file $wl$export_symbols' + + runpath_var=LD_RUN_PATH + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld"`; templist=`$ECHO "X$templist" | $Xsed -e "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' + ;; + xl*) + # IBM XL 8.0 on PPC, with GNU ld + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + _LT_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + if test "x$supports_anon_versioning" = xyes; then + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib' + fi + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs' + _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file ${wl}$export_symbols' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + _LT_TAGVAR(compiler_needs_object, $1)=yes + + # Not sure whether something based on + # $CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 + # would be better. + output_verbose_link_cmd='echo' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs' + ;; + esac + ;; + esac + ;; + + lynxos*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + m88k*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + mvs*) + case $cc_basename in + cxx*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags' + wlarc= + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + fi + # Workaround some broken pre-1.5 toolchains + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"' + ;; + + *nto* | *qnx*) + _LT_TAGVAR(ld_shlibs, $1)=yes + ;; + + openbsd2*) + # C++ shared libraries are fairly broken + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + openbsd*) + if test -f /usr/libexec/ld.so; then + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file,$export_symbols -o $lib' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + fi + output_verbose_link_cmd=echo + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo "$lib" | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Archives containing C++ object files must be created using + # the KAI C++ compiler. + case $host in + osf3*) _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' ;; + *) _LT_TAGVAR(old_archive_cmds, $1)='$CC -o $oldlib $oldobjs' ;; + esac + ;; + RCC*) + # Rational C++ 2.4.1 + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + cxx*) + case $host in + osf3*) + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $soname `test -n "$verstring" && $ECHO "X${wl}-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + ;; + *) + _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~ + echo "-hidden">> $lib.exp~ + $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname ${wl}-input ${wl}$lib.exp `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~ + $RM $lib.exp' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + ;; + esac + + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld" | $GREP -v "ld:"`; templist=`$ECHO "X$templist" | $Xsed -e "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' + ;; + *) + if test "$GXX" = yes && test "$with_gnu_ld" = no; then + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + case $host in + osf3*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + ;; + esac + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"' + + else + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + psos*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + lcc*) + # Lucid + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + solaris*) + case $cc_basename in + CC*) + # Sun C++ 4.2, 5.x and Centerline C++ + _LT_TAGVAR(archive_cmds_need_lc,$1)=yes + _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs' + _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G${allow_undefined_flag} ${wl}-M ${wl}$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + # The compiler driver will combine and reorder linker options, + # but understands `-z linker_flag'. + # Supported since Solaris 2.6 (maybe 2.5.1?) + _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' + ;; + esac + _LT_TAGVAR(link_all_deplibs, $1)=yes + + output_verbose_link_cmd='echo' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs' + ;; + gcx*) + # Green Hills C++ Compiler + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' + + # The C++ compiler must be used to create the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC $LDFLAGS -archive -o $oldlib $oldobjs' + ;; + *) + # GNU C++ compiler with Solaris linker + if test "$GXX" = yes && test "$with_gnu_ld" = no; then + _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-z ${wl}defs' + if $CC --version | $GREP -v '^2\.7' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -shared -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"' + else + # g++ 2.7 appears to require `-G' NOT `-shared' on this + # platform. + _LT_TAGVAR(archive_cmds, $1)='$CC -G -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"' + fi + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $wl$libdir' + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract' + ;; + esac + fi + ;; + esac + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*) + _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We can NOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' + _LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport' + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + vxworks*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + + AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)]) + test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no + + _LT_TAGVAR(GCC, $1)="$GXX" + _LT_TAGVAR(LD, $1)="$LD" + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + _LT_SYS_HIDDEN_LIBDEPS($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) + fi # test -n "$compiler" + + CC=$lt_save_CC + LDCXX=$LD + LD=$lt_save_LD + GCC=$lt_save_GCC + with_gnu_ld=$lt_save_with_gnu_ld + lt_cv_path_LDCXX=$lt_cv_path_LD + lt_cv_path_LD=$lt_save_path_LD + lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld + lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld +fi # test "$_lt_caught_CXX_error" != yes + +AC_LANG_POP +])# _LT_LANG_CXX_CONFIG + + +# _LT_SYS_HIDDEN_LIBDEPS([TAGNAME]) +# --------------------------------- +# Figure out "hidden" library dependencies from verbose +# compiler output when linking a shared library. +# Parse the compiler output and extract the necessary +# objects, libraries and library flags. +m4_defun([_LT_SYS_HIDDEN_LIBDEPS], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +# Dependencies to place before and after the object being linked: +_LT_TAGVAR(predep_objects, $1)= +_LT_TAGVAR(postdep_objects, $1)= +_LT_TAGVAR(predeps, $1)= +_LT_TAGVAR(postdeps, $1)= +_LT_TAGVAR(compiler_lib_search_path, $1)= + +dnl we can't use the lt_simple_compile_test_code here, +dnl because it contains code intended for an executable, +dnl not a library. It's possible we should let each +dnl tag define a new lt_????_link_test_code variable, +dnl but it's only used here... +m4_if([$1], [], [cat > conftest.$ac_ext <<_LT_EOF +int a; +void foo (void) { a = 0; } +_LT_EOF +], [$1], [CXX], [cat > conftest.$ac_ext <<_LT_EOF +class Foo +{ +public: + Foo (void) { a = 0; } +private: + int a; +}; +_LT_EOF +], [$1], [F77], [cat > conftest.$ac_ext <<_LT_EOF + subroutine foo + implicit none + integer*4 a + a=0 + return + end +_LT_EOF +], [$1], [FC], [cat > conftest.$ac_ext <<_LT_EOF + subroutine foo + implicit none + integer a + a=0 + return + end +_LT_EOF +], [$1], [GCJ], [cat > conftest.$ac_ext <<_LT_EOF +public class foo { + private int a; + public void bar (void) { + a = 0; + } +}; +_LT_EOF +]) +dnl Parse the compiler output and extract the necessary +dnl objects, libraries and library flags. +if AC_TRY_EVAL(ac_compile); then + # Parse the compiler output and extract the necessary + # objects, libraries and library flags. + + # Sentinel used to keep track of whether or not we are before + # the conftest object file. + pre_test_object_deps_done=no + + for p in `eval "$output_verbose_link_cmd"`; do + case $p in + + -L* | -R* | -l*) + # Some compilers place space between "-{L,R}" and the path. + # Remove the space. + if test $p = "-L" || + test $p = "-R"; then + prev=$p + continue + else + prev= + fi + + if test "$pre_test_object_deps_done" = no; then + case $p in + -L* | -R*) + # Internal compiler library paths should come after those + # provided the user. The postdeps already come after the + # user supplied libs so there is no need to process them. + if test -z "$_LT_TAGVAR(compiler_lib_search_path, $1)"; then + _LT_TAGVAR(compiler_lib_search_path, $1)="${prev}${p}" + else + _LT_TAGVAR(compiler_lib_search_path, $1)="${_LT_TAGVAR(compiler_lib_search_path, $1)} ${prev}${p}" + fi + ;; + # The "-l" case would never come before the object being + # linked, so don't bother handling this case. + esac + else + if test -z "$_LT_TAGVAR(postdeps, $1)"; then + _LT_TAGVAR(postdeps, $1)="${prev}${p}" + else + _LT_TAGVAR(postdeps, $1)="${_LT_TAGVAR(postdeps, $1)} ${prev}${p}" + fi + fi + ;; + + *.$objext) + # This assumes that the test object file only shows up + # once in the compiler output. + if test "$p" = "conftest.$objext"; then + pre_test_object_deps_done=yes + continue + fi + + if test "$pre_test_object_deps_done" = no; then + if test -z "$_LT_TAGVAR(predep_objects, $1)"; then + _LT_TAGVAR(predep_objects, $1)="$p" + else + _LT_TAGVAR(predep_objects, $1)="$_LT_TAGVAR(predep_objects, $1) $p" + fi + else + if test -z "$_LT_TAGVAR(postdep_objects, $1)"; then + _LT_TAGVAR(postdep_objects, $1)="$p" + else + _LT_TAGVAR(postdep_objects, $1)="$_LT_TAGVAR(postdep_objects, $1) $p" + fi + fi + ;; + + *) ;; # Ignore the rest. + + esac + done + + # Clean up. + rm -f a.out a.exe +else + echo "libtool.m4: error: problem compiling $1 test program" +fi + +$RM -f confest.$objext + +# PORTME: override above test on systems where it is broken +m4_if([$1], [CXX], +[case $host_os in +interix[[3-9]]*) + # Interix 3.5 installs completely hosed .la files for C++, so rather than + # hack all around it, let's just trust "g++" to DTRT. + _LT_TAGVAR(predep_objects,$1)= + _LT_TAGVAR(postdep_objects,$1)= + _LT_TAGVAR(postdeps,$1)= + ;; + +linux*) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + + # The more standards-conforming stlport4 library is + # incompatible with the Cstd library. Avoid specifying + # it if it's in CXXFLAGS. Ignore libCrun as + # -library=stlport4 depends on it. + case " $CXX $CXXFLAGS " in + *" -library=stlport4 "*) + solaris_use_stlport4=yes + ;; + esac + + if test "$solaris_use_stlport4" != yes; then + _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun' + fi + ;; + esac + ;; + +solaris*) + case $cc_basename in + CC*) + # The more standards-conforming stlport4 library is + # incompatible with the Cstd library. Avoid specifying + # it if it's in CXXFLAGS. Ignore libCrun as + # -library=stlport4 depends on it. + case " $CXX $CXXFLAGS " in + *" -library=stlport4 "*) + solaris_use_stlport4=yes + ;; + esac + + # Adding this requires a known-good setup of shared libraries for + # Sun compiler versions before 5.6, else PIC objects from an old + # archive will be linked into the output, leading to subtle bugs. + if test "$solaris_use_stlport4" != yes; then + _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun' + fi + ;; + esac + ;; +esac +]) + +case " $_LT_TAGVAR(postdeps, $1) " in +*" -lc "*) _LT_TAGVAR(archive_cmds_need_lc, $1)=no ;; +esac + _LT_TAGVAR(compiler_lib_search_dirs, $1)= +if test -n "${_LT_TAGVAR(compiler_lib_search_path, $1)}"; then + _LT_TAGVAR(compiler_lib_search_dirs, $1)=`echo " ${_LT_TAGVAR(compiler_lib_search_path, $1)}" | ${SED} -e 's! -L! !g' -e 's!^ !!'` +fi +_LT_TAGDECL([], [compiler_lib_search_dirs], [1], + [The directories searched by this compiler when creating a shared library]) +_LT_TAGDECL([], [predep_objects], [1], + [Dependencies to place before and after the objects being linked to + create a shared library]) +_LT_TAGDECL([], [postdep_objects], [1]) +_LT_TAGDECL([], [predeps], [1]) +_LT_TAGDECL([], [postdeps], [1]) +_LT_TAGDECL([], [compiler_lib_search_path], [1], + [The library search path used internally by the compiler when linking + a shared library]) +])# _LT_SYS_HIDDEN_LIBDEPS + + +# _LT_PROG_F77 +# ------------ +# Since AC_PROG_F77 is broken, in that it returns the empty string +# if there is no fortran compiler, we have our own version here. +m4_defun([_LT_PROG_F77], +[ +pushdef([AC_MSG_ERROR], [_lt_disable_F77=yes]) +AC_PROG_F77 +if test -z "$F77" || test "X$F77" = "Xno"; then + _lt_disable_F77=yes +fi +popdef([AC_MSG_ERROR]) +])# _LT_PROG_F77 + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([_LT_PROG_F77], []) + + +# _LT_LANG_F77_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for a Fortran 77 compiler are +# suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to `libtool'. +m4_defun([_LT_LANG_F77_CONFIG], +[AC_REQUIRE([_LT_PROG_F77])dnl +AC_LANG_PUSH(Fortran 77) + +_LT_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_TAGVAR(allow_undefined_flag, $1)= +_LT_TAGVAR(always_export_symbols, $1)=no +_LT_TAGVAR(archive_expsym_cmds, $1)= +_LT_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_TAGVAR(hardcode_direct, $1)=no +_LT_TAGVAR(hardcode_direct_absolute, $1)=no +_LT_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= +_LT_TAGVAR(hardcode_libdir_separator, $1)= +_LT_TAGVAR(hardcode_minus_L, $1)=no +_LT_TAGVAR(hardcode_automatic, $1)=no +_LT_TAGVAR(inherit_rpath, $1)=no +_LT_TAGVAR(module_cmds, $1)= +_LT_TAGVAR(module_expsym_cmds, $1)= +_LT_TAGVAR(link_all_deplibs, $1)=unknown +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(no_undefined_flag, $1)= +_LT_TAGVAR(whole_archive_flag_spec, $1)= +_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Source file extension for f77 test sources. +ac_ext=f + +# Object file extension for compiled f77 test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# No sense in running all these tests if we already determined that +# the F77 compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test "$_lt_disable_F77" != yes; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="\ + subroutine t + return + end +" + + # Code to be used in simple link tests + lt_simple_link_test_code="\ + program t + end +" + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + _LT_TAG_COMPILER + + # save warnings/boilerplate of simple test code + _LT_COMPILER_BOILERPLATE + _LT_LINKER_BOILERPLATE + + # Allow CC to be a program name with arguments. + lt_save_CC="$CC" + lt_save_GCC=$GCC + CC=${F77-"f77"} + compiler=$CC + _LT_TAGVAR(compiler, $1)=$CC + _LT_CC_BASENAME([$compiler]) + GCC=$G77 + if test -n "$compiler"; then + AC_MSG_CHECKING([if libtool supports shared libraries]) + AC_MSG_RESULT([$can_build_shared]) + + AC_MSG_CHECKING([whether to build shared libraries]) + test "$can_build_shared" = "no" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test "$enable_shared" = yes && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + aix[[4-9]]*) + if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then + test "$enable_shared" = yes && enable_static=no + fi + ;; + esac + AC_MSG_RESULT([$enable_shared]) + + AC_MSG_CHECKING([whether to build static libraries]) + # Make sure either enable_shared or enable_static is yes. + test "$enable_shared" = yes || enable_static=yes + AC_MSG_RESULT([$enable_static]) + + _LT_TAGVAR(GCC, $1)="$G77" + _LT_TAGVAR(LD, $1)="$LD" + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) + fi # test -n "$compiler" + + GCC=$lt_save_GCC + CC="$lt_save_CC" +fi # test "$_lt_disable_F77" != yes + +AC_LANG_POP +])# _LT_LANG_F77_CONFIG + + +# _LT_PROG_FC +# ----------- +# Since AC_PROG_FC is broken, in that it returns the empty string +# if there is no fortran compiler, we have our own version here. +m4_defun([_LT_PROG_FC], +[ +pushdef([AC_MSG_ERROR], [_lt_disable_FC=yes]) +AC_PROG_FC +if test -z "$FC" || test "X$FC" = "Xno"; then + _lt_disable_FC=yes +fi +popdef([AC_MSG_ERROR]) +])# _LT_PROG_FC + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([_LT_PROG_FC], []) + + +# _LT_LANG_FC_CONFIG([TAG]) +# ------------------------- +# Ensure that the configuration variables for a Fortran compiler are +# suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to `libtool'. +m4_defun([_LT_LANG_FC_CONFIG], +[AC_REQUIRE([_LT_PROG_FC])dnl +AC_LANG_PUSH(Fortran) + +_LT_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_TAGVAR(allow_undefined_flag, $1)= +_LT_TAGVAR(always_export_symbols, $1)=no +_LT_TAGVAR(archive_expsym_cmds, $1)= +_LT_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_TAGVAR(hardcode_direct, $1)=no +_LT_TAGVAR(hardcode_direct_absolute, $1)=no +_LT_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= +_LT_TAGVAR(hardcode_libdir_separator, $1)= +_LT_TAGVAR(hardcode_minus_L, $1)=no +_LT_TAGVAR(hardcode_automatic, $1)=no +_LT_TAGVAR(inherit_rpath, $1)=no +_LT_TAGVAR(module_cmds, $1)= +_LT_TAGVAR(module_expsym_cmds, $1)= +_LT_TAGVAR(link_all_deplibs, $1)=unknown +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(no_undefined_flag, $1)= +_LT_TAGVAR(whole_archive_flag_spec, $1)= +_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Source file extension for fc test sources. +ac_ext=${ac_fc_srcext-f} + +# Object file extension for compiled fc test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# No sense in running all these tests if we already determined that +# the FC compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test "$_lt_disable_FC" != yes; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="\ + subroutine t + return + end +" + + # Code to be used in simple link tests + lt_simple_link_test_code="\ + program t + end +" + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + _LT_TAG_COMPILER + + # save warnings/boilerplate of simple test code + _LT_COMPILER_BOILERPLATE + _LT_LINKER_BOILERPLATE + + # Allow CC to be a program name with arguments. + lt_save_CC="$CC" + lt_save_GCC=$GCC + CC=${FC-"f95"} + compiler=$CC + GCC=$ac_cv_fc_compiler_gnu + + _LT_TAGVAR(compiler, $1)=$CC + _LT_CC_BASENAME([$compiler]) + + if test -n "$compiler"; then + AC_MSG_CHECKING([if libtool supports shared libraries]) + AC_MSG_RESULT([$can_build_shared]) + + AC_MSG_CHECKING([whether to build shared libraries]) + test "$can_build_shared" = "no" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test "$enable_shared" = yes && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + aix[[4-9]]*) + if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then + test "$enable_shared" = yes && enable_static=no + fi + ;; + esac + AC_MSG_RESULT([$enable_shared]) + + AC_MSG_CHECKING([whether to build static libraries]) + # Make sure either enable_shared or enable_static is yes. + test "$enable_shared" = yes || enable_static=yes + AC_MSG_RESULT([$enable_static]) + + _LT_TAGVAR(GCC, $1)="$ac_cv_fc_compiler_gnu" + _LT_TAGVAR(LD, $1)="$LD" + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + _LT_SYS_HIDDEN_LIBDEPS($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) + fi # test -n "$compiler" + + GCC=$lt_save_GCC + CC="$lt_save_CC" +fi # test "$_lt_disable_FC" != yes + +AC_LANG_POP +])# _LT_LANG_FC_CONFIG + + +# _LT_LANG_GCJ_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for the GNU Java Compiler compiler +# are suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to `libtool'. +m4_defun([_LT_LANG_GCJ_CONFIG], +[AC_REQUIRE([LT_PROG_GCJ])dnl +AC_LANG_SAVE + +# Source file extension for Java test sources. +ac_ext=java + +# Object file extension for compiled Java test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="class foo {}" + +# Code to be used in simple link tests +lt_simple_link_test_code='public class conftest { public static void main(String[[]] argv) {}; }' + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. +_LT_TAG_COMPILER + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +# Allow CC to be a program name with arguments. +lt_save_CC="$CC" +lt_save_GCC=$GCC +GCC=yes +CC=${GCJ-"gcj"} +compiler=$CC +_LT_TAGVAR(compiler, $1)=$CC +_LT_TAGVAR(LD, $1)="$LD" +_LT_CC_BASENAME([$compiler]) + +# GCJ did not exist at the time GCC didn't implicitly link libc in. +_LT_TAGVAR(archive_cmds_need_lc, $1)=no + +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds + +## CAVEAT EMPTOR: +## There is no encapsulation within the following macros, do not change +## the running order or otherwise move them around unless you know exactly +## what you are doing... +if test -n "$compiler"; then + _LT_COMPILER_NO_RTTI($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) +fi + +AC_LANG_RESTORE + +GCC=$lt_save_GCC +CC="$lt_save_CC" +])# _LT_LANG_GCJ_CONFIG + + +# _LT_LANG_RC_CONFIG([TAG]) +# ------------------------- +# Ensure that the configuration variables for the Windows resource compiler +# are suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to `libtool'. +m4_defun([_LT_LANG_RC_CONFIG], +[AC_REQUIRE([LT_PROG_RC])dnl +AC_LANG_SAVE + +# Source file extension for RC test sources. +ac_ext=rc + +# Object file extension for compiled RC test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code='sample MENU { MENUITEM "&Soup", 100, CHECKED }' + +# Code to be used in simple link tests +lt_simple_link_test_code="$lt_simple_compile_test_code" + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. +_LT_TAG_COMPILER + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +# Allow CC to be a program name with arguments. +lt_save_CC="$CC" +lt_save_GCC=$GCC +GCC= +CC=${RC-"windres"} +compiler=$CC +_LT_TAGVAR(compiler, $1)=$CC +_LT_CC_BASENAME([$compiler]) +_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes + +if test -n "$compiler"; then + : + _LT_CONFIG($1) +fi + +GCC=$lt_save_GCC +AC_LANG_RESTORE +CC="$lt_save_CC" +])# _LT_LANG_RC_CONFIG + + +# LT_PROG_GCJ +# ----------- +AC_DEFUN([LT_PROG_GCJ], +[m4_ifdef([AC_PROG_GCJ], [AC_PROG_GCJ], + [m4_ifdef([A][M_PROG_GCJ], [A][M_PROG_GCJ], + [AC_CHECK_TOOL(GCJ, gcj,) + test "x${GCJFLAGS+set}" = xset || GCJFLAGS="-g -O2" + AC_SUBST(GCJFLAGS)])])[]dnl +]) + +# Old name: +AU_ALIAS([LT_AC_PROG_GCJ], [LT_PROG_GCJ]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([LT_AC_PROG_GCJ], []) + + +# LT_PROG_RC +# ---------- +AC_DEFUN([LT_PROG_RC], +[AC_CHECK_TOOL(RC, windres,) +]) + +# Old name: +AU_ALIAS([LT_AC_PROG_RC], [LT_PROG_RC]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([LT_AC_PROG_RC], []) + + +# _LT_DECL_EGREP +# -------------- +# If we don't have a new enough Autoconf to choose the best grep +# available, choose the one first in the user's PATH. +m4_defun([_LT_DECL_EGREP], +[AC_REQUIRE([AC_PROG_EGREP])dnl +AC_REQUIRE([AC_PROG_FGREP])dnl +test -z "$GREP" && GREP=grep +_LT_DECL([], [GREP], [1], [A grep program that handles long lines]) +_LT_DECL([], [EGREP], [1], [An ERE matcher]) +_LT_DECL([], [FGREP], [1], [A literal string matcher]) +dnl Non-bleeding-edge autoconf doesn't subst GREP, so do it here too +AC_SUBST([GREP]) +]) + + +# _LT_DECL_OBJDUMP +# -------------- +# If we don't have a new enough Autoconf to choose the best objdump +# available, choose the one first in the user's PATH. +m4_defun([_LT_DECL_OBJDUMP], +[AC_CHECK_TOOL(OBJDUMP, objdump, false) +test -z "$OBJDUMP" && OBJDUMP=objdump +_LT_DECL([], [OBJDUMP], [1], [An object symbol dumper]) +AC_SUBST([OBJDUMP]) +]) + + +# _LT_DECL_SED +# ------------ +# Check for a fully-functional sed program, that truncates +# as few characters as possible. Prefer GNU sed if found. +m4_defun([_LT_DECL_SED], +[AC_PROG_SED +test -z "$SED" && SED=sed +Xsed="$SED -e 1s/^X//" +_LT_DECL([], [SED], [1], [A sed program that does not truncate output]) +_LT_DECL([], [Xsed], ["\$SED -e 1s/^X//"], + [Sed that helps us avoid accidentally triggering echo(1) options like -n]) +])# _LT_DECL_SED + +m4_ifndef([AC_PROG_SED], [ +############################################################ +# NOTE: This macro has been submitted for inclusion into # +# GNU Autoconf as AC_PROG_SED. When it is available in # +# a released version of Autoconf we should remove this # +# macro and use it instead. # +############################################################ + +m4_defun([AC_PROG_SED], +[AC_MSG_CHECKING([for a sed that does not truncate output]) +AC_CACHE_VAL(lt_cv_path_SED, +[# Loop through the user's path and test for sed and gsed. +# Then use that list of sed's as ones to test for truncation. +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for lt_ac_prog in sed gsed; do + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$lt_ac_prog$ac_exec_ext"; then + lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext" + fi + done + done +done +IFS=$as_save_IFS +lt_ac_max=0 +lt_ac_count=0 +# Add /usr/xpg4/bin/sed as it is typically found on Solaris +# along with /bin/sed that truncates output. +for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do + test ! -f $lt_ac_sed && continue + cat /dev/null > conftest.in + lt_ac_count=0 + echo $ECHO_N "0123456789$ECHO_C" >conftest.in + # Check for GNU sed and select it if it is found. + if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then + lt_cv_path_SED=$lt_ac_sed + break + fi + while true; do + cat conftest.in conftest.in >conftest.tmp + mv conftest.tmp conftest.in + cp conftest.in conftest.nl + echo >>conftest.nl + $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break + cmp -s conftest.out conftest.nl || break + # 10000 chars as input seems more than enough + test $lt_ac_count -gt 10 && break + lt_ac_count=`expr $lt_ac_count + 1` + if test $lt_ac_count -gt $lt_ac_max; then + lt_ac_max=$lt_ac_count + lt_cv_path_SED=$lt_ac_sed + fi + done +done +]) +SED=$lt_cv_path_SED +AC_SUBST([SED]) +AC_MSG_RESULT([$SED]) +])#AC_PROG_SED +])#m4_ifndef + +# Old name: +AU_ALIAS([LT_AC_PROG_SED], [AC_PROG_SED]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([LT_AC_PROG_SED], []) + + +# _LT_CHECK_SHELL_FEATURES +# ------------------------ +# Find out whether the shell is Bourne or XSI compatible, +# or has some other useful features. +m4_defun([_LT_CHECK_SHELL_FEATURES], +[AC_MSG_CHECKING([whether the shell understands some XSI constructs]) +# Try some XSI features +xsi_shell=no +( _lt_dummy="a/b/c" + test "${_lt_dummy##*/},${_lt_dummy%/*},"${_lt_dummy%"$_lt_dummy"}, \ + = c,a/b,, \ + && eval 'test $(( 1 + 1 )) -eq 2 \ + && test "${#_lt_dummy}" -eq 5' ) >/dev/null 2>&1 \ + && xsi_shell=yes +AC_MSG_RESULT([$xsi_shell]) +_LT_CONFIG_LIBTOOL_INIT([xsi_shell='$xsi_shell']) + +AC_MSG_CHECKING([whether the shell understands "+="]) +lt_shell_append=no +( foo=bar; set foo baz; eval "$[1]+=\$[2]" && test "$foo" = barbaz ) \ + >/dev/null 2>&1 \ + && lt_shell_append=yes +AC_MSG_RESULT([$lt_shell_append]) +_LT_CONFIG_LIBTOOL_INIT([lt_shell_append='$lt_shell_append']) + +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + lt_unset=unset +else + lt_unset=false +fi +_LT_DECL([], [lt_unset], [0], [whether the shell understands "unset"])dnl + +# test EBCDIC or ASCII +case `echo X|tr X '\101'` in + A) # ASCII based system + # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr + lt_SP2NL='tr \040 \012' + lt_NL2SP='tr \015\012 \040\040' + ;; + *) # EBCDIC based system + lt_SP2NL='tr \100 \n' + lt_NL2SP='tr \r\n \100\100' + ;; +esac +_LT_DECL([SP2NL], [lt_SP2NL], [1], [turn spaces into newlines])dnl +_LT_DECL([NL2SP], [lt_NL2SP], [1], [turn newlines into spaces])dnl +])# _LT_CHECK_SHELL_FEATURES + + +# _LT_PROG_XSI_SHELLFNS +# --------------------- +# Bourne and XSI compatible variants of some useful shell functions. +m4_defun([_LT_PROG_XSI_SHELLFNS], +[case $xsi_shell in + yes) + cat << \_LT_EOF >> "$cfgfile" + +# func_dirname file append nondir_replacement +# Compute the dirname of FILE. If nonempty, add APPEND to the result, +# otherwise set result to NONDIR_REPLACEMENT. +func_dirname () +{ + case ${1} in + */*) func_dirname_result="${1%/*}${2}" ;; + * ) func_dirname_result="${3}" ;; + esac +} + +# func_basename file +func_basename () +{ + func_basename_result="${1##*/}" +} + +# func_dirname_and_basename file append nondir_replacement +# perform func_basename and func_dirname in a single function +# call: +# dirname: Compute the dirname of FILE. If nonempty, +# add APPEND to the result, otherwise set result +# to NONDIR_REPLACEMENT. +# value returned in "$func_dirname_result" +# basename: Compute filename of FILE. +# value retuned in "$func_basename_result" +# Implementation must be kept synchronized with func_dirname +# and func_basename. For efficiency, we do not delegate to +# those functions but instead duplicate the functionality here. +func_dirname_and_basename () +{ + case ${1} in + */*) func_dirname_result="${1%/*}${2}" ;; + * ) func_dirname_result="${3}" ;; + esac + func_basename_result="${1##*/}" +} + +# func_stripname prefix suffix name +# strip PREFIX and SUFFIX off of NAME. +# PREFIX and SUFFIX must not contain globbing or regex special +# characters, hashes, percent signs, but SUFFIX may contain a leading +# dot (in which case that matches only a dot). +func_stripname () +{ + # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are + # positional parameters, so assign one to ordinary parameter first. + func_stripname_result=${3} + func_stripname_result=${func_stripname_result#"${1}"} + func_stripname_result=${func_stripname_result%"${2}"} +} + +# func_opt_split +func_opt_split () +{ + func_opt_split_opt=${1%%=*} + func_opt_split_arg=${1#*=} +} + +# func_lo2o object +func_lo2o () +{ + case ${1} in + *.lo) func_lo2o_result=${1%.lo}.${objext} ;; + *) func_lo2o_result=${1} ;; + esac +} + +# func_xform libobj-or-source +func_xform () +{ + func_xform_result=${1%.*}.lo +} + +# func_arith arithmetic-term... +func_arith () +{ + func_arith_result=$(( $[*] )) +} + +# func_len string +# STRING may not start with a hyphen. +func_len () +{ + func_len_result=${#1} +} + +_LT_EOF + ;; + *) # Bourne compatible functions. + cat << \_LT_EOF >> "$cfgfile" + +# func_dirname file append nondir_replacement +# Compute the dirname of FILE. If nonempty, add APPEND to the result, +# otherwise set result to NONDIR_REPLACEMENT. +func_dirname () +{ + # Extract subdirectory from the argument. + func_dirname_result=`$ECHO "X${1}" | $Xsed -e "$dirname"` + if test "X$func_dirname_result" = "X${1}"; then + func_dirname_result="${3}" + else + func_dirname_result="$func_dirname_result${2}" + fi +} + +# func_basename file +func_basename () +{ + func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"` +} + +dnl func_dirname_and_basename +dnl A portable version of this function is already defined in general.m4sh +dnl so there is no need for it here. + +# func_stripname prefix suffix name +# strip PREFIX and SUFFIX off of NAME. +# PREFIX and SUFFIX must not contain globbing or regex special +# characters, hashes, percent signs, but SUFFIX may contain a leading +# dot (in which case that matches only a dot). +# func_strip_suffix prefix name +func_stripname () +{ + case ${2} in + .*) func_stripname_result=`$ECHO "X${3}" \ + | $Xsed -e "s%^${1}%%" -e "s%\\\\${2}\$%%"`;; + *) func_stripname_result=`$ECHO "X${3}" \ + | $Xsed -e "s%^${1}%%" -e "s%${2}\$%%"`;; + esac +} + +# sed scripts: +my_sed_long_opt='1s/^\(-[[^=]]*\)=.*/\1/;q' +my_sed_long_arg='1s/^-[[^=]]*=//' + +# func_opt_split +func_opt_split () +{ + func_opt_split_opt=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_opt"` + func_opt_split_arg=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_arg"` +} + +# func_lo2o object +func_lo2o () +{ + func_lo2o_result=`$ECHO "X${1}" | $Xsed -e "$lo2o"` +} + +# func_xform libobj-or-source +func_xform () +{ + func_xform_result=`$ECHO "X${1}" | $Xsed -e 's/\.[[^.]]*$/.lo/'` +} + +# func_arith arithmetic-term... +func_arith () +{ + func_arith_result=`expr "$[@]"` +} + +# func_len string +# STRING may not start with a hyphen. +func_len () +{ + func_len_result=`expr "$[1]" : ".*" 2>/dev/null || echo $max_cmd_len` +} + +_LT_EOF +esac + +case $lt_shell_append in + yes) + cat << \_LT_EOF >> "$cfgfile" + +# func_append var value +# Append VALUE to the end of shell variable VAR. +func_append () +{ + eval "$[1]+=\$[2]" +} +_LT_EOF + ;; + *) + cat << \_LT_EOF >> "$cfgfile" + +# func_append var value +# Append VALUE to the end of shell variable VAR. +func_append () +{ + eval "$[1]=\$$[1]\$[2]" +} + +_LT_EOF + ;; + esac +]) diff --git a/m4/ltoptions.m4 b/m4/ltoptions.m4 new file mode 100644 index 0000000..34151a3 --- /dev/null +++ b/m4/ltoptions.m4 @@ -0,0 +1,368 @@ +# Helper functions for option handling. -*- Autoconf -*- +# +# Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc. +# Written by Gary V. Vaughan, 2004 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# serial 6 ltoptions.m4 + +# This is to help aclocal find these macros, as it can't see m4_define. +AC_DEFUN([LTOPTIONS_VERSION], [m4_if([1])]) + + +# _LT_MANGLE_OPTION(MACRO-NAME, OPTION-NAME) +# ------------------------------------------ +m4_define([_LT_MANGLE_OPTION], +[[_LT_OPTION_]m4_bpatsubst($1__$2, [[^a-zA-Z0-9_]], [_])]) + + +# _LT_SET_OPTION(MACRO-NAME, OPTION-NAME) +# --------------------------------------- +# Set option OPTION-NAME for macro MACRO-NAME, and if there is a +# matching handler defined, dispatch to it. Other OPTION-NAMEs are +# saved as a flag. +m4_define([_LT_SET_OPTION], +[m4_define(_LT_MANGLE_OPTION([$1], [$2]))dnl +m4_ifdef(_LT_MANGLE_DEFUN([$1], [$2]), + _LT_MANGLE_DEFUN([$1], [$2]), + [m4_warning([Unknown $1 option `$2'])])[]dnl +]) + + +# _LT_IF_OPTION(MACRO-NAME, OPTION-NAME, IF-SET, [IF-NOT-SET]) +# ------------------------------------------------------------ +# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. +m4_define([_LT_IF_OPTION], +[m4_ifdef(_LT_MANGLE_OPTION([$1], [$2]), [$3], [$4])]) + + +# _LT_UNLESS_OPTIONS(MACRO-NAME, OPTION-LIST, IF-NOT-SET) +# ------------------------------------------------------- +# Execute IF-NOT-SET unless all options in OPTION-LIST for MACRO-NAME +# are set. +m4_define([_LT_UNLESS_OPTIONS], +[m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), + [m4_ifdef(_LT_MANGLE_OPTION([$1], _LT_Option), + [m4_define([$0_found])])])[]dnl +m4_ifdef([$0_found], [m4_undefine([$0_found])], [$3 +])[]dnl +]) + + +# _LT_SET_OPTIONS(MACRO-NAME, OPTION-LIST) +# ---------------------------------------- +# OPTION-LIST is a space-separated list of Libtool options associated +# with MACRO-NAME. If any OPTION has a matching handler declared with +# LT_OPTION_DEFINE, dispatch to that macro; otherwise complain about +# the unknown option and exit. +m4_defun([_LT_SET_OPTIONS], +[# Set options +m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), + [_LT_SET_OPTION([$1], _LT_Option)]) + +m4_if([$1],[LT_INIT],[ + dnl + dnl Simply set some default values (i.e off) if boolean options were not + dnl specified: + _LT_UNLESS_OPTIONS([LT_INIT], [dlopen], [enable_dlopen=no + ]) + _LT_UNLESS_OPTIONS([LT_INIT], [win32-dll], [enable_win32_dll=no + ]) + dnl + dnl If no reference was made to various pairs of opposing options, then + dnl we run the default mode handler for the pair. For example, if neither + dnl `shared' nor `disable-shared' was passed, we enable building of shared + dnl archives by default: + _LT_UNLESS_OPTIONS([LT_INIT], [shared disable-shared], [_LT_ENABLE_SHARED]) + _LT_UNLESS_OPTIONS([LT_INIT], [static disable-static], [_LT_ENABLE_STATIC]) + _LT_UNLESS_OPTIONS([LT_INIT], [pic-only no-pic], [_LT_WITH_PIC]) + _LT_UNLESS_OPTIONS([LT_INIT], [fast-install disable-fast-install], + [_LT_ENABLE_FAST_INSTALL]) + ]) +])# _LT_SET_OPTIONS + + +## --------------------------------- ## +## Macros to handle LT_INIT options. ## +## --------------------------------- ## + +# _LT_MANGLE_DEFUN(MACRO-NAME, OPTION-NAME) +# ----------------------------------------- +m4_define([_LT_MANGLE_DEFUN], +[[_LT_OPTION_DEFUN_]m4_bpatsubst(m4_toupper([$1__$2]), [[^A-Z0-9_]], [_])]) + + +# LT_OPTION_DEFINE(MACRO-NAME, OPTION-NAME, CODE) +# ----------------------------------------------- +m4_define([LT_OPTION_DEFINE], +[m4_define(_LT_MANGLE_DEFUN([$1], [$2]), [$3])[]dnl +])# LT_OPTION_DEFINE + + +# dlopen +# ------ +LT_OPTION_DEFINE([LT_INIT], [dlopen], [enable_dlopen=yes +]) + +AU_DEFUN([AC_LIBTOOL_DLOPEN], +[_LT_SET_OPTION([LT_INIT], [dlopen]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the `dlopen' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_DLOPEN], []) + + +# win32-dll +# --------- +# Declare package support for building win32 dll's. +LT_OPTION_DEFINE([LT_INIT], [win32-dll], +[enable_win32_dll=yes + +case $host in +*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-cegcc*) + AC_CHECK_TOOL(AS, as, false) + AC_CHECK_TOOL(DLLTOOL, dlltool, false) + AC_CHECK_TOOL(OBJDUMP, objdump, false) + ;; +esac + +test -z "$AS" && AS=as +_LT_DECL([], [AS], [0], [Assembler program])dnl + +test -z "$DLLTOOL" && DLLTOOL=dlltool +_LT_DECL([], [DLLTOOL], [0], [DLL creation program])dnl + +test -z "$OBJDUMP" && OBJDUMP=objdump +_LT_DECL([], [OBJDUMP], [0], [Object dumper program])dnl +])# win32-dll + +AU_DEFUN([AC_LIBTOOL_WIN32_DLL], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +_LT_SET_OPTION([LT_INIT], [win32-dll]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the `win32-dll' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_WIN32_DLL], []) + + +# _LT_ENABLE_SHARED([DEFAULT]) +# ---------------------------- +# implement the --enable-shared flag, and supports the `shared' and +# `disable-shared' LT_INIT options. +# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. +m4_define([_LT_ENABLE_SHARED], +[m4_define([_LT_ENABLE_SHARED_DEFAULT], [m4_if($1, no, no, yes)])dnl +AC_ARG_ENABLE([shared], + [AS_HELP_STRING([--enable-shared@<:@=PKGS@:>@], + [build shared libraries @<:@default=]_LT_ENABLE_SHARED_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_shared=yes ;; + no) enable_shared=no ;; + *) + enable_shared=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_shared=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac], + [enable_shared=]_LT_ENABLE_SHARED_DEFAULT) + + _LT_DECL([build_libtool_libs], [enable_shared], [0], + [Whether or not to build shared libraries]) +])# _LT_ENABLE_SHARED + +LT_OPTION_DEFINE([LT_INIT], [shared], [_LT_ENABLE_SHARED([yes])]) +LT_OPTION_DEFINE([LT_INIT], [disable-shared], [_LT_ENABLE_SHARED([no])]) + +# Old names: +AC_DEFUN([AC_ENABLE_SHARED], +[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[shared]) +]) + +AC_DEFUN([AC_DISABLE_SHARED], +[_LT_SET_OPTION([LT_INIT], [disable-shared]) +]) + +AU_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)]) +AU_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AM_ENABLE_SHARED], []) +dnl AC_DEFUN([AM_DISABLE_SHARED], []) + + + +# _LT_ENABLE_STATIC([DEFAULT]) +# ---------------------------- +# implement the --enable-static flag, and support the `static' and +# `disable-static' LT_INIT options. +# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. +m4_define([_LT_ENABLE_STATIC], +[m4_define([_LT_ENABLE_STATIC_DEFAULT], [m4_if($1, no, no, yes)])dnl +AC_ARG_ENABLE([static], + [AS_HELP_STRING([--enable-static@<:@=PKGS@:>@], + [build static libraries @<:@default=]_LT_ENABLE_STATIC_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_static=yes ;; + no) enable_static=no ;; + *) + enable_static=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_static=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac], + [enable_static=]_LT_ENABLE_STATIC_DEFAULT) + + _LT_DECL([build_old_libs], [enable_static], [0], + [Whether or not to build static libraries]) +])# _LT_ENABLE_STATIC + +LT_OPTION_DEFINE([LT_INIT], [static], [_LT_ENABLE_STATIC([yes])]) +LT_OPTION_DEFINE([LT_INIT], [disable-static], [_LT_ENABLE_STATIC([no])]) + +# Old names: +AC_DEFUN([AC_ENABLE_STATIC], +[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[static]) +]) + +AC_DEFUN([AC_DISABLE_STATIC], +[_LT_SET_OPTION([LT_INIT], [disable-static]) +]) + +AU_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)]) +AU_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AM_ENABLE_STATIC], []) +dnl AC_DEFUN([AM_DISABLE_STATIC], []) + + + +# _LT_ENABLE_FAST_INSTALL([DEFAULT]) +# ---------------------------------- +# implement the --enable-fast-install flag, and support the `fast-install' +# and `disable-fast-install' LT_INIT options. +# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. +m4_define([_LT_ENABLE_FAST_INSTALL], +[m4_define([_LT_ENABLE_FAST_INSTALL_DEFAULT], [m4_if($1, no, no, yes)])dnl +AC_ARG_ENABLE([fast-install], + [AS_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@], + [optimize for fast installation @<:@default=]_LT_ENABLE_FAST_INSTALL_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_fast_install=yes ;; + no) enable_fast_install=no ;; + *) + enable_fast_install=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_fast_install=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac], + [enable_fast_install=]_LT_ENABLE_FAST_INSTALL_DEFAULT) + +_LT_DECL([fast_install], [enable_fast_install], [0], + [Whether or not to optimize for fast installation])dnl +])# _LT_ENABLE_FAST_INSTALL + +LT_OPTION_DEFINE([LT_INIT], [fast-install], [_LT_ENABLE_FAST_INSTALL([yes])]) +LT_OPTION_DEFINE([LT_INIT], [disable-fast-install], [_LT_ENABLE_FAST_INSTALL([no])]) + +# Old names: +AU_DEFUN([AC_ENABLE_FAST_INSTALL], +[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[fast-install]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you put +the `fast-install' option into LT_INIT's first parameter.]) +]) + +AU_DEFUN([AC_DISABLE_FAST_INSTALL], +[_LT_SET_OPTION([LT_INIT], [disable-fast-install]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you put +the `disable-fast-install' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_ENABLE_FAST_INSTALL], []) +dnl AC_DEFUN([AM_DISABLE_FAST_INSTALL], []) + + +# _LT_WITH_PIC([MODE]) +# -------------------- +# implement the --with-pic flag, and support the `pic-only' and `no-pic' +# LT_INIT options. +# MODE is either `yes' or `no'. If omitted, it defaults to `both'. +m4_define([_LT_WITH_PIC], +[AC_ARG_WITH([pic], + [AS_HELP_STRING([--with-pic], + [try to use only PIC/non-PIC objects @<:@default=use both@:>@])], + [pic_mode="$withval"], + [pic_mode=default]) + +test -z "$pic_mode" && pic_mode=m4_default([$1], [default]) + +_LT_DECL([], [pic_mode], [0], [What type of objects to build])dnl +])# _LT_WITH_PIC + +LT_OPTION_DEFINE([LT_INIT], [pic-only], [_LT_WITH_PIC([yes])]) +LT_OPTION_DEFINE([LT_INIT], [no-pic], [_LT_WITH_PIC([no])]) + +# Old name: +AU_DEFUN([AC_LIBTOOL_PICMODE], +[_LT_SET_OPTION([LT_INIT], [pic-only]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the `pic-only' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_PICMODE], []) + +## ----------------- ## +## LTDL_INIT Options ## +## ----------------- ## + +m4_define([_LTDL_MODE], []) +LT_OPTION_DEFINE([LTDL_INIT], [nonrecursive], + [m4_define([_LTDL_MODE], [nonrecursive])]) +LT_OPTION_DEFINE([LTDL_INIT], [recursive], + [m4_define([_LTDL_MODE], [recursive])]) +LT_OPTION_DEFINE([LTDL_INIT], [subproject], + [m4_define([_LTDL_MODE], [subproject])]) + +m4_define([_LTDL_TYPE], []) +LT_OPTION_DEFINE([LTDL_INIT], [installable], + [m4_define([_LTDL_TYPE], [installable])]) +LT_OPTION_DEFINE([LTDL_INIT], [convenience], + [m4_define([_LTDL_TYPE], [convenience])]) diff --git a/m4/ltsugar.m4 b/m4/ltsugar.m4 new file mode 100644 index 0000000..9000a05 --- /dev/null +++ b/m4/ltsugar.m4 @@ -0,0 +1,123 @@ +# ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*- +# +# Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc. +# Written by Gary V. Vaughan, 2004 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# serial 6 ltsugar.m4 + +# This is to help aclocal find these macros, as it can't see m4_define. +AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])]) + + +# lt_join(SEP, ARG1, [ARG2...]) +# ----------------------------- +# Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their +# associated separator. +# Needed until we can rely on m4_join from Autoconf 2.62, since all earlier +# versions in m4sugar had bugs. +m4_define([lt_join], +[m4_if([$#], [1], [], + [$#], [2], [[$2]], + [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])]) +m4_define([_lt_join], +[m4_if([$#$2], [2], [], + [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])]) + + +# lt_car(LIST) +# lt_cdr(LIST) +# ------------ +# Manipulate m4 lists. +# These macros are necessary as long as will still need to support +# Autoconf-2.59 which quotes differently. +m4_define([lt_car], [[$1]]) +m4_define([lt_cdr], +[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])], + [$#], 1, [], + [m4_dquote(m4_shift($@))])]) +m4_define([lt_unquote], $1) + + +# lt_append(MACRO-NAME, STRING, [SEPARATOR]) +# ------------------------------------------ +# Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'. +# Note that neither SEPARATOR nor STRING are expanded; they are appended +# to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked). +# No SEPARATOR is output if MACRO-NAME was previously undefined (different +# than defined and empty). +# +# This macro is needed until we can rely on Autoconf 2.62, since earlier +# versions of m4sugar mistakenly expanded SEPARATOR but not STRING. +m4_define([lt_append], +[m4_define([$1], + m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])]) + + + +# lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...]) +# ---------------------------------------------------------- +# Produce a SEP delimited list of all paired combinations of elements of +# PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list +# has the form PREFIXmINFIXSUFFIXn. +# Needed until we can rely on m4_combine added in Autoconf 2.62. +m4_define([lt_combine], +[m4_if(m4_eval([$# > 3]), [1], + [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl +[[m4_foreach([_Lt_prefix], [$2], + [m4_foreach([_Lt_suffix], + ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[, + [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])]) + + +# lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ]) +# ----------------------------------------------------------------------- +# Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited +# by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ. +m4_define([lt_if_append_uniq], +[m4_ifdef([$1], + [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1], + [lt_append([$1], [$2], [$3])$4], + [$5])], + [lt_append([$1], [$2], [$3])$4])]) + + +# lt_dict_add(DICT, KEY, VALUE) +# ----------------------------- +m4_define([lt_dict_add], +[m4_define([$1($2)], [$3])]) + + +# lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE) +# -------------------------------------------- +m4_define([lt_dict_add_subkey], +[m4_define([$1($2:$3)], [$4])]) + + +# lt_dict_fetch(DICT, KEY, [SUBKEY]) +# ---------------------------------- +m4_define([lt_dict_fetch], +[m4_ifval([$3], + m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]), + m4_ifdef([$1($2)], [m4_defn([$1($2)])]))]) + + +# lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE]) +# ----------------------------------------------------------------- +m4_define([lt_if_dict_fetch], +[m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4], + [$5], + [$6])]) + + +# lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...]) +# -------------------------------------------------------------- +m4_define([lt_dict_filter], +[m4_if([$5], [], [], + [lt_join(m4_quote(m4_default([$4], [[, ]])), + lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]), + [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl +]) diff --git a/m4/ltversion.m4 b/m4/ltversion.m4 new file mode 100644 index 0000000..f3c5309 --- /dev/null +++ b/m4/ltversion.m4 @@ -0,0 +1,23 @@ +# ltversion.m4 -- version numbers -*- Autoconf -*- +# +# Copyright (C) 2004 Free Software Foundation, Inc. +# Written by Scott James Remnant, 2004 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# Generated from ltversion.in. + +# serial 3017 ltversion.m4 +# This file is part of GNU Libtool + +m4_define([LT_PACKAGE_VERSION], [2.2.6b]) +m4_define([LT_PACKAGE_REVISION], [1.3017]) + +AC_DEFUN([LTVERSION_VERSION], +[macro_version='2.2.6b' +macro_revision='1.3017' +_LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) +_LT_DECL(, macro_revision, 0) +]) diff --git a/m4/lt~obsolete.m4 b/m4/lt~obsolete.m4 new file mode 100644 index 0000000..637bb20 --- /dev/null +++ b/m4/lt~obsolete.m4 @@ -0,0 +1,92 @@ +# lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*- +# +# Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc. +# Written by Scott James Remnant, 2004. +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# serial 4 lt~obsolete.m4 + +# These exist entirely to fool aclocal when bootstrapping libtool. +# +# In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN) +# which have later been changed to m4_define as they aren't part of the +# exported API, or moved to Autoconf or Automake where they belong. +# +# The trouble is, aclocal is a bit thick. It'll see the old AC_DEFUN +# in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us +# using a macro with the same name in our local m4/libtool.m4 it'll +# pull the old libtool.m4 in (it doesn't see our shiny new m4_define +# and doesn't know about Autoconf macros at all.) +# +# So we provide this file, which has a silly filename so it's always +# included after everything else. This provides aclocal with the +# AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything +# because those macros already exist, or will be overwritten later. +# We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. +# +# Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here. +# Yes, that means every name once taken will need to remain here until +# we give up compatibility with versions before 1.7, at which point +# we need to keep only those names which we still refer to. + +# This is to help aclocal find these macros, as it can't see m4_define. +AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])]) + +m4_ifndef([AC_LIBTOOL_LINKER_OPTION], [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])]) +m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP])]) +m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])]) +m4_ifndef([_LT_AC_SHELL_INIT], [AC_DEFUN([_LT_AC_SHELL_INIT])]) +m4_ifndef([_LT_AC_SYS_LIBPATH_AIX], [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])]) +m4_ifndef([_LT_PROG_LTMAIN], [AC_DEFUN([_LT_PROG_LTMAIN])]) +m4_ifndef([_LT_AC_TAGVAR], [AC_DEFUN([_LT_AC_TAGVAR])]) +m4_ifndef([AC_LTDL_ENABLE_INSTALL], [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])]) +m4_ifndef([AC_LTDL_PREOPEN], [AC_DEFUN([AC_LTDL_PREOPEN])]) +m4_ifndef([_LT_AC_SYS_COMPILER], [AC_DEFUN([_LT_AC_SYS_COMPILER])]) +m4_ifndef([_LT_AC_LOCK], [AC_DEFUN([_LT_AC_LOCK])]) +m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE], [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])]) +m4_ifndef([_LT_AC_TRY_DLOPEN_SELF], [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])]) +m4_ifndef([AC_LIBTOOL_PROG_CC_C_O], [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])]) +m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])]) +m4_ifndef([AC_LIBTOOL_OBJDIR], [AC_DEFUN([AC_LIBTOOL_OBJDIR])]) +m4_ifndef([AC_LTDL_OBJDIR], [AC_DEFUN([AC_LTDL_OBJDIR])]) +m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])]) +m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP], [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])]) +m4_ifndef([AC_PATH_MAGIC], [AC_DEFUN([AC_PATH_MAGIC])]) +m4_ifndef([AC_PROG_LD_GNU], [AC_DEFUN([AC_PROG_LD_GNU])]) +m4_ifndef([AC_PROG_LD_RELOAD_FLAG], [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])]) +m4_ifndef([AC_DEPLIBS_CHECK_METHOD], [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])]) +m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])]) +m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])]) +m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])]) +m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])]) +m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])]) +m4_ifndef([LT_AC_PROG_EGREP], [AC_DEFUN([LT_AC_PROG_EGREP])]) +m4_ifndef([LT_AC_PROG_SED], [AC_DEFUN([LT_AC_PROG_SED])]) +m4_ifndef([_LT_CC_BASENAME], [AC_DEFUN([_LT_CC_BASENAME])]) +m4_ifndef([_LT_COMPILER_BOILERPLATE], [AC_DEFUN([_LT_COMPILER_BOILERPLATE])]) +m4_ifndef([_LT_LINKER_BOILERPLATE], [AC_DEFUN([_LT_LINKER_BOILERPLATE])]) +m4_ifndef([_AC_PROG_LIBTOOL], [AC_DEFUN([_AC_PROG_LIBTOOL])]) +m4_ifndef([AC_LIBTOOL_SETUP], [AC_DEFUN([AC_LIBTOOL_SETUP])]) +m4_ifndef([_LT_AC_CHECK_DLFCN], [AC_DEFUN([_LT_AC_CHECK_DLFCN])]) +m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER], [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])]) +m4_ifndef([_LT_AC_TAGCONFIG], [AC_DEFUN([_LT_AC_TAGCONFIG])]) +m4_ifndef([AC_DISABLE_FAST_INSTALL], [AC_DEFUN([AC_DISABLE_FAST_INSTALL])]) +m4_ifndef([_LT_AC_LANG_CXX], [AC_DEFUN([_LT_AC_LANG_CXX])]) +m4_ifndef([_LT_AC_LANG_F77], [AC_DEFUN([_LT_AC_LANG_F77])]) +m4_ifndef([_LT_AC_LANG_GCJ], [AC_DEFUN([_LT_AC_LANG_GCJ])]) +m4_ifndef([AC_LIBTOOL_RC], [AC_DEFUN([AC_LIBTOOL_RC])]) +m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])]) +m4_ifndef([_LT_AC_LANG_C_CONFIG], [AC_DEFUN([_LT_AC_LANG_C_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])]) +m4_ifndef([_LT_AC_LANG_CXX_CONFIG], [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])]) +m4_ifndef([_LT_AC_LANG_F77_CONFIG], [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])]) +m4_ifndef([_LT_AC_LANG_GCJ_CONFIG], [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])]) +m4_ifndef([_LT_AC_LANG_RC_CONFIG], [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])]) +m4_ifndef([AC_LIBTOOL_CONFIG], [AC_DEFUN([AC_LIBTOOL_CONFIG])]) +m4_ifndef([_LT_AC_FILE_LTDLL_C], [AC_DEFUN([_LT_AC_FILE_LTDLL_C])]) diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..2385948 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,17 @@ +MAINTAINERCLEANFILES = Makefile.in + +TESTS = tests +noinst_PROGRAMS = tests + +INCLUDES = \ + -DPACKAGE=\"@PACKAGE@\" \ + $(CRYPTIC_CFLAGS) + +tests_SOURCES = tests.c +tests_LDADD = \ + $(top_builddir)/cryptic/libcryptic.la \ + $(CRYPTIC_LIBS) + +tests_LDFLAGS = -rpath `cd $(top_builddir)/cryptic/.libs/; pwd` + +EXTRA_DIST = tests.c diff --git a/tests/tests.c b/tests/tests.c new file mode 100644 index 0000000..c36e15a --- /dev/null +++ b/tests/tests.c @@ -0,0 +1,870 @@ +/* Cryptic -- Cryptographic tools and protocols + * Copyright (C) 2009 Mikaël Ates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../cryptic/cryptic.h" +#include "../cryptic/utils.h" + +#ifdef OPENSSL_SYS_WIN16 +#define MS_CALLBACK _far _loadds +#else +#define MS_CALLBACK +#endif + +static int MS_CALLBACK qrn_cb(int p, int n, BN_GENCB *arg); +static BIO *bio_err=NULL; + +BN_GENCB cb; + +void activ_CB(){ + if (bio_err == NULL) bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); + BN_GENCB_set(&cb, qrn_cb, bio_err); + BN_GENCB_call(&cb, 2, 0); + printf("Callback function activated.\n\n"); +} + +int test_1(){ + int rc = CRYPTIC_ERROR_UNDEFINED; + + printf("\n"); + printf("------******------------------------------------------------------------------******------\n"); + printf("------******---------------------- Certificate generation --------------------******------\n"); + printf("------******-------------------------------- & -------------------------------******------\n"); + printf("------******------------------------ Parameters loading ----------------------******------\n"); + printf("------******------------------------------------------------------------------******------\n\n"); + + int i; + CrypticCommitDataStore *pdc; + CrypticClsig *param1, *param2, *param3, *param4; + BIGNUM *bases[2], *quantities[2], **tmp; + pdc = NULL; + param1 = NULL; + param2 = NULL; + param3 = NULL; + param4 = NULL; + bases[0] = NULL; + bases[1] = NULL; + quantities[0] = NULL; + quantities[1] = NULL; + + for(i=0; i<2; i++){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(bases[i] = BN_new()); + goto_cleanup_if_fail_with_rc_with_warning_openssl(quantities[i] = BN_new()); + } + + printf("*** 1. Issuer1\n"); + printf("\n----> \tParameters generation\n"); + + param1 = cryptic_clsig_new(1024, 80, 298, 0, 0, 0, 5); + goto_cleanup_if_fail_with_warning(param1 != NULL); + + //goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_clsig_generate_parameters(param1,&cb) == 0); + cryptic_check_good_rc(cryptic_clsig_generate_parameters(param1)); + + printf("\n----> \tCertificate generation\n"); + + cryptic_check_good_rc(cryptic_clsig_compute_dlrep_with_random_quantities(param1,5)); + cryptic_check_good_rc(cryptic_clsig_sign(param1)); + if (cryptic_clsig_verify_signature_not_randomized(param1)) { + printf("\t****** VALID SIGNATURE\n"); + } else { + printf("\t!!!!!! Bad signature\n"); + return(-1); + } + + + + + printf("\n*** 2. Prover1\n\n"); + printf("----> \tParameters loading\n"); + param2 = cryptic_clsig_new_load_public_parameters(cryptic_clsig_get_Z(param1), + cryptic_clsig_get_S(param1), + cryptic_clsig_get_nb_bases(param1), + cryptic_clsig_get_bases(param1), + cryptic_clsig_get_lg_quantities(param1), + cryptic_clsig_get_lg_exponent(param1), + cryptic_clsig_get_modulus(param1), + cryptic_clsig_get_lg_sec_param(param1), + cryptic_clsig_get_lg_zk_sec_param(param1), + cryptic_clsig_get_lg_clsig_sec_param(param1)); + goto_cleanup_if_fail_with_warning(param2 != NULL); + + printf("----> \tCertificate loading\n"); + if (cryptic_clsig_load_certificate(param2, + cryptic_clsig_get_signature(param1), + cryptic_clsig_get_exponent(param1), + cryptic_clsig_get_blind(param1), + cryptic_clsig_get_quantities(param1), cryptic_clsig_get_nb_quantities(param1), + 1) == 1 ){ + printf("\t****** VALID SIGNATURE\n"); + } else { + printf("\t!!!!!! Bad signature\n"); + return(-1); + } + + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_clsig_randomize_signature(param2) == 0); + if ( cryptic_clsig_verify_signature_randomized(param2) == 1 ){ + printf("\t****** VALID Randomized SIGNATURE\n"); + } else { + printf("\t!!!!!! Bad Randomized signature\n"); + return(-1); + } + + + + + printf("\n*** 1. Prover2\n\n"); + printf("----> \tParameters loading\n"); + param3 = cryptic_clsig_new_load_public_parameters(cryptic_clsig_get_Z(param1), + cryptic_clsig_get_S(param1), + cryptic_clsig_get_nb_bases(param1), + cryptic_clsig_get_bases(param1), + cryptic_clsig_get_lg_quantities(param1), + cryptic_clsig_get_lg_exponent(param1), + cryptic_clsig_get_modulus(param1), + cryptic_clsig_get_lg_sec_param(param1), + cryptic_clsig_get_lg_zk_sec_param(param1), + cryptic_clsig_get_lg_clsig_sec_param(param1)); + goto_cleanup_if_fail_with_warning(param3 != NULL); + + printf("----> \tGenerate Commitment\n"); + tmp = cryptic_clsig_get_bases(param3); + goto_cleanup_if_fail_with_warning(tmp != NULL); + for(i=0;i<2;i++){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(bases[i],tmp[i+3])); + } + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(quantities[0],123) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(quantities[1],456) == 1); + + pdc = cryptic_commit_data_store_new(); + goto_cleanup_if_fail_with_warning(pdc != NULL); + + goto_cleanup_if_fail_with_rc_with_warning_openssl( cryptic_clsig_compute_committed_value(param3, pdc, bases, quantities, 2) == 0); + + + + + printf("\n*** 2. Issuer1\n\n"); + printf("----> \tCertificate generation\n"); + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_clsig_compute_dlrep_with_random_quantities(param1,3) == 0); + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_clsig_sign_with_committed_value(param1, pdc->dlrep) == 0); + if (cryptic_clsig_verify_signature_not_randomized(param1)) { + printf("\t****** VALID SIGNATURE\n"); + } else { + printf("\t!!!!!! Bad signature\n"); + return(-1); + } + + + + + printf("\n*** 3. Prover2\n\n"); + printf("----> \tCertificate loading\n"); + if ( cryptic_clsig_load_certificate_with_committed_value(param3, + cryptic_clsig_get_signature(param1), + cryptic_clsig_get_exponent(param1), + cryptic_clsig_get_blind(param1), + cryptic_clsig_get_quantities(param1), cryptic_clsig_get_nb_quantities(param1), + quantities, 2, + pdc->dlrep, pdc->vprime) == 1 ){ + printf("\t****** VALID SIGNATURE\n"); + } else { + printf("\t!!!!!! Bad signature\n"); + return(-1); + } + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_clsig_randomize_signature(param3) == 0); + if ( cryptic_clsig_verify_signature_randomized(param3) == 1 ){ + printf("\t****** VALID Randomized SIGNATURE\n"); + } else { + printf("\t!!!!!! Bad Randomized signature\n"); + return(-1); + } + + + + + /* New issuer */ + printf("\n*** 2. Issuer2\n\n"); + printf("----> \tIssuer1 parameters loading\n"); + param4 = cryptic_clsig_new_load_parameters_issuer(cryptic_clsig_get_private_composite(param1), + cryptic_clsig_get_Z(param1), + cryptic_clsig_get_S(param1), + cryptic_clsig_get_nb_bases(param1), + cryptic_clsig_get_bases(param1), + cryptic_clsig_get_lg_quantities(param1), + cryptic_clsig_get_lg_exponent(param1), + cryptic_clsig_get_modulus(param1), + cryptic_clsig_get_lg_sec_param(param1), + cryptic_clsig_get_lg_zk_sec_param(param1), + cryptic_clsig_get_lg_clsig_sec_param(param1)); + //cryptic_clsig_get_lg_clsig_sec_param(param1), + //&cb); + goto_cleanup_if_fail_with_warning(param4 != NULL); + + printf("\n----> \tCertificate generation\n"); + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_clsig_compute_dlrep_with_random_quantities(param4,3) == 0); + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_clsig_sign_with_committed_value(param4, pdc->dlrep) == 0); + if (cryptic_clsig_verify_signature_not_randomized(param4)) { + printf("\t****** VALID SIGNATURE\n"); + } else { + printf("\t!!!!!! Bad signature\n"); + return(-1); + } + + + + + printf("\n*** 3. Prover2\n\n"); + printf("----> \tCertificate loading\n"); + if (cryptic_clsig_load_certificate_with_committed_value(param3, + cryptic_clsig_get_signature(param4), + cryptic_clsig_get_exponent(param4), + cryptic_clsig_get_blind(param4), + cryptic_clsig_get_quantities(param4), cryptic_clsig_get_nb_quantities(param4), + quantities, 2, + pdc->dlrep, pdc->vprime) == 1 ){ + printf("\t****** VALID SIGNATURE\n"); + } else { + printf("\t!!!!!! Bad signature\n"); + return(-1); + } + goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_clsig_randomize_signature(param3) == 0); + if ( cryptic_clsig_verify_signature_randomized(param3) == 1 ){ + printf("\t****** VALID Randomized SIGNATURE\n"); + } else { + printf("\t!!!!!! Bad Randomized signature\n"); + return(-1); + } + + + + + rc = CRYPTIC_NO_ERROR; +cleanup: + for(i=0; i<2; i++){ + cryptic_release_bn(bases[i]); + cryptic_release_bn(quantities[i]); + } + cryptic_release_gobject(param1); + cryptic_release_gobject(param2); + cryptic_release_gobject(param3); + cryptic_release_gobject(param4); + cryptic_release_gobject(pdc); + return rc; +} + +int test_2(){ + int rc = CRYPTIC_ERROR_UNDEFINED; + + printf("\n"); + printf("------******------------------------------------------------------------------******------\n"); + printf("------******---------------------------- Prove a CLSIG -----------------------******------\n"); + printf("------******------------------------------------------------------------------******------\n\n"); + + + int i, z, j; + int nb_bases = 5; + int nb_messages = 5; + int *i_q, *i_b; + i_q = NULL; + i_b = NULL; + char* str[5]; + for(i=0;i<5;i++){ + str[i] = NULL; + } + /* Issuer */ + CrypticClsig *param1 = NULL; + /* Prover */ + CrypticClsig *param2 = NULL; + CrypticZkpkSchnorr *shn1 = NULL; + CrypticZkpkSchnorr *shn3 = NULL; + CrypticProofrangeQrg *pr1 = NULL; + CrypticProofrangeQrg *pr3 = NULL; + CrypticHashForNiProofs* hash1 = NULL; + /* Verifier */ + CrypticClsig *param3 = NULL; + CrypticZkpkSchnorr *shn2 = NULL; + CrypticZkpkSchnorr *shn4 = NULL; + CrypticProofrangeQrg *pr2 = NULL; + CrypticProofrangeQrg *pr4 = NULL; + CrypticHashForNiProofs* hash2 = NULL; + BIGNUM *m = NULL, *b = NULL, *random_m = NULL, **tmp = NULL, *s1 = NULL, **s2 = NULL, *tmp1 = NULL, *P = NULL, *challenge = NULL; + BIGNUM *tab_gene[nb_messages+2]; + BIGNUM *tab_qty[nb_messages+2]; + for(j=0; j \tParameters generation - WARNING: for the non-interactive proof lg messages >= lg hash\n"); + param1 = cryptic_clsig_new(1024, 256, 596, 0, 0, 0, 5); + goto_cleanup_if_fail_with_warning(param1 != NULL); + //goto_cleanup_if_fail_with_rc_with_warning_openssl(cryptic_clsig_generate_parameters(param1,&cb) == 0); + cryptic_check_good_rc(cryptic_clsig_generate_parameters(param1)); + + printf("\n----> \tCertificate generation\n"); + //cryptic_check_good_rc(cryptic_clsig_compute_dlrep_bulk_from_offset(param1,tab_qty,0,5)); + int index[5] = {0,1,2,3,4}; + cryptic_check_good_rc(cryptic_clsig_compute_dlrep_by_index(param1,tab_qty,index,5)); + cryptic_check_good_rc(cryptic_clsig_sign(param1)); + + + + + printf("\n\n2. *** PROVER\n"); + printf("----> \tParameters loading\n"); + param2 = cryptic_clsig_new_load_public_parameters(cryptic_clsig_get_Z(param1), + cryptic_clsig_get_S(param1), + cryptic_clsig_get_nb_bases(param1), + cryptic_clsig_get_bases(param1), + cryptic_clsig_get_lg_quantities(param1), + cryptic_clsig_get_lg_exponent(param1), + cryptic_clsig_get_modulus(param1), + cryptic_clsig_get_lg_sec_param(param1), + cryptic_clsig_get_lg_zk_sec_param(param1), + cryptic_clsig_get_lg_clsig_sec_param(param1)); + goto_cleanup_if_fail_with_warning(param2 != NULL); + + printf("----> \tCertificate loading\n"); + if (cryptic_clsig_load_certificate(param2, + cryptic_clsig_get_signature(param1), + cryptic_clsig_get_exponent(param1), + cryptic_clsig_get_blind(param1), + cryptic_clsig_get_quantities(param1), cryptic_clsig_get_nb_quantities(param1), + 1) == 1 ){ + printf("\t****** VALID SIGNATURE\n"); + } else { + printf("\t!!!!!! Bad signature\n"); + return(-1); + } + printf("----> \tCertificate randomization\n"); + cryptic_check_good_rc(cryptic_clsig_randomize_signature(param2)); + if ( cryptic_clsig_verify_signature_randomized(param2) == 1 ){ + printf("\t****** VALID Randomized SIGNATURE\n"); + } else { + printf("\t!!!!!! Bad Randomized signature\n"); + return(-1); + } + + + + + printf("\n\n3. *** VERIFIER\n"); + printf("----> \tParameters loading\n"); + param3 = cryptic_clsig_new_load_public_parameters(cryptic_clsig_get_Z(param1), + cryptic_clsig_get_S(param1), + cryptic_clsig_get_nb_bases(param1), + cryptic_clsig_get_bases(param1), + cryptic_clsig_get_lg_quantities(param1), + cryptic_clsig_get_lg_exponent(param1), + cryptic_clsig_get_modulus(param1), + cryptic_clsig_get_lg_sec_param(param1), + cryptic_clsig_get_lg_zk_sec_param(param1), + cryptic_clsig_get_lg_clsig_sec_param(param1)); + goto_cleanup_if_fail_with_warning(param3 != NULL); + + printf("----> \tSay: 'Prove me that you have a valid certificate from ISSUER showing your name and prove you are over 18 years old'\n"); + /* The prover must prove that the quantity (exponent) of the base 2 is inferior to b */ + /* The base two is trusted by the verifier as being the base used by the issuer to represent the birth date */ + /* Prove an age: the birth date < Today - 18 years */ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(b,1992021900) == 1); + + + + + printf("\n\n4. *** PROVER\n"); + + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_gene[0],cryptic_clsig_get_randomized_signature(param2))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_gene[1],cryptic_clsig_get_S(param2))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_gene[2],cryptic_clsig_get_i_base(param2,0))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_gene[3],cryptic_clsig_get_i_base(param2,2))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_gene[4],cryptic_clsig_get_i_base(param2,3))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_gene[5],cryptic_clsig_get_i_base(param2,4))); + +// BN_copy(tab_qty[0],cryptic_clsig_get_exponent(param2)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_qty[0],cryptic_clsig_get_exponent_corrected(param2))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_qty[1],cryptic_clsig_get_random_blind(param2))); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_bin2bn((const unsigned char *) str[0],strlen(str[0]),tmp1)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_qty[2],tmp1)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_qty[3],m)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_bin2bn((const unsigned char *) str[3],strlen(str[3]),tmp1)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_qty[4],tmp1)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_bin2bn((const unsigned char *) str[4],strlen(str[4]),tmp1)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_qty[5],tmp1)); + + printf("----> \tTodo:\n"); + printf("----> \t1- Reveal the name\n"); + printf("----> \t2- Compute Z/base^Nom and prove it\n"); + printf("----> \t3- Prove that the quantity represented by the base 2 in the following proof is inferior to b.\n"); + + /* P = Z. R1^-nom . A^-(2le-1) = A_rand^e_corrected . S^v_rand ...*/ + i_q = (int*) g_malloc(sizeof(int)); + i_b = (int*) g_malloc(sizeof(int)); + i_q[0]=1; + i_b[0]=1; + P = cryptic_clsig_build_dlrep_before_proving(param2, i_q, i_b, 1); + goto_cleanup_if_fail_with_warning(P != NULL); + + + printf("----> \tProof initialization\n"); + shn1 = cryptic_zkpk_schnorr_new(tab_gene, 6, cryptic_clsig_get_modulus(param2)); + goto_cleanup_if_fail_with_warning(shn1 != NULL); + shn3 = cryptic_zkpk_schnorr_new(tab_gene, 6, cryptic_clsig_get_modulus(param2)); + goto_cleanup_if_fail_with_warning(shn3 != NULL); + pr1 = cryptic_proofrange_qrg_new(cryptic_clsig_get_Z(param2),cryptic_clsig_get_S(param2),cryptic_clsig_get_modulus(param2)); + goto_cleanup_if_fail_with_warning(pr1 != NULL); + pr3 = cryptic_proofrange_qrg_new(cryptic_clsig_get_Z(param2),cryptic_clsig_get_S(param2),cryptic_clsig_get_modulus(param2)); + goto_cleanup_if_fail_with_warning(pr3 != NULL); + + printf("----> \tProof first round: Commit -> Z/Generator_Nom^quantity_Nom\n"); + cryptic_check_good_rc(cryptic_clsig_run_zkpk_schnorr_round1(param2, shn1)); + cryptic_check_good_rc(cryptic_clsig_run_zkpk_schnorr_round1(param2, shn3)); + + printf("----> \tProof range interactive first round: same quantity (same random)\n"); + //same quantity, same random + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(random_m,cryptic_zkpk_schnorr_get_i_random(shn1,3))); + cryptic_check_good_rc(cryptic_proofrange_qrg_round1(pr1, + CRYPTIC_PROOF_RANGE_LT, + m, + b, + random_m, + cryptic_clsig_get_lg_sec_param(param2), + cryptic_clsig_get_lg_zk_sec_param(param2), + 256)); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(random_m,cryptic_zkpk_schnorr_get_i_random(shn3,3))); + cryptic_check_good_rc(cryptic_proofrange_qrg_round1(pr3, + CRYPTIC_PROOF_RANGE_LT, + m, + b, + random_m, + cryptic_clsig_get_lg_sec_param(param2), + cryptic_clsig_get_lg_zk_sec_param(param2), + 256)); + + printf("----> \tCompute hash\n"); + hash1 = cryptic_hash_for_ni_proofs_new(256); + goto_cleanup_if_fail_with_warning(hash1 != NULL); + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_proof(hash1,shn1,P)); + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_proofrange_prover(hash1,pr1)); + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_compute_hash(hash1)); + + + + + + printf("\n\n5. *** VERIFIER (for interactive proof)\n"); + + printf("----> \tProof initialization\n"); + shn2 = cryptic_zkpk_schnorr_new(tab_gene, 6, cryptic_clsig_get_modulus(param3)); + goto_cleanup_if_fail_with_warning(shn2 != NULL); + shn4 = cryptic_zkpk_schnorr_new(tab_gene, 6, cryptic_clsig_get_modulus(param3)); + goto_cleanup_if_fail_with_warning(shn4 != NULL); + pr2 = cryptic_proofrange_qrg_new(cryptic_clsig_get_Z(param3),cryptic_clsig_get_S(param3),cryptic_clsig_get_modulus(param3)); + goto_cleanup_if_fail_with_warning(pr2 != NULL); + pr4 = cryptic_proofrange_qrg_new(cryptic_clsig_get_Z(param3),cryptic_clsig_get_S(param3),cryptic_clsig_get_modulus(param3)); + goto_cleanup_if_fail_with_warning(pr4 != NULL); + + printf("----> \tCompute Challenge\n"); + cryptic_check_good_rc(cryptic_find_random(challenge,cryptic_clsig_get_lg_quantities(param3))); + + + + + + printf("\n\n6. *** PROVER\n"); + + printf("----> \tProof interactive second round\n"); + cryptic_check_good_rc(cryptic_zkpk_schnorr_round2_without_order(shn1,cryptic_hash_for_ni_proofs_get_hash(hash1),tab_qty)); + cryptic_check_good_rc(cryptic_zkpk_schnorr_round2_without_order(shn3,challenge,tab_qty)); + + printf("----> \tProof range interactive second round\n"); + cryptic_check_good_rc(cryptic_proofrange_qrg_round2(pr1,cryptic_hash_for_ni_proofs_get_hash(hash1))); + cryptic_check_good_rc(cryptic_proofrange_qrg_round2(pr3,challenge)); + + + + + + printf("\n\n7. *** VERIFIER\n"); + + printf("----> \tVerify non interactive proof\n"); + tmp = cryptic_zkpk_schnorr_get_responses(shn1); + goto_cleanup_if_fail_with_warning(tmp != NULL); + /* tester avec s = r + cx pour les réponses et inverser la rep en DL dans le verify*/ + z = 1; + for(i=2;i<6;i++){ + goto_cleanup_if_fail_with_warning(tmp[i] != NULL); + if(BN_num_bits(tmp[i]) >= (2*cryptic_clsig_get_lg_quantities(param3) + cryptic_clsig_get_lg_zk_sec_param(param3) + 1)) z = 0; + } + if(BN_num_bits(tmp[0]) >= (cryptic_clsig_get_interval_exponent(param3) + cryptic_clsig_get_lg_zk_sec_param(param3) + cryptic_clsig_get_lg_quantities(param3) + 1)) z = 0; + j = 0; + if(!z){ + printf("\t****** PROOF REJECTED: Size of responses for proof 1 too large!\n"); + }else{ + s1 = cryptic_zkpk_schnorr_get_i_response(shn1,3); + goto_cleanup_if_fail_with_warning(s1 != NULL); + s2 = cryptic_proofrange_qrg_get_responses(pr1); + goto_cleanup_if_fail_with_warning(s2 != NULL); + if(!BN_ucmp(s1,s2[8])){ + cryptic_check_good_rc(cryptic_zkpk_schnorr_verify_noninteractive_proof(shn2,P, cryptic_hash_for_ni_proofs_get_hash(hash1),cryptic_zkpk_schnorr_get_responses(shn1))); + + cryptic_check_good_rc(cryptic_proofrange_qrg_verify_noninteractive_proof( + pr2, + CRYPTIC_PROOF_RANGE_LT, + b, + cryptic_proofrange_qrg_get_dlreps(pr1), + cryptic_hash_for_ni_proofs_get_hash(hash1), + cryptic_proofrange_qrg_get_responses(pr1))); + + hash2 = cryptic_hash_for_ni_proofs_new(256); + goto_cleanup_if_fail_with_warning(hash2 != NULL); + + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_proof(hash2,shn2,P)); + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_proofrange_verifier(hash2,pr2,cryptic_proofrange_qrg_get_dlreps(pr1))); + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_compute_hash(hash2)); + + /* Verify the hash computed is the same as the one received */ + if(!BN_ucmp(cryptic_hash_for_ni_proofs_get_hash(hash1),cryptic_hash_for_ni_proofs_get_hash(hash2))){ + printf("\t****** PROOF ACCEPTED\n"); + }else{ + printf("\t****** PROOF REJECTED\n"); + } + cryptic_check_good_rc(cryptic_print_bn("hash1: ",cryptic_hash_for_ni_proofs_get_hash(hash1))); + cryptic_check_good_rc(cryptic_print_bn("hash2: ",cryptic_hash_for_ni_proofs_get_hash(hash2))); + + + }else{ + printf("\t****** PROOF 2 REJECTED: Not the same quantity\n"); + } + + } + + printf("----> \tVerify interactive proof\n"); + tmp = cryptic_zkpk_schnorr_get_responses(shn3); + goto_cleanup_if_fail_with_warning(tmp != NULL); + z = 1; + for(i=2;i<6;i++){ + goto_cleanup_if_fail_with_warning(tmp[i] != NULL); + if(BN_num_bits(tmp[i]) >= (2*cryptic_clsig_get_lg_quantities(param3) + cryptic_clsig_get_lg_zk_sec_param(param3) + 1)) z = 0; + } + if(BN_num_bits(tmp[0]) >= (cryptic_clsig_get_interval_exponent(param3) + cryptic_clsig_get_lg_zk_sec_param(param3) + cryptic_clsig_get_lg_quantities(param3) + 1)) z = 0; + j = 1; + if(!z){ + printf("\t****** PROOF 1 REJECTED: Size of responses too large!\n"); j = 0; + }else{ + if(cryptic_zkpk_schnorr_verify_interactive_proof(shn4,P, shn3->commitment, challenge,cryptic_zkpk_schnorr_get_responses(shn3)) == 1){ + printf("\t****** PROOF 1 ACCEPTED\n"); + }else{ + printf("\t****** PROOF 1 REJECTED\n"); + j = 0; + } + } + s1 = cryptic_zkpk_schnorr_get_i_response(shn3,3); + goto_cleanup_if_fail_with_warning(s1 != NULL); + s2 = cryptic_proofrange_qrg_get_responses(pr3); + goto_cleanup_if_fail_with_warning(s2 != NULL); + if(!BN_ucmp(s1,s2[8])){ + if(cryptic_proofrange_qrg_verify_interactive_proof( + pr4, + CRYPTIC_PROOF_RANGE_LT, + b, + cryptic_proofrange_qrg_get_dlreps(pr3), + cryptic_proofrange_qrg_get_commitments(pr3), + challenge, + cryptic_proofrange_qrg_get_responses(pr3)) == 1){ + printf("\t****** PROOF 2 ACCEPTED\n"); + }else{ + printf("\t****** PROOF 2 REJECTED\n"); + j = 0; + } + }else{ + printf("\t****** PROOF 2 REJECTED\n"); + j = 0; + } + if(j){ + printf("\t****** PROOF ACCEPTED\n\n"); + }else{ + printf("\t****** PROOF REJECTED\n\n"); + } + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + g_free(i_q); + g_free(i_b); + cryptic_release_gobject(param1); + cryptic_release_gobject(param2); + cryptic_release_gobject(param3); + cryptic_release_gobject(shn1); + cryptic_release_gobject(shn2); + cryptic_release_gobject(shn3); + cryptic_release_gobject(shn4); + cryptic_release_gobject(pr1); + cryptic_release_gobject(pr2); + cryptic_release_gobject(pr3); + cryptic_release_gobject(pr4); + cryptic_release_gobject(hash1); + cryptic_release_gobject(hash2); + for(i=0;ip,ctx)); + + cryptic_check_good_rc(cryptic_prime_order_group_more_bases(g,3)); + + for(i=0;i<3;i++){ + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp(tmp,g->bases[i],tab_qty[i],g->p,ctx) == 1); + goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(dlrep,dlrep,tmp,g->p,ctx) == 1); + } + + + + printf("\n\n1. *** PROVER\n"); + /* Proof for prover */ + shn1 = cryptic_zkpk_schnorr_new(g->bases, 3, g->p); + goto_cleanup_if_fail_with_warning(shn1 != NULL); + + /* Compute commitment */ + cryptic_check_good_rc(cryptic_zkpk_schnorr_round1(shn1)); + + /* Compute hash for all proofs */ + hash1 = cryptic_hash_for_ni_proofs_new(256); + goto_cleanup_if_fail_with_warning(hash1 != NULL); + + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_modulus(hash1,g->p)); + for(i=0;i<3;i++){ + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_base(hash1,g->bases[i])); + } + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_dlrep(hash1,dlrep)); + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_commitment(hash1,shn1->commitment)); + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_compute_hash(hash1)); + + /* Compute responses with the hash*/ + cryptic_check_good_rc(cryptic_zkpk_schnorr_round2_without_order(shn1,cryptic_hash_for_ni_proofs_get_hash(hash1),tab_qty)); + + + + + printf("\n\n2. *** VERIFIER\n"); + /* Proof for verifier */ + shn2 = cryptic_zkpk_schnorr_new(g->bases, 3, g->p); + goto_cleanup_if_fail_with_warning(shn2 != NULL); + + /* Compute commitment with the hash and responses received*/ + cryptic_check_good_rc(cryptic_zkpk_schnorr_verify_noninteractive_proof(shn2, dlrep, cryptic_hash_for_ni_proofs_get_hash(hash1), shn1->responses)); + + /* Compute hash for all proofs */ + hash2 = cryptic_hash_for_ni_proofs_new(256); + goto_cleanup_if_fail_with_warning(hash2 != NULL); + + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_modulus(hash2,g->p)); + for(i=0;i<3;i++){ + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_base(hash2,g->bases[i])); + } + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_dlrep(hash2,dlrep)); + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_add_commitment(hash2,shn2->commitment)); + cryptic_check_good_rc(cryptic_hash_for_ni_proofs_compute_hash(hash2)); + + /* Verify the hash computed is the same as the one received */ + cryptic_check_good_rc(cryptic_print_bn("hash1: ",cryptic_hash_for_ni_proofs_get_hash(hash1))); + cryptic_check_good_rc(cryptic_print_bn("hash2: ",cryptic_hash_for_ni_proofs_get_hash(hash2))); + + + + + rc = CRYPTIC_NO_ERROR; +cleanup: + cryptic_release_ctx(ctx); + cryptic_release_mont(mont); + for(i=0;i<3;i++){ + cryptic_release_bn(tab_qty[i]); + } + cryptic_release_bn(m); + cryptic_release_bn(tmp); + cryptic_release_bn(dlrep); + cryptic_release_gobject(g); + cryptic_release_gobject(hash1); + cryptic_release_gobject(hash2); + cryptic_release_gobject(shn1); + cryptic_release_gobject(shn2); + return rc; +} + +int main(int argc, char **argv) { + + printf("\n\n\n"); + printf("----------------------------------------***********---------------------------------------\n"); + printf("------******------------------------------------------------------------------******------\n"); + printf("------****---------------------------- Cryptic Tests ---------------------------****------\n"); + printf("------****--------------------------------- v0.1 -------------------------------****------\n"); + printf("------******------------------------------------------------------------------******------\n"); + printf("----------------------------------------***********---------------------------------------\n"); + + cryptic_init(); + + //activ_CB(); + test_1(); + test_2(); + test_3(); + + return(CRYPTIC_NO_ERROR); +} + +static int MS_CALLBACK qrn_cb(int p, int n, BN_GENCB *arg){ + char c='*'; + static int ok=0,num=0; + + if (p == 0) { c='.'; num++; }; + if (p == 1) c='+'; + if (p == 2) { c='*'; ok++; } + if (p == 3) c='\n'; + BIO_write(arg->arg,&c,1); + (void)BIO_flush(arg->arg); + + if (!ok && (p == 0) && (num > 1)) + { + BIO_printf((BIO *)arg,"Error in CB tests.\n"); + return(0); + } + return(1); +} +