From 82b57dd058ee46b12789783c3097874f4df4e906 Mon Sep 17 00:00:00 2001 From: Douglas Wikstrom Date: Wed, 14 Feb 2018 21:50:59 +0100 Subject: [PATCH] Initial commit to GitHub and licensed under AGPL. --- .macros.m4 | 8 + .version.m4 | 2 + AUTHORS | 5 + COPYING | 661 ++++++++++++++++++ ChangeLog | 5 + Makefile.am | 230 ++++++ Makefile.build | 49 ++ NEWS | 2 + README | 107 +++ README_DEV | 85 +++ configure.ac | 43 ++ native/.macros.m4 | 8 + native/.version.m4 | 2 + native/INSTALL | 370 ++++++++++ native/Makefile.am | 46 ++ native/Makefile.build | 43 ++ native/com_verificatum_vmgj_VMG.c | 467 +++++++++++++ native/configure.ac | 99 +++ native/convert.c | 128 ++++ native/convert.h | 52 ++ native/extract_GMP_CFLAGS.c | 29 + native/m4src/ace_prog_javac.m4 | 27 + native/m4src/ax_jni_include_dir.m4 | 116 +++ src/bin/vmgj-info.src | 38 + src/java/com/verificatum/vmgj/BenchVMG.java | 280 ++++++++ src/java/com/verificatum/vmgj/FpowmTab.java | 110 +++ .../com/verificatum/vmgj/MillerRabin.java | 156 +++++ src/java/com/verificatum/vmgj/TestVMG.java | 437 ++++++++++++ src/java/com/verificatum/vmgj/VMG.magic | 299 ++++++++ .../com/verificatum/vmgj/package-info.java | 27 + src/m4/ac_check_class.m4 | 141 ++++ src/m4/ac_check_classpath.m4 | 57 ++ src/m4/ac_check_java_home.m4 | 56 ++ src/m4/ac_check_rqrd_class.m4 | 59 ++ src/m4/ac_java_options.m4 | 44 ++ src/m4/ac_prog_jar.m4 | 48 ++ src/m4/ac_prog_java.m4 | 113 +++ src/m4/ac_prog_java_works.m4 | 131 ++++ src/m4/ac_prog_javac_works.m4 | 69 ++ src/m4/ac_prog_javadoc.m4 | 49 ++ src/m4/ac_prog_javah.m4 | 39 ++ src/m4/ac_try_compile_java.m4 | 51 ++ src/m4/ac_try_run_javac.m4 | 52 ++ src/m4/ace_check_jvmg.m4 | 32 + src/m4/ace_prog_jar.m4 | 27 + src/m4/ace_prog_java.m4 | 27 + src/m4/ace_prog_javac.m4 | 27 + src/m4/ace_prog_javadoc.m4 | 27 + src/m4/ace_prog_javah.m4 | 27 + src/m4/dps_check_plugin.m4 | 98 +++ src/m4/dps_java_check_class.m4 | 82 +++ src/mf/MANIFEST.MF.src | 7 + .../checkstyle/checkstyle_configure.xml | 212 ++++++ .../checkstyle/checkstyle_filter.sh | 26 + .../checkstyle/checkstyle_ruleset.xml | 337 +++++++++ .../checkstyle/checkstyle_suppressions.xml | 90 +++ .../checkstyle/checkstyle_wrapper | 26 + .../findbugs/findbugs_configure.xml | 5 + .../staticanalysis/findbugs/findbugs_wrapper | 21 + tools/staticanalysis/generate_analysis.sh | 46 ++ tools/staticanalysis/pmd/pmd_filter.sh | 24 + tools/staticanalysis/pmd/pmd_ruleset.xml | 369 ++++++++++ tools/staticanalysis/pmd/pmd_wrapper | 56 ++ 63 files changed, 6406 insertions(+) create mode 100644 .macros.m4 create mode 100644 .version.m4 create mode 100644 AUTHORS create mode 100644 COPYING create mode 100644 ChangeLog create mode 100644 Makefile.am create mode 100644 Makefile.build create mode 100644 NEWS create mode 100644 README create mode 100644 README_DEV create mode 100644 configure.ac create mode 100644 native/.macros.m4 create mode 100644 native/.version.m4 create mode 100644 native/INSTALL create mode 100644 native/Makefile.am create mode 100644 native/Makefile.build create mode 100644 native/com_verificatum_vmgj_VMG.c create mode 100644 native/configure.ac create mode 100644 native/convert.c create mode 100644 native/convert.h create mode 100644 native/extract_GMP_CFLAGS.c create mode 100644 native/m4src/ace_prog_javac.m4 create mode 100644 native/m4src/ax_jni_include_dir.m4 create mode 100644 src/bin/vmgj-info.src create mode 100644 src/java/com/verificatum/vmgj/BenchVMG.java create mode 100644 src/java/com/verificatum/vmgj/FpowmTab.java create mode 100644 src/java/com/verificatum/vmgj/MillerRabin.java create mode 100644 src/java/com/verificatum/vmgj/TestVMG.java create mode 100644 src/java/com/verificatum/vmgj/VMG.magic create mode 100644 src/java/com/verificatum/vmgj/package-info.java create mode 100644 src/m4/ac_check_class.m4 create mode 100644 src/m4/ac_check_classpath.m4 create mode 100644 src/m4/ac_check_java_home.m4 create mode 100644 src/m4/ac_check_rqrd_class.m4 create mode 100644 src/m4/ac_java_options.m4 create mode 100644 src/m4/ac_prog_jar.m4 create mode 100644 src/m4/ac_prog_java.m4 create mode 100644 src/m4/ac_prog_java_works.m4 create mode 100644 src/m4/ac_prog_javac_works.m4 create mode 100644 src/m4/ac_prog_javadoc.m4 create mode 100644 src/m4/ac_prog_javah.m4 create mode 100644 src/m4/ac_try_compile_java.m4 create mode 100644 src/m4/ac_try_run_javac.m4 create mode 100644 src/m4/ace_check_jvmg.m4 create mode 100644 src/m4/ace_prog_jar.m4 create mode 100644 src/m4/ace_prog_java.m4 create mode 100644 src/m4/ace_prog_javac.m4 create mode 100644 src/m4/ace_prog_javadoc.m4 create mode 100644 src/m4/ace_prog_javah.m4 create mode 100644 src/m4/dps_check_plugin.m4 create mode 100644 src/m4/dps_java_check_class.m4 create mode 100644 src/mf/MANIFEST.MF.src create mode 100644 tools/staticanalysis/checkstyle/checkstyle_configure.xml create mode 100755 tools/staticanalysis/checkstyle/checkstyle_filter.sh create mode 100644 tools/staticanalysis/checkstyle/checkstyle_ruleset.xml create mode 100644 tools/staticanalysis/checkstyle/checkstyle_suppressions.xml create mode 100755 tools/staticanalysis/checkstyle/checkstyle_wrapper create mode 100644 tools/staticanalysis/findbugs/findbugs_configure.xml create mode 100755 tools/staticanalysis/findbugs/findbugs_wrapper create mode 100755 tools/staticanalysis/generate_analysis.sh create mode 100755 tools/staticanalysis/pmd/pmd_filter.sh create mode 100644 tools/staticanalysis/pmd/pmd_ruleset.xml create mode 100755 tools/staticanalysis/pmd/pmd_wrapper diff --git a/.macros.m4 b/.macros.m4 new file mode 100644 index 0000000..c40701f --- /dev/null +++ b/.macros.m4 @@ -0,0 +1,8 @@ +dnl +dnl The triple is called "major", "minor", and "micro". Bump the major +dnl version every time there is an interface-altering rework of the +dnl library. The minor version should alternate between even (for stable +dnl releases) and odd (for development releases). Finally, bump the micro +dnl version every time you do a release of the software. +dnl +define(VMGJ_VERSION_STRING, 1.2.1)dnl diff --git a/.version.m4 b/.version.m4 new file mode 100644 index 0000000..4e96c22 --- /dev/null +++ b/.version.m4 @@ -0,0 +1,2 @@ +include(`.macros.m4')dnl +VMGJ_VERSION_STRING \ No newline at end of file diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..612e115 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,5 @@ +Authors of VMGJ (in chronological order of initial contribution) + +Douglas Wikström Main author + + diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..be3f7b2 --- /dev/null +++ b/COPYING @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + 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 +them 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. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If 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 convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero 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 +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..b7ef125 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,5 @@ + +2018-02-02 Douglas Wikstrom + + * Version 1.2.1 Licensed under AGPL. + diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..3b1eabd --- /dev/null +++ b/Makefile.am @@ -0,0 +1,230 @@ + +# Copyright 2008-2018 Douglas Wikstrom +# +# This file is part of Verificatum Multiplicative Groups library for +# Java (VMGJ). +# +# VMGJ is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# VMGJ 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 Affero General +# Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with VMGJ. If not, see . + +.PHONY: clean cleandoc + +ACLOCAL_AMFLAGS=-I m4 + + +##################### Variables used by Automake ############################ + +# Installation directory of jar files. +jardir = $(datadir)/java + +# Distribution file. +distfile = $(PACKAGE)-$(VERSION).tar.gz + + +########################## Custom variables ################################# + +CWD = $(shell pwd) +SRC = src +PKGPATH = $(SRC)/java +MFSRC = $(SRC)/mf +JHDROUT = native +BINDIR = bin +JARFILE = $(PACKAGE)-$(VERSION).jar +VMGJ_JAR = $(jardir)/$(JARFILE) +CLASSESROOT = classes +CLASSPATH := $(CLASSESROOT) +SRC_BINDIR = $(SRC)/bin +NATLIBS = $(CWD)/native/.libs + +# Code analysis +STATANA = tools/staticanalysis +CSDIR = $(STATANA)/checkstyle +FBDIR = $(STATANA)/findbugs +PMDDIR = $(STATANA)/pmd + +# Coverage analysis. +COVERAGE = $(CWD)/tools/coverage +JCOVDIR = $(COVERAGE)/jcov +COBDIR = $(COVERAGE)/cobertura + +# Variables pointing to external resources. +GMPMEE_VERSION = $(shell gmpmee-info version) +JCOVJARDIR = $(HOME)/jcov_2.0 +COBHOME = $(HOME)/cobertura-2.1.1 +COBCLASSPATH=$(shell find $(COBHOME) | grep "\.jar" | grep -E "cobertura.*/cobertura-[^-]*\.jar|asm-|slf4j-|logback-|oro-"| tr "\n" ":") +JDK_DOC = "http://docs.oracle.com/javase/8/docs/api" + +# Java sources. +JAVA_FILES := $(PKGPATH)/com/verificatum/vmgj/VMG.java \ +$(PKGPATH)/com/verificatum/vmgj/TestVMG.java \ +$(PKGPATH)/com/verificatum/vmgj/BenchVMG.java \ +$(PKGPATH)/com/verificatum/vmgj/FpowmTab.java \ +$(PKGPATH)/com/verificatum/vmgj/MillerRabin.java + + +########################### Compilation ##################################### + +all: .headers.stamp + +$(PKGPATH)/com/verificatum/vmgj/VMG.java: $(PKGPATH)/com/verificatum/vmgj/VMG.magic scriptmacros.m4 + cat scriptmacros.m4 $(PKGPATH)/com/verificatum/vmgj/VMG.magic | m4 > $(PKGPATH)/com/verificatum/vmgj/VMG.java + +# Create the destination directory. +.classesroot.stamp: + mkdir -p $(CLASSESROOT) + @touch .classesroot.stamp + +# Jar manifest generated with current version. +$(CLASSESROOT)/MANIFEST.MF: $(MFSRC)/MANIFEST.MF.src + cat .macros.m4 $(MFSRC)/MANIFEST.MF.src | m4 > $(CLASSESROOT)/MANIFEST.MF + +# Compile Java sources. +.classes.stamp: .classesroot.stamp $(JAVA_FILES) + $(JAVAC) -Xlint:unchecked $(AM_JAVACFLAGS) $(JAVACFLAGS) -d $(CLASSESROOT) $(JAVA_FILES) + @touch .classes.stamp + +# Build JAR file. +$(JARFILE): .classes.stamp $(CLASSESROOT)/MANIFEST.MF + cd $(CLASSESROOT); $(JAR) cfm $@ MANIFEST.MF com; cp $@ .. + +# Generate header files for native code. +.headers.stamp: $(JARFILE) + CLASSPATH=$(CLASSPATH) $(JAVAH) -jni -d $(JHDROUT) $(JAVAHFLAGS) com.verificatum.vmgj.VMG; + @touch .headers.stamp + +scriptmacros.m4: + @printf "define(M4_VERSION, $(VERSION))dnl\n" > scriptmacros.m4 + @printf "define(M4_GMPMEE_VERSION, $(GMPMEE_VERSION))dnl\n" >> scriptmacros.m4 + @printf "define(M4_BINDIR, $(bindir))dnl\n" >> scriptmacros.m4 + @printf "define(M4_LIBDIR, $(libdir))dnl\n" >> scriptmacros.m4 + @printf "define(M4_VMGJ_JAR, $(VMGJ_JAR))dnl\n" >> scriptmacros.m4 + +$(BINDIR)/vmgj-$(VERSION)-info: scriptmacros.m4 $(SRC_BINDIR)/vmgj-info.src + mkdir -p $(BINDIR) + cat scriptmacros.m4 $(SRC_BINDIR)/vmgj-info.src | m4 > $(BINDIR)/vmgj-$(VERSION)-info + chmod +x $(BINDIR)/vmgj-$(VERSION)-info + +# Variables with special meaning in Autotools. +SUBDIRS = . native + +# Variables that determines which files are part of the distribution +# and how they are installed. +jar_DATA = $(JARFILE) +dist_noinst_DATA = $(SRC) README COPYING NEWS AUTHORS ChangeLog .version.m4 .macros.m4 +dist_bin = $(BINDIR)/vmgj-$(VERSION)-info +dist_bin_SCRIPTS = $(BINDIR)/vmgj-$(VERSION)-info + + +########################## Static analysis ################################## + +# Edit the wrappers in the subdirectories of $(STATANA) if needed. + +# Do a Checkstyle analysis of the source and save the result in +# $(CSDIR)/checkstyle_report.txt. +checkstyle: $(CSDIR)/checkstyle_report.txt $(CSDIR)/checkstyle_filter.sh +$(CSDIR)/checkstyle_report.txt: .headers.stamp + rm -f $(CSDIR)/checkstyle_report_tmp.txt + cd $(CSDIR); ./checkstyle_wrapper checkstyle_configure.xml checkstyle_raw_report.txt $(CWD)/$(PKGPATH); ./checkstyle_filter.sh checkstyle_raw_report.txt checkstyle_report.txt + +# Do a Findbugs analysis of the jar and save the result in +# $(FBDIR)/findbugs_report.txt. +findbugs: $(FBDIR)/findbugs_report.txt +$(FBDIR)/findbugs_report.txt: .headers.stamp + ./$(FBDIR)/findbugs_wrapper -textui -exclude $(FBDIR)/findbugs_configure.xml $(JARFILE) > $(FBDIR)/findbugs_report.txt + +# Do a PMD analysis of the source and save the result in +# $(PMDDIR)/pmd_report.txt. PMD does not provide any proper way of +# installation. The $(PMDDIR)/pmd_wrapper tries to find the directory +# named pmd-bin-?-?-? for the most recent version. If no such +# directory exists, then it tries the same in the home directory. Edit +# the wrapper if needed. +pmd: $(PMDDIR)/pmd_report.txt +$(PMDDIR)/pmd_report.txt: .headers.stamp + ./$(PMDDIR)/pmd_wrapper -rulesets $(PMDDIR)/pmd_ruleset.xml -d $(PKGPATH) | sed "s/.*verificatum\/\(com\/verificatum.*\)/\1/p" | uniq > $(PMDDIR)/pmd_raw_report.txt + cd $(PMDDIR); ./pmd_filter.sh pmd_raw_report.txt pmd_report.txt + +# Execute all static analyzers. +analysis: checkstyle findbugs pmd $(STATANA)/generate_analysis.sh + cd $(STATANA); ./generate_analysis.sh + cat $(STATANA)/analysis_report.txt + + +########################## Coverage analysis ################################ + +# Set JCOVJARDIR above to use this. +jcov: .headers.stamp + mkdir -p $(JCOVDIR) + cd $(JCOVDIR); rm -f filtered.xml + cp $(JARFILE) $(JCOVDIR)/ + cd $(JCOVDIR); java -jar $(JCOVJARDIR)/jcov.jar Instr -t template.xml -e com.verificatum.vmgj.TestVMG -e com.verificatum.vmgj.BenchVMG -field on -native off $(JARFILE) + cd $(JCOVDIR); java -ea -Djava.library.path=$(NATLIBS):$(libdir) -classpath $(JCOVJARDIR)/jcov_file_saver.jar:$(JARFILE) com.verificatum.vmgj.TestVMG 1024 + cd $(JCOVDIR); java -jar $(JCOVJARDIR)/jcov.jar RepGen result.xml + +# Set COBHOME above to use this. A recent version is required. After +# downloading Cobertura you need to convert the .sh files to Unix +# format with dos2unix and make them executable before running. +cobertura: .headers.stamp + rm -rf $(COBDIR) + rm -f cobertura.ser + mkdir -p $(COBDIR)/classes + $(COBHOME)/cobertura-instrument.sh --ignore "java.lang.Error" --destination $(COBDIR)/classes $(CLASSESROOT)/com/verificatum/vmgj/VMG.class $(CLASSESROOT)/com/verificatum/vmgj/FpowmTab.class $(CLASSESROOT)/com/verificatum/vmgj/MillerRabin.class + java -ea -Djava.library.path=$(NATLIBS):$(libdir) -classpath $(COBCLASSPATH):$(COBDIR)/classes:$(CLASSESROOT) com.verificatum.vmgj.TestVMG 1024 + $(COBHOME)/cobertura-report.sh --srcdir /home/dog/verificatum/vmgj/src/java/ --destination $(COBDIR)/report --format html $(COBDIR)/classes + +coverage: jcov cobertura + + +########################### Usage targets ################################### + +check: .headers.stamp + @java -ea -Djava.library.path=$(NATLIBS):$(libdir) -classpath $(JARFILE):$(jardir)/$(JARFILE) com.verificatum.vmgj.TestVMG + +bench: .headers.stamp + @java -Djava.library.path=$(NATLIBS):$(libdir) -classpath $(JARFILE):$(jardir)/$(JARFILE) com.verificatum.vmgj.BenchVMG + +api: .headers.stamp + rm -rf api + javadoc -d api -link $(JDK_DOC) $(JAVA_FILES) + + +########################## Cleaning targets ################################# + +# Autoconf variable for files to be cleaned. +CLEANFILES = .*.stamp $(JARFILE) $(distfile) $(JHDROUT)/com_verificatum_vmgj_VMG.h scriptmacros.m4 $(PKGPATH)/com/verificatum/vmgj/VMG.java + +cleanapi: + rm -rf api .libs + +cleancheckstyle: + rm -rf $(CSDIR)/checkstyle_raw_report.txt $(CSDIR)/checkstyle_report.txt + +cleanfindbugs: + rm -rf $(FBDIR)/findbugs_report.txt + +cleanpmd: + rm -rf $(PMDDIR)/pmd_report.txt $(PMDDIR)/pmd_raw_report.txt + +cleananalysis: cleancheckstyle cleanfindbugs cleanpmd + rm -rf $(STATANA)/analysis_report.txt + +cleanjcov: + rm -rf $(JCOVDIR) + +cleancobertura: + rm -rf $(COBDIR) cobertura.ser + +cleancoverage: cleanjcov cleancobertura + +clean-local: cleanapi cleananalysis cleancoverage + find . -name "*~" -delete + rm -rf report result.xml template.xml $(CLASSESROOT) compile $(BINDIR)/vmgj-$(VERSION)-info diff --git a/Makefile.build b/Makefile.build new file mode 100644 index 0000000..757bab4 --- /dev/null +++ b/Makefile.build @@ -0,0 +1,49 @@ + +# Copyright 2008-2018 Douglas Wikstrom +# +# This file is part of Verificatum Multiplicative Groups library for +# Java (VMGJ). +# +# VMGJ is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# VMGJ 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 Affero General +# Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with VMGJ. If not, see . + +# Two files define the build-process of this package: +# +# configure.ac and Makefile.am + +.PHONY: clean dist + +all: .build.bstamp +.build.bstamp: + cp COPYING NEWS README AUTHORS ChangeLog .macros.m4 .version.m4 native/ + $(MAKE) -C native -f Makefile.build + mkdir -p m4 + cp src/m4/* m4/ + aclocal -I m4 + autoconf + automake --add-missing --force-missing --copy + @touch .build.bstamp + +dist: .build.bstamp + ./configure --disable-check_gmpmee + $(MAKE) dist + +api: .build.bstamp + ./configure --disable-check_gmpmee + $(MAKE) api + +clean: + -$(MAKE) clean + $(MAKE) -C native -f Makefile.build clean + @find . -name "*~" -delete + @rm -rf aclocal.m4 autom4te.cache config.guess config.h config.h.in config.log config.status config.sub configure depcomp install-sh libtool ltmain.sh m4 Makefile.in Makefile missing stamp-h1 INSTALL confdefs.h conftest.tar configure.lineno vmgj-*.tar.gz *.bstamp .*.bstamp *.stamp diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..1d90852 --- /dev/null +++ b/NEWS @@ -0,0 +1,2 @@ + +Please see https://www.verificatum.org for news. diff --git a/README b/README new file mode 100644 index 0000000..be3b23b --- /dev/null +++ b/README @@ -0,0 +1,107 @@ + + + VERIFICATUM MULTIPLICATIVE GROUPS LIBRARY FOR JAVA (VMGJ) + + +This package allows invoking GMP's modular exponentiation, including +the extension provided by the GMP Modular Exponentiation Extension +package (GMPMEE) for simultaneous or fixed base modular exponentiation +and primality testing, from within a Java application. This +drastically improves the speed of such operations compared to pure +Java implementations. + +The following assumes that you are using a release. Developers should +also read README_DEV. + + + QUICK START + + $ ./configure; make; sudo make install + + + BUILDING + +The source consists of both Java and C code. The Java source +essentially provides a wrapper of the functionality implemented in C +on top of GMP using Java Native Interface (JNI). + +You also need to build and install the GMPMEE package before building +this package. The LIBRARY_PATH must point to libgmp.la and +libgmpmee.a and C_INCLUDE_PATH must point to gmp.h and gmpmee.h. This +is usually the case automatically after installing GMP and GMPMEE. + +The javah command also needs to find the header files (jni.h and +jni_md.h). The building scripts attempts to find these files +automatically, but if this fails you need to add their locations to +C_INCLUDE_PATH. + +Then use + + $ ./configure + $ make + +to build the library. + + + INSTALLING + +1) Use + + $ make install + + to install the library libvmgj-.{la,a,so} and the jar-file + verificatum-vmgj-.jar in the standard locations. See + INSTALL for details on other ways to invoke ./configure, e.g., to + use a user-local installation. + + +2) You should also make sure that the newly installed jar-file is + found by java by updating your CLASSPATH, e.g., on Ubuntu, you can + use something similar to the following snippet in your init script. + + export CLASSPATH=/usr/local/share/java/verificatum-vmgj-.jar:${CLASSPATH} + +3) You need to tell the JVM where your native library, i.e., + libvmgj-.{la,a,so} can be found. You may either pass the location + using the java.library.path property, e.g., + + $ java -Djava.library.path=/usr/local/lib/ + + or you can set the shell variable LD_LIBRARY_PATH once and for all + in an init file, e.g., + + export LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH} + +4) You can test if you managed to build correctly by executing: + + $ make check + + This runs a set of tests. + + + BENCHMARKS + +You can run a set of benchmarks using + + $ make bench + +Consult Makefile.am to see how these are invoked if you are interested +in customizing this for other security parameters. + + + API DOCUMENTATION + +You may use + + $ make api + +to invoke Javadoc to build the API. The API is not installed +anywhere. You can copy it to any location. + + + REPORTING BUGS + +Minor bugs should be reported in the repository system as issues or +bugs. Security critical bugs, vulnerabilities, etc should be reported +directly to Verificatum AB. We will make best effort to disclose the +information in a responsible way before the finder gets proper credit. diff --git a/README_DEV b/README_DEV new file mode 100644 index 0000000..71ec86d --- /dev/null +++ b/README_DEV @@ -0,0 +1,85 @@ + + + ADDITIONAL INFORMATION FOR DEVELOPERS + + +When you start from the actual repository source and not a +distribution you can use + + $ make -f Makefile.build + +to run the necessary libtool, autoconf, etc routines and copy a few +additional m4 scripts to the right place to put the directory in a +similar state to that of a distribution directory. Then you can run +the usual ./configure; make; sudo make install. + +If the state of the directory is messed up, then you can run + + $ make -f Makefile.build clean + +to do a brutal cleanup of everything. Yes, there are various clean +commands in Makefile, but this seems more robust and convenient when +developing. After this command "git status" should not list any magic +files. Finally, you can use + + $ make -f Makefile.build dist + +to build a distribution tar.gz-ball in a single command. This merely +sets up things and then runs the usual "make dist". + + + STATIC ANALYSIS + +We currently use three different static analyzers: Checkstyle, +FindBugs, and PMD. To encapsulate installation hazzle on some +platforms and adapt to changes, we use them through wrappers and +filters contained in subdirectories of the tools-directory. This is +also where their configuration files are found, and where reports go +when performing the analysis. + +You can either run a single tool, e.g., + + $ make checkstyle + +(or correspondingly with "findbugs" or "pmd") and your report will end +up in tools/staticanalysis/checkstyle/checkstyle_report.txt (or +similarly for FindBugs and PMD), or you can generate an aggregate +report using + + $ make analysis + +which ends up in tools/staticanalysis/analysis_report.txt. + +Any set of style rules is somewhat arbitrary, and there are silly +rules, but fixing any such problems only takes a couple of minutes and +makes it easier to identify real issues if the code is consistent. + +Real issues must either be resolved, or examined carefully and handled +using the rules or inline suppressions. + +We comment everything instead of thinking about what should be +commented and not. This makes it easy to verify that everything that +must be commented have been commented. Developers that find it +disturbing should fold comments in their editors. + + + COVERAGE ANALYSIS + +We use JCov and Cobertura for coverage analysis. These tools do not +provide proper installation packages, so you need to edit Makefile.am +to make sure that they are found. Then you can do + + $ make jcov + +and the resulting report is found in tools/coverage/jcov/report, and +correspondingly for Cobertura. You can do both using + + $ make coverage + +Keep in mind that coverage analysis is a blunt tool that should be +viewed as a way to identify portions of code that lack testing and not +as a confirmation that code covered by tests is tested properly. + +A number of things are correct to leave uncovered by tests. Examples +include: private constructors used to avoid accidental instantiation, +fatal errors, and trivial wrapper functions. diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..d9051c2 --- /dev/null +++ b/configure.ac @@ -0,0 +1,43 @@ + +# Copyright 2008-2018 Douglas Wikstrom +# +# This file is part of Verificatum Multiplicative Groups library for +# Java (VMGJ). +# +# VMGJ is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# VMGJ 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 Affero General +# Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with VMGJ. If not, see . + +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ([2.63]) +AC_INIT([verificatum-vmgj], + [m4_esyscmd([m4 .version.m4])], + [info@verificatum.com]) +AC_CANONICAL_SYSTEM # Must appear before AM_INIT_AUTOMAKE +AM_INIT_AUTOMAKE([tar-ustar -Wall -Werror -Wno-portability]) +AC_CONFIG_MACRO_DIR([m4]) + +# Checks for programs. +ACE_PROG_JAVA +ACE_PROG_JAVAC +ACE_PROG_JAVAH +ACE_PROG_JAR +ACE_PROG_JAVADOC + +AC_CONFIG_SUBDIRS([native]) + +AM_CONDITIONAL([BITS64], [test x`getconf LONG_BIT` = x64]) + +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/native/.macros.m4 b/native/.macros.m4 new file mode 100644 index 0000000..c40701f --- /dev/null +++ b/native/.macros.m4 @@ -0,0 +1,8 @@ +dnl +dnl The triple is called "major", "minor", and "micro". Bump the major +dnl version every time there is an interface-altering rework of the +dnl library. The minor version should alternate between even (for stable +dnl releases) and odd (for development releases). Finally, bump the micro +dnl version every time you do a release of the software. +dnl +define(VMGJ_VERSION_STRING, 1.2.1)dnl diff --git a/native/.version.m4 b/native/.version.m4 new file mode 100644 index 0000000..4e96c22 --- /dev/null +++ b/native/.version.m4 @@ -0,0 +1,2 @@ +include(`.macros.m4')dnl +VMGJ_VERSION_STRING \ No newline at end of file diff --git a/native/INSTALL b/native/INSTALL new file mode 100644 index 0000000..2099840 --- /dev/null +++ b/native/INSTALL @@ -0,0 +1,370 @@ +Installation Instructions +************************* + +Copyright (C) 1994-1996, 1999-2002, 2004-2013 Free Software Foundation, +Inc. + + 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. This file is offered as-is, +without warranty of any kind. + +Basic Installation +================== + + Briefly, the shell command `./configure && make && make install' +should configure, build, and install this package. The following +more-detailed instructions are generic; see the `README' file for +instructions specific to this package. Some packages provide this +`INSTALL' file but do not implement all of the features documented +below. The lack of an optional feature in a given package is not +necessarily a bug. More recommendations for GNU packages can be found +in *note Makefile Conventions: (standards)Makefile Conventions. + + The `configure' shell script attempts to guess correct values for +various system-dependent variables used during compilation. It uses +those values to create a `Makefile' in each directory of the package. +It may also create one or more `.h' files containing system-dependent +definitions. Finally, it creates a shell script `config.status' that +you can run in the future to recreate the current configuration, and a +file `config.log' containing compiler output (useful mainly for +debugging `configure'). + + It can also use an optional file (typically called `config.cache' +and enabled with `--cache-file=config.cache' or simply `-C') that saves +the results of its tests to speed up reconfiguring. Caching is +disabled by default to prevent problems with accidental use of stale +cache files. + + If you need to do unusual things to compile the package, please try +to figure out how `configure' could check whether to do them, and mail +diffs or instructions to the address given in the `README' so they can +be considered for the next release. If you are using the cache, and at +some point `config.cache' contains results you don't want to keep, you +may remove or edit it. + + The file `configure.ac' (or `configure.in') is used to create +`configure' by a program called `autoconf'. You need `configure.ac' if +you want to change it or regenerate `configure' using a newer version +of `autoconf'. + + The simplest way to compile this package is: + + 1. `cd' to the directory containing the package's source code and type + `./configure' to configure the package for your system. + + Running `configure' might take a while. While running, it prints + some messages telling which features it is checking for. + + 2. Type `make' to compile the package. + + 3. Optionally, type `make check' to run any self-tests that come with + the package, generally using the just-built uninstalled binaries. + + 4. Type `make install' to install the programs and any data files and + documentation. When installing into a prefix owned by root, it is + recommended that the package be configured and built as a regular + user, and only the `make install' phase executed with root + privileges. + + 5. Optionally, type `make installcheck' to repeat any self-tests, but + this time using the binaries in their final installed location. + This target does not install anything. Running this target as a + regular user, particularly if the prior `make install' required + root privileges, verifies that the installation completed + correctly. + + 6. You can remove the program binaries and object files from the + source code directory by typing `make clean'. To also remove the + files that `configure' created (so you can compile the package for + a different kind of computer), type `make distclean'. There is + also a `make maintainer-clean' target, but that is intended mainly + for the package's developers. If you use it, you may have to get + all sorts of other programs in order to regenerate files that came + with the distribution. + + 7. Often, you can also type `make uninstall' to remove the installed + files again. In practice, not all packages have tested that + uninstallation works correctly, even though it is required by the + GNU Coding Standards. + + 8. Some packages, particularly those that use Automake, provide `make + distcheck', which can by used by developers to test that all other + targets like `make install' and `make uninstall' work correctly. + This target is generally not run by end users. + +Compilers and Options +===================== + + Some systems require unusual options for compilation or linking that +the `configure' script does not know about. Run `./configure --help' +for details on some of the pertinent environment variables. + + You can give `configure' initial values for configuration parameters +by setting variables in the command line or in the environment. Here +is an example: + + ./configure CC=c99 CFLAGS=-g LIBS=-lposix + + *Note Defining Variables::, for more details. + +Compiling For Multiple Architectures +==================================== + + You can compile the package for more than one kind of computer at the +same time, by placing the object files for each architecture in their +own directory. To do this, you can use GNU `make'. `cd' to the +directory where you want the object files and executables to go and run +the `configure' script. `configure' automatically checks for the +source code in the directory that `configure' is in and in `..'. This +is known as a "VPATH" build. + + With a non-GNU `make', it is safer to compile the package for one +architecture at a time in the source code directory. After you have +installed the package for one architecture, use `make distclean' before +reconfiguring for another architecture. + + On MacOS X 10.5 and later systems, you can create libraries and +executables that work on multiple system types--known as "fat" or +"universal" binaries--by specifying multiple `-arch' options to the +compiler but only a single `-arch' option to the preprocessor. Like +this: + + ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ + CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ + CPP="gcc -E" CXXCPP="g++ -E" + + This is not guaranteed to produce working output in all cases, you +may have to build one architecture at a time and combine the results +using the `lipo' tool if you have problems. + +Installation Names +================== + + By default, `make install' installs the package's commands under +`/usr/local/bin', include files under `/usr/local/include', etc. You +can specify an installation prefix other than `/usr/local' by giving +`configure' the option `--prefix=PREFIX', where PREFIX must be an +absolute file name. + + You can specify separate installation prefixes for +architecture-specific files and architecture-independent files. If you +pass the option `--exec-prefix=PREFIX' to `configure', the package uses +PREFIX as the prefix for installing programs and libraries. +Documentation and other data files still use the regular prefix. + + In addition, if you use an unusual directory layout you can give +options like `--bindir=DIR' to specify different values for particular +kinds of files. Run `configure --help' for a list of the directories +you can set and what kinds of files go in them. In general, the +default for these options is expressed in terms of `${prefix}', so that +specifying just `--prefix' will affect all of the other directory +specifications that were not explicitly provided. + + The most portable way to affect installation locations is to pass the +correct locations to `configure'; however, many packages provide one or +both of the following shortcuts of passing variable assignments to the +`make install' command line to change installation locations without +having to reconfigure or recompile. + + The first method involves providing an override variable for each +affected directory. For example, `make install +prefix=/alternate/directory' will choose an alternate location for all +directory configuration variables that were expressed in terms of +`${prefix}'. Any directories that were specified during `configure', +but not in terms of `${prefix}', must each be overridden at install +time for the entire installation to be relocated. The approach of +makefile variable overrides for each directory variable is required by +the GNU Coding Standards, and ideally causes no recompilation. +However, some platforms have known limitations with the semantics of +shared libraries that end up requiring recompilation when using this +method, particularly noticeable in packages that use GNU Libtool. + + The second method involves providing the `DESTDIR' variable. For +example, `make install DESTDIR=/alternate/directory' will prepend +`/alternate/directory' before all installation names. The approach of +`DESTDIR' overrides is not required by the GNU Coding Standards, and +does not work on platforms that have drive letters. On the other hand, +it does better at avoiding recompilation issues, and works well even +when some directory options were not specified in terms of `${prefix}' +at `configure' time. + +Optional Features +================= + + If the package supports it, you can cause programs to be installed +with an extra prefix or suffix on their names by giving `configure' the +option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. + + Some packages pay attention to `--enable-FEATURE' options to +`configure', where FEATURE indicates an optional part of the package. +They may also pay attention to `--with-PACKAGE' options, where PACKAGE +is something like `gnu-as' or `x' (for the X Window System). The +`README' should mention any `--enable-' and `--with-' options that the +package recognizes. + + For packages that use the X Window System, `configure' can usually +find the X include and library files automatically, but if it doesn't, +you can use the `configure' options `--x-includes=DIR' and +`--x-libraries=DIR' to specify their locations. + + Some packages offer the ability to configure how verbose the +execution of `make' will be. For these packages, running `./configure +--enable-silent-rules' sets the default to minimal output, which can be +overridden with `make V=1'; while running `./configure +--disable-silent-rules' sets the default to verbose, which can be +overridden with `make V=0'. + +Particular systems +================== + + On HP-UX, the default C compiler is not ANSI C compatible. If GNU +CC is not installed, it is recommended to use the following options in +order to use an ANSI C compiler: + + ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" + +and if that doesn't work, install pre-built binaries of GCC for HP-UX. + + HP-UX `make' updates targets which have the same time stamps as +their prerequisites, which makes it generally unusable when shipped +generated files such as `configure' are involved. Use GNU `make' +instead. + + On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot +parse its `' header file. The option `-nodtk' can be used as +a workaround. If GNU CC is not installed, it is therefore recommended +to try + + ./configure CC="cc" + +and if that doesn't work, try + + ./configure CC="cc -nodtk" + + On Solaris, don't put `/usr/ucb' early in your `PATH'. This +directory contains several dysfunctional programs; working variants of +these programs are available in `/usr/bin'. So, if you need `/usr/ucb' +in your `PATH', put it _after_ `/usr/bin'. + + On Haiku, software installed for all users goes in `/boot/common', +not `/usr/local'. It is recommended to use the following options: + + ./configure --prefix=/boot/common + +Specifying the System Type +========================== + + There may be some features `configure' cannot figure out +automatically, but needs to determine by the type of machine the package +will run on. Usually, assuming the package is built to be run on the +_same_ architectures, `configure' can figure that out, but if it prints +a message saying it cannot guess the machine type, give it the +`--build=TYPE' option. TYPE can either be a short name for the system +type, such as `sun4', or a canonical name which has the form: + + CPU-COMPANY-SYSTEM + +where SYSTEM can have one of these forms: + + OS + KERNEL-OS + + See the file `config.sub' for the possible values of each field. If +`config.sub' isn't included in this package, then this package doesn't +need to know the machine type. + + If you are _building_ compiler tools for cross-compiling, you should +use the option `--target=TYPE' to select the type of system they will +produce code for. + + If you want to _use_ a cross compiler, that generates code for a +platform different from the build platform, you should specify the +"host" platform (i.e., that on which the generated programs will +eventually be run) with `--host=TYPE'. + +Sharing Defaults +================ + + If you want to set default values for `configure' scripts to share, +you can create a site shell script called `config.site' that gives +default values for variables like `CC', `cache_file', and `prefix'. +`configure' looks for `PREFIX/share/config.site' if it exists, then +`PREFIX/etc/config.site' if it exists. Or, you can set the +`CONFIG_SITE' environment variable to the location of the site script. +A warning: not all `configure' scripts look for a site script. + +Defining Variables +================== + + Variables not defined in a site shell script can be set in the +environment passed to `configure'. However, some packages may run +configure again during the build, and the customized values of these +variables may be lost. In order to avoid this problem, you should set +them in the `configure' command line, using `VAR=value'. For example: + + ./configure CC=/usr/local2/bin/gcc + +causes the specified `gcc' to be used as the C compiler (unless it is +overridden in the site shell script). + +Unfortunately, this technique does not work for `CONFIG_SHELL' due to +an Autoconf limitation. Until the limitation is lifted, you can use +this workaround: + + CONFIG_SHELL=/bin/bash ./configure CONFIG_SHELL=/bin/bash + +`configure' Invocation +====================== + + `configure' recognizes the following options to control how it +operates. + +`--help' +`-h' + Print a summary of all of the options to `configure', and exit. + +`--help=short' +`--help=recursive' + Print a summary of the options unique to this package's + `configure', and exit. The `short' variant lists options used + only in the top level, while the `recursive' variant lists options + also present in any nested packages. + +`--version' +`-V' + Print the version of Autoconf used to generate the `configure' + script, and exit. + +`--cache-file=FILE' + Enable the cache: use and save the results of the tests in FILE, + traditionally `config.cache'. FILE defaults to `/dev/null' to + disable caching. + +`--config-cache' +`-C' + Alias for `--cache-file=config.cache'. + +`--quiet' +`--silent' +`-q' + Do not print messages saying which checks are being made. To + suppress all normal output, redirect it to `/dev/null' (any error + messages will still be shown). + +`--srcdir=DIR' + Look for the package's source code in directory DIR. Usually + `configure' can determine that directory automatically. + +`--prefix=DIR' + Use DIR as the installation prefix. *note Installation Names:: + for more details, including other options available for fine-tuning + the installation locations. + +`--no-create' +`-n' + Run the configure checks, but stop before creating any output + files. + +`configure' also accepts some other, not widely useful, options. Run +`configure --help' for more details. diff --git a/native/Makefile.am b/native/Makefile.am new file mode 100644 index 0000000..a19f478 --- /dev/null +++ b/native/Makefile.am @@ -0,0 +1,46 @@ + +# Copyright 2008-2018 Douglas Wikstrom +# +# This file is part of Verificatum Multiplicative Groups library for +# Java (VMGJ). +# +# VMGJ is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# VMGJ 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 Affero General +# Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with VMGJ. If not, see . + +ACLOCAL_AMFLAGS=-I m4 + +# Extracts the flags used by GMP. +GMP_CFLAGS := $(shell ./extract_GMP_CFLAGS) + +# We use pedantic flags, strip the optimization flag of GMP, and +# insert our own level of optimization. +AM_CFLAGS := -O3 -Wall -W -Werror $(shell echo ${GMP_CFLAGS} | sed -e "s/-O[O12345]//") + +libvmgj_la_LIBADD = -lgmp -lgmpmee + +# We use -release to glue the native code and Java code together. We +# are aware that this violate common practice for library versioning. +libvmgj_la_LDFLAGS = -release $(VERSION) + +# This is generated from a Java file and copied to this directory by +# the parent directory. +# include_HEADERS = com_verificatum_vmgj_VMG.h + +lib_LTLIBRARIES = libvmgj.la +libvmgj_la_SOURCES = com_verificatum_vmgj_VMG.c convert.c convert.h + +dist_noinst_DATA = extract_GMP_CFLAGS.c + +clean-local: + find . -name "*~" -delete + rm -rf compile diff --git a/native/Makefile.build b/native/Makefile.build new file mode 100644 index 0000000..a5653a9 --- /dev/null +++ b/native/Makefile.build @@ -0,0 +1,43 @@ +#!/bin/sh + +# Copyright 2008-2018 Douglas Wikstrom +# +# This file is part of Verificatum Multiplicative Groups library for +# Java (VMGJ). +# +# VMGJ is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# VMGJ 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 Affero General +# Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with VMGJ. If not, see . + +# Two files define the build-process of this package: +# +# configure.ac and Makefile.am + +.PHONY: clean + +C_INCLUDE_PATH := $(C_INCLUDE_PATH):$(JNI_LOCATION) + +# Create build system. +all: .build.bstamp +.build.bstamp: + mkdir -p m4 + autoheader + cp m4src/* m4/ + aclocal -I m4 + autoconf + libtoolize --force --copy + automake --add-missing --force-missing --copy + @touch .build.bstamp + +clean: + @find . -name "*~" -delete + @rm -rf extract_GMP_CFLAGS COPYING NEWS ChangeLog README AUTHORS .deps aclocal.m4 autom4te.cache config.guess config.h config.h.in config.log config.status config.sub configure depcomp install-sh libtool ltmain.sh m4 Makefile.in Makefile missing stamp-h1 compile *.bstamp .*.bstamp diff --git a/native/com_verificatum_vmgj_VMG.c b/native/com_verificatum_vmgj_VMG.c new file mode 100644 index 0000000..cdf9637 --- /dev/null +++ b/native/com_verificatum_vmgj_VMG.c @@ -0,0 +1,467 @@ + +/* + * Copyright 2008-2018 Douglas Wikstrom + * + * This file is part of Verificatum Multiplicative Groups library for + * Java (VMGJ). + * + * VMGJ is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * VMGJ 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 Affero General + * Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with VMGJ. If not, see + * . + */ + +#include +#include + +#include +#include "gmpmee.h" +#include "convert.h" +#include +/* + * We use compiler flags that enforce that unused variables are + * flagged as errors. Here we are forced to use a given API, so we + * need to explicitly trick the compiler to not issue an error for + * those parameters that we do not use. + */ +#define VMGJ_UNUSED(x) ((void)(x)) + +#ifdef __cplusplus +extern "C" { +#endif + + /* + * Class: com_verificatum_vmgj_VMG + * Method: powm + * Signature: ([B[B[B)[B + */ + JNIEXPORT jbyteArray JNICALL Java_com_verificatum_vmgj_VMG_powm + (JNIEnv *env, jclass clazz, jbyteArray javaBasis, jbyteArray javaExponent, + jbyteArray javaModulus) + { + + mpz_t basis; + mpz_t exponent; + mpz_t modulus; + mpz_t result; + + jbyteArray javaResult; + + VMGJ_UNUSED(clazz); + + /* Translate jbyteArray-parameters to their corresponding GMP + mpz_t-elements. */ + jbyteArray_to_mpz_t(env, &basis, javaBasis); + jbyteArray_to_mpz_t(env, &exponent, javaExponent); + jbyteArray_to_mpz_t(env, &modulus, javaModulus); + + /* Compute modular exponentiation. */ + mpz_init(result); + + mpz_powm(result, basis, exponent, modulus); + + /* Translate result back to jbyteArray (this also allocates the + result array on the JVM heap). */ + mpz_t_to_jbyteArray(env, &javaResult, result); + + /* Deallocate resources. */ + mpz_clear(result); + mpz_clear(modulus); + mpz_clear(exponent); + mpz_clear(basis); + + return javaResult; + } + + + /* + * Class: com_verificatum_vmgj_VMG + * Method: spowm + * Signature: ([[B[[B[B)[B + */ + JNIEXPORT jbyteArray JNICALL Java_com_verificatum_vmgj_VMG_spowm + (JNIEnv *env, jclass clazz, jobjectArray javaBases, + jobjectArray javaExponents, jbyteArray javaModulus) + { + + int i; + mpz_t *bases; + mpz_t *exponents; + mpz_t modulus; + mpz_t result; + + jbyteArray javaResult; + jbyteArray javaBase; + jbyteArray javaExponent; + + /* Extract number of bases/exponents. */ + jsize numberOfBases = (*env)->GetArrayLength(env, javaBases); + + VMGJ_UNUSED(clazz); + + /* Convert exponents represented as array of byte[] to array of + mpz_t. */ + bases = gmpmee_array_alloc(numberOfBases); + for (i = 0; i < numberOfBases; i++) + { + javaBase = (jbyteArray)(*env)->GetObjectArrayElement(env, javaBases, i); + jbyteArray_to_mpz_t(env, &(bases[i]), javaBase); + } + + /* Convert exponents represented as array of byte[] to an array of + mpz_t. */ + exponents = gmpmee_array_alloc(numberOfBases); + for (i = 0; i < numberOfBases; i++) + { + javaExponent = + (jbyteArray)(*env)->GetObjectArrayElement(env, javaExponents, i); + jbyteArray_to_mpz_t(env, &(exponents[i]), javaExponent); + } + + /* Convert modulus represented as a byte[] to a mpz_t. */ + jbyteArray_to_mpz_t(env, &modulus, javaModulus); + + /* Call GMP's exponentiated product function. */ + mpz_init(result); + gmpmee_spowm(result, bases, exponents, numberOfBases, modulus); + + /* Convert result to a jbyteArray. */ + mpz_t_to_jbyteArray(env, &javaResult, result); + + /* Deallocate resources. */ + mpz_clear(result); + mpz_clear(modulus); + gmpmee_array_clear_dealloc(exponents, numberOfBases); + gmpmee_array_clear_dealloc(bases, numberOfBases); + + return javaResult; + } + + + /* + * Class: com_verificatum_vmgj_VMG + * Method: fpowm_precomp + * Signature: ([B[BII)J + */ + JNIEXPORT jlong JNICALL Java_com_verificatum_vmgj_VMG_fpowm_1precomp + (JNIEnv *env, jclass clazz, jbyteArray javaBasis, jbyteArray javaModulus, + jint javaBlockWidth, jint javaExponentBitlen) + { + mpz_t basis; + mpz_t modulus; + gmpmee_fpowm_tab *tablePtr = + (gmpmee_fpowm_tab *)malloc(sizeof(gmpmee_fpowm_tab)); + + VMGJ_UNUSED(clazz); + + jbyteArray_to_mpz_t(env, &basis, javaBasis); + jbyteArray_to_mpz_t(env, &modulus, javaModulus); + + gmpmee_fpowm_init_precomp(*tablePtr, basis, modulus, + (int)javaBlockWidth, (int)javaExponentBitlen); + mpz_clear(modulus); + mpz_clear(basis); + + return (jlong)(long)tablePtr; + } + + + /* + * Class: com_verificatum_vmgj_VMG + * Method: fpowm + * Signature: (J[B)[B + */ + JNIEXPORT jbyteArray JNICALL Java_com_verificatum_vmgj_VMG_fpowm + (JNIEnv *env, jclass clazz, jlong javaTablePtr, jbyteArray javaExponent) + { + mpz_t exponent; + mpz_t result; + + jbyteArray javaResult; + + VMGJ_UNUSED(clazz); + + jbyteArray_to_mpz_t(env, &exponent, javaExponent); + mpz_init(result); + + gmpmee_fpowm(result, *(gmpmee_fpowm_tab *)(long)javaTablePtr, exponent); + + /* Translate result back to jbyteArray (this also allocates the + result array on the JVM heap). */ + mpz_t_to_jbyteArray(env, &javaResult, result); + + mpz_clear(result); + mpz_clear(exponent); + + return javaResult; + } + + + /* + * Class: com_verificatum_vmgj_VMG + * Method: fpowm_clear + * Signature: (J)V + */ + JNIEXPORT void JNICALL Java_com_verificatum_vmgj_VMG_fpowm_1clear + (JNIEnv *env, jclass clazz, jlong javaTablePtr) + { + VMGJ_UNUSED(env); + VMGJ_UNUSED(clazz); + gmpmee_fpowm_clear(*(gmpmee_fpowm_tab *)(long)javaTablePtr); + } + + + /* + * Class: com_verificatum_vmgj_VMG + * Method: legendre + * Signature: ([B[B)I + */ + JNIEXPORT jint JNICALL Java_com_verificatum_vmgj_VMG_legendre + (JNIEnv *env, jclass clazz, jbyteArray javaOp, jbyteArray javaOddPrime) + { + mpz_t op; + mpz_t oddPrime; + int symbol; + + VMGJ_UNUSED(clazz); + + jbyteArray_to_mpz_t(env, &op, javaOp); + jbyteArray_to_mpz_t(env, &oddPrime, javaOddPrime); + + symbol = mpz_legendre(op, oddPrime); + + mpz_clear(op); + mpz_clear(oddPrime); + + return (jint)symbol; + } + + /* + * Class: com_verificatum_vmgj_VMG + * Method: millerrabin_init + * Signature: ([BZ)J + */ + JNIEXPORT jlong JNICALL Java_com_verificatum_vmgj_VMG_millerrabin_1init + (JNIEnv *env, jclass clazz, jbyteArray javaN, jboolean search) + { + mpz_t n; + gmpmee_millerrabin_state *statePtr = (void*)0; + + VMGJ_UNUSED(clazz); + + jbyteArray_to_mpz_t(env, &n, javaN); + + if (search || gmpmee_millerrabin_trial(n)) { + statePtr = + (gmpmee_millerrabin_state *)malloc(sizeof(gmpmee_millerrabin_state)); + gmpmee_millerrabin_init(*statePtr, n); + } + if (search) { + gmpmee_millerrabin_next_cand(*statePtr); + } + + mpz_clear(n); + + return (jlong)(long)statePtr; + } + + + /* + * Class: com_verificatum_vmgj_VMG + * Method: millerrabin_next_cand + * Signature: (J)V + */ + JNIEXPORT void JNICALL Java_com_verificatum_vmgj_VMG_millerrabin_1next_1cand + (JNIEnv *env, jclass clazz, jlong javaStatePtr) + { + VMGJ_UNUSED(env); + VMGJ_UNUSED(clazz); + gmpmee_millerrabin_next_cand(*(gmpmee_millerrabin_state *)(long) + javaStatePtr); + } + + + /* + * Class: com_verificatum_vmgj_VMG + * Method: millerrabin_once + * Signature: (J[B)I + */ + JNIEXPORT jint JNICALL Java_com_verificatum_vmgj_VMG_millerrabin_1once + (JNIEnv *env, jclass clazz, jlong javaStatePtr, jbyteArray javaBase) + { + mpz_t base; + int res; + + VMGJ_UNUSED(clazz); + + jbyteArray_to_mpz_t(env, &base, javaBase); + res = gmpmee_millerrabin_once(*(gmpmee_millerrabin_state *)(long) + javaStatePtr, base); + + mpz_clear(base); + + return res; + } + + + /* + * Class: com_verificatum_vmgj_VMG + * Method: millerrabin_clear + * Signature: (J)V + */ + JNIEXPORT void JNICALL Java_com_verificatum_vmgj_VMG_millerrabin_1clear + (JNIEnv *env, jclass clazz, jlong javaStatePtr) + { + VMGJ_UNUSED(env); + VMGJ_UNUSED(clazz); + gmpmee_millerrabin_clear(*(gmpmee_millerrabin_state *)(long)javaStatePtr); + } + + + /* + * Class: com_verificatum_vmgj_VMG + * Method: millerrabin_current + * Signature: (J)[B + */ + JNIEXPORT jbyteArray JNICALL + Java_com_verificatum_vmgj_VMG_millerrabin_1current + (JNIEnv *env, jclass clazz, jlong javaStatePtr) + { + jbyteArray javaResult; + + VMGJ_UNUSED(env); + VMGJ_UNUSED(clazz); + + mpz_t_to_jbyteArray(env, &javaResult, + (*(gmpmee_millerrabin_state *)(long) + javaStatePtr)->n); + return javaResult; + } + + + /* + * Class: com_verificatum_vmgj_VMG + * Method: millerrabin_safe_init + * Signature: ([BZ)J + */ + JNIEXPORT jlong JNICALL Java_com_verificatum_vmgj_VMG_millerrabin_1safe_1init + (JNIEnv *env, jclass clazz, jbyteArray javaN, jboolean search) + { + mpz_t n; + gmpmee_millerrabin_safe_state *statePtr = (void*)0; + + VMGJ_UNUSED(clazz); + + jbyteArray_to_mpz_t(env, &n, javaN); + + if (search || gmpmee_millerrabin_safe_trial(n)) { + statePtr = (gmpmee_millerrabin_safe_state *) + malloc(sizeof(gmpmee_millerrabin_safe_state)); + gmpmee_millerrabin_safe_init(*statePtr, n); + } + if (search) { + gmpmee_millerrabin_safe_next_cand(*statePtr); + } + + mpz_clear(n); + + return (jlong)(long)statePtr; + } + + + /* + * Class: com_verificatum_vmgj_VMG + * Method: millerrabin_safe_next_cand + * Signature: (J)V + */ + JNIEXPORT void JNICALL + Java_com_verificatum_vmgj_VMG_millerrabin_1safe_1next_1cand + (JNIEnv *env, jclass clazz, jlong javaStatePtr) + { + VMGJ_UNUSED(env); + VMGJ_UNUSED(clazz); + gmpmee_millerrabin_safe_next_cand(*(gmpmee_millerrabin_safe_state *)(long) + javaStatePtr); + } + + + /* + * Class: com_verificatum_vmgj_VMG + * Method: millerrabin_safe_once + * Signature: (J[BI)I + */ + JNIEXPORT jint JNICALL Java_com_verificatum_vmgj_VMG_millerrabin_1safe_1once + (JNIEnv *env, jclass clazz, jlong javaStatePtr, jbyteArray javaBase, + jint javaIndex) { + + mpz_t base; + int res; + + VMGJ_UNUSED(clazz); + + jbyteArray_to_mpz_t(env, &base, javaBase); + + if (((int)javaIndex) % 2 == 0) + { + res = gmpmee_millerrabin_once((*(gmpmee_millerrabin_safe_state *)(long) + javaStatePtr)->nstate, + base); + } + else + { + res = gmpmee_millerrabin_once((*(gmpmee_millerrabin_safe_state *)(long) + javaStatePtr)->mstate, + base); + } + + mpz_clear(base); + + return res; + } + + + /* + * Class: com_verificatum_vmgj_VMG + * Method: millerrabin_safe_clear + * Signature: (J)V + */ + JNIEXPORT void JNICALL Java_com_verificatum_vmgj_VMG_millerrabin_1safe_1clear + (JNIEnv *env, jclass clazz, jlong javaStatePtr) + { + VMGJ_UNUSED(env); + VMGJ_UNUSED(clazz); + gmpmee_millerrabin_safe_clear(*(gmpmee_millerrabin_safe_state *)(long) + javaStatePtr); + } + + + /* + * Class: com_verificatum_vmgj_VMG + * Method: millerrabin_current_safe + * Signature: (J)[B + */ + JNIEXPORT jbyteArray JNICALL + Java_com_verificatum_vmgj_VMG_millerrabin_1current_1safe + (JNIEnv *env, jclass clazz, jlong javaStatePtr) + { + jbyteArray javaResult; + + VMGJ_UNUSED(clazz); + mpz_t_to_jbyteArray(env, &javaResult, + (*(gmpmee_millerrabin_safe_state *)(long) + javaStatePtr)->nstate->n); + return javaResult; + } + +#ifdef __cplusplus +} +#endif diff --git a/native/configure.ac b/native/configure.ac new file mode 100644 index 0000000..2092e8b --- /dev/null +++ b/native/configure.ac @@ -0,0 +1,99 @@ + +# Copyright 2008-2018 Douglas Wikstrom +# +# This file is part of Verificatum Multiplicative Groups library for +# Java (VMGJ). +# +# VMGJ is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# VMGJ 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 Affero General +# Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with VMGJ. If not, see . + +AC_PREREQ([2.63]) +AC_INIT([vmgj], + [m4_esyscmd([m4 .version.m4])], + [info@verificatum.com]) +AC_LANG_PUSH([C]) +AM_INIT_AUTOMAKE([tar-ustar -Wall -Werror -Wno-portability]) +AC_CONFIG_SRCDIR([com_verificatum_vmgj_VMG.c]) +AC_CONFIG_HEADERS([config.h]) + +AC_CONFIG_MACRO_DIR([m4]) + +# Disable any default flags set by AC_PROG_CC. This still allows the +# user to specify CFLAGS. +CFLAGSTEST=`echo ${CFLAGS} | tr -d " "` +if test x${CFLAGSTEST} = x; +then + # This is needed since AC_PROG_CC is implemented incorrectly. It + # checks if CFLAGS is undefined or defined to the empty string. It + # should check if CFLAGS is white space. + CFLAGS="-fmessage-length=0" +fi + +# Checks for programs. +AC_PROG_CC + +# We are building a library. +AC_PROG_LIBTOOL + +# Check for header files. +AC_CHECK_HEADERS([stdlib.h string.h unistd.h]) + +AC_CHECK_HEADERS([gmp.h], , + [AC_MSG_ERROR(["GNU MP header not found, see http://gmplib.org/"])]) + +gcc extract_GMP_CFLAGS.c -o extract_GMP_CFLAGS + +AC_MSG_NOTICE([Attempting to add locations of jni.h and jni_md.h.]) + +ACE_PROG_JAVAC +AX_JNI_INCLUDE_DIR + +for JNI_INCLUDE_DIR in $JNI_INCLUDE_DIRS +do + CPPFLAGS="$CPPFLAGS -I$JNI_INCLUDE_DIR" +done + +AC_CHECK_HEADERS([jni_md.h jni.h], , + [AC_MSG_ERROR([ + +Unable to find jni.h or jni_md.h in the compiler's include path! These +header files are needed to compile C-code that can be called from a +JVM. They are included in a standard installation of Sun's Java 6 +JDK. Normally, the include path is set using the environment variable +C_INCLUDE_PATH. On Ubuntu 10.04 you can use the following snippet: + +JNI=`find /usr/lib/jvm -name jni.h` +JNI_MD=`find /usr/lib/jvm -name jni_md.h` +JDK_PATHS=\${JNI%jni.h}:\${JNI_MD%jni_md.h} +export C_INCLUDE_PATH=\${JDK_PATHS}:\${C_INCLUDE_PATH} + +])]) + + +# Checks for libraries. Due to the dependence of GMPMEE on GMP, this +# guarantees that GMP is installed as well. +AC_ARG_ENABLE([check_gmpmee], + [ --disable-check_gmpmee Skip checking that GMPMEE is installed (only for maintainers who know what they are doing).], + [],[AC_CHECK_LIB(gmpmee, gmpmee_spowm_init, , [AC_MSG_ERROR(["GNU MP Modular Exponentiation Extension library not found, see https://www.verificatum.org/."])]) AC_CHECK_HEADERS([gmpmee.h], , [AC_MSG_ERROR(["GNU MP Modular Exponentiation Extension header not found, see https://www.verificatum.org/."])])]) + AM_CONDITIONAL([CHECK_GMPMEE], [test x$check_gmpmee = xtrue]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_TYPE_SIZE_T + +# Checks for library functions. +AC_FUNC_MALLOC + +AM_CONDITIONAL([BITS64], [test x`getconf LONG_BIT` = x64]) + +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/native/convert.c b/native/convert.c new file mode 100644 index 0000000..e03c6fe --- /dev/null +++ b/native/convert.c @@ -0,0 +1,128 @@ + +/* + * Copyright 2008-2018 Douglas Wikstrom + * + * This file is part of Verificatum Multiplicative Groups library for + * Java (VMGJ). + * + * VMGJ is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * VMGJ 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 Affero General + * Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with VMGJ. If not, see + * . + */ + +#include +#include "convert.h" + +void +jbyteArray_to_mpz_t(JNIEnv* env, mpz_t* gmpValue, jbyteArray javaBytes) +{ + + jsize byte_len; + jbyte *cBytes; + mpz_t tmp; + + /* Find length in bytes of the jbyteArray. */ + byte_len = (*env)->GetArrayLength(env, javaBytes); + + /* Fetch a pointer to the jbyteArray, viewed as a jbyte[]. The NULL + parameter indicates that we do not need to know if the JVM copies + the bytes for us to a new array or not. */ + cBytes = (*env)->GetByteArrayElements(env, javaBytes, NULL); + + /* Allocate space for result. */ + mpz_init(*gmpValue); + + /* Execute unsigned conversion. */ + mpz_import(*gmpValue, /* Resulting mpz_t */ + byte_len, /* Number of words */ + 1, /* Most significant word first */ + 1, /* Number of bytes in each word (is one) */ + 1, /* Most signif. byte of each word first */ + 0, /* No. ignored leading bits of words */ + (void*)cBytes); /* Source of the bytes */ + + /* If the original integer is negative, then the jbyteArray + corresponds to 2^n-gmpValue, where n/8 is the number of bytes in + jbyteArray integer. Thus, we must subtract 2^n. */ + if (cBytes[0] & 0x80) + { + mpz_init(tmp); + mpz_setbit(tmp, 8 * byte_len); + mpz_sub(*gmpValue, *gmpValue, tmp); + mpz_clear(tmp); + } + + /* Release our handle to the jbyteArray. JNI_ABORT indicates that we + do not require that the jbyteArray is copied back into JVM + memory, even if the JVM has a separate native memory space. */ + (*env)->ReleaseByteArrayElements(env, javaBytes, cBytes, JNI_ABORT); +} + +void mpz_t_to_jbyteArray(JNIEnv* env, jbyteArray* javaBytes, mpz_t gmpValue) +{ + + size_t byte_len; + jbyte* cBytes; + mpz_t tmp; + + /* Find length in bytes of the GMP mpz_t element. We add an + additional leading byte where the sign of the integer is + encoded. */ + byte_len = (mpz_sizeinbase(gmpValue, 2) + 7) / 8 + 1; + + /* Allocate a new java byte array in JVM space. */ + *javaBytes = (*env)->NewByteArray(env, byte_len); + + /* Fetch a pointer to the java byte array, viewed as a jbyte + array. */ + cBytes = (*env)->GetByteArrayElements(env, *javaBytes, NULL); + + /* If the integer gmpValue is negative we add the smallest integer + of the form 2^n such that 2^n > |gmpValue| and n is a multiple of + 8. */ + if (mpz_sgn(gmpValue) < 0) + { + mpz_init(tmp); + mpz_setbit(tmp, 8 * byte_len); + mpz_add(tmp, tmp, gmpValue); + cBytes[0] = (jbyte)0xff; + + /* Execute unsigned conversion. */ + mpz_export((void*)&(cBytes[1]), + &byte_len, + 1, /* Most significant word first */ + 1, /* Number of bytes in each word (is one) */ + 1, /* Most signif. byte of each word first */ + 0, /* No. ignored leading bits of words */ + tmp); /* Source of the bytes */ + mpz_clear(tmp); + } + else + { + cBytes[0] = (jbyte)0x00; + + /* Execute unsigned conversion. */ + mpz_export((void*)&(cBytes[1]), + &byte_len, + 1, /* Most significant word first */ + 1, /* Number of bytes in each word (is one) */ + 1, /* Most signif. byte of each word first */ + 0, /* No. ignored leading bits of words */ + gmpValue); /* Source of the bytes */ + } + + + /* Release our handle to the java bytes. Force "copy" of the bytes + into JVM memory space only if needed. */ + (*env)->ReleaseByteArrayElements(env, *javaBytes, cBytes, 0); +} diff --git a/native/convert.h b/native/convert.h new file mode 100644 index 0000000..77fafb7 --- /dev/null +++ b/native/convert.h @@ -0,0 +1,52 @@ + +/* + * Copyright 2008-2018 Douglas Wikstrom + * + * This file is part of Verificatum Multiplicative Groups library for + * Java (VMGJ). + * + * VMGJ is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * VMGJ 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 Affero General + * Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with VMGJ. If not, see + * . + */ + +#include + +#ifndef _convert +#define _convert +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Translates the representation of a positive integer given as a + * jbyteArray in two's complement representation into its + * representation as a GMP mpz_t element. It initializes gmpValue, so + * it should point to an uninitialized variable before the call. + */ +void +jbyteArray_to_mpz_t(JNIEnv* env, mpz_t* gmpValue, jbyteArray javaBytes); + +/* + * Translates the representation of a positive integer given as a GMP + * mpz_t element into its representation as a two's complement in a + * jbyteArray. It allocates a jbyteArray in JVM memory space, so it + * should be uninitialized before the call. + */ +void +mpz_t_to_jbyteArray(JNIEnv* env, jbyteArray* javaBytes, mpz_t gmpValue); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/native/extract_GMP_CFLAGS.c b/native/extract_GMP_CFLAGS.c new file mode 100644 index 0000000..95d4c9f --- /dev/null +++ b/native/extract_GMP_CFLAGS.c @@ -0,0 +1,29 @@ + +/* + * Copyright 2008-2018 Douglas Wikstrom + * + * This file is part of Verificatum Multiplicative Groups library for + * Java (VMGJ). + * + * VMGJ is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * VMGJ 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 Affero General + * Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with VMGJ. If not, see + * . + */ + +#include +#include "gmp.h" + +int main() +{ + puts(__GMP_CFLAGS); +} diff --git a/native/m4src/ace_prog_javac.m4 b/native/m4src/ace_prog_javac.m4 new file mode 100644 index 0000000..d287203 --- /dev/null +++ b/native/m4src/ace_prog_javac.m4 @@ -0,0 +1,27 @@ + +# Copyright 2008-2018 Douglas Wikstrom +# +# This file is part of Verificatum Multiplicative Groups library for +# Java (VMGJ). +# +# VMGJ is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# VMGJ 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 Affero General +# Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with VMGJ. If not, see . + +AC_DEFUN([ACE_PROG_JAVAC],[ +AC_CHECK_PROG([JAVAC], [javac], [javac], [no]) + +if test $JAVAC = no +then + AC_MSG_ERROR([No javac found in \$PATH. Please install JDK 6!]) +fi +]) diff --git a/native/m4src/ax_jni_include_dir.m4 b/native/m4src/ax_jni_include_dir.m4 new file mode 100644 index 0000000..04f4095 --- /dev/null +++ b/native/m4src/ax_jni_include_dir.m4 @@ -0,0 +1,116 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_jni_include_dir.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_JNI_INCLUDE_DIR +# +# DESCRIPTION +# +# AX_JNI_INCLUDE_DIR finds include directories needed for compiling +# programs using the JNI interface. +# +# JNI include directories are usually in the java distribution This is +# deduced from the value of JAVAC. When this macro completes, a list of +# directories is left in the variable JNI_INCLUDE_DIRS. +# +# Example usage follows: +# +# AX_JNI_INCLUDE_DIR +# +# for JNI_INCLUDE_DIR in $JNI_INCLUDE_DIRS +# do +# CPPFLAGS="$CPPFLAGS -I$JNI_INCLUDE_DIR" +# done +# +# If you want to force a specific compiler: +# +# - at the configure.in level, set JAVAC=yourcompiler before calling +# AX_JNI_INCLUDE_DIR +# +# - at the configure level, setenv JAVAC +# +# Note: This macro can work with the autoconf M4 macros for Java programs. +# This particular macro is not part of the original set of macros. +# +# LICENSE +# +# Copyright (c) 2008 Don Anderson +# +# 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. This file is offered as-is, without any +# warranty. +#serial 6 + +AU_ALIAS([AC_JNI_INCLUDE_DIR], [AX_JNI_INCLUDE_DIR]) +AC_DEFUN([AX_JNI_INCLUDE_DIR],[ + +JNI_INCLUDE_DIRS="" + +test "x$JAVAC" = x && AC_MSG_ERROR(['\$JAVAC' undefined]) +AC_PATH_PROG(_ACJNI_JAVAC, $JAVAC, no) +test "x$_ACJNI_JAVAC" = xno && AC_MSG_ERROR([$JAVAC could not be found in path]) + +_ACJNI_FOLLOW_SYMLINKS("$_ACJNI_JAVAC") +_JTOPDIR=`echo "$_ACJNI_FOLLOWED" | sed -e 's://*:/:g' -e 's:/[[^/]]*$::'` +case "$host_os" in + darwin*) _JTOPDIR=`echo "$_JTOPDIR" | sed -e 's:/[[^/]]*$::'` + _JINC="$_JTOPDIR/Headers";; + freebsd*) _JTOPDIR_TMP=`JAVAVM_DRYRUN=yes javac | grep JAVA_HOME` + _JTOPDIR=`echo $_JTOPDIR_TMP | tr -d "JAVA_HOME="` + _JINC="$_JTOPDIR/include";; + *) _JINC="$_JTOPDIR/include";; +esac +if test -f "$_JINC/jni.h"; then + JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $_JINC" +else + _JTOPDIR=`echo "$_JTOPDIR" | sed -e 's:/[[^/]]*$::'` + if test -f "$_JTOPDIR/include/jni.h"; then + JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $_JTOPDIR/include" + else + AC_MSG_ERROR([cannot find java include files]) + fi +fi + +# get the likely subdirectories for system specific java includes +case "$host_os" in +bsdi*) _JNI_INC_SUBDIRS="bsdos";; +linux*) _JNI_INC_SUBDIRS="linux genunix";; +osf*) _JNI_INC_SUBDIRS="alpha";; +solaris*) _JNI_INC_SUBDIRS="solaris";; +free*) _JNI_INC_SUBDIRS="freebsd";; +mingw*) _JNI_INC_SUBDIRS="win32";; +cygwin*) _JNI_INC_SUBDIRS="win32";; +*) _JNI_INC_SUBDIRS="genunix";; +esac + +# add any subdirectories that are present +for JINCSUBDIR in $_JNI_INC_SUBDIRS +do + if test -d "$_JTOPDIR/include/$JINCSUBDIR"; then + JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $_JTOPDIR/include/$JINCSUBDIR" + fi +done +]) + +# _ACJNI_FOLLOW_SYMLINKS +# Follows symbolic links on , +# finally setting variable _ACJNI_FOLLOWED +# -------------------- +AC_DEFUN([_ACJNI_FOLLOW_SYMLINKS],[ +# find the include directory relative to the javac executable +_cur="$1" +while ls -ld "$_cur" 2>/dev/null | grep " -> " >/dev/null; do + AC_MSG_CHECKING(symlink for $_cur) + _slink=`ls -ld "$_cur" | sed 's/.* -> //'` + case "$_slink" in + /*) _cur="$_slink";; + # 'X' avoids triggering unwanted echo options. + *) _cur=`echo "X$_cur" | sed -e 's/^X//' -e 's:[[^/]]*$::'`"$_slink";; + esac + AC_MSG_RESULT($_cur) +done +_ACJNI_FOLLOWED="$_cur" +])# _ACJNI diff --git a/src/bin/vmgj-info.src b/src/bin/vmgj-info.src new file mode 100644 index 0000000..4110465 --- /dev/null +++ b/src/bin/vmgj-info.src @@ -0,0 +1,38 @@ +#!/bin/sh + +# Copyright 2008-2018 Douglas Wikstrom +# +# This file is part of Verificatum Multiplicative Groups library for +# Java (VMGJ). +# +# VMGJ is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# VMGJ 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 Affero General +# Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with VMGJ. If not, see . + +if test x$1 = x"bin"; +then + printf "M4_BINDIR" +elif test x$1 = x"lib"; +then + printf "M4_LIBDIR" +elif test x$1 = x"jar"; +then + printf "M4_VMGJ_JAR" +elif test x$1 = x"version"; +then + printf "M4_VERSION" +elif test x$1 = x"complete"; +then + printf "vmgj-M4_VERSION`('gmpmee-M4_GMPMEE_VERSION`)'" +else + printf "Illegal parameter! (%s)\n" $1 +fi diff --git a/src/java/com/verificatum/vmgj/BenchVMG.java b/src/java/com/verificatum/vmgj/BenchVMG.java new file mode 100644 index 0000000..01eb313 --- /dev/null +++ b/src/java/com/verificatum/vmgj/BenchVMG.java @@ -0,0 +1,280 @@ + +/* + * Copyright 2008-2018 Douglas Wikstrom + * + * This file is part of Verificatum Multiplicative Groups library for + * Java (VMGJ). + * + * VMGJ is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * VMGJ 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 Affero General + * Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with VMGJ. If not, see + * . + */ + +package com.verificatum.vmgj; + +import java.math.BigInteger; +import java.security.SecureRandom; + +// We use C style to name things in this file, since it should +// correspond to the native code. + +//CHECKSTYLE.OFF: LocalVariableName +//CHECKSTYLE.OFF: LocalFinalVariableName +//CHECKSTYLE.OFF: MethodName +//CHECKSTYLE.OFF: ParameterName + +/** + * Allows invoking the modular exponentiation, simultaneous modular + * exponentiation routines, primality tests, and related routines of + * the Gnu Multiprecision Library + * (GMP)and GMPMEE (a minor extension of GMP). + * + *

+ * + * @author Douglas Wikstrom + */ +@SuppressWarnings("PMD.MethodNamingConventions") +public final class BenchVMG { + + /** + * Avoid accidental instantiation. + */ + private BenchVMG() { + } + + /** + * Default number of seconds used for a timing. + */ + static final int DEFAULT_SPEED_TIME = 2000; + + /** + * Convenience method for bounding the execution time of a test. + * + * @param t Time when the test started. + * @param milliSecs Milliseconds the should proceed. + * @return True if the deadline has passed and false otherwise. + */ + private static boolean done(final long t, final long milliSecs) { + return System.currentTimeMillis() > t + milliSecs; + } + + /** + * Times exponentiation. + * + * @param bitLength Number of bits of integers in the operation + * timed. + * @param milliSecs Duration of the timing. + * @return Number of exponentiations performed. + */ + protected static long time_powm(final int bitLength, final long milliSecs) { + + final SecureRandom random = new SecureRandom(); + + final int len = 100; + + // Generate random modulus. + BigInteger modulus = new BigInteger(bitLength, random); + modulus = modulus.setBit(bitLength - 1); + + BigInteger basis = new BigInteger(bitLength, random); + basis = basis.setBit(bitLength - 1); + + BigInteger[] exponents = new BigInteger[len]; + + for (int l = 0; l < len; l++) { + exponents[l] = new BigInteger(bitLength, random); + } + + // Time optimized code. + final long t = System.currentTimeMillis(); + long i = 0; + int l = 0; + while (!done(t, milliSecs)) { + + VMG.powm(basis, exponents[l], modulus); + + l = (l + 1) % len; + + i++; + } + return i; + } + + /** + * Times simultaneous exponentiation. + * + * @param bitLength Number of bits of integers in the operation + * timed. + * @param milliSecs Duration of the timing. + * @return Number of simultaneous exponentiations performed. + */ + protected static long time_spowm(final int bitLength, + final long milliSecs) { + + final SecureRandom random = new SecureRandom(); + + final int len = 100; + + // Generate random modulus. + BigInteger modulus = new BigInteger(bitLength, random); + modulus = modulus.setBit(bitLength - 1); + + final BigInteger[] bases = new BigInteger[len]; + final BigInteger[] exponents = new BigInteger[len]; + + for (int l = 0; l < len; l++) { + bases[l] = new BigInteger(bitLength, random); + bases[l] = bases[l].setBit(bitLength - 1); + + exponents[l] = new BigInteger(bitLength, random); + } + + final long t = System.currentTimeMillis(); + + long i = 0; + while (!done(t, milliSecs)) { + + VMG.spowm(bases, exponents, modulus); + + i++; + } + return i * len; + } + + /** + * Times fixed-basis exponentiation. + * + * @param bitLength Number of bits of integers in the operation + * timed. + * @param milliSecs Duration of the timing. + * @return Number of fixed-basis exponentiations performed. + */ + protected static long time_fpowm(final int bitLength, + final long milliSecs) { + + final SecureRandom random = new SecureRandom(); + + final int len = 100; + + // Generate random modulus. + BigInteger modulus = new BigInteger(bitLength, random); + modulus = modulus.setBit(bitLength - 1); + + BigInteger basis = new BigInteger(bitLength, random); + basis = basis.setBit(bitLength - 1); + + final BigInteger[] exponents = new BigInteger[len]; + + for (int l = 0; l < len; l++) { + exponents[l] = new BigInteger(bitLength, random); + } + + final FpowmTab tab = new FpowmTab(basis, modulus, bitLength); + + // Time optimized code. + final long t = System.currentTimeMillis(); + long i = 0; + int l = 0; + while (!done(t, milliSecs)) { + + tab.fpowm(exponents[l]); + + l = (l + 1) % len; + + i++; + } + return i; + } + + /** + * Times modular arithmetic and prints the results. + * + * @param bitLength Number of bits of integers in the operation + * timed. + * @param milliSecs Duration of the timing. + */ + public static void time_modulus(final int bitLength, final int milliSecs) { + + final String f = + "%nTiming modular arithmetic: %d bitlength (%d ms/function)"; + + System.out.println(String.format(f, bitLength, milliSecs)); + System.out.println( + "----------------------------------------------------------------"); + + System.out.println(String.format("%12d exponentiations", + time_powm(bitLength, milliSecs))); + System.out.println(String.format("%12d simultaneous exponentiations", + time_spowm(bitLength, milliSecs))); + System.out.println(String.format("%12d fixed-basis exponentiations", + time_fpowm(bitLength, milliSecs))); + } + + /** + * Prints usage information. + */ + protected static void usage() { + System.out.println("Usage: vmgj.VMG [bitLength]... "); + } + + /** + * Executes the timing routines. + * + * @param args Command line arguments. + */ + public static void main(final String[] args) { + + int[] bitLengths = new int[4]; + bitLengths[0] = 1024; + bitLengths[1] = 2048; + bitLengths[2] = 3072; + bitLengths[3] = 4096; + + if (args.length > 0) { + + bitLengths = new int[args.length]; + for (int i = 0; i < args.length; i++) { + + try { + bitLengths[i] = Integer.parseInt(args[i]); + } catch (NumberFormatException nfe) { + usage(); + System.exit(1); + } + } + } + + final String s = +"\n================================================================\n" ++ "\n BENCHMARKS FOR com.verificatum.vmgj.VMG \n\n" ++ "You need to consult the code understand exactly what is \n" ++ "measured before drawing any conclusions, but the benchmarks \n" ++ "are fairly self explanatory.\n" ++ "\n" ++ "The code makes calls to the GNU Multiple Precision Arithmetic\n" ++ "library (GMP) and GMP Modular Exponentiation Extension (VMG).\n" ++ "================================================================"; + + System.out.println(s); + + for (int i = 0; i < bitLengths.length; i++) { + + time_modulus(bitLengths[i], DEFAULT_SPEED_TIME); + } + System.out.println(""); + } +} +//CHECKSTYLE.ON: LocalVariableName +//CHECKSTYLE.ON: LocalFinalVariableName +//CHECKSTYLE.ON: MethodName +//CHECKSTYLE.ON: ParameterName diff --git a/src/java/com/verificatum/vmgj/FpowmTab.java b/src/java/com/verificatum/vmgj/FpowmTab.java new file mode 100644 index 0000000..571110b --- /dev/null +++ b/src/java/com/verificatum/vmgj/FpowmTab.java @@ -0,0 +1,110 @@ + +/* + * Copyright 2008-2018 Douglas Wikstrom + * + * This file is part of Verificatum Multiplicative Groups library for + * Java (VMGJ). + * + * VMGJ is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * VMGJ 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 Affero General + * Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with VMGJ. If not, see + * . + */ + +package com.verificatum.vmgj; + +import java.math.BigInteger; + +/** + * Provides a Java wrapper for a pointer to a native pre-computed + * table used for fixed based modular exponentiation as implemented in + * {@link VMG}. + * + * @author Douglas Wikstrom + */ +public class FpowmTab { + + /** + * Stores native pointer to a precomputed fixed base + * exponentiation table. + */ + protected long tablePtr; + + /** + * Creates a precomputed table for the given basis, modulus, and + * exponent bit length. + * + * @param basis Basis element. + * @param modulus Modulus used during modular exponentiations. + * @param exponentBitlen Expected bit length of exponents used when + * invoking the table. + */ + public FpowmTab(final BigInteger basis, + final BigInteger modulus, + final int exponentBitlen) { + this(basis, modulus, 16, exponentBitlen); + } + + /** + * Creates a precomputed table for the given basis, modulus, and + * exponent bit length. + * + * @param basis Basis element. + * @param modulus Modulus used during modular exponentiations. + * @param blockWidth Number of basis elements used during + * splitting. + * @param exponentBitlen Expected bit length of exponents used when + * invoking the table. + */ + public FpowmTab(final BigInteger basis, + final BigInteger modulus, + final int blockWidth, + final int exponentBitlen) { + tablePtr = VMG.fpowm_precomp(basis.toByteArray(), + modulus.toByteArray(), + blockWidth, + exponentBitlen); + } + + /** + * Computes a modular exponentiation using the given exponent and + * the basis and modulus previously used to construct this table. + * + * @param exponent Exponent used in modular exponentiation. + * @return Power of basis for which pre-computation took place. + */ + public BigInteger fpowm(final BigInteger exponent) { + return new BigInteger(VMG.fpowm(tablePtr, + exponent.toByteArray())); + } + + /** + * Release resources allocated by native code. + */ + public void free() { + if (tablePtr != 0) { + VMG.fpowm_clear(tablePtr); + tablePtr = 0; + } + } + + /** + * This is optimistic, but we only allocate a fixed amount of + * memory and do not rely on this. + * + * @throws Throwable If this instance can not be finalized. + */ + protected void finalize() throws Throwable { + free(); + super.finalize(); + } +} diff --git a/src/java/com/verificatum/vmgj/MillerRabin.java b/src/java/com/verificatum/vmgj/MillerRabin.java new file mode 100644 index 0000000..501ef16 --- /dev/null +++ b/src/java/com/verificatum/vmgj/MillerRabin.java @@ -0,0 +1,156 @@ + +/* + * Copyright 2008-2018 Douglas Wikstrom + * + * This file is part of Verificatum Multiplicative Groups library for + * Java (VMGJ). + * + * VMGJ is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * VMGJ 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 Affero General + * Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with VMGJ. If not, see + * . + */ + +package com.verificatum.vmgj; + +import java.math.BigInteger; + +/** + * Implements primality tests and safe-primality tests such that the + * caller provides the randomness. This allows a theoretically sound + * primality test in contrast to builtin routines. Interlacing and + * trial division is used in the test of safe primes, which speeds up + * searching drastically. Consult the native code for more + * information. + * + * @author Douglas Wikstrom + */ +public class MillerRabin { + + /** + * Stores native pointer to state. + */ + protected long statePtr; + + /** + * Decides if we are checking primality or safe primality. + */ + protected boolean primality; + + /** + * Initializes the Miller-Rabin test for the given + * integers. Please use the method {@link #trial()} and read the + * comment. + * + * @param n Integer to test. + * @param primality Decides if we are checking primality or safe + * primality. + * @param search Decides if we are searching for an integer or testing. + */ + public MillerRabin(final BigInteger n, final boolean primality, + final boolean search) { + if (n.compareTo(BigInteger.ZERO) <= 0) { + throw new ArithmeticException("Primality check of non-positive " + + "integer!"); + } + this.primality = primality; + if (primality) { + statePtr = VMG.millerrabin_init(n.toByteArray(), search); + } else { + statePtr = VMG.millerrabin_safe_init(n.toByteArray(), search); + } + } + + /** + * Returns the result of the trial divisions. {@link + * #once(BigInteger)} or {@link #done()} must not be called if this + * function returns false. Note that if this instance is created + * for searching, this will always return true, since + * the constructor in that case moves to the first candidate + * integer that passes trial divisions. + * + * @return Returns true or false + * depending on if the integer is found not to be a candidate + * after trial divisions. + */ + public boolean trial() { + return statePtr != 0; + } + + /** + * Increases the integer to the next candidate prime, or safe + * prime, depending on how this instance was created a candidate + * prime passes all trial divisions. + */ + public void nextCandidate() { + if (primality) { + VMG.millerrabin_next_cand(statePtr); + } else { + VMG.millerrabin_safe_next_cand(statePtr); + } + } + + /** + * Returns the current candidate. + * + * @return Current candidate. + */ + public BigInteger getCurrentCandidate() { + if (primality) { + return new BigInteger(VMG.millerrabin_current(statePtr)); + } else { + return new BigInteger(VMG.millerrabin_current_safe(statePtr)); + } + } + + /** + * Perform one Miller-Rabin test using the given base. + * + * @param base Base used in testing. + * @return false if the integer is not prime and + * true otherwise. + */ + public boolean once(final BigInteger base) { + return VMG.millerrabin_once(statePtr, base.toByteArray()) == 1; + } + + /** + * Perform one Miller-Rabin test using the given base. + * + * @param base Base used in testing. + * @param index Determines if Miller-Rabin is executed on the + * tested integer n or (n-1)/2. + * @return false if the integer is not prime and + * true otherwise. + */ + public boolean once(final BigInteger base, final int index) { + return VMG.millerrabin_safe_once(statePtr, + base.toByteArray(), + index) == 1; + } + + /** + * Releases resources allocated for testing. This must be called + * after testing is completed, but it must not be called if {@link + * #trial()} returns 0. + */ + public void done() { + if (statePtr != 0) { + if (primality) { + VMG.millerrabin_clear(statePtr); + } else { + VMG.millerrabin_safe_clear(statePtr); + } + statePtr = 0; + } + } +} diff --git a/src/java/com/verificatum/vmgj/TestVMG.java b/src/java/com/verificatum/vmgj/TestVMG.java new file mode 100644 index 0000000..bf3f19c --- /dev/null +++ b/src/java/com/verificatum/vmgj/TestVMG.java @@ -0,0 +1,437 @@ + +/* + * Copyright 2008-2018 Douglas Wikstrom + * + * This file is part of Verificatum Multiplicative Groups library for + * Java (VMGJ). + * + * VMGJ is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * VMGJ 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 Affero General + * Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with VMGJ. If not, see + * . + */ + +package com.verificatum.vmgj; + +import java.math.BigInteger; +import java.security.SecureRandom; + +// We use C style to name things in this file, since it should +// correspond to the native code. + +//CHECKSTYLE.OFF: LocalVariableName +//CHECKSTYLE.OFF: LocalFinalVariableName +//CHECKSTYLE.OFF: MethodName +//CHECKSTYLE.OFF: ParameterName + +/** + * Testing routines for VMG, FpowmTab, and MillerRabin. These tests + * are not meant to be a complete test of the arithmetic. This is + * handled by the more comprehensive tests in the underlying native + * code. Here we merely run basic sanity checks to make sure that the + * native code is called correctly from Java. + * + * @author Douglas Wikstrom + */ +@SuppressWarnings("PMD.MethodNamingConventions") +public final class TestVMG { + + /** + * Avoid accidental instantiation. + */ + private TestVMG() { + } + + /** + * Default number of milliseconds used for a single test during + * testing of a curve. + */ + static final int DEFAULT_TEST_TIME = 2000; + + /** + * Convenience method for bounding the execution time of a test. + * + * @param t Time when the test started. + * @param milliSecs Milliseconds the should proceed. + * @return True if the deadline has passed and false otherwise. + */ + private static boolean done(final long t, final long milliSecs) { + return System.currentTimeMillis() > t + milliSecs; + } + + /** + * Tests exponentiation. + * + * @param bitLength Number of bits of integers. + * @param milliSecs Duration of the timing. + */ + protected static void test_powm(final int bitLength, final long milliSecs) { + + final SecureRandom random = new SecureRandom(); + + // Test optimized code. + final long t = System.currentTimeMillis(); + while (!done(t, milliSecs)) { + + final BigInteger modulus = new BigInteger(bitLength, random); + final BigInteger basis = new BigInteger(bitLength, random); + final BigInteger exponent = new BigInteger(bitLength, random); + + final BigInteger vmg = VMG.powm(basis, exponent, modulus); + final BigInteger java = basis.modPow(exponent, modulus); + + assert vmg.equals(java) : "Fixed basis exponentiation failed!"; + } + } + + /** + * Test simultaneous exponentiation. + * + * @param bitLength Number of bits of integers. + * @param milliSecs Duration of the timing. + */ + protected static void test_spowm(final int bitLength, + final long milliSecs) { + + final SecureRandom random = new SecureRandom(); + + final int len = 50; + + // Generate random modulus. + final BigInteger modulus = new BigInteger(bitLength, random); + + final BigInteger[] bases = new BigInteger[len]; + final BigInteger[] exponents = new BigInteger[len]; + + final long t = System.currentTimeMillis(); + while (!done(t, milliSecs)) { + for (int l = 0; l < len; l++) { + bases[l] = new BigInteger(bitLength, random).mod(modulus); + exponents[l] = new BigInteger(bitLength, random); + } + + final BigInteger vmg = VMG.spowm(bases, exponents, modulus); + + BigInteger res = BigInteger.ONE; + for (int l = 0; l < len; l++) { + res = res.multiply(bases[l].modPow(exponents[l], modulus)); + res = res.mod(modulus); + } + + assert vmg.equals(res) : "Failed to simultanously exponentiate!"; + } + } + + /** + * Tests fixed-basis exponentiation. + * + * @param bitLength Number of bits of integers in the operation + * timed. + * @param milliSecs Duration of the timing. + */ + protected static void test_fpowm(final int bitLength, + final long milliSecs) { + + final SecureRandom random = new SecureRandom(); + + // Generate random modulus. + final BigInteger modulus = new BigInteger(bitLength, random); + final BigInteger basis = new BigInteger(bitLength, random); + final FpowmTab tab = new FpowmTab(basis, modulus, bitLength); + + // Test optimized code. + final long t = System.currentTimeMillis(); + while (!done(t, milliSecs)) { + + final BigInteger exponent = new BigInteger(bitLength, random); + final BigInteger vmg = tab.fpowm(exponent); + final BigInteger res = basis.modPow(exponent, modulus); + + assert vmg.equals(res) : "Failed to fixed-basis exponentiate!"; + } + } + + /** + * Tests computation of Legendre symbols. + * + * @param bitLength Number of bits of integers in the operation + * timed. + * @param milliSecs Duration of the timing. + */ + protected static void test_legendre(final int bitLength, + final long milliSecs) { + + final SecureRandom random = new SecureRandom(); + + final BigInteger two = BigInteger.ONE.add(BigInteger.ONE); + + // Test optimized code. + final long t = System.currentTimeMillis(); + while (!done(t, milliSecs)) { + + // Make sure we have an odd prime modulus. + final BigInteger prime = + BigInteger.probablePrime(bitLength, random); + final BigInteger exponent = + prime.subtract(BigInteger.ONE).divide(two); + + final BigInteger bi = new BigInteger(bitLength, random); + + final int ivmg = VMG.legendre(bi, prime); + final BigInteger vmg = + new BigInteger(Integer.toString(ivmg)).mod(prime); + final BigInteger res = bi.modPow(exponent, prime); + + assert vmg.equals(res) : "Failed to compute Legendre symbol!"; + } + } + + /** + * Generates random integer between 2 and modulus - 1. + * + * @param modulus Modulus. + * @param random Random source. + * @return Random integer between 2 and modulus - 1. + */ + private static BigInteger getBasis(final BigInteger modulus, + final SecureRandom random) { + BigInteger basis; + + // Pick a random base in [2,modulus - 1]. + do { + basis = new BigInteger(modulus.bitLength(), random).mod(modulus); + } while (basis.equals(BigInteger.ZERO) || basis.equals(BigInteger.ONE)); + return basis; + } + + /** + * Tests primality testing. + * + * @param bitLength Number of bits of integers in the operation + * timed. + * @param milliSecs Duration of the timing. + */ + public static void test_millerrabin_prime(final int bitLength, + final int milliSecs) { + + final SecureRandom random = new SecureRandom(); + + // Test optimized code. + final long t = System.currentTimeMillis(); + while (!done(t, milliSecs)) { + + // Make sure we have an odd prime modulus. + final BigInteger bi = new BigInteger(bitLength, random); + + final MillerRabin mr = new MillerRabin(bi, true, false); + boolean vmg = mr.trial(); + for (int i = 0; vmg && i < 30; i++) { + final BigInteger b = getBasis(bi, random); + vmg = mr.once(b); + } + mr.done(); + + final boolean res = bi.isProbablePrime(50); + + assert vmg == res : "Failed to test for primality!"; + } + } + + /** + * Tests next prime. + * + * @param bitLength Number of bits of integers in the operation + * timed. + * @param milliSecs Duration of the timing. + */ + public static void test_millerrabin_nextprime(final int bitLength, + final int milliSecs) { + + final SecureRandom random = new SecureRandom(); + + // Test optimized code. + final long t = System.currentTimeMillis(); + while (!done(t, milliSecs)) { + + // Make sure we have an odd prime modulus. + final BigInteger bi = new BigInteger(bitLength, random); + final BigInteger primeA = bi.nextProbablePrime(); + + final MillerRabin mr = new MillerRabin(bi, true, true); + boolean vmg = false; + BigInteger primeB = null; + while (!vmg) { + primeB = mr.getCurrentCandidate(); + vmg = true; + for (int i = 0; vmg && i < 30; i++) { + final BigInteger b = getBasis(primeB, random); + vmg = mr.once(b); + } + mr.nextCandidate(); + } + mr.done(); + + assert primeA.equals(primeB) : "Failed get next prime!"; + } + } + + /** + * Tests next prime. + * + * @param bitLength Number of bits of integers in the operation + * timed. + * @param milliSecs Duration of the timing. + */ + public static void test_millerrabin_nextsafeprime(final int bitLength, + final int milliSecs) { + + final BigInteger two = BigInteger.ONE.add(BigInteger.ONE); + final SecureRandom random = new SecureRandom(); + + // Test optimized code. + final long t = System.currentTimeMillis(); + while (!done(t, milliSecs)) { + + // Search for the next safe prime naively. + BigInteger bi; + BigInteger primeA; + BigInteger subA; + do { + bi = new BigInteger(bitLength, random); + primeA = bi.nextProbablePrime(); + subA = primeA.subtract(BigInteger.ONE).divide(two); + } while (!subA.isProbablePrime(20)); + + // Search using our routines. + MillerRabin mr = new MillerRabin(bi, false, true); + boolean vmg = false; + BigInteger primeB = null; + BigInteger subB = null; + BigInteger b = null; + while (!vmg) { + primeB = mr.getCurrentCandidate(); + subB = primeB.subtract(BigInteger.ONE).divide(two); + vmg = true; + for (int i = 0; vmg && i < 30; i++) { + if (i % 2 == 0) { + b = getBasis(primeB, random); + } else { + b = getBasis(subB, random); + } + vmg = mr.once(b, i % 2); + } + mr.nextCandidate(); + } + mr.done(); + + assert primeA.equals(primeB) : "Failed get next prime!"; + + mr = new MillerRabin(primeA, false, false); + vmg = mr.trial(); + for (int i = 0; vmg && i < 40; i++) { + if (i % 2 == 0) { + b = getBasis(primeA, random); + } else { + b = getBasis(subA, random); + } + vmg = mr.once(b, i % 2); + } + mr.done(); + + assert vmg && primeA.equals(primeB) : "Failed verify safe prime!"; + } + } + + /** + * Tests modular arithmetic and prints the results. + * + * @param bitLength Number of bits of integers in the operation + * timed. + * @param milliSecs Duration of the timing. + */ + public static void test_vmg(final int bitLength, final int milliSecs) { + + final String f = + "%nTesting modular arithmetic: %d bitlength (%d ms/function)"; + + System.out.println(String.format(f, bitLength, milliSecs)); + System.out.println( + "----------------------------------------------------------------"); + + System.out.println("powm (plain modular exponentiation)"); + test_powm(bitLength, milliSecs); + System.out.println("spowm (simultaneous modular exponentiation)"); + test_spowm(bitLength, milliSecs); + System.out.println("fpowm (fixed-basis modular exponentiation)"); + test_fpowm(bitLength, milliSecs); + System.out.println("legendre (Legendre symbol)"); + test_legendre(bitLength, milliSecs); + System.out.println("prime (test random integers for primality)"); + test_millerrabin_prime(bitLength, milliSecs); + System.out.println("nextprime (find next prime)"); + test_millerrabin_nextprime(100, milliSecs); + System.out.println("nextsafeprime (find next and check safe prime " + + "100 bits)"); + test_millerrabin_nextsafeprime(70, milliSecs); + } + + /** + * Executes the testing routines. + * + * @param args Command line arguments. + */ + public static void main(final String[] args) { + + int[] bitLengths = new int[4]; + bitLengths[0] = 1024; + bitLengths[1] = 2048; + bitLengths[2] = 3072; + bitLengths[3] = 4096; + + if (args.length > 0) { + + bitLengths = new int[args.length]; + for (int i = 0; i < args.length; i++) { + + try { + bitLengths[i] = Integer.parseInt(args[i]); + } catch (NumberFormatException nfe) { + System.err.println("Failed to parse a bit length! (" + + args[i] + ")"); + System.exit(1); + } + } + } + + final String s = +"\n================================================================\n" ++ "\n TEST com.verificatum.vmgj.VMG \n\n" ++ " Although these tests technically give full coverage, they are\n" ++ " not sufficient to verify the correctness of the arithmetic.\n" ++ " The correctness of the arithmetic is guaranteed by the tests\n" ++ " of the native code. The tests run here merely verify that\n" ++ " native calls are handled correctly.\n\n" ++ "================================================================"; + + System.out.println(s); + + for (int i = 0; i < bitLengths.length; i++) { + + test_vmg(bitLengths[i], DEFAULT_TEST_TIME); + } + System.out.println(""); + } +} +//CHECKSTYLE.ON: LocalVariableName +//CHECKSTYLE.ON: LocalFinalVariableName +//CHECKSTYLE.ON: MethodName +//CHECKSTYLE.ON: ParameterName diff --git a/src/java/com/verificatum/vmgj/VMG.magic b/src/java/com/verificatum/vmgj/VMG.magic new file mode 100644 index 0000000..e57a7f4 --- /dev/null +++ b/src/java/com/verificatum/vmgj/VMG.magic @@ -0,0 +1,299 @@ + +/* + * Copyright 2008-2018 Douglas Wikstrom + * + * This file is part of Verificatum Multiplicative Groups library for + * Java (VMGJ). + * + * VMGJ is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * VMGJ 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 Affero General + * Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with VMGJ. If not, see + * . + */ + +package com.verificatum.vmgj; + +import java.math.BigInteger; + +// We use C style to name things in this file, since it should +// correspond to the native code. + +//CHECKSTYLE.OFF: LocalVariableName +//CHECKSTYLE.OFF: LocalFinalVariableName +//CHECKSTYLE.OFF: MethodName +//CHECKSTYLE.OFF: ParameterName + +/** + * Allows invoking the modular exponentiation, simultaneous modular + * exponentiation routines, primality tests, and related routines of + * the Gnu Multiprecision Library + * (GMP)and GMPMEE (a minor extension of GMP). + * + *

+ * + * @author Douglas Wikstrom + */ +@SuppressWarnings("PMD.MethodNamingConventions") +public final class VMG { + + /** + * Avoid accidental instantiation. + */ + private VMG() { + } + + /** + * Load native code upon loading this class. + */ + static { + System.loadLibrary("vmgj-M4_VERSION"); + } + + /** + * Converts an array of BigInteger to an array of + * byte[] representing the integers in two's + * complement representation. + * + * @param bis Integers to be converted. + * @return Array of converted integers. + */ + static byte[][] convert(final BigInteger[] bis) { + + final byte[][] native_bis = new byte[bis.length][]; + for (int i = 0; i < native_bis.length; i++) { + native_bis[i] = bis[i].toByteArray(); + } + return native_bis; + } + + /** + * Computes a modular exponentiation. + * + * @param basis Basis integer. + * @param exponent Exponent used to compute power. + * @param modulus Modulus. + * @return This instance to the power of exponent + * modulo modulus. + */ + static native byte[] powm(final byte[] basis, + final byte[] exponent, + final byte[] modulus); + + /** + * Computes a modular exponentiation. + * + * @param basis Basis integer. + * @param exponent Exponent used to compute power. + * @param modulus Modulus. + * @return This instance to the power of exponent + * modulo modulus. + * @throws ArithmeticException If the result from the native code + * can not be interpreted as a BigInteger. + */ + public static BigInteger powm(final BigInteger basis, + final BigInteger exponent, + final BigInteger modulus) + throws ArithmeticException { + return new BigInteger(powm(basis.toByteArray(), + exponent.toByteArray(), + modulus.toByteArray())); + } + + /** + * Computes a simultaneous modular exponentiation. + * + * @param bases Basis integers. + * @param exponents Exponent used to compute power. + * @param modulus Modulus. + * @return Product of the bases to the powers of + * exponents modulo modulus. + */ + static native byte[] spowm(final byte[][] bases, + final byte[][] exponents, + final byte[] modulus); + + /** + * Computes a simultaneous modular exponentiation. + * + * @param bases Basis elements. + * @param exponents Exponent used to compute power. + * @param modulus Modulus. + * @return Product of the bases to the powers of + * exponents modulo modulus. + */ + public static BigInteger spowm(final BigInteger[] bases, + final BigInteger[] exponents, + final BigInteger modulus) { + final byte[][] native_bases = convert(bases); + final byte[][] native_exponents = convert(exponents); + return new BigInteger(spowm(native_bases, + native_exponents, + modulus.toByteArray())); + } + + /** + * Performs precomputation for the given basis and modulus + * assuming the given exponent bit length. + * + * @param basis Basis elements. + * @param modulus Modulus used during modular exponentiation. + * @param exponentBitlen Expected bit length of exponents. + * @param blockWidth Decides how many distinct generators are used + * when translating an exponentiation into a simultaneous + * exponentiation. + * @return Native pointer to a precomputed table. + */ + static native long fpowm_precomp(byte[] basis, + byte[] modulus, + int blockWidth, + int exponentBitlen); + + /** + * Performs precomputation for the given basis and modulus + * assuming the given exponent bit length. + * + * @param tablePtr Native pointer to a precomputed table output by + * {@link #fpowm_precomp(byte[], byte[], int, int)}. + * @param exponent Exponent given in two's complement. + * @return Result of modular exponentiation. + */ + static native byte[] fpowm(long tablePtr, byte[] exponent); + + /** + * Frees the resources allocated by the native object pointed to + * by the input. + * + * @param tablePtr Native pointer to a precomputed table output by + * {@link #fpowm_precomp(byte[], byte[], int, int)}. + */ + static native void fpowm_clear(long tablePtr); + + /** + * Returns the Legendre symbol of op modulo + * odd_prime. + * + * @param op An integer. + * @param odd_prime An odd prime modulus. + * @return Legendre symbol of op modulo + * odd_prime. + */ + static native int legendre(final byte[] op, final byte[] odd_prime); + + /** + * Returns the Legendre symbol of this instance modulo the + * input. + * + * @param odd_prime An odd prime modulus. + * @param value Integer to be tested. + * @return Legendre symbol of value modulo + * odd_prime. + */ + public static int legendre(final BigInteger value, + final BigInteger odd_prime) { + return legendre(value.toByteArray(), odd_prime.toByteArray()); + } + + /** + * Allocate and initialize Miller-Rabin state using the given + * integer. + * + * @param n Integer to test. + * @param search Decides if we are searching for an integer or testing. + * @return Pointer to structure in native space. + */ + static native long millerrabin_init(byte[] n, boolean search); + + /** + * Increase the tested number to the next candidate integer. + * + * @param statePtr Native pointer to state for testing. + */ + static native void millerrabin_next_cand(long statePtr); + + /** + * Executes one round of the Miller-Rabin test and returns 0 or 1 + * depending on if the tested integer is deemed to be composite or + * not. + * + * @param statePtr Native pointer to state for testing. + * @param base Base element used for testing. This must be + * non-zero and non-one modulo the tested integer. + * @return Result of the test as a 0/1 integer. + */ + static native int millerrabin_once(long statePtr, byte[] base); + + /** + * Free memory resources allocated for testing. + * + * @param statePtr Native pointer to state for testing. + */ + static native void millerrabin_clear(long statePtr); + + /** + * Returns the current candidate integer. + * + * @param statePtr Native pointer to state for testing. + * @return Current candidate integer. + */ + static native byte[] millerrabin_current(long statePtr); + + /** + * Allocate and initialize Miller-Rabin state using the given + * integer. + * + * @param n Integer to test. + * @param search Decides if we are searching for an integer or testing. + * @return Native pointer to state for testing. + */ + static native long millerrabin_safe_init(byte[] n, boolean search); + + /** + * Increase the tested number to the next candidate integer. + * + * @param statePtr Native pointer to state for testing. + */ + static native void millerrabin_safe_next_cand(long statePtr); + + /** + * Executes one round of the Miller-Rabin test and returns 0 or 1 + * depending on if the tested integer is deemed to not be a safe + * prime, or a safe prime. + * + * @param statePtr Native pointer to state for testing. + * @param base Base element used for testing. + * @param index Must be zero for testing the integer and one for + * testing m, where n=2m+1. + * @return Result of test. + */ + static native int millerrabin_safe_once(long statePtr, + byte[] base, + int index); + + /** + * Free memory resources allocated for testing. + * + * @param statePtr Native pointer to state for testing. + */ + static native void millerrabin_safe_clear(long statePtr); + + /** + * Returns the current safe-prime candidate. + * + * @param statePtr Pointer to structure in native space. + * @return Current candidate safe-prime. + */ + static native byte[] millerrabin_current_safe(long statePtr); +} +//CHECKSTYLE.ON: LocalVariableName +//CHECKSTYLE.ON: LocalFinalVariableName +//CHECKSTYLE.ON: MethodName +//CHECKSTYLE.ON: ParameterName diff --git a/src/java/com/verificatum/vmgj/package-info.java b/src/java/com/verificatum/vmgj/package-info.java new file mode 100644 index 0000000..3ed9b1b --- /dev/null +++ b/src/java/com/verificatum/vmgj/package-info.java @@ -0,0 +1,27 @@ + +/* + * Copyright 2008-2018 Douglas Wikstrom + * + * This file is part of Verificatum Multiplicative Groups library for + * Java (VMGJ). + * + * VMGJ is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * VMGJ 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 Affero General + * Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with VMGJ. If not, see + * . + */ + + /** + * This library allows calling GMP and GMPMEE from Java. + */ + +package com.verificatum.vmgj; diff --git a/src/m4/ac_check_class.m4 b/src/m4/ac_check_class.m4 new file mode 100644 index 0000000..dcc8197 --- /dev/null +++ b/src/m4/ac_check_class.m4 @@ -0,0 +1,141 @@ +# =========================================================================== +# http://www.nongnu.org/autoconf-archive/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. +# +# LICENSE +# +# Copyright (c) 2008 Stephane Bortzmeyer +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# 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 Archive. When you make and distribute a +# modified version of the Autoconf Macro, you may extend this special +# exception to the GPL to apply to your modified version as well. + +AC_DEFUN([AC_CHECK_CLASS],[ +AC_REQUIRE([AC_PROG_JAVA]) +ac_var_name=`echo $1 | sed 's/\./_/g'` +dnl Normaly I'd use a AC_CACHE_CHECK here but since the variable name is +dnl dynamic I need an extra level of extraction +AC_MSG_CHECKING([for $1 class]) +AC_CACHE_VAL(ac_cv_class_$ac_var_name, [ +if test x$ac_cv_prog_uudecode_base64 = xyes; then +dnl /** +dnl * Test.java: used to test dynamicaly if a class exists. +dnl */ +dnl public class Test +dnl { +dnl +dnl public static void +dnl main( String[] argv ) +dnl { +dnl Class lib; +dnl if (argv.length < 1) +dnl { +dnl System.err.println ("Missing argument"); +dnl System.exit (77); +dnl } +dnl try +dnl { +dnl lib = Class.forName (argv[0]); +dnl } +dnl catch (ClassNotFoundException e) +dnl { +dnl System.exit (1); +dnl } +dnl lib = null; +dnl System.exit (0); +dnl } +dnl +dnl } +cat << \EOF > Test.uue +begin-base64 644 Test.class +yv66vgADAC0AKQcAAgEABFRlc3QHAAQBABBqYXZhL2xhbmcvT2JqZWN0AQAE +bWFpbgEAFihbTGphdmEvbGFuZy9TdHJpbmc7KVYBAARDb2RlAQAPTGluZU51 +bWJlclRhYmxlDAAKAAsBAANlcnIBABVMamF2YS9pby9QcmludFN0cmVhbTsJ +AA0ACQcADgEAEGphdmEvbGFuZy9TeXN0ZW0IABABABBNaXNzaW5nIGFyZ3Vt +ZW50DAASABMBAAdwcmludGxuAQAVKExqYXZhL2xhbmcvU3RyaW5nOylWCgAV +ABEHABYBABNqYXZhL2lvL1ByaW50U3RyZWFtDAAYABkBAARleGl0AQAEKEkp +VgoADQAXDAAcAB0BAAdmb3JOYW1lAQAlKExqYXZhL2xhbmcvU3RyaW5nOylM +amF2YS9sYW5nL0NsYXNzOwoAHwAbBwAgAQAPamF2YS9sYW5nL0NsYXNzBwAi +AQAgamF2YS9sYW5nL0NsYXNzTm90Rm91bmRFeGNlcHRpb24BAAY8aW5pdD4B +AAMoKVYMACMAJAoAAwAlAQAKU291cmNlRmlsZQEACVRlc3QuamF2YQAhAAEA +AwAAAAAAAgAJAAUABgABAAcAAABtAAMAAwAAACkqvgSiABCyAAwSD7YAFBBN +uAAaKgMyuAAeTKcACE0EuAAaAUwDuAAasQABABMAGgAdACEAAQAIAAAAKgAK +AAAACgAAAAsABgANAA4ADgATABAAEwASAB4AFgAiABgAJAAZACgAGgABACMA +JAABAAcAAAAhAAEAAQAAAAUqtwAmsQAAAAEACAAAAAoAAgAAAAQABAAEAAEA +JwAAAAIAKA== +==== +EOF + if uudecode$EXEEXT Test.uue; then + : + else + echo "configure: __oline__: uudecode had trouble decoding base 64 file 'Test.uue'" >&AC_FD_CC + echo "configure: failed file was:" >&AC_FD_CC + cat Test.uue >&AC_FD_CC + ac_cv_prog_uudecode_base64=no + fi + rm -f Test.uue + if AC_TRY_COMMAND($JAVA $JAVAFLAGS Test $1) >/dev/null 2>&1; then + eval "ac_cv_class_$ac_var_name=yes" + else + eval "ac_cv_class_$ac_var_name=no" + fi + rm -f Test.class +else + AC_TRY_COMPILE_JAVA([$1], , [eval "ac_cv_class_$ac_var_name=yes"], + [eval "ac_cv_class_$ac_var_name=no"]) +fi +eval "ac_var_val=$`eval echo ac_cv_class_$ac_var_name`" +eval "HAVE_$ac_var_name=$`echo ac_cv_class_$ac_var_val`" +HAVE_LAST_CLASS=$ac_var_val +if test x$ac_var_val = xyes; then + ifelse([$2], , :, [$2]) +else + ifelse([$3], , :, [$3]) +fi +]) +dnl for some reason the above statment didn't fall though here? +dnl do scripts have variable scoping? +eval "ac_var_val=$`eval echo ac_cv_class_$ac_var_name`" +AC_MSG_RESULT($ac_var_val) +]) diff --git a/src/m4/ac_check_classpath.m4 b/src/m4/ac_check_classpath.m4 new file mode 100644 index 0000000..ea3e779 --- /dev/null +++ b/src/m4/ac_check_classpath.m4 @@ -0,0 +1,57 @@ +# =========================================================================== +# http://www.nongnu.org/autoconf-archive/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. +# +# LICENSE +# +# Copyright (c) 2008 Stephane Bortzmeyer +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# 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 Archive. When you make and distribute a +# modified version of the Autoconf Macro, you may extend this special +# exception to the GPL to apply to your modified version as well. + +AC_DEFUN([AC_CHECK_CLASSPATH],[ +if test "x$CLASSPATH" = x; then + echo "You have no CLASSPATH, I hope it is good" +else + echo "You have CLASSPATH $CLASSPATH, hope it is correct" +fi +]) diff --git a/src/m4/ac_check_java_home.m4 b/src/m4/ac_check_java_home.m4 new file mode 100644 index 0000000..13b1e51 --- /dev/null +++ b/src/m4/ac_check_java_home.m4 @@ -0,0 +1,56 @@ +# =========================================================================== +# http://www.nongnu.org/autoconf-archive/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. +# +# LICENSE +# +# Copyright (c) 2008 Gleen Salmon +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# 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 Archive. When you make and distribute a +# modified version of the Autoconf Macro, you may extend this special +# exception to the GPL to apply to your modified version as well. + +AC_DEFUN([AC_CHECK_JAVA_HOME],[ +AC_REQUIRE([AC_EXEEXT])dnl +TRY_JAVA_HOME=`ls -dr /usr/java/* 2> /dev/null | head -n 1` +if test x$TRY_JAVA_HOME != x; then + PATH=$PATH:$TRY_JAVA_HOME/bin +fi +AC_PATH_PROG(JAVA_PATH_NAME, java$EXEEXT) +if test x$JAVA_PATH_NAME != x; then + JAVA_HOME=`echo $JAVA_PATH_NAME | sed "s/\(.*\)[[/]]bin[[/]]java$EXEEXT$/\1/"` +fi;dnl +]) diff --git a/src/m4/ac_check_rqrd_class.m4 b/src/m4/ac_check_rqrd_class.m4 new file mode 100644 index 0000000..62b130f --- /dev/null +++ b/src/m4/ac_check_rqrd_class.m4 @@ -0,0 +1,59 @@ +# =========================================================================== +# http://www.nongnu.org/autoconf-archive/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. +# +# LICENSE +# +# Copyright (c) 2008 Stephane Bortzmeyer +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# 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 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 + AC_MSG_ERROR([Required class $1 missing, exiting.]) +fi +]) diff --git a/src/m4/ac_java_options.m4 b/src/m4/ac_java_options.m4 new file mode 100644 index 0000000..c51aa7e --- /dev/null +++ b/src/m4/ac_java_options.m4 @@ -0,0 +1,44 @@ +# =========================================================================== +# http://www.nongnu.org/autoconf-archive/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. +# +# LICENSE +# +# Copyright (c) 2008 Devin Weaver +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. + +AC_DEFUN([AC_JAVA_OPTIONS],[ +AC_ARG_WITH(java-prefix, + [ --with-java-prefix=PFX prefix where Java runtime is installed (optional)]) +AC_ARG_WITH(javac-flags, + [ --with-javac-flags=FLAGS flags to pass to the Java compiler (optional)]) +AC_ARG_WITH(java-flags, + [ --with-java-flags=FLAGS flags to pass to the Java VM (optional)]) +JAVAPREFIX=$with_java_prefix +JAVACFLAGS=$with_javac_flags +JAVAFLAGS=$with_java_flags +AC_SUBST(JAVAPREFIX)dnl +AC_SUBST(JAVACFLAGS)dnl +AC_SUBST(JAVAFLAGS)dnl +AC_SUBST(JAVA)dnl +AC_SUBST(JAVAC)dnl +]) diff --git a/src/m4/ac_prog_jar.m4 b/src/m4/ac_prog_jar.m4 new file mode 100644 index 0000000..2b0a595 --- /dev/null +++ b/src/m4/ac_prog_jar.m4 @@ -0,0 +1,48 @@ +# =========================================================================== +# http://www.nongnu.org/autoconf-archive/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. +# +# LICENSE +# +# Copyright (c) 2008 Egon Willighagen +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. + +AC_DEFUN([AC_PROG_JAR],[ +AC_REQUIRE([AC_EXEEXT])dnl +if test "x$JAVAPREFIX" = x; then + test "x$JAR" = x && AC_CHECK_PROGS(JAR, jar$EXEEXT) +else + test "x$JAR" = x && AC_CHECK_PROGS(JAR, jar, $JAVAPREFIX) +fi +test "x$JAR" = x && AC_MSG_ERROR([no acceptable jar program found in \$PATH]) +AC_PROVIDE([$0])dnl +]) diff --git a/src/m4/ac_prog_java.m4 b/src/m4/ac_prog_java.m4 new file mode 100644 index 0000000..d28dc12 --- /dev/null +++ b/src/m4/ac_prog_java.m4 @@ -0,0 +1,113 @@ +# =========================================================================== +# http://www.nongnu.org/autoconf-archive/ac_prog_java.html +# =========================================================================== +# +# SYNOPSIS +# +# AC_PROG_JAVA +# +# DESCRIPTION +# +# Here is a summary of the main macros: +# +# AC_PROG_JAVAC: finds a Java compiler. +# +# AC_PROG_JAVA: finds a Java virtual machine. +# +# AC_CHECK_CLASS: finds if we have the given class (beware of CLASSPATH!). +# +# AC_CHECK_RQRD_CLASS: finds if we have the given class and stops +# otherwise. +# +# AC_TRY_COMPILE_JAVA: attempt to compile user given source. +# +# AC_TRY_RUN_JAVA: attempt to compile and run user given source. +# +# AC_JAVA_OPTIONS: adds Java configure options. +# +# AC_PROG_JAVA tests an existing Java virtual machine. It uses the +# environment variable JAVA then tests in sequence various common Java +# virtual machines. For political reasons, it starts with the free ones. +# You *must* call [AC_PROG_JAVAC] before. +# +# If you want to force a specific VM: +# +# - at the configure.in level, set JAVA=yourvm before calling AC_PROG_JAVA +# +# (but after AC_INIT) +# +# - at the configure level, setenv JAVA +# +# You can use the JAVA variable in your Makefile.in, with @JAVA@. +# +# *Warning*: its success or failure can depend on a proper setting of the +# CLASSPATH env. variable. +# +# TODO: allow to exclude virtual machines (rationale: most Java programs +# cannot run with some VM like kaffe). +# +# Note: This is part of the set of autoconf M4 macros for Java programs. +# It is VERY IMPORTANT that you download the whole set, some macros depend +# on other. Unfortunately, the autoconf archive does not support the +# concept of set of macros, so I had to break it for submission. +# +# A Web page, with a link to the latest CVS snapshot is at +# . +# +# This is a sample configure.in Process this file with autoconf to produce +# a configure script. +# +# AC_INIT(UnTag.java) +# +# dnl Checks for programs. +# AC_CHECK_CLASSPATH +# AC_PROG_JAVAC +# AC_PROG_JAVA +# +# dnl Checks for classes +# AC_CHECK_RQRD_CLASS(org.xml.sax.Parser) +# AC_CHECK_RQRD_CLASS(com.jclark.xml.sax.Driver) +# +# AC_OUTPUT(Makefile) +# +# LICENSE +# +# Copyright (c) 2008 Stephane Bortzmeyer +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# 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 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 +test x$JAVA = x && AC_MSG_ERROR([no acceptable Java virtual machine found in \$PATH]) +AC_PROG_JAVA_WORKS +AC_PROVIDE([$0])dnl +]) diff --git a/src/m4/ac_prog_java_works.m4 b/src/m4/ac_prog_java_works.m4 new file mode 100644 index 0000000..3a36319 --- /dev/null +++ b/src/m4/ac_prog_java_works.m4 @@ -0,0 +1,131 @@ +# =========================================================================== +# http://www.nongnu.org/autoconf-archive/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. +# +# LICENSE +# +# Copyright (c) 2008 Stephane Bortzmeyer +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# 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 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 + AC_MSG_ERROR([Cannot compile java source. $JAVAC does not work properly]) + 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 + AC_MSG_ERROR(The Java compiler $JAVAC failed (see config.log, check the CLASSPATH?)) + 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 + AC_MSG_ERROR(The Java VM $JAVA failed (see config.log, check the CLASSPATH?)) +fi +rm -fr $JAVA_TEST $CLASS_TEST Test.uue +]) +AC_PROVIDE([$0])dnl +] +) diff --git a/src/m4/ac_prog_javac_works.m4 b/src/m4/ac_prog_javac_works.m4 new file mode 100644 index 0000000..36164a4 --- /dev/null +++ b/src/m4/ac_prog_javac_works.m4 @@ -0,0 +1,69 @@ +# =========================================================================== +# http://www.nongnu.org/autoconf-archive/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. +# +# LICENSE +# +# Copyright (c) 2008 Stephane Bortzmeyer +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# 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 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 + AC_MSG_ERROR([The Java compiler $JAVAC failed (see config.log, check the CLASSPATH?)]) + echo "configure: failed program was:" >&AC_FD_CC + cat $JAVA_TEST >&AC_FD_CC +fi +rm -f $JAVA_TEST $CLASS_TEST +]) +AC_PROVIDE([$0])dnl +]) diff --git a/src/m4/ac_prog_javadoc.m4 b/src/m4/ac_prog_javadoc.m4 new file mode 100644 index 0000000..e689cbb --- /dev/null +++ b/src/m4/ac_prog_javadoc.m4 @@ -0,0 +1,49 @@ +# =========================================================================== +# http://www.nongnu.org/autoconf-archive/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. +# +# LICENSE +# +# Copyright (c) 2008 Egon Willighagen +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. + +AC_DEFUN([AC_PROG_JAVADOC],[ +AC_REQUIRE([AC_EXEEXT])dnl +if test "x$JAVAPREFIX" = x; then + test "x$JAVADOC" = x && AC_CHECK_PROGS(JAVADOC, javadoc$EXEEXT) +else + test "x$JAVADOC" = x && AC_CHECK_PROGS(JAVADOC, javadoc, $JAVAPREFIX) +fi +test "x$JAVADOC" = x && AC_MSG_ERROR([no acceptable javadoc generator found in \$PATH]) +AC_PROVIDE([$0])dnl +]) diff --git a/src/m4/ac_prog_javah.m4 b/src/m4/ac_prog_javah.m4 new file mode 100644 index 0000000..ed0a5c3 --- /dev/null +++ b/src/m4/ac_prog_javah.m4 @@ -0,0 +1,39 @@ +# =========================================================================== +# http://www.nongnu.org/autoconf-archive/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. +# +# LICENSE +# +# Copyright (c) 2008 Luc Maisonobe +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. + +AC_DEFUN([AC_PROG_JAVAH],[ +AC_REQUIRE([AC_CANONICAL_SYSTEM])dnl +AC_REQUIRE([AC_PROG_CPP])dnl +AC_PATH_PROG(JAVAH,javah) +if test x"`eval 'echo $ac_cv_path_JAVAH'`" != x ; then + AC_TRY_CPP([#include ],,[ + ac_save_CPPFLAGS="$CPPFLAGS" +changequote(, )dnl + ac_dir=`echo $ac_cv_path_JAVAH | sed 's,\(.*\)/[^/]*/[^/]*$,\1/include,'` + ac_machdep=`echo $build_os | sed 's,[-0-9].*,,' | sed 's,cygwin,win32,'` +changequote([, ])dnl + CPPFLAGS="$ac_save_CPPFLAGS -I$ac_dir -I$ac_dir/$ac_machdep" + AC_TRY_CPP([#include ], + ac_save_CPPFLAGS="$CPPFLAGS", + AC_MSG_WARN([unable to include ])) + CPPFLAGS="$ac_save_CPPFLAGS"]) +fi]) diff --git a/src/m4/ac_try_compile_java.m4 b/src/m4/ac_try_compile_java.m4 new file mode 100644 index 0000000..8e776f8 --- /dev/null +++ b/src/m4/ac_try_compile_java.m4 @@ -0,0 +1,51 @@ +# =========================================================================== +# http://www.nongnu.org/autoconf-archive/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. +# +# LICENSE +# +# Copyright (c) 2008 Devin Weaver +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. + +AC_DEFUN([AC_TRY_COMPILE_JAVA],[ +AC_REQUIRE([AC_PROG_JAVAC])dnl +cat << \EOF > Test.java +/* [#]line __oline__ "configure" */ +ifelse([$1], , , [import $1;]) +public class Test { +[$2] +} +EOF +if AC_TRY_COMMAND($JAVAC $JAVACFLAGS Test.java) && test -s Test.class +then +dnl Don't remove the temporary files here, so they can be examined. + ifelse([$3], , :, [$3]) +else + echo "configure: failed program was:" >&AC_FD_CC + cat Test.java >&AC_FD_CC +ifelse([$4], , , [ rm -fr Test* + $4 +])dnl +fi +rm -fr Test*]) diff --git a/src/m4/ac_try_run_javac.m4 b/src/m4/ac_try_run_javac.m4 new file mode 100644 index 0000000..c7cf925 --- /dev/null +++ b/src/m4/ac_try_run_javac.m4 @@ -0,0 +1,52 @@ +# =========================================================================== +# http://www.nongnu.org/autoconf-archive/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. +# +# LICENSE +# +# Copyright (c) 2008 Devin Weaver +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. + +AC_DEFUN([AC_TRY_RUN_JAVA],[ +AC_REQUIRE([AC_PROG_JAVAC])dnl +AC_REQUIRE([AC_PROG_JAVA])dnl +cat << \EOF > Test.java +/* [#]line __oline__ "configure" */ +ifelse([$1], , , [include $1;]) +public class Test { +[$2] +} +EOF +if AC_TRY_COMMAND($JAVAC $JAVACFLAGS Test.java) && test -s Test.class && ($JAVA $JAVAFLAGS Test; exit) 2>/dev/null +then +dnl Don't remove the temporary files here, so they can be examined. + ifelse([$3], , :, [$3]) +else + echo "configure: failed program was:" >&AC_FD_CC + cat Test.java >&AC_FD_CC +ifelse([$4], , , [ rm -fr Test* + $4 +])dnl +fi +rm -fr Test*]) diff --git a/src/m4/ace_check_jvmg.m4 b/src/m4/ace_check_jvmg.m4 new file mode 100644 index 0000000..2e7ee77 --- /dev/null +++ b/src/m4/ace_check_jvmg.m4 @@ -0,0 +1,32 @@ + +# Copyright 2008-2018 Douglas Wikstrom +# +# This file is part of Verificatum Multiplicative Groups library for +# Java (VMGJ). +# +# VMGJ is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# VMGJ 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 Affero General +# Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with VMGJ. If not, see . + +AC_DEFUN([ACE_CHECK_VMGJ],[ +AC_REQUIRE([ACE_PROG_JAVA]) +ace_res=$($JAVA $JAVAFLAGS -classpath $CLASSPATH TestLoadVMGJ) + +echo -n "checking for vmgj.jar... " +if test "x$ace_res" = x +then + echo "yes" +else + echo "no" + AC_MSG_ERROR([$ace_res Please make sure that VMGJ is installed (found at www.verificatum.org) and that your \$CLASSPATH points to the proper location. You can check your VMGJ installation using \"java vmgj.Test\". This should give you a usage description.]) +fi +]) diff --git a/src/m4/ace_prog_jar.m4 b/src/m4/ace_prog_jar.m4 new file mode 100644 index 0000000..7edddfd --- /dev/null +++ b/src/m4/ace_prog_jar.m4 @@ -0,0 +1,27 @@ + +# Copyright 2008-2018 Douglas Wikstrom +# +# This file is part of Verificatum Multiplicative Groups library for +# Java (VMGJ). +# +# VMGJ is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# VMGJ 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 Affero General +# Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with VMGJ. If not, see . + +AC_DEFUN([ACE_PROG_JAR],[ +AC_CHECK_PROG([JAR], [jar], [jar], [no]) + +if test $JAR = no +then + AC_MSG_ERROR([No jar found in \$PATH. Please install JDK 6!]) +fi +]) diff --git a/src/m4/ace_prog_java.m4 b/src/m4/ace_prog_java.m4 new file mode 100644 index 0000000..653ac0d --- /dev/null +++ b/src/m4/ace_prog_java.m4 @@ -0,0 +1,27 @@ + +# Copyright 2008-2018 Douglas Wikstrom +# +# This file is part of Verificatum Multiplicative Groups library for +# Java (VMGJ). +# +# VMGJ is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# VMGJ 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 Affero General +# Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with VMGJ. If not, see . + +AC_DEFUN([ACE_PROG_JAVA],[ +AC_CHECK_PROG([JAVA], [java], [java], [no]) + +if test $JAVA = no +then + AC_MSG_ERROR([No java found in \$PATH. Please install JDK 6!]) +fi +]) diff --git a/src/m4/ace_prog_javac.m4 b/src/m4/ace_prog_javac.m4 new file mode 100644 index 0000000..d287203 --- /dev/null +++ b/src/m4/ace_prog_javac.m4 @@ -0,0 +1,27 @@ + +# Copyright 2008-2018 Douglas Wikstrom +# +# This file is part of Verificatum Multiplicative Groups library for +# Java (VMGJ). +# +# VMGJ is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# VMGJ 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 Affero General +# Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with VMGJ. If not, see . + +AC_DEFUN([ACE_PROG_JAVAC],[ +AC_CHECK_PROG([JAVAC], [javac], [javac], [no]) + +if test $JAVAC = no +then + AC_MSG_ERROR([No javac found in \$PATH. Please install JDK 6!]) +fi +]) diff --git a/src/m4/ace_prog_javadoc.m4 b/src/m4/ace_prog_javadoc.m4 new file mode 100644 index 0000000..5dfe820 --- /dev/null +++ b/src/m4/ace_prog_javadoc.m4 @@ -0,0 +1,27 @@ + +# Copyright 2008-2018 Douglas Wikstrom +# +# This file is part of Verificatum Multiplicative Groups library for +# Java (VMGJ). +# +# VMGJ is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# VMGJ 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 Affero General +# Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with VMGJ. If not, see . + +AC_DEFUN([ACE_PROG_JAVADOC],[ +AC_CHECK_PROG([JAVADOC], [javadoc], [javadoc], [no]) + +if test $JAVADOC = no +then + AC_MSG_ERROR([No javadoc found in \$PATH. Please install JDK 6!]) +fi +]) diff --git a/src/m4/ace_prog_javah.m4 b/src/m4/ace_prog_javah.m4 new file mode 100644 index 0000000..f11add8 --- /dev/null +++ b/src/m4/ace_prog_javah.m4 @@ -0,0 +1,27 @@ + +# Copyright 2008-2018 Douglas Wikstrom +# +# This file is part of Verificatum Multiplicative Groups library for +# Java (VMGJ). +# +# VMGJ is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# VMGJ 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 Affero General +# Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with VMGJ. If not, see . + +AC_DEFUN([ACE_PROG_JAVAH],[ +AC_CHECK_PROG([JAVAH], [javah], [javah], [no]) + +if test $JAVAH = no +then + AC_MSG_ERROR([No javah found in \$PATH. Please install JDK 6!]) +fi +]) diff --git a/src/m4/dps_check_plugin.m4 b/src/m4/dps_check_plugin.m4 new file mode 100644 index 0000000..a06ad6a --- /dev/null +++ b/src/m4/dps_check_plugin.m4 @@ -0,0 +1,98 @@ +# =========================================================================== +# http://www.nongnu.org/autoconf-archive/dps_check_plugin.html +# =========================================================================== +# +# SYNOPSIS +# +# DPS_CHECK_JAVA_PLUGIN() +# +# DESCRIPTION +# +# This macro sets to empty on failure and to a compatible +# version of plugin.jar otherwise. Directories searched are /usr/java/* +# and /usr/local/java/*, which are assumed to be j{dk,re} installations. +# Apply the shell variable as you see fit. If sun changes things so +# /lib/plugin.jar is not the magic file it will stop working. +# +# This macro assumes that unzip, zipinfo or pkzipc is avialable (and can +# list the contents of the jar archive). The first two are assumed to work +# similarly enough to the infozip versisonms. The pkzipc version is +# assumed to work if I undertstand the documentation on pkware's site but +# YMMV. I do not have access to pwkware's version to test it. +# +# LICENSE +# +# Copyright (c) 2008 Duncan Simpson +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# 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 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_CHECK_JAVA_PLUGIN], +[AC_REQUIRE([AC_PROG_AWK]) +AC_REQUIRE([AC_PROG_FGREP]) +AC_CHECK_PROG(ZIPINFO,[zipinfo unzip pkzipc]) +AC_MSG_CHECKING([for the java plugin]) +case "x$ZIPINFO" in +[*/zipinfo)] + zipinf="zipinfo -1" ;; +[*/unzip)] + zipinf="unzip -l";; +[*/pkzipc)] + ziping="unzipc -view";; +[x*)] + AC_MSG_RESULT([skiped, none of zipinfo, unzip and pkzipc found]) + AC_SUBST($1,[]) + zipinf="";; +esac +if test "x$zipinf" != "x"; then +jplugin="" +for jhome in `ls -dr /usr/java/* /usr/local/java/* 2> /dev/null`; do +for jfile in lib/plugin.jar jre/lib/plugin.jar; do +if test "x$jplugin" = "x" && test -f "$jhome/$jfile"; then +eval "$zipinf $jhome/$jfile | $AWK '{ print \$NF; }' | $FGREP netscape/javascript/JSObject" >/dev/null 2>/dev/null +if test $? -eq 0; then +dnl Some version of gcj (and javac) refuse to work with some files +dnl that pass this test. To stop this problem make sure that the compiler +dnl still works with this jar file in the classpath +cat << \EOF > Test.java +/* [#]line __oline__ "configure" */ +public class Test { +} +EOF +if eval "$JAVAC -classpath $jhome/$jfile Test.java 2>/dev/null >/dev/null" && test -f Test.class; then +jplugin="$jhome/$jfile" +fi +rm -f Test.java Test.class +fi; fi; done; done +if test "x$jplugin" != "x"; then +AC_SUBST($1,$jplugin) +AC_MSG_RESULT($jplugin) +else +AC_MSG_RESULT([java plugin not found]) +AC_SUBST($1,[]) +fi +fi +]) diff --git a/src/m4/dps_java_check_class.m4 b/src/m4/dps_java_check_class.m4 new file mode 100644 index 0000000..1f521b6 --- /dev/null +++ b/src/m4/dps_java_check_class.m4 @@ -0,0 +1,82 @@ +# =========================================================================== +# http://www.nongnu.org/autoconf-archive/dps_java_check_class.html +# =========================================================================== +# +# SYNOPSIS +# +# DPS_JAVA_CHECK_CLASS(,,) +# +# DESCRIPTION +# +# Test if a Java class is available. Based on AC_PROG_JAVAC_WORKS. This +# version uses a cache variable which is both compiler, options and +# classpath dependent (so if you switch from javac to gcj it correctly +# notices and redoes the test). +# +# The macro tries to compile a minimal program importing . Some +# newer compilers moan about the failure to use this but fail or produce a +# class file anyway. All moaing is sunk to /dev/null since I only wanted +# to know if the class could be imported. This is a recommended followup +# to DPS_CHECK_JAVA_PLUGIN with classpath appropriately adjusted. +# +# LICENSE +# +# Copyright (c) 2008 Duncan Simpson +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# 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 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 avialable$xtra], [$cache_var], [ +JAVA_TEST=Test.java +CLASS_TEST=Test.class +cat << \EOF > $JAVA_TEST +/* [#]xline __oline__ "configure" */ +import $1; +public class Test { +} +EOF +if AC_TRY_COMMAND($JAVAC $JAVACFLAGS $xopts $JAVA_TEST) >/dev/null 2>&1; then + eval "${cache_var}=yes" +else + eval "${cache_var}=no" + echo "configure: failed program was:" >&AC_FD_CC + cat $JAVA_TEST >&AC_FD_CC +fi +rm -f $JAVA_TEST $CLASS_TEST +]) +if eval 'test "x$'${cache_var}'" = "xyes"'; then +$2 +true; else +$3 +false; fi]) diff --git a/src/mf/MANIFEST.MF.src b/src/mf/MANIFEST.MF.src new file mode 100644 index 0000000..1f75dca --- /dev/null +++ b/src/mf/MANIFEST.MF.src @@ -0,0 +1,7 @@ +Name: com/verificatum/vmgj/ +Specification-Title: VMGJ +Specification-Version: VMGJ_VERSION_STRING +Specification-Vendor: Verificatum Project +Implementation-Title: com.verificatum.vmgj +Implementation-Version: VMGJ_VERSION_STRING +Implementation-Vendor: Verificatum Project diff --git a/tools/staticanalysis/checkstyle/checkstyle_configure.xml b/tools/staticanalysis/checkstyle/checkstyle_configure.xml new file mode 100644 index 0000000..a498fd8 --- /dev/null +++ b/tools/staticanalysis/checkstyle/checkstyle_configure.xml @@ -0,0 +1,212 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/staticanalysis/checkstyle/checkstyle_filter.sh b/tools/staticanalysis/checkstyle/checkstyle_filter.sh new file mode 100755 index 0000000..bb5a302 --- /dev/null +++ b/tools/staticanalysis/checkstyle/checkstyle_filter.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +# Copyright 2008-2018 Douglas Wikstrom +# +# This file is part of Verificatum Multiplicative Groups library for +# Java (VMGJ). +# +# VMGJ is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# VMGJ 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 Affero General +# Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with VMGJ. If not, see . + +RAW_REPORT_FILE=$1 +REPORT_FILE=$2 + +cat $RAW_REPORT_FILE | grep -E -v "Starting audit|Audit done" | sed "s/.*verificatum\/\(verificatum.*\)/\1/p" > $REPORT_FILE + +return 0 diff --git a/tools/staticanalysis/checkstyle/checkstyle_ruleset.xml b/tools/staticanalysis/checkstyle/checkstyle_ruleset.xml new file mode 100644 index 0000000..a238660 --- /dev/null +++ b/tools/staticanalysis/checkstyle/checkstyle_ruleset.xml @@ -0,0 +1,337 @@ + + + + + Ruleset used by PDM to analyze Verificatum. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/staticanalysis/checkstyle/checkstyle_suppressions.xml b/tools/staticanalysis/checkstyle/checkstyle_suppressions.xml new file mode 100644 index 0000000..a2013f1 --- /dev/null +++ b/tools/staticanalysis/checkstyle/checkstyle_suppressions.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/staticanalysis/checkstyle/checkstyle_wrapper b/tools/staticanalysis/checkstyle/checkstyle_wrapper new file mode 100755 index 0000000..6487803 --- /dev/null +++ b/tools/staticanalysis/checkstyle/checkstyle_wrapper @@ -0,0 +1,26 @@ +#!/bin/sh + +# Copyright 2008-2018 Douglas Wikstrom +# +# This file is part of Verificatum Multiplicative Groups library for +# Java (VMGJ). +# +# VMGJ is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# VMGJ 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 Affero General +# Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with VMGJ. If not, see . + +# The authors of checkstyle report the total number of issues in the +# exit code. This is an abuse of the exit codes. + +checkstyle -c $1 -o $2 $3 + +exit 0 diff --git a/tools/staticanalysis/findbugs/findbugs_configure.xml b/tools/staticanalysis/findbugs/findbugs_configure.xml new file mode 100644 index 0000000..551c055 --- /dev/null +++ b/tools/staticanalysis/findbugs/findbugs_configure.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/tools/staticanalysis/findbugs/findbugs_wrapper b/tools/staticanalysis/findbugs/findbugs_wrapper new file mode 100755 index 0000000..0a93535 --- /dev/null +++ b/tools/staticanalysis/findbugs/findbugs_wrapper @@ -0,0 +1,21 @@ +#!/bin/sh + +# Copyright 2008-2018 Douglas Wikstrom +# +# This file is part of Verificatum Multiplicative Groups library for +# Java (VMGJ). +# +# VMGJ is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# VMGJ 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 Affero General +# Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with VMGJ. If not, see . + +findbugs $@ diff --git a/tools/staticanalysis/generate_analysis.sh b/tools/staticanalysis/generate_analysis.sh new file mode 100755 index 0000000..cf61b5a --- /dev/null +++ b/tools/staticanalysis/generate_analysis.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +# Copyright 2008-2018 Douglas Wikstrom +# +# This file is part of Verificatum Multiplicative Groups library for +# Java (VMGJ). +# +# VMGJ is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# VMGJ 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 Affero General +# Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with VMGJ. If not, see . + +add_result() { + + TOOLNAME=$1 + CONTENTFILE=$2 + OUTPUTFILE=$3 + + printf "\n#########################################################\n" \ +>> $OUTPUTFILE + printf "$TOOLNAME\n\n" >> $OUTPUTFILE + + CONTENT=`cat $CONTENTFILE` + + if test "x$CONTENT" = x; + then + printf "NO COMPLAINTS!\n" >> $OUTPUTFILE + else + printf "%s" "$CONTENT" >> $OUTPUTFILE + fi +} + +printf "\nCODE ANALYSIS REPORTS\n" > analysis_report.txt +add_result "Checkstyle (configured using checkstyle_ruleset.xml and checkstyle_suppressions.xml)" checkstyle/checkstyle_report.txt analysis_report.txt +add_result "Findbugs (configured using findbugs_configure.xml)" findbugs/findbugs_report.txt analysis_report.txt +add_result "PMD (configured using pmd_ruleset.xml and pmd_filter.sh)" pmd/pmd_report.txt analysis_report.txt + +printf "\n" diff --git a/tools/staticanalysis/pmd/pmd_filter.sh b/tools/staticanalysis/pmd/pmd_filter.sh new file mode 100755 index 0000000..959ac90 --- /dev/null +++ b/tools/staticanalysis/pmd/pmd_filter.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +# Copyright 2008-2018 Douglas Wikstrom +# +# This file is part of Verificatum Multiplicative Groups library for +# Java (VMGJ). +# +# VMGJ is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# VMGJ 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 Affero General +# Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with VMGJ. If not, see . + +# No filtering so far. +cp $1 $2 + +return 0 diff --git a/tools/staticanalysis/pmd/pmd_ruleset.xml b/tools/staticanalysis/pmd/pmd_ruleset.xml new file mode 100644 index 0000000..a9d5cd3 --- /dev/null +++ b/tools/staticanalysis/pmd/pmd_ruleset.xml @@ -0,0 +1,369 @@ + + + + + Ruleset used by PDM to analyze VECJ. Please read the comments to + see what rules have been commented out and why. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/staticanalysis/pmd/pmd_wrapper b/tools/staticanalysis/pmd/pmd_wrapper new file mode 100755 index 0000000..0e402b6 --- /dev/null +++ b/tools/staticanalysis/pmd/pmd_wrapper @@ -0,0 +1,56 @@ +#!/bin/sh + + +# Copyright 2008-2018 Douglas Wikstrom +# +# This file is part of Verificatum Multiplicative Groups library for +# Java (VMGJ). +# +# VMGJ is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# VMGJ 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 Affero General +# Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with VMGJ. If not, see . + +# The authors of PMD have not provided any installation program, so we +# need this wrapper to give a clean Makefile.am. You can simply unpack +# the pmd directory in your home directory. + +pmd_run_in_dir() { + RES=`ls -1 $2 | grep -v zip | grep -v tar.gz | sort | grep -E "pmd-bin-?\.?\.?" | tail -n 1` + eval "$1=\$2/\$RES/bin/run.sh" +} + + +pmd_run_in_dir PMD_RUN $PWD + +if test -f $PMD_RUN; +then + + $PMD_RUN pmd $@ + +else + + pmd_run_in_dir PMD_RUN $HOME + + if test -f $PMD_RUN; + then + + $PMD_RUN pmd $@ + + else + + echo "Failed to find any pmd binary! Please consult Makefile.am for more information." + + exit 1 + fi +fi + +exit 0