Initial version.

This commit is contained in:
Mikaël Ates 2010-12-09 23:22:44 +01:00
parent bb020efc17
commit acf552ff54
92 changed files with 27771 additions and 0 deletions

1
AUTHORS Normal file
View File

@ -0,0 +1 @@
Mikaël Ates <mates@entrouvert.com>

482
COPYING Normal file
View File

@ -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.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

20
Makefile.am Normal file
View File

@ -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`

19
README
View File

@ -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 <mates@entrouvert.com>

21
TODO Normal file
View File

@ -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.

96
autogen.sh Executable file
View File

@ -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."

2
autoregen.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
./autogen.sh $@

25
bindings/Makefile.am Normal file
View File

@ -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

683
bindings/Makefile.in Normal file
View File

@ -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:

632
bindings/bindings.py Normal file
View File

@ -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 '<Struct name:%s, childof:%s>' % (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 '<Function return_type:%s name:%s args:%r>' % (
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'\<const\>', 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()

81
bindings/ghashtable.h Normal file
View File

@ -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 */

View File

@ -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;

View File

@ -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<arr.length;i+=2) {
map.put(arr[i],arr[i+1]);
}
return map;
}
protected void mapToArray(Map map, Object[] arr) {
int s = map.size();
if (map == null)
return;
Iterator it;
it = map.entrySet().iterator();
int i = 0;
while (it.hasNext() && i < 2*s) {
Map.Entry e = (Map.Entry)it.next();
arr[i++] = (Object)e.getKey();
arr[i++] = (Object)e.getValue();
}
}
protected void listToArray(List list, Object[] arr) {
Iterator it = list.iterator();
int s = arr.length;
int i = 0;
while (it.hasNext() && i < s) {
arr[i++] = (Object)it.next();
}
}
protected void finalize() throws Throwable {
CrypticJNI.destroy(cptr);
}
}

109
bindings/java/Makefile.am Normal file
View File

@ -0,0 +1,109 @@
.NOTPARALLEL:
MAINTAINERCLEANFILES = Makefile.in
INCLUDES = \
-I$(top_builddir) \
-I$(top_srcdir) \
$(SASL_CFLAGS)
CLASSPATH_ENV= CLASSPATH=.:$(CLASSPATH_JUNIT)
CLASSPATH=.:tests
AM_V_JAVAC = $(am__v_JAVAC_$(V))
am__v_JAVAC_ = $(am__v_JAVAC_$(AM_DEFAULT_VERBOSITY))
am__v_JAVAC_0 = @echo " JAVAC " $@;
AM_V_JAR = $(am__v_JAR_$(V))
am__v_JAR_ = $(am__v_JAR_$(AM_DEFAULT_VERBOSITY))
am__v_JAR_0 = @echo " JAR " $@;
java_extension_LTLIBRARIES = libjnicryptic.la
java_extensiondir = ${libdir}/java
#if WSF_ENABLED
#EXTRA_ARGS = --enable-id-wsf
#endif
java_cryptic_source_files := $(shell python $(top_srcdir)/bindings/bindings.py -l java-list --src-dir=$(top_srcdir)/cryptic/ $(EXTRA_ARGS) )
cryptic_jardir=$(prefix)/share/java
cryptic_jar_DATA=cryptic.jar
cryptic_jar_class_files = $(java_cryptic_source_files:.java=.class)
%.class: %.java
$(AM_V_JAVAC) $(JAVAC) $(CLASSPATH_OPT) $(CLASSPATH) $(JAVAC_FLAGS) -d . $<
all_jar_class_files = $(shell find com/entrouvert/cryptic -name '*.class' | sed 's%\$$%\\$$%g')
cryptic.jar: $(java_cryptic_source_files:.java=.class)
$(AM_V_JAR) $(JAR) -cf $@ $(all_jar_class_files)
# Doc
apidir = $(docbasedir)/cryptic/java-api
doc:
-mkdir .doc
-javadoc -link http://java.sun.com/j2se/1.4.2/docs/api -public -d .doc -sourcepath . -subpackages com.entrouvert.cryptic
mv .doc doc
com_entrouvert_cryptic_CrypticJNI.h: com/entrouvert/cryptic/CrypticJNI.class $(java_cryptic_source_files:.java=.class)
$(AM_V_GEN) $(JAVAH) $(JAVAH_FLAGS) -classpath . `echo $< | sed 'su/u.ug;su.classuu'`
libjnicryptic_la_CFLAGS = -fno-strict-aliasing $(CRYPTIC_CORE_CFLAGS) -I$(top_srcdir) -I$(top_builddir) $(AM_CFLAGS) @JAVA_INCLUDE@
libjnicryptic_la_CFLAGS += -Wno-unused-parameter
libjnicryptic_la_LDFLAGS = -export-dynamic -prefer-pic -module -avoid-version
libjnicryptic_la_LIBADD = $(top_builddir)/cryptic/libcryptic.la $(CRYPTIC_LIBS)
nodist_libjnicryptic_la_SOURCES = com_entrouvert_cryptic_CrypticJNI.c
BUILT_SOURCES = com_entrouvert_cryptic_CrypticJNI.c com_entrouvert_cryptic_CrypticJNI.h
BINDING_OPTION=#--enable-exception-docs
$(java_cryptic_source_files) com_entrouvert_cryptic_CrypticJNI.c: wrapper_top.c wrapper_bottom.c lang.py ../bindings.py
$(AM_V_GEN) $(PYTHON) $(top_srcdir)/bindings/bindings.py $(BINDING_OPTION) -l java --src-dir=$(top_srcdir)/cryptic/ $(EXTRA_ARGS) && cp $(srcdir)/GObject.java com/entrouvert/cryptic
#doc-publish: doc
# tar czf doc.tgz -C doc .
# scp doc.tgz bdauvergne@perso.entrouvert.org:
# ssh bdauvergne@perso.entrouvert.org tar czf -C public_html/java-binding-doc doc.tgz
# rm doc.tgz
#$(TESTS) \
MOSTLYCLEANFILES = com_entrouvert_cryptic_CrypticJNI.c com_entrouvert_cryptic_CrypticJNI.h \
com/entrouvert/cryptic/* cryptic.jar *.class \
__init__.pyc lang.pyc
# tests/BindingTests.java \
# tests/LoginTest.java \
EXTRA_DIST = \
GObject.java \
CrypticException_top.java \
lang.py \
__init__.py \
wrapper_bottom.c \
wrapper_top.c
# Some of the following classes are built only if junit is available
#if JUNIT_ENABLED
#test_source_files= tests/BindingTests.java tests/LoginTest.java
#$(test_source_files:.java=.class): CLASSPATH=.:$(CLASSPATH_JUNIT)
#TESTS = AllJunitTests
#AllJunitTests: JAVAFLAGS +="-Dsrcdir=$(srcdir)"
#AllJunitTests: $(test_source_files:.java=.class)
# echo "#! /bin/sh" > $@
# 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

View File

@ -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);
}
}

View File

978
bindings/java/lang.py Normal file
View File

@ -0,0 +1,978 @@
# Cryptic -- Cryptographic tools and protocols
# Copyright (C) 2010 Mikael Ates <mates@entrouvert.com>
#
# 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()

View File

1006
bindings/java/wrapper_top.c Normal file

File diff suppressed because it is too large Load Diff

6
bindings/overrides.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0"?>
<overrides>
<!-- Functions -->
<!-- <func name="lasso_strerror" rename="strError"/> -->
</overrides>

View File

@ -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

705
bindings/python/Makefile.in Normal file
View File

@ -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:

View File

1054
bindings/python/lang.py Normal file

File diff suppressed because it is too large Load Diff

View File

@ -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);
}

View File

@ -0,0 +1,777 @@
#include <Python.h>
#include <structmember.h>
#include <cryptic/cryptic.h>
#include <config.h>
#include "../ghashtable.h"
#include "../../cryptic/utils.h"
#include <openssl/bn.h>
//#include <libxml/tree.h>
#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; i<l; i++) {
PyObject *pystr = PySequence_Fast_GET_ITEM(seq, i);
if (! PyString_Check(pystr)) {
PyErr_SetString(PyExc_TypeError,
"value should be a tuple of strings");
goto failure;
}
list = g_list_append(list, g_strdup(PyString_AsString(pystr)));
}
free_list(a_list, (GFunc)g_free);
*a_list = list;
return;
failure:
free_list(&list, (GFunc)g_free);
}
/** 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 xmlNode*.
*/
/*
static void
set_list_of_xml_nodes(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; i<l; i++) {
PyObject *item = PySequence_Fast_GET_ITEM(seq, i);
xmlNode *item_node;
if (! PyString_Check(item)) {
PyErr_SetString(PyExc_TypeError,
"value should be a tuple of strings");
goto failure;
}
item_node = get_xml_node_from_pystring(item);
list = g_list_append(list, item_node);
}
free_list(a_list, (GFunc)xmlFreeNode);
*a_list = list;
return;
failure:
free_list(&list, (GFunc)xmlFreeNode);
}
*/
/** 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 GObject*.
*/
static void
set_list_of_pygobject(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; i<l; i++) {
PyObject *item = PySequence_Fast_GET_ITEM(seq, i);
GObject *gobject;
if (! PyObject_TypeCheck(item, &PyGObjectPtrType)) {
PyErr_SetString(PyExc_TypeError,
"value should be a tuple of PyGobject");
goto failure;
}
gobject = g_object_ref(((PyGObjectPtr*)item)->obj);
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("<PyGObjectPtr to %p (type: %s, refcount: %d)>",
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<l; i++) {
PyObject *item = PySequence_Fast_GET_ITEM(seq, i);
if(!(tabbn[i] = BN_new())){
goto cleanup;
}
tabbn[i] = get_bignum_from_pylong(item);
}
return tabbn;
cleanup:
g_free(tabbn);
return NULL;
}
static PyObject *
get_list_of_int(int* tabi)
{
PyObject *a_tuple = NULL;
int i = 0;
if (! tabi) {
return noneRef();
}
while (tabi+i != NULL) {i++;}
a_tuple = PyTuple_New(i);
if (! a_tuple)
goto failure;
i = 0;
while (tabi+i != NULL) {
// PyObject *item = (PyObject*) PyInt_FromInt(tabi[i], NULL, 10);
PyObject *item = (PyObject*) PyInt_FromLong((long)tabi[i]);
if (item) {
PyTuple_SetItem(a_tuple, i, item);
i++;
} else {
PyErr_Warn(PyExc_RuntimeWarning, "could not convert an int 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_int");
Py_XDECREF(a_tuple);
return noneRef();
}
int*
set_list_of_int(PyObject *seq)
{
int *output = NULL;
int l=0,i;
if (seq != Py_None) {
l = PySequence_Length(seq);
}
output = g_malloc0(l * sizeof (*output));
if(output == NULL){
goto failure;
}
for (i=0; i<l; i++) {
PyObject *item = PySequence_Fast_GET_ITEM(seq, i);
output[i] = (int) PyInt_AsLong(item);
}
return output;
failure:
g_free(output);
return NULL;
}

View File

@ -0,0 +1,147 @@
#! /usr/bin/perl -w
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; #$running_under_some_shell
use strict;
use File::Find ();
use Data::Dumper;
# Set the variable $File::Find::dont_use_nlink if you're using AFS,
# since AFS cheats.
# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
sub wanted;
sub unique {
my @in = @_;
my @ret = ();
for my $x (@in) {
push @ret, $x if (! grep /$x/, @ret);
}
return @ret;
}
my $functions = {};
my $p = $ARGV[0];
# Traverse desired filesystems
-d $p && File::Find::find({wanted => \&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 (<FD>) {
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.*/);
}

258
bindings/utils.py Normal file
View File

@ -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 ]

827
configure.ac Normal file
View File

@ -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 <stdio.h>
#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}
)

93
cryptic-src-config.in Normal file
View File

@ -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<<EOF
Usage: cryptic-src-config [OPTION]
known values for OPTION are:
--libs print library linking information
--cflags print pre-processor and compiler flags
--help display this help and exit
--version output version information
--run COMMAND run the COMMAND with the shared libraries for
the source tree
EOF
exit $1
}
if test $# -eq 0; then
usage 1 1>&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

11
cryptic.pc.in Normal file
View File

@ -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

40
cryptic/Makefile.am Normal file
View File

@ -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

58
cryptic/cryptic.c Normal file
View File

@ -0,0 +1,58 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2010 Mikaël Ates <mates@entrouvert.com>
*
* 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 <glib.h>
#include <glib-object.h>
#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);
}

47
cryptic/cryptic.h Normal file
View File

@ -0,0 +1,47 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 */

644
cryptic/errors.h Normal file
View File

@ -0,0 +1,644 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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

89
cryptic/export.h Normal file
View File

@ -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__ */

View File

@ -0,0 +1,607 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2010 Mikaël Ates <mates@entrouvert.com>
*
* 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 <glib.h>
#include <glib-object.h>
#include <openssl/bn.h>
#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;i<red;i++){
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mul(numToDecompose,numToDecompose,di->FOUR,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;
}

View File

@ -0,0 +1,100 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 <glib.h>
#include <glib-object.h>
#include <openssl/bn.h>
#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 */

281
cryptic/maths/group_prime_order.c Executable file
View File

@ -0,0 +1,281 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 <glib.h>
#include <glib-object.h>
#include <openssl/bn.h>
#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;i<nb;i++){
group->bases[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;i<nb;i++){
group->bases[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;
}

View File

@ -0,0 +1,82 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 <glib.h>
#include <glib-object.h>
#include <openssl/bn.h>
#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 */

169
cryptic/maths/maths_utils.c Normal file
View File

@ -0,0 +1,169 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 <openssl/bn.h>
#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;
}

View File

@ -0,0 +1,40 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 <openssl/bn.h>
#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 */

View File

@ -0,0 +1,528 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 <glib.h>
#include <glib-object.h>
#include <openssl/bn.h>
#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;i<nb_bases;i++){
cryptic_return_val_if_fail(out_bases[i] != NULL,CRYPTIC_MATHS_QR_GROUP_BASE_UNALLOCATED);
}
for(i=0;i<nb_bases;i++){
cryptic_return_val_if_fail(cryptic_qrg_pick_base(qrg,out_bases[i]) == 0,
CRYPTIC_MATHS_QR_GROUP_PICKING_BASE_FAILED);
}
return(CRYPTIC_NO_ERROR);
}
/* Getters */
BIGNUM*
cryptic_qrg_get_p(CrypticQRG *qrg)
{
cryptic_return_null_if_fail(qrg->p);
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;
}

View File

@ -0,0 +1,107 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 <glib.h>
#include <glib-object.h>
#include <openssl/bn.h>
#include <openssl/bio.h>
#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 */

302
cryptic/protocols/clsig/clsig.h Executable file
View File

@ -0,0 +1,302 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 <glib.h>
#include <glib-object.h>
#include <openssl/bn.h>
#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 */

View File

@ -0,0 +1,675 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 <glib.h>
#include <glib-object.h>
#include <openssl/bn.h>
#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;i<clsig->nb_bases;i++){
cryptic_release_bn(clsig->bases[i]);
}
}
cryptic_release(clsig->bases);
if(clsig->quantities){
for(i=0;i<clsig->nb_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;i<clsig->nb_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;i<nb_bases;i++){
if(!bases[i]){
cryptic_critical("Unable to load CLSIG public parameters: element missing");
return NULL;
}
}
clsig = cryptic_clsig_new(BN_num_bits(modulus), lg_quantities, lg_exponent, lg_sec_param, lg_zk_sec_param, lg_clsig_sec_param, nb_bases);
if(clsig == NULL){
cryptic_critical("Error creating CrypticClsig object");
return NULL;
}
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, 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;i<nb_bases;i++){
goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->bases[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;i<nb;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));
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;i<nb;i++){
goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->bases[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;
}

View File

@ -0,0 +1,215 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 <openssl/bn.h>
#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;
}

View File

@ -0,0 +1,792 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 <openssl/bn.h>
#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;i<clsig->nb_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;i<clsig->nb_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;i<clsig->nb_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;i<clsig->nb_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;i<clsig->nb_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;i<clsig->nb_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;i<nb_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);
}
goto_cleanup_if_fail_with_rc_with_warning(bases != NULL,
CRYPTIC_CLSIG_MISSING_BASES);
for(i=0;i<nb_quantities;i++){
goto_cleanup_if_fail_with_rc_with_warning(bases[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;i<nb_quantities;i++){
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp_mont(tmp,bases[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;
}
/**
* 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;i<nb_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);
}
goto_cleanup_if_fail_with_rc_with_warning(clsig->bases != NULL,
CRYPTIC_CLSIG_MISSING_BASES);
for(i=0;i<nb_quantities;i++){
goto_cleanup_if_fail_with_rc_with_warning(clsig->bases[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;i<nb_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(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;i<nb_quantities;i++){
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_inverse(tmp2,clsig->bases[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;i<shn->nb_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;i<shn->nb_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;i<shn->nb_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; i<clsig->nb_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; i<clsig->nb_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; i<nb_gen; 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; i<nb_gen; i++){
goto_cleanup_if_fail_with_rc_with_warning_openssl(ret[i+2] = BN_new());
BN_copy(ret[i+2],clsig->bases[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; i<nb_gen; 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; i<nb_gen; i++){
goto_cleanup_if_fail_with_rc_with_warning_openssl(ret[i+2] = BN_new());
BN_copy(ret[i+2],clsig->bases[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; i<clsig->nb_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; i<clsig->nb_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;
}

View File

@ -0,0 +1,551 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 <openssl/bn.h>
#include <openssl/rsa.h>
#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;i<nb_quantitiesC;i++){
goto_cleanup_if_fail_with_rc_with_warning(quantitiesC[i] != NULL,
CRYPTIC_CLSIG_MISSING_QUANTITIES);
goto_cleanup_if_fail_with_rc_with_warning(BN_num_bits(quantitiesC[i]) <= clsig->lg_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;i<nb_quantitiesC;i++){
goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->quantities[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;i<nb_quantitiesC;i++){
goto_cleanup_if_fail_with_rc_with_warning(quantitiesC[i] != NULL,
CRYPTIC_CLSIG_MISSING_QUANTITIES);
goto_cleanup_if_fail_with_rc_with_warning(BN_num_bits(quantitiesC[i]) <= clsig->lg_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;i<nb_quantitiesC;i++){
goto_cleanup_if_fail_with_rc_with_warning_openssl(clsig->quantities[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;
}

View File

@ -0,0 +1,109 @@
/* X23 -- Certificates tools
* Copyright (C) 2010 Mikaël Ates <mates@entrouvert.com>
*
* 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 <glib.h>
#include <glib-object.h>
#include <stdio.h>
#include <string.h>
#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;
}

View File

@ -0,0 +1,75 @@
/* CRYPTIC -- Certificates tools
* Copyright (C) 2010 Mikaël Ates <mates@entrouvert.com>
*
* 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 <glib.h>
#include <glib-object.h>
#include <openssl/bn.h>
#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 */

View File

@ -0,0 +1,138 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 <openssl/bn.h>
#include <string.h>
#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<nb_quantities; j++){
goto_cleanup_if_fail(bases[j] != NULL);
goto_cleanup_if_fail(quantities[j] != NULL);
}
goto_cleanup_if_fail_with_rc_with_warning_openssl(ret = BN_new());
goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp = BN_new());
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(ret,1) == 1);
goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new());
for(j=0; j<nb_quantities; j++){
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_exp(tmp,bases[j],quantities[j],modulus,ctx) == 1);
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_mul(ret,ret,tmp,modulus,ctx) == 1);
}
rc = CRYPTIC_NO_ERROR;
cleanup:
cryptic_release_ctx(ctx);
cryptic_release_bn(tmp);
if(rc != CRYPTIC_NO_ERROR){
cryptic_release_bn(ret);
return NULL;
}
return ret;
}
BIGNUM* cryptic_inv_mod(BIGNUM* value, BIGNUM* modulus)
{
int rc = CRYPTIC_ERROR_UNDEFINED;
if(!modulus || !value) return NULL;
BIGNUM *ret = NULL, *tmp = 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(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(BN_gcd(tmp, modulus, value, ctx) == 1);
goto_cleanup_if_fail(BN_ucmp(tmp, BN_value_one()) == 0); /* Not inversible */
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_mod_inverse(ret,value,modulus,ctx));
rc = CRYPTIC_NO_ERROR;
cleanup:
cryptic_release_ctx(ctx);
cryptic_release_bn(tmp);
if(rc != CRYPTIC_NO_ERROR){
cryptic_release_bn(ret);
return NULL;
}
return ret;
}
int cryptic_cmp_bn(BIGNUM* value1, BIGNUM* value2)
{
if(!value1 || !value2) return -1;
if(BN_ucmp(value1,value2) == 0)
return 1;
else
return 0;
}
BIGNUM*
cryptic_char_to_bn(char* value)
{
if(!value || value[0]==0) return NULL;
BIGNUM *ret = NULL;
if(!(ret = BN_new())) return NULL;
BN_bin2bn((const unsigned char *) value,strlen(value),ret);
return ret;
}
BIGNUM*
cryptic_int_to_bn(int value)
{
int rc = CRYPTIC_ERROR_UNDEFINED;
BIGNUM *ret = NULL;
goto_cleanup_if_fail_with_rc_with_warning_openssl(ret = BN_new());
if(value < 0){
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(ret,abs(value)) == 1);
BN_set_negative(ret,1);
}else{
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(ret,value) == 1);
}
rc = CRYPTIC_NO_ERROR;
cleanup:
if(rc != CRYPTIC_NO_ERROR){
cryptic_release_bn(ret);
return NULL;
}
return ret;
}

View File

@ -0,0 +1,43 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 <openssl/bn.h>
#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 */

View File

@ -0,0 +1,614 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2010 Mikaël Ates <mates@entrouvert.com>
*
* 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 <stdio.h>
#include <glib.h>
#include <glib-object.h>
#include <openssl/bn.h>
#include <openssl/sha.h>
#include <openssl/evp.h>
#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;i<h->nb_modulus;i++){
cryptic_release_bn(h->modulus[i]);
}
}
cryptic_release(h->modulus);
if(h->bases != NULL) {
for(i=0;i<h->nb_bases;i++){
cryptic_release_bn(h->bases[i]);
}
}
cryptic_release(h->bases);
if(h->dlreps != NULL) {
for(i=0;i<h->nb_dlreps;i++){
cryptic_release_bn(h->dlreps[i]);
}
}
cryptic_release(h->dlreps);
if(h->commitments != NULL) {
for(i=0;i<h->nb_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;i<shn->nb_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;i<h->nb_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;i<h->nb_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;i<h->nb_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;i<h->nb_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;i<h->nb_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;i<h->nb_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;i<h->nb_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;i<h->nb_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;
}

View File

@ -0,0 +1,95 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 <glib.h>
#include <glib-object.h>
#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 */

View File

@ -0,0 +1,745 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 <stdio.h>
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include <openssl/bn.h>
#include <openssl/evp.h>
#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;i<shn->nb_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;i<nb_quantities;i++){
shn->bases[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;j<size_hash;j++){
for(i=0;i<shn->nb_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<<z;
y=t&k;
if(y!=0){ //ci = 2^i
BN_set_word(exp,(j*8)+z);
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_exp(c,two,exp,ctx) == 1);
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_add(count,count,c) == 1);
for(i=0;i<shn->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;i<shn->nb_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;i<shn->nb_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;i<shn->nb_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;i<shn->nb_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;i<shn->nb_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;i<shn->nb_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;i<shn->nb_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;j<size_hash;j++){
for(i=0;i<shn->nb_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;i<shn->nb_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;i<shn->nb_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;
}

View File

@ -0,0 +1,114 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 <glib.h>
#include <glib-object.h>
#include <openssl/bn.h>
#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 */

View File

@ -0,0 +1,934 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2010 Mikaël Ates <mates@entrouvert.com>
*
* 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 <stdio.h>
#include <glib.h>
#include <glib-object.h>
#include <openssl/bn.h>
#include <openssl/bio.h>
#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_SEC_PARAM){
lg_sec_param = CRYPTIC_PROOF_RANGE_TEST_SEC_PARAM;
}
if(lg_zk_sec_param<CRYPTIC_PROOF_RANGE_TEST_ZK_SEC_PARAM){
lg_zk_sec_param = CRYPTIC_PROOF_RANGE_TEST_ZK_SEC_PARAM;
}
goto_cleanup_if_fail_with_rc_with_warning(lg_challenge >= 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);
}
}

View File

@ -0,0 +1,184 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 <glib.h>
#include <glib-object.h>
#include <openssl/bn.h>
#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: <describe>
* @dLRepDelta: dlrep Delta (Td)
* @tabRandDLRepSqrRoot: random to dlrep the square roots of Delta
* @tabDLRepSqrRoot: dlrep of the square roots of Delta (Ti)
* @randQ: <describe>
* @Q: <describe>
* @challenge: <describe>
* @tabBases: e.g. S and Z for CLSIG
* @responserho: <describe>
* @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: <describe>
* @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 */

533
cryptic/utils.h Normal file
View File

@ -0,0 +1,533 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 <glib.h>
#include <openssl/bn.h>
#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 */

92
cryptic/utils/print.c Normal file
View File

@ -0,0 +1,92 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 <stdio.h>
#include <openssl/bn.h>
#include <openssl/err.h>
#include <openssl/bio.h>
//#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;i<clsig->nb_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;
}

32
cryptic/utils/print.h Normal file
View File

@ -0,0 +1,32 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 <openssl/bn.h>
#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

1
gtk-doc.make Symbolic link
View File

@ -0,0 +1 @@
/usr/share/gtk-doc/data/gtk-doc.notmpl.make

147
m4/ac_check_class.m4 Normal file
View File

@ -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 <bortzmeyer@pasteur.fr>
#
# 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)
])

63
m4/ac_check_classpath.m4 Normal file
View File

@ -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 <bortzmeyer@pasteur.fr>
#
# 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
])

62
m4/ac_check_java_home.m4 Normal file
View File

@ -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 <gleensalmon@yahoo.com>
#
# 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
])

69
m4/ac_check_junit.m4 Normal file
View File

@ -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 <luc@spaceroots.org>
#
# 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)])

65
m4/ac_check_rqrd_class.m4 Normal file
View File

@ -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 <bortzmeyer@pasteur.fr>
#
# 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
])

46
m4/ac_java_options.m4 Normal file
View File

@ -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 <ktohg@tritarget.com>
#
# 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
])

52
m4/ac_prog_jar.m4 Normal file
View File

@ -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 <e.willighagen@science.ru.nl>
#
# 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
])

122
m4/ac_prog_java.m4 Normal file
View File

@ -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
# <http://www.internatif.org/bortzmeyer/autoconf-Java/>.
#
# 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 <bortzmeyer@pasteur.fr>
#
# 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
])

107
m4/ac_prog_java_cc.m4 Normal file
View File

@ -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 <nferrier@tapsellferrier.co.uk>
#
# 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

137
m4/ac_prog_java_works.m4 Normal file
View File

@ -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 <bortzmeyer@pasteur.fr>
#
# 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
]
)

84
m4/ac_prog_javac.m4 Normal file
View File

@ -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 <bortzmeyer@pasteur.fr>
#
# 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
])

75
m4/ac_prog_javac_works.m4 Normal file
View File

@ -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 <bortzmeyer@pasteur.fr>
#
# 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
])

53
m4/ac_prog_javadoc.m4 Normal file
View File

@ -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 <e.willighagen@science.ru.nl>
#
# 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
])

43
m4/ac_prog_javah.m4 Normal file
View File

@ -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 <luc@spaceroots.org>
#
# 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 <jni.h>],,[
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 <jni.h>],
ac_save_CPPFLAGS="$CPPFLAGS",
AC_MSG_WARN([unable to include <jni.h>]))
CPPFLAGS="$ac_save_CPPFLAGS"])
else
true
fi])

53
m4/ac_try_compile_java.m4 Normal file
View File

@ -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 <ktohg@tritarget.com>
#
# 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*])

54
m4/ac_try_run_javac.m4 Normal file
View File

@ -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 <ktohg@tritarget.com>
#
# 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*])

62
m4/as-compiler-flag.m4 Normal file
View File

@ -0,0 +1,62 @@
dnl as-compiler-flag.m4 0.1.0
dnl autostars m4 macro for detection of compiler flags
dnl David Schleef <ds@schleef.org>
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"
])

133
m4/check.m4 Normal file
View File

@ -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 <stdio.h>
#include <stdlib.h>
#include <check.h>
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, &micro) != 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 <stdio.h>
#include <stdlib.h>
#include <check.h>
], , [ 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
])

View File

@ -0,0 +1,89 @@
##### http://autoconf-archive.cryp.to/dps_java_check_class.html
#
# SYNOPSIS
#
# DPS_JAVA_CHECK_CLASS(<class>,<action-if-found>,<action-if-not-found>)
#
# 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 <class>.
# 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 <dps@simpson.demon.co.uk>
#
# 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])

86
m4/dps_libgcj_jar.m4 Normal file
View File

@ -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 <dps@simpson.demon.co.uk>
#
# 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
])

71
m4/dps_xtra_classpath.m4 Normal file
View File

@ -0,0 +1,71 @@
##### http://autoconf-archive.cryp.to/dps_xtra_classpath.html
#
# SYNOPSIS
#
# DPS_XTRA_CLASSPATH(<classpath>,<class>,<jarfile>,<action-if-found>,<action-if-not-found>)
#
# 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 <dps@simpson.demon.co.uk>
#
# 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
])

1
m4/gtk-doc.m4 Symbolic link
View File

@ -0,0 +1 @@
/usr/share/aclocal/gtk-doc.m4

7377
m4/libtool.m4 vendored Normal file

File diff suppressed because it is too large Load Diff

368
m4/ltoptions.m4 vendored Normal file
View File

@ -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])])

123
m4/ltsugar.m4 vendored Normal file
View File

@ -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
])

23
m4/ltversion.m4 vendored Normal file
View File

@ -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)
])

92
m4/lt~obsolete.m4 vendored Normal file
View File

@ -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])])

17
tests/Makefile.am Normal file
View File

@ -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

870
tests/tests.c Normal file
View File

@ -0,0 +1,870 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2009 Mikaël Ates <mates@entrouvert.com>
*
* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include <openssl/bn.h>
#include <openssl/rsa.h>
#include <openssl/sha.h>
#include <openssl/dsa.h>
#include <openssl/evp.h>
#include <openssl/crypto.h>
#include <openssl/bio.h>
#include <openssl/rand.h>
#include <openssl/err.h>
#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<nb_messages+2; j++){
tab_gene[j] = NULL;
tab_qty[j] = NULL;
}
BN_CTX *ctx = NULL;
goto_cleanup_if_fail_with_rc_with_warning_openssl(b = BN_new());
goto_cleanup_if_fail_with_rc_with_warning_openssl(m = BN_new());
goto_cleanup_if_fail_with_rc_with_warning_openssl(random_m = BN_new());
goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp1 = BN_new());
goto_cleanup_if_fail_with_rc_with_warning_openssl(challenge = BN_new());
//goto_cleanup_if_fail_with_rc_with_warning_openssl(P = BN_new());
for(j=0; j<nb_messages+2; j++){
goto_cleanup_if_fail_with_rc_with_warning_openssl(tab_gene[j] = BN_new());
goto_cleanup_if_fail_with_rc_with_warning_openssl(tab_qty[j] = BN_new());
}
goto_cleanup_if_fail_with_rc_with_warning_openssl(ctx = BN_CTX_new());
str[0]="Gui";
printf("PRENOM:\t\t\t%s\n",str[0]);
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_bin2bn((const unsigned char *) str[0],strlen(str[0]),tab_qty[0]));
cryptic_check_good_rc(cryptic_print_bn("\t\t\t",tab_qty[0]));
str[1]="Montag";
printf("NOM:\t\t\t%s\n",str[1]);
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_bin2bn((const unsigned char *) str[1],strlen(str[1]),tab_qty[1]));
cryptic_check_good_rc(cryptic_print_bn("\t\t\t",tab_qty[1]));
str[2]="1950010100";
printf("DATE DE NAISSANCE:\t%s\n",str[2]);
//Put an int not a string!
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(m,1982012803) == 1);
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_qty[2],m));
cryptic_check_good_rc(cryptic_print_bn("\t\t\t",tab_qty[2]));
str[3]="unknown";
printf("LIEU DE NAISSANCE:\t%s\n",str[3]);
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_bin2bn((const unsigned char *) str[3],strlen(str[3]),tab_qty[3]));
cryptic_check_good_rc(cryptic_print_bn("\t\t\t",tab_qty[3]));
str[4]="Fahrenheit";
printf("ADRESSE:\t\t%s\n",str[4]);
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_bin2bn((const unsigned char *) str[4],strlen(str[4]),tab_qty[4]));
cryptic_check_good_rc(cryptic_print_bn("\t\t\t",tab_qty[4]));
printf("\n\n1. *** ISSUER\n");
printf("\n----> \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;i<nb_messages+2;i++){
cryptic_release_bn(tab_gene[i]);
cryptic_release_bn(tab_qty[i]);
}
cryptic_release_bn(tmp1);
cryptic_release_bn(P);
cryptic_release_bn(m);
cryptic_release_bn(b);
cryptic_release_bn(challenge);
cryptic_release_bn(random_m);
return rc;
}
int test_3(){
int rc = CRYPTIC_ERROR_UNDEFINED;
printf("\n");
printf("------******------------------------------------------------------------------******------\n");
printf("------******------------------------------- NI ZKPK --------------------------******------\n");
printf("------******------------------------------------------------------------------******------\n\n");
int i;
CrypticPrimeOrderGroup *g = NULL;
CrypticZkpkSchnorr *shn1 = NULL, *shn2 = NULL;
CrypticHashForNiProofs *hash1 = NULL, *hash2 = NULL;
BIGNUM* tmp = NULL, *m = NULL, *dlrep = NULL;
BIGNUM *tab_qty[3];
BN_CTX *ctx = NULL;
BN_MONT_CTX *mont = NULL;
char* str[3];
for(i=0; i<3; i++){
tab_qty[i] = NULL;
str[i] = NULL;
}
goto_cleanup_if_fail_with_rc_with_warning_openssl(tmp = BN_new());
goto_cleanup_if_fail_with_rc_with_warning_openssl(m = BN_new());
goto_cleanup_if_fail_with_rc_with_warning_openssl(dlrep = BN_new());
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(dlrep,1));
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(tab_qty[2] = 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());
str[0]="Gui";
printf("PRENOM:\t\t\t%s\n",str[0]);
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_bin2bn((const unsigned char *) str[0],strlen(str[0]),tab_qty[0]));
cryptic_check_good_rc(cryptic_print_bn("\t\t\t",tab_qty[0]));
str[1]="Montag";
printf("NOM:\t\t\t%s\n",str[1]);
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_bin2bn((const unsigned char *) str[1],strlen(str[1]),tab_qty[1]));
cryptic_check_good_rc(cryptic_print_bn("\t\t\t",tab_qty[1]));
str[2]="1950010100";
printf("DATE DE NAISSANCE:\t%s\n",str[2]);
//Put an int not a string!
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_set_word(m,1982012803) == 1);
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_copy(tab_qty[2],m));
cryptic_check_good_rc(cryptic_print_bn("\t\t\t",tab_qty[2]));
g = cryptic_prime_order_group_new(512); //TODO: Why 345 sometimes fails?
goto_cleanup_if_fail_with_warning(g != NULL);
goto_cleanup_if_fail_with_rc_with_warning_openssl(BN_MONT_CTX_set(mont,g->p,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);
}