├── .classpath
├── .project
├── FUSION DCRM Verification v1 Guide.pdf
├── LICENSE
├── Lib
├── Jpair_v1.03.jar
├── assertj-core-3.5.2.jar
├── bcprov-ext-jdk15on-154.jar
├── bcprov-jdk15on-154.jar
├── commons-beanutils-1.9.3.jar
├── commons-cli-1.3.1.jar
├── commons-collections-3.2.1.jar
├── commons-lang-2.6.jar
├── commons-lang3-3.7.jar
├── commons-logging-1.2.jar
├── config-1.3.1.jar
├── core-1.58.0.0.jar
├── core-2.1.0.jar
├── curl-0.0.19.jar
├── ethereumj-core-1.7.2-RELEASE.jar
├── ezmorph-1.0.6.jar
├── httpclient-4.5.jar
├── httpcore-4.4.jar
├── httpmime-4.5.2.jar
├── javassist-3.20.0-GA.jar
├── jna-4.5.1.jar
├── jpbc-api-2.0.0.jar
├── jpbc-benchmark-2.0.0.jar
├── jpbc-crypto-2.0.0.jar
├── jpbc-mm-2.0.0.jar
├── jpbc-pbc-2.0.0.jar
├── jpbc-plaf-2.0.0.jar
├── json-lib-2.4-jdk13.jar
├── junit-4.12.jar
├── log4j-1.2.17.jar
├── mockserver-netty-3.10.4.jar
├── prov-1.58.0.0.jar
├── slf4j-api-1.7.25.jar
├── slf4j-log4j12-1.7.25.jar
├── spring-boot-starter-1.4.0.RELEASE.jar
├── spring-boot-starter-jetty-1.4.0.RELEASE.jar
├── spring-boot-starter-security-1.4.0.RELEASE.jar
└── spring-boot-starter-web-1.4.0.RELEASE.jar
├── README.md
├── bin
└── org
│ ├── fsn_cfc
│ ├── cmt
│ │ ├── CmtMasterPublicKey.class
│ │ ├── Commitment.class
│ │ ├── MTDCommitment.class
│ │ └── Open.class
│ ├── fusiondcrm
│ │ └── FusionDCRM.class
│ ├── paillier
│ │ ├── AbstractPaillier.class
│ │ ├── PaPrivateKey.class
│ │ ├── PaPrivateKeyGen.class
│ │ ├── PaPublicKey.class
│ │ └── Paillier.class
│ ├── paillierp
│ │ ├── AbstractPaillier.class
│ │ └── Paillier.class
│ ├── pakey
│ │ ├── PaPrivateKey.class
│ │ ├── PaPrivateKeyGen.class
│ │ └── PaPublicKey.class
│ ├── test
│ │ └── DCRMSign.class
│ ├── util
│ │ ├── BitcoinParams.class
│ │ ├── ByteArrayHexString.class
│ │ ├── ECDSASignature.class
│ │ ├── ECKeyUtil.class
│ │ ├── OtherParams.class
│ │ ├── OtherUtil.class
│ │ ├── RandomUtil.class
│ │ └── User.class
│ └── zkp
│ │ ├── PublicParameters.class
│ │ ├── ZkpKG$1.class
│ │ ├── ZkpKG$2.class
│ │ ├── ZkpKG$3.class
│ │ ├── ZkpKG$4.class
│ │ ├── ZkpKG.class
│ │ ├── ZkpSignOne$1.class
│ │ ├── ZkpSignOne$2.class
│ │ ├── ZkpSignOne$3.class
│ │ ├── ZkpSignOne$4.class
│ │ ├── ZkpSignOne.class
│ │ ├── ZkpSignTwo$1.class
│ │ ├── ZkpSignTwo$2.class
│ │ ├── ZkpSignTwo$3.class
│ │ ├── ZkpSignTwo$4.class
│ │ ├── ZkpSignTwo$5.class
│ │ └── ZkpSignTwo.class
│ └── squareup
│ └── jnagmp
│ ├── Gmp$1.class
│ ├── Gmp$2.class
│ ├── Gmp.class
│ ├── GmpInteger$MpzMemory.class
│ ├── GmpInteger.class
│ ├── LibGmp$SizeT4.class
│ ├── LibGmp$SizeT8.class
│ ├── LibGmp$mpz_t.class
│ └── LibGmp.class
├── gmp.dll
├── log4j.properties
└── src
└── org
├── fsn_cfc
├── cmt
│ ├── CmtMasterPublicKey.java
│ ├── Commitment.java
│ ├── MTDCommitment.java
│ └── Open.java
├── fusiondcrm
│ └── FusionDCRM.java
├── main
│ └── DCRMTest.java
├── paillier
│ ├── AbstractPaillier.java
│ ├── PaPrivateKey.java
│ ├── PaPrivateKeyGen.java
│ ├── PaPublicKey.java
│ └── Paillier.java
├── paillierp
│ ├── AbstractPaillier.java
│ └── Paillier.java
├── pakey
│ ├── PaPrivateKey.java
│ ├── PaPrivateKeyGen.java
│ └── PaPublicKey.java
├── service
│ ├── TxBTCService.java
│ └── TxETHService.java
├── util
│ ├── BTCAPIUtil.java
│ ├── BTCUtil.java
│ ├── Base58Util.java
│ ├── BitcoinParams.java
│ ├── ByteArrayHexString.java
│ ├── ECDSASignature.java
│ ├── ETHECKeyUtil.java
│ ├── OtherParams.java
│ ├── OtherUtil.java
│ ├── RandomUtil.java
│ └── User.java
└── zkp
│ ├── PublicParameters.java
│ ├── ZkpKG.java
│ ├── ZkpSignOne.java
│ └── ZkpSignTwo.java
└── squareup
└── jnagmp
├── Gmp.java
├── GmpInteger.java
└── LibGmp.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | FUSIONDCRM
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/FUSION DCRM Verification v1 Guide.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/FUSION DCRM Verification v1 Guide.pdf
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/Lib/Jpair_v1.03.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/Jpair_v1.03.jar
--------------------------------------------------------------------------------
/Lib/assertj-core-3.5.2.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/assertj-core-3.5.2.jar
--------------------------------------------------------------------------------
/Lib/bcprov-ext-jdk15on-154.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/bcprov-ext-jdk15on-154.jar
--------------------------------------------------------------------------------
/Lib/bcprov-jdk15on-154.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/bcprov-jdk15on-154.jar
--------------------------------------------------------------------------------
/Lib/commons-beanutils-1.9.3.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/commons-beanutils-1.9.3.jar
--------------------------------------------------------------------------------
/Lib/commons-cli-1.3.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/commons-cli-1.3.1.jar
--------------------------------------------------------------------------------
/Lib/commons-collections-3.2.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/commons-collections-3.2.1.jar
--------------------------------------------------------------------------------
/Lib/commons-lang-2.6.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/commons-lang-2.6.jar
--------------------------------------------------------------------------------
/Lib/commons-lang3-3.7.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/commons-lang3-3.7.jar
--------------------------------------------------------------------------------
/Lib/commons-logging-1.2.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/commons-logging-1.2.jar
--------------------------------------------------------------------------------
/Lib/config-1.3.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/config-1.3.1.jar
--------------------------------------------------------------------------------
/Lib/core-1.58.0.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/core-1.58.0.0.jar
--------------------------------------------------------------------------------
/Lib/core-2.1.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/core-2.1.0.jar
--------------------------------------------------------------------------------
/Lib/curl-0.0.19.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/curl-0.0.19.jar
--------------------------------------------------------------------------------
/Lib/ethereumj-core-1.7.2-RELEASE.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/ethereumj-core-1.7.2-RELEASE.jar
--------------------------------------------------------------------------------
/Lib/ezmorph-1.0.6.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/ezmorph-1.0.6.jar
--------------------------------------------------------------------------------
/Lib/httpclient-4.5.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/httpclient-4.5.jar
--------------------------------------------------------------------------------
/Lib/httpcore-4.4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/httpcore-4.4.jar
--------------------------------------------------------------------------------
/Lib/httpmime-4.5.2.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/httpmime-4.5.2.jar
--------------------------------------------------------------------------------
/Lib/javassist-3.20.0-GA.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/javassist-3.20.0-GA.jar
--------------------------------------------------------------------------------
/Lib/jna-4.5.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/jna-4.5.1.jar
--------------------------------------------------------------------------------
/Lib/jpbc-api-2.0.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/jpbc-api-2.0.0.jar
--------------------------------------------------------------------------------
/Lib/jpbc-benchmark-2.0.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/jpbc-benchmark-2.0.0.jar
--------------------------------------------------------------------------------
/Lib/jpbc-crypto-2.0.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/jpbc-crypto-2.0.0.jar
--------------------------------------------------------------------------------
/Lib/jpbc-mm-2.0.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/jpbc-mm-2.0.0.jar
--------------------------------------------------------------------------------
/Lib/jpbc-pbc-2.0.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/jpbc-pbc-2.0.0.jar
--------------------------------------------------------------------------------
/Lib/jpbc-plaf-2.0.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/jpbc-plaf-2.0.0.jar
--------------------------------------------------------------------------------
/Lib/json-lib-2.4-jdk13.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/json-lib-2.4-jdk13.jar
--------------------------------------------------------------------------------
/Lib/junit-4.12.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/junit-4.12.jar
--------------------------------------------------------------------------------
/Lib/log4j-1.2.17.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/log4j-1.2.17.jar
--------------------------------------------------------------------------------
/Lib/mockserver-netty-3.10.4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/mockserver-netty-3.10.4.jar
--------------------------------------------------------------------------------
/Lib/prov-1.58.0.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/prov-1.58.0.0.jar
--------------------------------------------------------------------------------
/Lib/slf4j-api-1.7.25.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/slf4j-api-1.7.25.jar
--------------------------------------------------------------------------------
/Lib/slf4j-log4j12-1.7.25.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/slf4j-log4j12-1.7.25.jar
--------------------------------------------------------------------------------
/Lib/spring-boot-starter-1.4.0.RELEASE.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/spring-boot-starter-1.4.0.RELEASE.jar
--------------------------------------------------------------------------------
/Lib/spring-boot-starter-jetty-1.4.0.RELEASE.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/spring-boot-starter-jetty-1.4.0.RELEASE.jar
--------------------------------------------------------------------------------
/Lib/spring-boot-starter-security-1.4.0.RELEASE.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/spring-boot-starter-security-1.4.0.RELEASE.jar
--------------------------------------------------------------------------------
/Lib/spring-boot-starter-web-1.4.0.RELEASE.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/Lib/spring-boot-starter-web-1.4.0.RELEASE.jar
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Distributed Control Rights Management Signature Verification Program
2 |
3 | FUSION's Distributed Control Rights Management technology uses distributed computing, homomorphic encryption, zero knowledge proofs and other cryptographic techniques to replace the complete private key with private key fragments. Distributed generation of a valid public key, address and transaction signature in accordance with the targeted blockchain ECDSA algorithm and specification is implemented. With this technology, the management and operation of the crypto-assets on all different blockchains may be realized on FUSION. DCRM is the core technology facilitating the management of assets across heterogeneous blockchains.
4 |
5 | To learn more about DCRM, please read the [FUSION DCRM Verification v1 Guide.pdf](https://github.com/FUSIONFoundation/dcrm/).
6 |
7 | *Note: FUSIONDCRM is considered verification program. We make no warranties or guarantees of its security or stability.*
8 |
9 | ## Release info
10 | **FUSIONDCRM-v2.0** uses the same DCRM technology as the previous version, and build multiple virtual users locally to demonstrate how to complete the distributed execution of the DCRM. On the basis of the previous version, the new version completes a transfer transaction signature for assets controlled by distributed private key, and generates the RAW transaction. By broadcasting the original transaction to the target main chain, the user can transfer these assets, thus making the user have a more intuitive experience of dcrm technology.
11 |
12 | This release shows the DCRM technology's support for Ethereum.
13 |
14 | We will continue to update v2.0 in the near future. In v2.1, we will implement support for the DCRM technology used in both Ethereum and Bitcoin.
15 |
16 | In the next phase, we will release **v3.0** of the DCRM verification. In this release, we plan to build a distributed DCRM verification network based on P2P network environment. At that time, users can participate and experience the complete process of distributed generation of private keys, public keys and transaction signatures in a way that acts as one of the nodes.
17 |
18 | ## 1. Description of the verification
19 |
20 | ### 1.1 Function of distributed generation
21 |
22 | The verification program demonstrates the verification process of the FUSION Distributed Control Rights Management, including:
23 |
24 | 1. The private key fragments are generated and stored separately by multiple nodes. The public key is generated through distributed computation with the private key fragments.
25 | 2. It implements the signature of the designated messages by multiple nodes based on distributed computation.
26 | 3. There is no passing of the private key fragment or assembling a complete private key in this process.
27 |
28 | ### 1.2 Verification of public key and signature
29 |
30 | The signature generated by Distributed Control Rights Management complies with the digital signature specification of the targeted blockchain. Signature verification remains unchanged. The validation of message signatures involves three input items:
31 |
32 | - The public key. In this case, it will be generated by the private key fragments based on distributed computation.
33 | - The message signature. In this case, using private key fragments to generate signature for hash of message based on distributed computation.
34 | - The message itself.
35 |
36 | In this verification program, we verify the public key, message and message signature generated by using the method that conforms to the targeted blockchain ECDSA specification. If verification succeeds, we have demonstrated that FUSION Distributed Control Rights Management achieves the status of using the private key fragments, distributed computation, and zero knowledge proofs to generate the public/private key pairing and the message signature for the targeted blockchain.
37 |
38 | WithDistributed Control Rights Management, the control and management of the target blockchain account system and crypto assets can be realized on FUSION.
39 |
40 | ### 1.3 Verification of application scope for Distributed Control Rights Management management
41 |
42 | At present, most blockchains use ECDSA algorithm to implement public and private key pairing and message signature.
43 |
44 | According to bitcoin and Ethereum's official documentation and code, both adopt the secp256k1 specification. USDT is based on bitcoin implementation. Therefore, all the above three adopt the same ECDSA specification, that is, secp256k1.
45 |
46 | The specification of secp256k1 is adopted in this verification program, which shows that the Distributed Control Rights Management of FUSION can generate the public and private key pairs and the message signatures that are valid on bitcoin, Ethereum and USDT.
47 |
48 |
49 | As can be seen in the source code, the program can support the other specification of ECDSA algorithms, such as secp256v1 / secp256r1, so it can adapt to control of the different targeted blockchain account and assets by adjusting the parameter. You can find this parameter in the source code. (`/FUSIONDCRM/src/org.fsn_cfc.util/BitcoinParams.java`)
50 |
51 | ### 1.4 Additional Notes
52 |
53 | **Paillier Cryptosystem**
54 |
55 | The FUSION's Distributed Control Rights Management, adopts the Paillier Cryptosystem to achieve secure computations among nodes without leaking any information. In the scheme design and final implementation, the private key of the Paillier Cryptosystem is generated and stored in a distributed manner, which ensures that no node can decrypt the result alone. There are a lot of mature implementations of Paillier encryption. In this demo verification program, in order to demonstrate Distributed ECDSA Key Generation, we simplify the process of distributed Paillier encryption.
56 |
57 | **Blockchain Address Generation**
58 |
59 | The conversion of public key to blockchrain address is standard hash functions. Distributed computation is not needed. So, the demo verification program does not cover any generation or verification of blockchain address.
60 |
61 | **Some notes about Java Programming**
62 |
63 | In order to implement and demonstrate verification program more rapidly, we use Java for developing purposes. After this, we will switch to Golang, and finally run Distributed Control Rights Management on the FUSION mainnet.
64 |
65 | In anticipation of the Lock-in and management of real assets, Distributed Control Rights Management will be tested in the FUSION testnet to demonstrate and tune, and so as to get the optimal implementation.
66 |
67 |
68 | ## 2. Compilation on Windows
69 |
70 | ### 2.1 Contents
71 |
72 | The compressed file, named "FUSION DCRM verification v1.zip", includes the source code of verification program, and a dynamic linking library file named gmp.dll.
73 |
74 | Gmp.dll comes from the mathematical computing algorithm library of GMP (The GNU Multiple Precision Arithmetic Library, https://gmplib.org/).
75 |
76 | ### 2.2 Environment
77 |
78 | Windows environment configuration.
79 |
80 | 1. Download and install the JDK 1.8 32bit for Windows.
81 |
82 | Download address:
83 |
84 | [http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
85 |
86 | And configure system environment variables based on where JDK is actually installed, such as:
87 |
88 | And put the `gmp.dll` in this directory: `jre/bin`.
89 |
90 | 2. Download and install the Eclipse 32 bit for Windows.
91 |
92 | Download address:
93 |
94 | [http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/oxygen/3a/eclipse-jee-oxygen-3a-win32.zip](http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/oxygen/3a/eclipse-jee-oxygen-3a-win32.zip)
95 |
96 | ### 2.3 Compile and execute
97 |
98 | Run the Eclipse, and click the "import" option on the "file" menu.
99 |
100 |
101 | Select the option named "Existing projects into workspace" of "General" item and click "next".
102 |
103 |
104 | By clicking the button named "browse", select the folder where the validator program folder resides, and click "finish".
105 |
106 |
107 | The project directory of FUSIONDCRM is displayed on the left of the Eclipse window. There are two programs: TestThresholdECDSA.java and BatchThresholdECDSA.javain the path of /FUSIONDCRM/src/org.fsn\_cfc.test.
108 |
109 |
110 | Double-click one of them, you can see the source code in the middle of the Eclipse window. Right-click on the code area, select "Run As" from the menu that appears, and click "Java Application" to execute the program.
111 |
112 |
113 | The output information during execution is displayed in the "Console" window.
114 |
115 |
116 | ## 3. Compilation on Mac OS
117 |
118 | ### 3.1 Contents
119 |
120 | The compressed file, named "FUSION DCRM verification v1.zip", includes the source code of verification program.
121 |
122 | ### 3.2 Environment
123 |
124 | Mac OS environment configuration:
125 |
126 | 1. Download and install the JDK 10.0. for Mac OS.
127 |
128 | Download address:
129 |
130 | [http://www.oracle.com/technetwork/java/javase/downloads/jdk10-downloads-4416644.html](http://www.oracle.com/technetwork/java/javase/downloads/jdk10-downloads-4416644.html)
131 |
132 | 2. Download and install the Visual Studio Code for Mac OS.
133 |
134 | Download address:
135 |
136 | [https://code.visualstudio.com/#alt-downloads](https://code.visualstudio.com/%2523alt-downloads)
137 |
138 | 3. Download and install the java debugging plug-in for Visual Studio Code.
139 |
140 | Download address:
141 |
142 | [https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug)
143 |
144 | 4.Install the brew and libgmp
145 |
146 | Install the brew package management, and enter the command under the terminal as follow.
147 |
148 | ```
149 | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
150 | ```
151 |
152 | 5. Install the libgmp.
153 |
154 | ```
155 | brew install gmp
156 | ```
157 |
158 | After successful brew package management installation, enter the command in the terminal as follows.
159 |
160 | ### 3.3 Compile and execute
161 |
162 | 1. Open the project folder in the Visual Studio Code
163 |
164 | 2. After generating the project configuration file launch.json, press F5, run the main program.
165 |
166 | Note: because the default configuration of VSCode does not support accepting input parameters in a debug environment, there will be an error message: Failed to evaluate. Reason: Cannot evaluate because the thread is resumed.
167 |
168 | The solution is to change the parameters of the main class in `launch.json` as this `"console": "integratedTerminal"`
169 |
170 | 3. After inputting the signature message and number of nodes in the debugging terminal window, output the execution state information content and pass the test.
171 |
172 | ## 4. Compilation on Linux
173 |
174 | ### 4.1 Contents
175 |
176 | The compressed file named "FUSION DCRM verification v1.zip", includes the source code of verification program.
177 |
178 | ### 4.2 Environment
179 |
180 | Linux environment configuration:
181 |
182 | 1. Download and install the JDK10.0.1 64bit for Linux.
183 |
184 | Download address:
185 |
186 | [http://www.oracle.com/technetwork/java/javase/downloads/jdk10-downloads-4416644.html](http://www.oracle.com/technetwork/java/javase/downloads/jdk10-downloads-4416644.html)
187 |
188 |
189 | Configure the system environment variables.
190 |
191 | 2. Download and install the Eclipse for Linux.
192 |
193 | Download address:
194 |
195 | [http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/oxygen/3a/eclipse-jee-oxygen-3a-linux-gtk-x86\_64.tar.gz](http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/oxygen/3a/eclipse-jee-oxygen-3a-linux-gtk-x86_64.tar.gz)
196 |
197 | ### 4.3 Compile and execute
198 |
199 | Run the program in the Eclipse is as same as running on Windows.
200 |
201 | ## 5 How to test
202 |
203 | [User Test Guide](https://github.com/FUSIONFoundation/dcrm/wiki/User-Test-Guide)
204 |
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/cmt/CmtMasterPublicKey.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/cmt/CmtMasterPublicKey.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/cmt/Commitment.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/cmt/Commitment.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/cmt/MTDCommitment.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/cmt/MTDCommitment.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/cmt/Open.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/cmt/Open.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/fusiondcrm/FusionDCRM.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/fusiondcrm/FusionDCRM.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/paillier/AbstractPaillier.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/paillier/AbstractPaillier.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/paillier/PaPrivateKey.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/paillier/PaPrivateKey.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/paillier/PaPrivateKeyGen.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/paillier/PaPrivateKeyGen.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/paillier/PaPublicKey.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/paillier/PaPublicKey.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/paillier/Paillier.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/paillier/Paillier.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/paillierp/AbstractPaillier.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/paillierp/AbstractPaillier.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/paillierp/Paillier.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/paillierp/Paillier.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/pakey/PaPrivateKey.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/pakey/PaPrivateKey.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/pakey/PaPrivateKeyGen.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/pakey/PaPrivateKeyGen.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/pakey/PaPublicKey.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/pakey/PaPublicKey.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/test/DCRMSign.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/test/DCRMSign.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/util/BitcoinParams.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/util/BitcoinParams.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/util/ByteArrayHexString.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/util/ByteArrayHexString.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/util/ECDSASignature.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/util/ECDSASignature.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/util/ECKeyUtil.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/util/ECKeyUtil.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/util/OtherParams.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/util/OtherParams.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/util/OtherUtil.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/util/OtherUtil.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/util/RandomUtil.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/util/RandomUtil.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/util/User.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/util/User.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/zkp/PublicParameters.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/zkp/PublicParameters.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/zkp/ZkpKG$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/zkp/ZkpKG$1.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/zkp/ZkpKG$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/zkp/ZkpKG$2.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/zkp/ZkpKG$3.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/zkp/ZkpKG$3.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/zkp/ZkpKG$4.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/zkp/ZkpKG$4.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/zkp/ZkpKG.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/zkp/ZkpKG.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/zkp/ZkpSignOne$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/zkp/ZkpSignOne$1.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/zkp/ZkpSignOne$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/zkp/ZkpSignOne$2.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/zkp/ZkpSignOne$3.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/zkp/ZkpSignOne$3.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/zkp/ZkpSignOne$4.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/zkp/ZkpSignOne$4.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/zkp/ZkpSignOne.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/zkp/ZkpSignOne.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/zkp/ZkpSignTwo$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/zkp/ZkpSignTwo$1.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/zkp/ZkpSignTwo$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/zkp/ZkpSignTwo$2.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/zkp/ZkpSignTwo$3.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/zkp/ZkpSignTwo$3.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/zkp/ZkpSignTwo$4.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/zkp/ZkpSignTwo$4.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/zkp/ZkpSignTwo$5.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/zkp/ZkpSignTwo$5.class
--------------------------------------------------------------------------------
/bin/org/fsn_cfc/zkp/ZkpSignTwo.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/fsn_cfc/zkp/ZkpSignTwo.class
--------------------------------------------------------------------------------
/bin/org/squareup/jnagmp/Gmp$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/squareup/jnagmp/Gmp$1.class
--------------------------------------------------------------------------------
/bin/org/squareup/jnagmp/Gmp$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/squareup/jnagmp/Gmp$2.class
--------------------------------------------------------------------------------
/bin/org/squareup/jnagmp/Gmp.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/squareup/jnagmp/Gmp.class
--------------------------------------------------------------------------------
/bin/org/squareup/jnagmp/GmpInteger$MpzMemory.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/squareup/jnagmp/GmpInteger$MpzMemory.class
--------------------------------------------------------------------------------
/bin/org/squareup/jnagmp/GmpInteger.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/squareup/jnagmp/GmpInteger.class
--------------------------------------------------------------------------------
/bin/org/squareup/jnagmp/LibGmp$SizeT4.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/squareup/jnagmp/LibGmp$SizeT4.class
--------------------------------------------------------------------------------
/bin/org/squareup/jnagmp/LibGmp$SizeT8.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/squareup/jnagmp/LibGmp$SizeT8.class
--------------------------------------------------------------------------------
/bin/org/squareup/jnagmp/LibGmp$mpz_t.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/squareup/jnagmp/LibGmp$mpz_t.class
--------------------------------------------------------------------------------
/bin/org/squareup/jnagmp/LibGmp.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/bin/org/squareup/jnagmp/LibGmp.class
--------------------------------------------------------------------------------
/gmp.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FUSIONFoundation/dcrm-java/56e3a75ae62f2543a71e0a9930d36dd2b575934e/gmp.dll
--------------------------------------------------------------------------------
/log4j.properties:
--------------------------------------------------------------------------------
1 | # Set root logger level to DEBUG and its only appender to A1.
2 | log4j.rootLogger=DEBUG, A1
3 |
4 | # A1 is set to be a ConsoleAppender.
5 | log4j.appender.A1=org.apache.log4j.ConsoleAppender
6 |
7 | # A1 uses PatternLayout.
8 | log4j.appender.A1.layout=org.apache.log4j.PatternLayout
9 | log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
--------------------------------------------------------------------------------
/src/org/fsn_cfc/cmt/CmtMasterPublicKey.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.cmt;
2 |
3 | import java.math.BigInteger;
4 |
5 | import uk.ac.ic.doc.jpair.api.Pairing;
6 | import uk.ac.ic.doc.jpair.pairing.Point;
7 |
8 |
9 | public class CmtMasterPublicKey {
10 |
11 |
12 | public final Point g;
13 | public final BigInteger q;
14 | public final Point h;
15 | public final Pairing pairing;
16 |
17 | public CmtMasterPublicKey(Point g, BigInteger q, Point h, uk.ac.ic.doc.jpair.api.Pairing pairing) {
18 | this.g = g;
19 | this.h = h;
20 | this.q = q;
21 | this.pairing = pairing;
22 | }
23 |
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/cmt/Commitment.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.cmt;
2 |
3 | import java.math.BigInteger;
4 |
5 | import uk.ac.ic.doc.jpair.pairing.Point;
6 |
7 | public class Commitment {
8 |
9 | public final BigInteger pubkey;
10 | public final Point committment;
11 |
12 | public Commitment(BigInteger pubkey, Point a) {
13 | this.pubkey = pubkey;
14 | this.committment = a;
15 |
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/cmt/MTDCommitment.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.cmt;
2 |
3 | import java.math.BigInteger;
4 | import java.security.SecureRandom;
5 |
6 | import org.fsn_cfc.util.RandomUtil;
7 | import org.fsn_cfc.util.OtherUtil;
8 |
9 | import uk.ac.ic.doc.jpair.api.Field;
10 | import uk.ac.ic.doc.jpair.api.FieldElement;
11 | import uk.ac.ic.doc.jpair.api.Pairing;
12 | import uk.ac.ic.doc.jpair.pairing.BigInt;
13 | import uk.ac.ic.doc.jpair.pairing.EllipticCurve;
14 | import uk.ac.ic.doc.jpair.pairing.Point;
15 | import uk.ac.ic.doc.jpair.pairing.Predefined;
16 |
17 | public class MTDCommitment {
18 |
19 | private final Commitment commitment;
20 | private final Open open;
21 |
22 |
23 |
24 | private MTDCommitment(Commitment commitment, Open open) {
25 | this.commitment = commitment;
26 | this.open = open;
27 | }
28 |
29 |
30 |
31 | public static MTDCommitment multiLinnearCommit(SecureRandom rand, CmtMasterPublicKey mpk, BigInteger... secrets) {
32 |
33 | EllipticCurve curve = mpk.pairing.getCurve();
34 |
35 | BigInteger e = RandomUtil.randomFromZn(mpk.q, rand);
36 | BigInteger r = RandomUtil.randomFromZn(mpk.q, rand);
37 |
38 | byte[][] secretsBytes = new byte[secrets.length][];
39 | for (int i = 0; i < secrets.length; i++) {
40 | secretsBytes[i] = secrets[i].toByteArray();
41 | }
42 |
43 | BigInteger digest = new BigInteger(OtherUtil.sha256Hash(secretsBytes)).mod(mpk.q);
44 |
45 | Point he = curve.add(mpk.h, curve.multiply(mpk.g, new BigInt(e)));
46 |
47 | Point a = curve.add(curve.multiply(mpk.g, new BigInt(digest)), curve.multiply(he, new BigInt(r)));
48 |
49 | Open open = new Open(r, secrets);
50 |
51 | Commitment commitment = new Commitment(e, a);
52 |
53 | return new MTDCommitment(commitment, open);
54 | }
55 |
56 |
57 | public static boolean checkcommitment(Commitment commitment, Open open, CmtMasterPublicKey mpk) {
58 |
59 | EllipticCurve curve = mpk.pairing.getCurve();
60 |
61 | Point g = mpk.g;
62 | Point h = mpk.h;
63 |
64 | BigInteger[] secrets = open.getSecrets();
65 | byte[][] secretsBytes = new byte[secrets.length][];
66 | for (int i = 0; i < secrets.length; i++) {
67 | secretsBytes[i] = secrets[i].toByteArray();
68 | }
69 |
70 | BigInteger digest = new BigInteger(OtherUtil.sha256Hash(secretsBytes)).mod(mpk.q);
71 |
72 | return DDH(curve.multiply(g,new BigInt(open.getRandomness())),
73 | curve.add(h, curve.multiply(g, new BigInt(commitment.pubkey))),
74 | curve.add(commitment.committment, curve.multiply(g, new BigInt(digest.negate()))), g,
75 | mpk.pairing);
76 |
77 | }
78 |
79 | static boolean DDH(Point a, Point b, Point c, Point generator, Pairing pairing)
80 | {
81 | return pairing.compute(a, b).equals(pairing.compute(generator, c));
82 | }
83 |
84 |
85 | public static CmtMasterPublicKey generateMasterPK() {
86 |
87 | Pairing pairing = Predefined.ssTate();
88 |
89 | SecureRandom rnd = new SecureRandom();
90 |
91 | EllipticCurve G = pairing.getCurve();
92 |
93 | Point g = G.getBasePoint(rnd, pairing.getGroupOrder(), pairing.getCofactor());
94 | BigInteger q = new BigInteger(pairing.getGroupOrder().toByteArray());
95 |
96 | Point h = pairing.RandomPointInG1(rnd);
97 |
98 | return new CmtMasterPublicKey(g, q, h, pairing);
99 |
100 | }
101 |
102 |
103 |
104 | public Open cmtOpen(){
105 | return open;
106 | }
107 |
108 |
109 |
110 |
111 | public Commitment cmtCommitment() {
112 | return commitment;
113 | }
114 |
115 |
116 | }
--------------------------------------------------------------------------------
/src/org/fsn_cfc/cmt/Open.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.cmt;
2 |
3 | public class Open {
4 |
5 | private final T[] secrets;
6 | private final T randomness;
7 |
8 | public Open(T randomness, T... secrets) {
9 | this.secrets = secrets;
10 | this.randomness = randomness;
11 | }
12 |
13 | public T[] getSecrets() {
14 | return secrets;
15 | }
16 |
17 | public T getRandomness() {
18 | return randomness;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/fusiondcrm/FusionDCRM.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.fusiondcrm;
2 |
3 | import java.math.BigInteger;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | import org.bouncycastle.math.ec.ECPoint;
8 | import org.ethereum.util.ByteUtil;
9 | import org.fsn_cfc.cmt.Commitment;
10 | import org.fsn_cfc.cmt.MTDCommitment;
11 | import org.fsn_cfc.cmt.Open;
12 | import org.fsn_cfc.util.BitcoinParams;
13 | import org.fsn_cfc.util.ECDSASignature;
14 | import org.fsn_cfc.util.OtherParams;
15 | import org.fsn_cfc.util.RandomUtil;
16 | import org.fsn_cfc.util.User;
17 | import org.fsn_cfc.zkp.ZkpKG;
18 | import org.fsn_cfc.zkp.ZkpSignOne;
19 | import org.fsn_cfc.zkp.ZkpSignTwo;
20 | import org.spongycastle.util.encoders.Hex;
21 | import org.fsn_cfc.util.OtherUtil;
22 |
23 | public class FusionDCRM {
24 |
25 |
26 |
27 |
28 |
29 | public static List keyGenerate(int userCnt) {
30 |
31 | List userList = new ArrayList();
32 |
33 | kgRoundOne(userList,userCnt);
34 | kgRoundTwo(userList);
35 | kgRoundThree(userList);
36 |
37 | return userList;
38 | }
39 |
40 |
41 |
42 |
43 |
44 | public static ECDSASignature sign(List userList, BigInteger encX, String message, String tokenType) {
45 |
46 | signRoudOne(userList, encX);
47 | signRoudTwo(userList, encX);
48 |
49 | Boolean roudThreeAborted = signRoundThree(userList, encX);
50 | if(roudThreeAborted) {
51 | System.out.println("FAIL to SIGN at FusionDCRM.java: sign()");
52 | return null;
53 | }
54 |
55 |
56 | BigInteger u = calculateU(userList);
57 | BigInteger v = calculateV(userList);
58 |
59 |
60 | signRoundFour(userList, u);
61 |
62 |
63 | ECDSASignature signature = signRoundFive(userList, u, v, message, tokenType);
64 | if(signature.getRoudFiveAborted()) {
65 | System.out.println("FAIL to SIGN at FusionDCRM.java: sign()");
66 | return null;
67 | }
68 |
69 | return signature;
70 | }
71 |
72 |
73 |
74 |
75 |
76 |
77 | public static Boolean verify(ECDSASignature signature, String message, ECPoint pk) {
78 |
79 | return signature.verify(message, pk);
80 | }
81 |
82 |
83 |
84 | public static void kgRoundOne(List userList, int userCnt) {
85 |
86 | BigInteger xShare, xShareRnd, encXShare;
87 | ECPoint yShare;
88 | User temUser;
89 |
90 | MTDCommitment mpkEncXiYi;
91 | Open openEncXiYi;
92 | Commitment cmtEncXiYi;
93 |
94 |
95 | for(int i=0 ; i userList) {
124 |
125 | ZkpKG zkpKG;
126 |
127 | for(int i = 0; i < userList.size() ; i ++) {
128 | zkpKG = new ZkpKG(OtherParams.ZKParams, userList.get(i).getxShare(), OtherParams.SecureRnd, BitcoinParams.G,
129 | userList.get(i).getEncXShare(), userList.get(i).getxShareRnd());
130 |
131 | userList.get(i).setZkpKG(zkpKG);
132 |
133 | System.out.println("\n--Info: User "+i+" calculate Zero-Knowledge in KG round TWO");
134 |
135 | }
136 |
137 | }
138 |
139 |
140 | public static void kgRoundThree(List userList) {
141 |
142 | Boolean aborted = false;
143 |
144 | for (int i = 0; i < userList.size(); i++) {
145 | if (!MTDCommitment.checkcommitment(userList.get(i).getCmtEncXiYi(), userList.get(i).getOpenEncXiYi(), OtherParams.MPK)) {
146 | aborted = true;
147 | System.out.println("\n##Error####################: "+
148 | "\n KG Round 3, User "+i+"does not pass checking Commitment!");
149 | }
150 | }
151 |
152 | for (int i = 0; i < userList.size(); i++) {
153 | if (!userList.get(i).getZkpKG().verify(OtherParams.ZKParams, BitcoinParams.CURVE,
154 | BitcoinParams.CURVE.getCurve().decodePoint(userList.get(i).getOpenEncXiYi().getSecrets()[1].toByteArray()),
155 | userList.get(i).getOpenEncXiYi().getSecrets()[0])) {
156 | aborted = true;
157 | System.out.println("\n##Error####################: "+
158 | "\n KG Round 3, User "+i+"does not pass verifying Zero-Knowledge!");
159 | }
160 | }
161 |
162 |
163 | ECPoint pubKey = calculatePubKey(userList);
164 | BigInteger encX = calculateEncPrivateKey(userList);
165 |
166 | ECPoint pkTem = pubKey.normalize();
167 | String xPk = OtherUtil.formatString(pkTem.getX().toBigInteger().toString(16), 64);
168 | String yPk = OtherUtil.formatString(pkTem.getY().toBigInteger().toString(16), 64);
169 |
170 |
171 | for (int i = 0; i < userList.size(); i++) {
172 | userList.get(i).setEncX(encX);
173 | userList.get(i).setPk(pkTem);
174 | userList.get(i).setPkStr(xPk+yPk);
175 | }
176 | }
177 |
178 |
179 |
180 | public static void signRoudOne(List userList, BigInteger encX) {
181 |
182 | BigInteger rhoI, rhoIRnd, uI, vI;
183 |
184 | MTDCommitment mpkUiVi;
185 | Open openUiVi;
186 | Commitment cmtUiVi;
187 |
188 |
189 | for(int i = 0; i < userList.size() ; i ++) {
190 |
191 | rhoI = RandomUtil.randomFromZn(BitcoinParams.q, OtherParams.SecureRnd);
192 | rhoIRnd = RandomUtil.randomFromZnStar(OtherParams.PaillPubKey.getN(), OtherParams.SecureRnd);
193 |
194 | uI = OtherParams.PaillEnc.encrypt(rhoI, rhoIRnd);
195 | vI = OtherParams.PaillEnc.cipherMultiply(encX, rhoI);
196 |
197 | mpkUiVi = MTDCommitment.multiLinnearCommit(OtherParams.SecureRnd, OtherParams.MPK, uI, vI);
198 | openUiVi = mpkUiVi.cmtOpen();
199 | cmtUiVi = mpkUiVi.cmtCommitment();
200 |
201 | userList.get(i).setRhoI(rhoI);
202 | userList.get(i).setRhoIRnd(rhoIRnd);
203 | userList.get(i).setuI(uI);
204 | userList.get(i).setvI(vI);
205 | userList.get(i).setMpkUiVi(mpkUiVi);
206 | userList.get(i).setOpenUiVi(openUiVi);
207 |
208 | userList.get(i).setCmtUiVi(cmtUiVi);
209 |
210 | System.out.println("\n--Info: User "+i+" calculate Commitment in Signning round ONE");
211 |
212 | }
213 |
214 | }
215 |
216 |
217 |
218 |
219 |
220 |
221 | public static void signRoudTwo(List userList, BigInteger encX) {
222 |
223 | ZkpSignOne zkp1;
224 |
225 | for(int i = 0; i < userList.size() ; i ++) {
226 | zkp1 = new ZkpSignOne(OtherParams.ZKParams, userList.get(i).getRhoI(), OtherParams.SecureRnd, userList.get(i).getRhoIRnd(),
227 | userList.get(i).getvI(), encX, userList.get(i).getuI());
228 |
229 | userList.get(i).setZkp1(zkp1);
230 |
231 | System.out.println("\n--Info: User "+i+" calculate Zero-Knowledge in Signning round TWO");
232 |
233 | }
234 | }
235 |
236 |
237 |
238 |
239 |
240 |
241 | public static Boolean signRoundThree(List userList, BigInteger encX) {
242 |
243 | Boolean aborted = false;
244 |
245 | for (int i = 0; i < userList.size(); i++) {
246 | if (!MTDCommitment.checkcommitment(userList.get(i).getCmtUiVi(), userList.get(i).getOpenUiVi(), OtherParams.MPK)) {
247 | aborted = true;
248 | System.out.println("\n##Error####################: "+
249 | "\n SignRound 3, User "+i+"does not pass checking Commitment!");
250 | return aborted;
251 | }
252 | }
253 |
254 | for (int i = 0; i < userList.size(); i++) {
255 | if (!userList.get(i).getZkp1().verify(OtherParams.ZKParams, BitcoinParams.CURVE, userList.get(i).getOpenUiVi().getSecrets()[1],
256 | encX, userList.get(i).getOpenUiVi().getSecrets()[0])) {
257 |
258 | aborted = true;
259 | System.out.println("\n##Error####################: "+
260 | "\n SignRound 3, User "+i+"does not pass verifying Zero-Knowledge!");
261 | return aborted;
262 | }
263 | }
264 |
265 |
266 | BigInteger u = calculateU(userList);
267 | BigInteger v = calculateV(userList);
268 |
269 |
270 | BigInteger kI, cI, cIRnd;
271 | ECPoint rI;
272 |
273 | BigInteger mask, wI;
274 |
275 | MTDCommitment mpkRiWi;
276 | Open openRiWi;
277 | Commitment cmtRiWi;
278 |
279 |
280 | for (int i = 0; i < userList.size(); i++) {
281 | kI = RandomUtil.randomFromZn(BitcoinParams.q, OtherParams.SecureRnd);
282 | rI = BitcoinParams.G.multiply(kI);
283 |
284 | cI = RandomUtil.randomFromZn(BitcoinParams.q, OtherParams.SecureRnd);
285 | cIRnd = RandomUtil.randomFromZnStar(OtherParams.PaillPubKey.getN(),OtherParams.SecureRnd);
286 |
287 | mask = OtherParams.PaillEnc.encrypt(BitcoinParams.q.multiply(cI), cIRnd);
288 | wI = OtherParams.PaillEnc.cipherAdd(OtherParams.PaillEnc.cipherMultiply(u, kI), mask);
289 |
290 | mpkRiWi = MTDCommitment.multiLinnearCommit(OtherParams.SecureRnd, OtherParams.MPK, new BigInteger(rI.getEncoded()), wI);
291 | openRiWi = mpkRiWi.cmtOpen();
292 | cmtRiWi = mpkRiWi.cmtCommitment();
293 |
294 | userList.get(i).setkI(kI);
295 | userList.get(i).setcI(cI);
296 | userList.get(i).setcIRnd(cIRnd);
297 | userList.get(i).setrI(rI);
298 |
299 | userList.get(i).setMask(mask);
300 | userList.get(i).setwI(wI);
301 |
302 | userList.get(i).setMpkRiWi(mpkRiWi);
303 | userList.get(i).setOpenRiWi(openRiWi);
304 | userList.get(i).setCmtRiWi(cmtRiWi);
305 |
306 | System.out.println("\n--Info: User "+i+" calculate Commitment in Signning round THREE");
307 |
308 | }
309 |
310 | return aborted;
311 | }
312 |
313 |
314 |
315 | public static void signRoundFour(List userList, BigInteger u) {
316 |
317 | ZkpSignTwo zkp2;
318 |
319 | for (int i = 0; i < userList.size(); i++) {
320 | zkp2 = new ZkpSignTwo(OtherParams.ZKParams, userList.get(i).getkI(), userList.get(i).getcI(), OtherParams.SecureRnd, BitcoinParams.G,
321 | userList.get(i).getwI(), u, userList.get(i).getcIRnd());
322 |
323 | userList.get(i).setZkp_i2(zkp2);
324 |
325 | System.out.println("\n--Info: User "+i+" calculate Zero-Knowledge in Signning round FOUR");
326 |
327 | }
328 |
329 | }
330 |
331 |
332 |
333 |
334 |
335 |
336 | public static ECDSASignature signRoundFive(List userList, BigInteger u, BigInteger v, String message, String tokenType) {
337 |
338 | ECDSASignature signature = new ECDSASignature();
339 | Boolean aborted = false;
340 |
341 | for (int i = 0; i < userList.size(); i++) {
342 | if (!MTDCommitment.checkcommitment(userList.get(i).getCmtRiWi(), userList.get(i).getOpenRiWi(), OtherParams.MPK)) {
343 | aborted = true;
344 | System.out.println("\n##Error####################: "+
345 | "\n SignRound 5, User "+i+"does not pass checking Commitment!");
346 | signature.setRoudFiveAborted(aborted);
347 | }
348 | }
349 |
350 | for (int i = 0; i < userList.size(); i++) {
351 | if (!userList.get(i).getZkp_i2().verify(OtherParams.ZKParams, BitcoinParams.CURVE,
352 | BitcoinParams.CURVE.getCurve().decodePoint(userList.get(i).getOpenRiWi().getSecrets()[0].toByteArray()),
353 | u, userList.get(i).getOpenRiWi().getSecrets()[1])){
354 | aborted = true;
355 | System.out.println("\n##Error####################: "+
356 | "\n SignRound 5, User "+i+"does not pass verifying Zero-Knowledge!");
357 | signature.setRoudFiveAborted(aborted);
358 | }
359 | }
360 |
361 |
362 | BigInteger msgDigest = new BigInteger(message, 16);
363 |
364 | BigInteger w = calculateW(userList);
365 | ECPoint R = calculateR(userList);
366 |
367 | BigInteger r, mu;
368 | r = R.normalize().getX().toBigInteger().mod(BitcoinParams.q);
369 | mu = OtherParams.PaillDec.decrypt(w).mod(BitcoinParams.q);
370 |
371 | BigInteger muInverse, mMultiU, rMultiV, sEnc, s;
372 | muInverse = mu.modInverse(BitcoinParams.q);
373 | mMultiU = OtherParams.PaillEnc.cipherMultiply(u, msgDigest);
374 | rMultiV = OtherParams.PaillEnc.cipherMultiply(v, r);
375 | sEnc = OtherParams.PaillEnc.cipherMultiply(OtherParams.PaillEnc.cipherAdd(mMultiU, rMultiV), muInverse);
376 | s = OtherParams.PaillDec.decrypt(sEnc).mod(BitcoinParams.q);
377 |
378 | signature.setRoudFiveAborted(aborted);
379 | signature.setR(r);
380 | signature.setS(s);
381 |
382 | if(tokenType.equals("ETH") && s.compareTo(BitcoinParams.q.shiftRight(1))>0) {
383 | s = BitcoinParams.q.subtract(s);
384 | signature.setS(s);
385 | }
386 |
387 |
388 | if(tokenType.equals("BTC") && s.compareTo(BitcoinParams.q.shiftRight(1))>0) {
389 | s = BitcoinParams.q.subtract(s);
390 | signature.setS(s);
391 | }
392 |
393 | return signature;
394 | }
395 |
396 |
397 |
398 | public static ECPoint calculatePubKey(List userList) {
399 |
400 | ECPoint pubKey = userList.get(0).getyShare();
401 |
402 | for(int i = 1; i < userList.size() ; i++) {
403 | pubKey = pubKey.add(userList.get(i).getyShare());
404 | }
405 |
406 | ECPoint pkTem = pubKey.normalize();
407 | String xPk_ = OtherUtil.convertBytesToHexString(pkTem.getX().toBigInteger().toByteArray());
408 | String yPk_ = OtherUtil.convertBytesToHexString(pkTem.getY().toBigInteger().toByteArray());
409 | String xPk = OtherUtil.subLast64(xPk_);
410 | String yPk = OtherUtil.subLast64(yPk_);
411 |
412 | System.out.println("\n--Info: Calculate the Public Key"+
413 | "\n PublicKey: "+"("+xPk+","+yPk+")");
414 |
415 | return pubKey;
416 | }
417 |
418 |
419 |
420 |
421 | public static BigInteger calculateEncPrivateKey(List userList) {
422 |
423 | BigInteger encX = userList.get(0).getEncXShare();
424 |
425 | for(int i = 1; i < userList.size() ; i++) {
426 | encX = OtherParams.PaillEnc.cipherAdd(encX, userList.get(i).getEncXShare());
427 | }
428 |
429 | System.out.println("\n--Info: Calculate the Encrypted Private Key"+
430 | "\n EncPrivateKey: "+encX);
431 |
432 | return encX;
433 | }
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 | public static BigInteger calculateU(List userList) {
442 | BigInteger u;
443 |
444 | u = userList.get(0).getOpenUiVi().getSecrets()[0];
445 | for (int i = 1; i < userList.size(); i++) {
446 | u = OtherParams.PaillEnc.cipherAdd(u, userList.get(i).getOpenUiVi().getSecrets()[0]);
447 | }
448 |
449 | System.out.println("\n--Info: Calculate the Encrypted Inner-Data u"+
450 | "\n u: "+u);
451 |
452 | return u;
453 | }
454 |
455 |
456 |
457 | public static BigInteger calculateV(List userList) {
458 | BigInteger v;
459 |
460 | v = userList.get(0).getOpenUiVi().getSecrets()[1];
461 | for (int i = 1; i < userList.size(); i++) {
462 | v = OtherParams.PaillEnc.cipherAdd(v, userList.get(i).getOpenUiVi().getSecrets()[1]);
463 | }
464 |
465 | System.out.println("\n--Info: Calculate the Encrypted Inner-Data v"+
466 | "\n v: "+v);
467 |
468 | return v;
469 | }
470 |
471 |
472 |
473 |
474 |
475 |
476 | public static BigInteger calculateW(List userList) {
477 | BigInteger w;
478 |
479 | w = userList.get(0).getOpenRiWi().getSecrets()[1];
480 | for (int i = 1; i < userList.size(); i++) {
481 | w = OtherParams.PaillEnc.cipherAdd(w, userList.get(i).getOpenRiWi().getSecrets()[1]);
482 | }
483 |
484 | System.out.println("\n--Info: Calculate the Encrypted Inner-Data w"+
485 | "\n w: "+w);
486 |
487 | return w;
488 | }
489 |
490 |
491 |
492 |
493 |
494 |
495 | public static ECPoint calculateR(List userList) {
496 | ECPoint R;
497 |
498 | R= BitcoinParams.CURVE.getCurve().decodePoint(userList.get(0).getOpenRiWi().getSecrets()[0].toByteArray());
499 | for (int i = 1; i < userList.size(); i++) {
500 | R = R.add(BitcoinParams.CURVE.getCurve().decodePoint(userList.get(i).getOpenRiWi().getSecrets()[0].toByteArray()));
501 | }
502 |
503 | System.out.println("\n--Info: Calculate the Encrypted Inner-Data R"+
504 | "\n R: "+R.normalize().toString());
505 |
506 | return R;
507 | }
508 |
509 | }
510 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/main/DCRMTest.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.main;
2 |
3 | import java.security.Security;
4 | import java.util.Scanner;
5 |
6 | import org.fsn_cfc.service.TxBTCService;
7 | import org.fsn_cfc.service.TxETHService;
8 | public class DCRMTest {
9 |
10 |
11 | public static void main(String[] args) {
12 |
13 | sysSet();
14 |
15 | Scanner sc = new Scanner(System.in);
16 | //@INPUT@ Input the type of Token
17 |
18 | String tokenType = null;
19 | do {
20 | System.out.println("\n##########################################################################################################################\n");
21 | System.out.println("Please input the type of Token which you would like to test DCRM, ETH or BTC ? (For example: ETH)");
22 | System.out.println("\n##########################################################################################################################\n");
23 | tokenType = "ETH";
24 | String inputTokenType = sc.nextLine();
25 | tokenType = inputTokenType.equals("") ? tokenType : inputTokenType;
26 | if(!(tokenType.equals("BTC")||tokenType.equals("ETH"))) {
27 | System.out.println("You have input the wrong type of Token, please try again.");
28 | tokenType = "";
29 | }
30 | }while(!(tokenType.equals("BTC")||tokenType.equals("ETH")));
31 |
32 | if(tokenType.equals("ETH")) {
33 | TxETHService.run(tokenType);
34 | }else if(tokenType.equals("BTC")) {
35 | TxBTCService.run(tokenType);
36 | }
37 |
38 | }
39 |
40 |
41 | private static void sysSet() {
42 |
43 | String osName = System.getProperty("os.name");
44 | if(osName.contains("Windows")) {
45 | System.loadLibrary("gmp");
46 | }
47 | Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
48 |
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/paillier/AbstractPaillier.java:
--------------------------------------------------------------------------------
1 |
2 | package org.fsn_cfc.paillier;
3 |
4 | import java.math.BigInteger;
5 |
6 | import org.squareup.jnagmp.Gmp;
7 |
8 | public abstract class AbstractPaillier {
9 |
10 |
11 | /** Public Key allowing encryption. */
12 | protected PaPublicKey publicKey = null;
13 |
14 |
15 |
16 |
17 |
18 |
19 | public PaPublicKey getPublicKey()
20 | {
21 | if (publicKey==null) {
22 | return null;
23 | }
24 | return publicKey.getPublicKey();
25 | }
26 |
27 |
28 |
29 |
30 | public BigInteger encrypt(BigInteger m, BigInteger r)
31 | {
32 | return encrypt(m, r, publicKey);
33 | }
34 |
35 |
36 | public static BigInteger encrypt(BigInteger m, BigInteger r, PaPublicKey key) {
37 | return encrypt(m, r, key.getN(), key.getNS(), key.getNSPlusOne());
38 | }
39 |
40 | public static BigInteger encrypt(BigInteger m, BigInteger r, BigInteger n, BigInteger ns, BigInteger nSPlusOne) {
41 | if(!(PaPublicKey.inModN(m,ns))) {
42 | throw new IllegalArgumentException("m must be less than n^s");
43 | }
44 |
45 | if(!(PaPublicKey.inModNStar(r,n))) {
46 | throw new IllegalArgumentException("r must be relatively prime to n and 0 <= r < n");
47 | }
48 |
49 | return (n.add(BigInteger.ONE).modPow(m, nSPlusOne).multiply(r.modPow(ns, nSPlusOne))).mod(nSPlusOne);
50 | }
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | public BigInteger cipherAdd(BigInteger c1, BigInteger c2)
61 | {
62 | if(!(publicKey.inModNSPlusOne(c1))) throw new IllegalArgumentException("c1 must be less than n^(s+1)");
63 | if(!(publicKey.inModNSPlusOne(c2))) throw new IllegalArgumentException("c2 must be less than n^(s+1)");
64 | return (c1.multiply(c2)).mod(publicKey.getNSPlusOne());
65 | }
66 |
67 | public BigInteger cipherMultiply(BigInteger c1, BigInteger cons)
68 | {
69 | if(!(publicKey.inModNSPlusOne(c1))) throw new IllegalArgumentException("c1 must be less than n^2");
70 | return Gmp.modPowSecure(c1, cons, publicKey.getNSPlusOne());
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/paillier/PaPrivateKey.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.paillier;
2 |
3 | import java.math.BigInteger;
4 |
5 | public class PaPrivateKey extends PaPublicKey {
6 |
7 |
8 | protected BigInteger d = null;
9 |
10 | protected BigInteger dInverse = null;
11 |
12 |
13 | public PaPrivateKey(BigInteger n, BigInteger d, long seed){
14 | super(n, seed);
15 |
16 | if (!(inModNStar(d.mod(n))))
17 | throw new IllegalArgumentException("d must be relatively prime to n");
18 |
19 | this.d = d;
20 | this.dInverse = this.d.modInverse(ns);
21 | }
22 |
23 |
24 | public PaPrivateKey(BigInteger p, BigInteger q, BigInteger d, long seed) {
25 | super(p,q,seed);
26 |
27 | if (!(inModNStar(d.mod(n))))
28 | throw new IllegalArgumentException("d must be relatively prime to n");
29 |
30 | BigInteger phin = p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE));
31 |
32 | BigInteger lambda = phin.divide(p.subtract(BigInteger.ONE).gcd(q.subtract(BigInteger.ONE)));
33 |
34 | if (!(d.mod(lambda).compareTo(BigInteger.ZERO)==0))
35 | throw new IllegalArgumentException("d must be a multiple of lcm(p-1,q-1)");
36 |
37 | this.d = d;
38 | this.dInverse = this.d.modInverse(ns);
39 | }
40 |
41 |
42 |
43 | public BigInteger getD() {
44 | return d;
45 | }
46 |
47 | public BigInteger getDInverse() {
48 | return dInverse;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/paillier/PaPrivateKeyGen.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.paillier;
2 |
3 | import java.math.BigInteger;
4 | import java.security.SecureRandom;
5 | import java.util.Random;
6 |
7 |
8 | public class PaPrivateKeyGen {
9 |
10 |
11 | public static PaPrivateKey PaPrivateKeyGen(int s, long seed) {
12 |
13 | BigInteger minprm=null;
14 | BigInteger maxprm=null;
15 | BigInteger phin=null;
16 | BigInteger p;
17 | BigInteger q;
18 | BigInteger d;
19 | BigInteger n;
20 | SecureRandom rnd;
21 |
22 | boolean ok=false;
23 |
24 |
25 | rnd= new SecureRandom(BigInteger.valueOf(seed).toByteArray());
26 |
27 | do {
28 | p = PaPrivateKeyGen.getPrime(s, rnd);
29 | q = PaPrivateKeyGen.getPrime(s, rnd);
30 | minprm = q.min(p);
31 | maxprm = q.max(p);
32 |
33 | p = minprm;
34 | q = maxprm;
35 |
36 | if((q.mod(p.subtract(BigInteger.ONE))).compareTo(BigInteger.ZERO)!=0) {
37 | ok=true;
38 | }
39 |
40 | } while(!ok);
41 |
42 | n=p.multiply(q);
43 |
44 | phin=(p.subtract(BigInteger.ONE)).multiply(q.subtract(BigInteger.ONE));
45 |
46 | d=phin.divide((p.subtract(BigInteger.ONE)).gcd(q.subtract(BigInteger.ONE)));
47 |
48 | return new PaPrivateKey(n, d, seed);
49 | }
50 |
51 |
52 |
53 | public static BigInteger getPrime(int length, Random random) {
54 | return BigInteger.probablePrime(length, random);
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/paillier/PaPublicKey.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.paillier;
2 |
3 | import java.math.BigInteger;
4 | import java.security.SecureRandom;
5 |
6 | public class PaPublicKey{
7 |
8 | protected BigInteger n=null;
9 |
10 | protected BigInteger ns=null;
11 |
12 | protected BigInteger nSPlusOne=null;
13 |
14 | protected BigInteger nPlusOne=null;
15 |
16 | protected SecureRandom rnd=null;
17 |
18 |
19 |
20 |
21 |
22 | public PaPublicKey(BigInteger n, SecureRandom rnd) {
23 |
24 |
25 | this.n = n;
26 | this.ns = n;
27 | this.nSPlusOne = this.n.multiply(this.n);
28 | this.nPlusOne = this.n.add(BigInteger.ONE);
29 | this.rnd = rnd;
30 | }
31 |
32 |
33 | public PaPublicKey(BigInteger n, long seed)
34 | {
35 | this(n, new SecureRandom(BigInteger.valueOf(seed).toByteArray()));
36 | }
37 |
38 |
39 | public PaPublicKey(BigInteger p, BigInteger q, long seed) {
40 | this(p.multiply(p), seed);
41 |
42 | if (p.compareTo(q) == 0)
43 | throw new IllegalArgumentException("p and q must be different primes");
44 | }
45 |
46 | public PaPublicKey(byte[] b, long seed) {
47 | this(new BigInteger(b), seed);
48 | }
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | public BigInteger getRandomModN() {
58 | BigInteger r;
59 | do {
60 | r = new BigInteger(n.bitLength(),rnd);
61 | } while (r.compareTo(n)>=0);
62 | return r;
63 | }
64 |
65 | public BigInteger getRandomModNStar() {
66 | BigInteger r;
67 | do {
68 | r = new BigInteger(n.bitLength(),rnd);
69 | } while (!inModNStar(r, n));
70 | return r;
71 | }
72 |
73 | public BigInteger getRandomModNSPlusOneStar() {
74 | BigInteger r;
75 | do {
76 | r = new BigInteger(nSPlusOne.bitLength(),rnd);
77 | } while (!inModNStar(r, nSPlusOne));
78 | return r;
79 | }
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 | public static boolean inModN(BigInteger a, BigInteger n) {
93 | return (a.compareTo(n) < 0 && a.compareTo(BigInteger.ZERO) >= 0);
94 | }
95 |
96 | public static boolean inModNStar(BigInteger a, BigInteger n) {
97 | return (a.gcd(n).equals(BigInteger.ONE) && inModN(a, n));
98 | }
99 |
100 |
101 | public boolean inModNStar(BigInteger a) {
102 | return inModNStar(a, n);
103 | }
104 |
105 | public boolean inModNSPlusOneStar(BigInteger a) {
106 | return inModNStar(a, nSPlusOne);
107 | }
108 |
109 | public boolean inModN(BigInteger a) {
110 | return inModN(a, n);
111 | }
112 |
113 | public boolean inModNS(BigInteger a) {
114 | return inModN(a, ns);
115 | }
116 |
117 | public boolean inModNSPlusOne(BigInteger a) {
118 | return inModN(a, nSPlusOne);
119 | }
120 |
121 | public byte[] toByteArray() {
122 |
123 | int size = n.toByteArray().length;
124 | byte[] r = new byte[size];
125 | System.arraycopy(n.toByteArray(), 0, r, 4, size);
126 |
127 | return r;
128 | }
129 |
130 |
131 | public PaPublicKey getPublicKey() {
132 | return new PaPublicKey(n, rnd.nextLong());
133 | }
134 |
135 | public boolean canEncrypt() {
136 | return false;
137 | }
138 |
139 | public BigInteger getN() {
140 | return n;
141 | }
142 |
143 | public BigInteger getNS() {
144 | return ns;
145 | }
146 |
147 | public BigInteger getNSPlusOne() {
148 | return nSPlusOne;
149 | }
150 |
151 | public BigInteger getNPlusOne() {
152 | return nPlusOne;
153 | }
154 |
155 | public SecureRandom getRnd() {
156 | return rnd;
157 | }
158 |
159 | public void updateRnd() {
160 | setRnd(rnd.nextLong());
161 | }
162 |
163 | public void setRnd(long seed) {
164 | setRnd(new SecureRandom(BigInteger.valueOf(seed).toByteArray()));
165 | }
166 |
167 | public void setRnd(SecureRandom rnd) {
168 | this.rnd = rnd;
169 | }
170 |
171 | }
172 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/paillier/Paillier.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.paillier;
2 |
3 | import java.math.*;
4 |
5 | public class Paillier extends AbstractPaillier{
6 |
7 | protected PaPrivateKey privateKey = null;
8 |
9 |
10 | public Paillier(){}
11 |
12 |
13 | public Paillier(PaPublicKey pubkey) {
14 | this.publicKey = pubkey;
15 | }
16 |
17 |
18 | public Paillier(PaPrivateKey prikey) {
19 | this(prikey.getPublicKey());
20 | this.privateKey = prikey;
21 | }
22 |
23 |
24 |
25 | public BigInteger decrypt(BigInteger c)
26 | {
27 | BigInteger c1=null;
28 |
29 | c1= c.modPow(privateKey.getD(),privateKey.getNSPlusOne());
30 |
31 | return (privateKey.getDInverse().multiply((c1.subtract(BigInteger.ONE)).divide(privateKey.getN()))).mod(privateKey.getN());
32 | }
33 |
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/paillierp/AbstractPaillier.java:
--------------------------------------------------------------------------------
1 |
2 | package org.fsn_cfc.paillierp;
3 |
4 | import java.math.BigInteger;
5 |
6 | import org.fsn_cfc.pakey.*;
7 | import org.squareup.jnagmp.Gmp;
8 |
9 | public abstract class AbstractPaillier {
10 |
11 |
12 | /** Public Key allowing encryption. */
13 | protected PaPublicKey publicKey = null;
14 |
15 |
16 |
17 |
18 |
19 |
20 | public PaPublicKey getPublicKey()
21 | {
22 | if (publicKey==null) {
23 | return null;
24 | }
25 | return publicKey.getPublicKey();
26 | }
27 |
28 |
29 |
30 |
31 | public BigInteger encrypt(BigInteger m, BigInteger r)
32 | {
33 | return encrypt(m, r, publicKey);
34 | }
35 |
36 |
37 | public static BigInteger encrypt(BigInteger m, BigInteger r, PaPublicKey key) {
38 | return encrypt(m, r, key.getN(), key.getNS(), key.getNSPlusOne());
39 | }
40 |
41 | public static BigInteger encrypt(BigInteger m, BigInteger r, BigInteger n, BigInteger ns, BigInteger nSPlusOne) {
42 | if(!(PaPublicKey.inModN(m,ns))) {
43 | throw new IllegalArgumentException("m must be less than n^s");
44 | }
45 |
46 | if(!(PaPublicKey.inModNStar(r,n))) {
47 | throw new IllegalArgumentException("r must be relatively prime to n and 0 <= r < n");
48 | }
49 |
50 | return (n.add(BigInteger.ONE).modPow(m, nSPlusOne).multiply(r.modPow(ns, nSPlusOne))).mod(nSPlusOne);
51 | }
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | public BigInteger cipherAdd(BigInteger c1, BigInteger c2)
62 | {
63 | if(!(publicKey.inModNSPlusOne(c1))) throw new IllegalArgumentException("c1 must be less than n^(s+1)");
64 | if(!(publicKey.inModNSPlusOne(c2))) throw new IllegalArgumentException("c2 must be less than n^(s+1)");
65 | return (c1.multiply(c2)).mod(publicKey.getNSPlusOne());
66 | }
67 |
68 | public BigInteger cipherMultiply(BigInteger c1, BigInteger cons)
69 | {
70 | if(!(publicKey.inModNSPlusOne(c1))) throw new IllegalArgumentException("c1 must be less than n^2");
71 | return Gmp.modPowSecure(c1, cons, publicKey.getNSPlusOne());
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/paillierp/Paillier.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Paillier.java
3 | */
4 | package org.fsn_cfc.paillierp;
5 |
6 | import java.math.*;
7 |
8 | import org.fsn_cfc.pakey.*;
9 |
10 | public class Paillier extends AbstractPaillier{
11 |
12 | protected PaPrivateKey privateKey = null;
13 |
14 |
15 | public Paillier(){}
16 |
17 |
18 | public Paillier(PaPublicKey pubkey) {
19 | this.publicKey = pubkey;
20 | }
21 |
22 |
23 | public Paillier(PaPrivateKey prikey) {
24 | this(prikey.getPublicKey());
25 | this.privateKey = prikey;
26 | }
27 |
28 |
29 |
30 | public BigInteger decrypt(BigInteger c)
31 | {
32 | BigInteger c1=null;
33 |
34 | c1= c.modPow(privateKey.getD(),privateKey.getNSPlusOne());
35 |
36 | return (privateKey.getDInverse().multiply((c1.subtract(BigInteger.ONE)).divide(privateKey.getN()))).mod(privateKey.getN());
37 | }
38 |
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/pakey/PaPrivateKey.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.pakey;
2 |
3 | import java.math.BigInteger;
4 |
5 | public class PaPrivateKey extends PaPublicKey {
6 |
7 |
8 | protected BigInteger d = null;
9 |
10 | protected BigInteger dInverse = null;
11 |
12 |
13 | public PaPrivateKey(BigInteger n, BigInteger d, long seed){
14 | super(n, seed);
15 |
16 | if (!(inModNStar(d.mod(n))))
17 | throw new IllegalArgumentException("d must be relatively prime to n");
18 |
19 | this.d = d;
20 | this.dInverse = this.d.modInverse(ns);
21 | }
22 |
23 |
24 | public PaPrivateKey(BigInteger p, BigInteger q, BigInteger d, long seed) {
25 | super(p,q,seed);
26 |
27 | if (!(inModNStar(d.mod(n))))
28 | throw new IllegalArgumentException("d must be relatively prime to n");
29 |
30 | BigInteger phin = p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE));
31 |
32 | BigInteger lambda = phin.divide(p.subtract(BigInteger.ONE).gcd(q.subtract(BigInteger.ONE)));
33 |
34 | if (!(d.mod(lambda).compareTo(BigInteger.ZERO)==0))
35 | throw new IllegalArgumentException("d must be a multiple of lcm(p-1,q-1)");
36 |
37 | this.d = d;
38 | this.dInverse = this.d.modInverse(ns);
39 | }
40 |
41 |
42 |
43 | public BigInteger getD() {
44 | return d;
45 | }
46 |
47 | public BigInteger getDInverse() {
48 | return dInverse;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/pakey/PaPrivateKeyGen.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.pakey;
2 |
3 | import java.math.BigInteger;
4 | import java.security.SecureRandom;
5 | import java.util.Random;
6 |
7 |
8 | public class PaPrivateKeyGen {
9 |
10 |
11 | public static PaPrivateKey PaPrivateKeyGen(int s, long seed) {
12 |
13 | if (s<=0) {
14 | throw new IllegalArgumentException("Number of bits set is less than 0");
15 | }
16 |
17 | BigInteger minprm=null;
18 | BigInteger maxprm=null;
19 | BigInteger phin=null;
20 | BigInteger p;
21 | BigInteger q;
22 | BigInteger d;
23 | BigInteger n;
24 | SecureRandom rnd;
25 |
26 | boolean ok=false;
27 |
28 |
29 | rnd= new SecureRandom(BigInteger.valueOf(seed).toByteArray());
30 |
31 | do {
32 | p = PaPrivateKeyGen.getPrime(s, rnd);
33 | q = PaPrivateKeyGen.getPrime(s, rnd);
34 | minprm = q.min(p);
35 | maxprm = q.max(p);
36 |
37 | p = minprm;
38 | q = maxprm;
39 |
40 | if((q.mod(p.subtract(BigInteger.ONE))).compareTo(BigInteger.ZERO)!=0) {
41 | ok=true;
42 | }
43 |
44 | } while(!ok);
45 |
46 | n=p.multiply(q);
47 |
48 | phin=(p.subtract(BigInteger.ONE)).multiply(q.subtract(BigInteger.ONE));
49 |
50 | d=phin.divide((p.subtract(BigInteger.ONE)).gcd(q.subtract(BigInteger.ONE)));
51 |
52 | return new PaPrivateKey(n, d, seed);
53 | }
54 |
55 |
56 |
57 | public static BigInteger getPrime(int length, Random random) {
58 | return BigInteger.probablePrime(length, random);
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/pakey/PaPublicKey.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.pakey;
2 |
3 | import java.math.BigInteger;
4 | import java.security.SecureRandom;
5 |
6 | public class PaPublicKey{
7 |
8 | protected BigInteger n=null;
9 |
10 | protected BigInteger ns=null;
11 |
12 | protected BigInteger nSPlusOne=null;
13 |
14 | protected BigInteger nPlusOne=null;
15 |
16 |
17 | protected SecureRandom rnd=null;
18 |
19 | public PaPublicKey(BigInteger n, SecureRandom rnd) {
20 |
21 |
22 | this.n = n;
23 | this.ns = n;
24 | this.nSPlusOne = this.n.multiply(this.n);
25 | this.nPlusOne = this.n.add(BigInteger.ONE);
26 | this.rnd = rnd;
27 | }
28 |
29 |
30 | public PaPublicKey(BigInteger n, long seed)
31 | {
32 | this(n, new SecureRandom(BigInteger.valueOf(seed).toByteArray()));
33 | }
34 |
35 |
36 | public PaPublicKey(BigInteger p, BigInteger q, long seed) {
37 | this(p.multiply(p), seed);
38 |
39 | if (p.compareTo(q) == 0)
40 | throw new IllegalArgumentException("p and q must be different primes");
41 | }
42 |
43 | public PaPublicKey(byte[] b, long seed) {
44 | this(new BigInteger(b), seed);
45 | }
46 |
47 |
48 | public BigInteger getRandomModN() {
49 | BigInteger r;
50 | do {
51 | r = new BigInteger(n.bitLength(),rnd);
52 | } while (r.compareTo(n)>=0);
53 | return r;
54 | }
55 |
56 | public BigInteger getRandomModNStar() {
57 | BigInteger r;
58 | do {
59 | r = new BigInteger(n.bitLength(),rnd);
60 | } while (!inModNStar(r, n));
61 | return r;
62 | }
63 |
64 | public BigInteger getRandomModNSPlusOneStar() {
65 | BigInteger r;
66 | do {
67 | r = new BigInteger(nSPlusOne.bitLength(),rnd);
68 | } while (!inModNStar(r, nSPlusOne));
69 | return r;
70 | }
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 | public static boolean inModN(BigInteger a, BigInteger n) {
84 | return (a.compareTo(n) < 0 && a.compareTo(BigInteger.ZERO) >= 0);
85 | }
86 |
87 | public static boolean inModNStar(BigInteger a, BigInteger n) {
88 | return (a.gcd(n).equals(BigInteger.ONE) && inModN(a, n));
89 | }
90 |
91 |
92 | public boolean inModNStar(BigInteger a) {
93 | return inModNStar(a, n);
94 | }
95 |
96 | public boolean inModNSPlusOneStar(BigInteger a) {
97 | return inModNStar(a, nSPlusOne);
98 | }
99 |
100 | public boolean inModN(BigInteger a) {
101 | return inModN(a, n);
102 | }
103 |
104 | public boolean inModNS(BigInteger a) {
105 | return inModN(a, ns);
106 | }
107 |
108 | public boolean inModNSPlusOne(BigInteger a) {
109 | return inModN(a, nSPlusOne);
110 | }
111 |
112 | public byte[] toByteArray() {
113 |
114 | int size = n.toByteArray().length;
115 | byte[] r = new byte[size];
116 | System.arraycopy(n.toByteArray(), 0, r, 4, size);
117 |
118 | return r;
119 | }
120 |
121 |
122 | public PaPublicKey getPublicKey() {
123 | return new PaPublicKey(n, rnd.nextLong());
124 | }
125 |
126 | public boolean canEncrypt() {
127 | return false;
128 | }
129 |
130 | public BigInteger getN() {
131 | return n;
132 | }
133 |
134 | public BigInteger getNS() {
135 | return ns;
136 | }
137 |
138 | public BigInteger getNSPlusOne() {
139 | return nSPlusOne;
140 | }
141 |
142 | public BigInteger getNPlusOne() {
143 | return nPlusOne;
144 | }
145 |
146 | public SecureRandom getRnd() {
147 | return rnd;
148 | }
149 |
150 | public void updateRnd() {
151 | setRnd(rnd.nextLong());
152 | }
153 |
154 | public void setRnd(long seed) {
155 | setRnd(new SecureRandom(BigInteger.valueOf(seed).toByteArray()));
156 | }
157 |
158 | public void setRnd(SecureRandom rnd) {
159 | this.rnd = rnd;
160 | }
161 |
162 | }
163 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/service/TxBTCService.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.service;
2 |
3 | import java.math.BigInteger;
4 | import java.util.List;
5 | import java.util.Scanner;
6 |
7 | import org.bouncycastle.math.ec.ECPoint;
8 | import org.fsn_cfc.fusiondcrm.FusionDCRM;
9 | import org.fsn_cfc.util.BTCAPIUtil;
10 | import org.fsn_cfc.util.BTCUtil;
11 | import org.fsn_cfc.util.Base58Util;
12 | import org.fsn_cfc.util.ECDSASignature;
13 | import org.fsn_cfc.util.OtherUtil;
14 | import org.fsn_cfc.util.User;
15 |
16 | public class TxBTCService {
17 |
18 | public static void run(String tokenType) {
19 |
20 | Scanner sc = new Scanner(System.in);
21 |
22 | //@INPUT@ Input the number of Supreme Nodes
23 | System.out.println("\n##########################################################################################################################\n");
24 | System.out.println("Please input the number of Supreme Nodes to generate the FUSION DCRM private key: (For example: 4)");
25 | System.out.println("\n##########################################################################################################################\n");
26 | int userCount = 4;
27 | String inputUserCount = sc.nextLine();
28 | userCount = inputUserCount.equals("") ? userCount : Integer.parseInt(inputUserCount);
29 |
30 | //key generate
31 | List userList = FusionDCRM.keyGenerate(userCount);
32 |
33 | //Encrypted Private Key
34 | BigInteger encX = userList.get(0).getEncX();
35 |
36 | //public key
37 | ECPoint pk = userList.get(0).getPk();
38 | String pkStr = userList.get(0).getPkStr();
39 |
40 | //calculate address
41 | String pkHex = "04"+ pkStr;
42 | String address = BTCUtil.ConvertPublicKeyToBitcoinAdress(pkHex);
43 |
44 |
45 | //@INPUT@ Transfer some Testnet BTC to DCRM address
46 | String inputTransferOk = null;
47 |
48 | String[] utxoV = null;
49 | do{
50 | System.out.println("\n##########################################################################################################################\n");
51 | System.out.println("Please tranfer some Testnet BTC to the DCRM Address: " + address + ", (For example: transfer 0.1 Testnet BTC)");
52 | System.out.println("Do you complete the procedure of Transferring Testnet BTC? Yes or No? (For example: No)");
53 | System.out.println("\n##########################################################################################################################\n");
54 | inputTransferOk = sc.nextLine();
55 |
56 | if(inputTransferOk.equals("Yes")) {
57 | utxoV = BTCAPIUtil.getUtxoByAddress(address);
58 |
59 | if(utxoV[0]=="address_error") {
60 | System.out.println("address_error!!");
61 | inputTransferOk = "No";
62 | }else if(utxoV[0]=="no_money"){
63 | System.out.println("You do not complete the procedure of Transferring Testnet BTC, and please try again.");
64 | inputTransferOk = "No";
65 | }else if(utxoV[0]=="wait_confirm") {
66 | System.out.println("The transfer transaction is waitting for confirmation, and please try again.");
67 | inputTransferOk = "No";
68 | }
69 | }
70 | }while(!inputTransferOk.equals("Yes"));
71 |
72 |
73 | //@INPUT@ Input the receive Testnet Address
74 | String inputToAddress = null;
75 | do {
76 | System.out.println("\n##########################################################################################################################\n");
77 | System.out.println("Please input Bitcoin Testnet Address (P2PKH, with the leading symbol m or n) to receive BTC, not with the prefix '0x': (For example: mwv8hYDLHaoA4DXMFNjBTX5VFosMbRVVvS )");
78 | System.out.println("\n##########################################################################################################################\n");
79 | inputToAddress = sc.nextLine();
80 | if(inputToAddress.length()!=34) {
81 | System.out.println("You have input the wrong Bitcoin Testnet Address, and please try again.");
82 | }else if(!(inputToAddress.charAt(0)=='m' || inputToAddress.charAt(0)=='n')){
83 | System.out.println("The Bitcoin Testnet Address you have input is not the P2PKH Address which with the leading symbol m or n, and please try again.");
84 | inputToAddress = "";
85 | }
86 | }while(inputToAddress.length()!=34);
87 |
88 | String fromAddress = address;
89 | String toAddress = inputToAddress;
90 |
91 |
92 | StringBuffer inBf = new StringBuffer();
93 | inBf.append("76");
94 | inBf.append("a9");
95 | inBf.append("14");
96 | inBf.append(Base58Util.Base58ToHexString(fromAddress, 50).substring(2, 42));
97 | inBf.append("88");
98 | inBf.append("ac");
99 | String inScript = inBf.toString();
100 |
101 |
102 | StringBuffer toBf = new StringBuffer();
103 | toBf.append("76");
104 | toBf.append("a9");
105 | toBf.append("14");
106 | toBf.append(Base58Util.Base58ToHexString(toAddress, 50).substring(2, 42));
107 | toBf.append("88");
108 | toBf.append("ac");
109 | String outScript = toBf.toString();
110 |
111 |
112 | String utxo = utxoV[0];
113 | int utxoIndex = Integer.parseInt(utxoV[1]);
114 | int txValue = Integer.parseInt(utxoV[2]);
115 |
116 |
117 | StringBuffer input = new StringBuffer();
118 | input.append(strBn2Ln(utxo));
119 | input.append(int2LnStr(utxoIndex, 8));
120 | input.append(Integer.toHexString(inScript.length()/2));
121 | input.append(inScript);
122 | input.append("ffffffff");
123 | String tx_input = input.toString();
124 |
125 |
126 | // miner fee is 10000 satoshi, 1 BTC = 10^8 satoshi
127 | int value = txValue - 10000;
128 | StringBuffer output = new StringBuffer();
129 | output.append(int2LnStr(value, 16));
130 | output.append(Integer.toHexString(outScript.length()/2));
131 | output.append(outScript);
132 | String tx_output = output.toString();
133 |
134 |
135 | int inCnt = 1;
136 | int outCnt = 1;
137 | int version = 1;
138 | int lockTime = 0;
139 | StringBuffer txBf = new StringBuffer();
140 | txBf.append(int2LnStr(version, 8));
141 | txBf.append(strBn2Ln(int2LnStr(inCnt, 2)));
142 | txBf.append(tx_input);
143 | txBf.append(strBn2Ln(int2LnStr(outCnt, 2)));
144 | txBf.append(tx_output);
145 | txBf.append(int2LnStr(lockTime, 8));
146 | String tx = txBf.toString();
147 |
148 |
149 | StringBuffer rawTxBf = new StringBuffer(tx);
150 | //hashtype
151 | int hashType = 1;
152 | rawTxBf.append(int2LnStr(hashType, 8));
153 | String rawTx = rawTxBf.toString();
154 |
155 |
156 | //################################################# generate raw_tx_hash ###############################################
157 | String raw_tx_hash = BTCUtil.getHashSHA256_from_HexString(rawTx);
158 | raw_tx_hash = BTCUtil.getHashSHA256_from_HexString(raw_tx_hash);
159 |
160 | String msgHash = raw_tx_hash;
161 | ECDSASignature signature = FusionDCRM.sign(userList, encX, msgHash, tokenType);
162 | FusionDCRM.verify(signature, msgHash, pk);
163 |
164 |
165 |
166 | StringBuffer DERSigBuf = new StringBuffer();
167 | String rHex = OtherUtil.convertBytesToHexString(signature.getR().toByteArray());
168 | String sHex = OtherUtil.convertBytesToHexString(signature.getS().toByteArray());
169 | int rLen = rHex.length()/2;
170 | int sLen = sHex.length()/2;
171 | int sigLen = rLen + sLen + 4;
172 |
173 | String rLenHex = int2LnStr(rLen,2);
174 | String sLenHex = int2LnStr(sLen,2);
175 | String sigLenHex = int2LnStr(sigLen,2);
176 |
177 | DERSigBuf.append("30");
178 | DERSigBuf.append(sigLenHex);
179 | DERSigBuf.append("02");
180 | DERSigBuf.append(rLenHex);
181 | DERSigBuf.append(rHex);
182 | DERSigBuf.append("02");
183 | DERSigBuf.append(sLenHex);
184 | DERSigBuf.append(sHex);
185 |
186 | String DERSig = DERSigBuf.toString() + int2LnStr(hashType, 2);
187 |
188 |
189 |
190 | //################################################# generate signedScriptSig ###############################################
191 | StringBuffer signedScriptSigBuffer = new StringBuffer(int2LnStr(DERSig.length()/2, 2));
192 | signedScriptSigBuffer.append(DERSig);
193 | signedScriptSigBuffer.append(int2LnStr(pkHex.length()/2, 2));
194 | signedScriptSigBuffer.append(pkHex);
195 |
196 | String signedScriptSig = signedScriptSigBuffer.toString();
197 |
198 | //################################################# generate tx ###############################################
199 | input = new StringBuffer();
200 | input.append(strBn2Ln(utxo));
201 | input.append(int2LnStr(utxoIndex, 8));
202 | input.append(Integer.toHexString(signedScriptSig.length()/2));
203 | input.append(signedScriptSig);
204 | input.append("ffffffff");
205 | tx_input = input.toString();
206 |
207 |
208 |
209 | txBf = new StringBuffer();
210 | txBf.append(int2LnStr(version, 8));
211 | txBf.append(strBn2Ln(int2LnStr(inCnt, 2)));
212 | txBf.append(tx_input);
213 | txBf.append(strBn2Ln(int2LnStr(inCnt, 2)));
214 | txBf.append(tx_output);
215 | txBf.append(int2LnStr(lockTime, 8));
216 |
217 | tx = txBf.toString();
218 |
219 | //Send the signed tranaction to ethereum Rinkeby testnet
220 | System.out.println("\n##########################################################################################################################\n");
221 | System.out.println("Successfully generate the FUSION DCRM signed transaction: "+ tx);
222 | System.out.println("\nPlease paste the FUSION DCRM signed transaction to the website (https://live.blockcypher.com/btc/pushtx/#) with the Network selection of \"Bitcoin Testnet\" and press the \"BROADCAST TRANSACTION\" button.");
223 | System.out.println("\n##########################################################################################################################\n");
224 |
225 |
226 | }
227 |
228 |
229 |
230 | private static String int2LnStr(int var0, int length) {
231 | int var1 = 1;
232 | int var2 = var0 >> 8;
233 | int var3 = var0 & 255;
234 | String var4 = Integer.toHexString(var2);
235 | String var5 = Integer.toHexString(var3);
236 | if(var4.length() > 2) {
237 | do {
238 | if(var1 > 1) {
239 | var2 >>= 8;
240 | }
241 | var4 = Integer.toHexString(var2 >> 8);
242 | var5 = var5 + Integer.toHexString(var2 & 255);
243 | ++var1;
244 | } while(var4.length() > 2);
245 | }
246 | if(var4.length() < 2) {
247 | var4 = "0" + var4;
248 | }
249 | if(var5.length() < 2) {
250 | var5 = "0" + var5;
251 | }
252 |
253 | String tem = var5 + var4;
254 | StringBuffer result = new StringBuffer(tem);
255 |
256 | if(tem.length() < length) {
257 | for(int i = 0 ; i < length-tem.length() ; i++) {
258 | result.append(0);
259 | }
260 | }
261 |
262 | if(tem.length() > length) {
263 | for(int i = 0 ; i < tem.length() - length ; i++) {
264 | result.deleteCharAt(result.length()-1);
265 | }
266 | }
267 |
268 | return result.toString();
269 | }
270 |
271 |
272 |
273 | private static String strBn2Ln(String bn) {
274 | char[] bnArray = bn.toCharArray();
275 |
276 | StringBuffer rlt = new StringBuffer();
277 |
278 | for(int i=bn.length()/2; i>0; i--) {
279 | rlt.append(bnArray[i*2-2]);
280 | rlt.append(bnArray[i*2-1]);
281 | }
282 |
283 | return rlt.toString();
284 | }
285 |
286 |
287 |
288 | }
289 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/service/TxETHService.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.service;
2 |
3 | import java.math.BigInteger;
4 | import java.util.Arrays;
5 | import java.util.List;
6 | import java.util.Scanner;
7 |
8 | import org.bouncycastle.math.ec.ECPoint;
9 | import org.bouncycastle.util.encoders.Hex;
10 | import org.ethereum.core.Transaction;
11 | import org.ethereum.crypto.HashUtil;
12 | import org.ethereum.util.ByteUtil;
13 | import org.fsn_cfc.fusiondcrm.FusionDCRM;
14 | import org.fsn_cfc.util.ECDSASignature;
15 | import org.fsn_cfc.util.ETHECKeyUtil;
16 | import org.fsn_cfc.util.User;
17 |
18 | public class TxETHService {
19 |
20 |
21 | public static void run(String tokenType) {
22 |
23 | Scanner sc = new Scanner(System.in);
24 |
25 | //@INPUT@ Input the number of Supreme Nodes
26 | System.out.println("\n##########################################################################################################################\n");
27 | System.out.println("Please input the number of Supreme Nodes to generate the FUSION DCRM private key: (For example: 4)");
28 | System.out.println("\n##########################################################################################################################\n");
29 | int userCount = 4;
30 | String inputUserCount = sc.nextLine();
31 | userCount = inputUserCount.equals("") ? userCount : Integer.parseInt(inputUserCount);
32 |
33 |
34 | //DCRM Key generate
35 | List userList = FusionDCRM.keyGenerate(userCount);
36 |
37 | //Encrypted Private Key
38 | BigInteger encX = userList.get(0).getEncX();
39 | //Generate DCRM public key
40 | ECPoint pk = userList.get(0).getPk();
41 |
42 | //Generate DCRM Address
43 | byte[] xyPkByte = pk.getEncoded(false);
44 | byte[] addressByte = HashUtil.sha3omit12(Arrays.copyOfRange(xyPkByte, 1, xyPkByte.length));
45 | String address = ByteUtil.bytesToBigInteger(addressByte).toString(16);
46 |
47 |
48 | //@INPUT@ Transfer some Rinkeby Testnet ETH to DCRM address
49 | String inputTransferOk = null;
50 | do{
51 | System.out.println("\n##########################################################################################################################\n");
52 | System.out.println("Please tranfer some Rinkeby Testnet ETH to the DCRM Address: " + address + ", (For example: transfer 0.1 Rinkeby Testnet ETH)");
53 | System.out.println("Do you complete the procedure of Transferring Rinkeby Testnet ETH? Yes or No? (For example: No)");
54 | System.out.println("\n##########################################################################################################################\n");
55 | inputTransferOk = sc.nextLine();
56 | }while(!inputTransferOk.equals("Yes"));
57 |
58 |
59 | //@INPUT@ Input the receive Rinkeby Testnet Address
60 | String inputToAddress = null;
61 | do {
62 | System.out.println("\n##########################################################################################################################\n");
63 | System.out.println("Please input Ethereum Rinkeby Testnet Address to receive ETH, not with the prefix '0x': (For example: 0520e8e5e08169c4dbc1580dc9bf56638532773a )");
64 | System.out.println("\n##########################################################################################################################\n");
65 | inputToAddress = sc.nextLine();
66 | if(inputToAddress.length()!=40) {
67 | System.out.println("You have input the wrong Ethereum Rinkeby Testnet Address, and please try again.");
68 | }
69 | }while(inputToAddress.length()!=40);
70 |
71 | byte[] toAddress = Hex.decode(inputToAddress);
72 |
73 | //@INPUT@ Input the transfer value
74 | System.out.println("\n##########################################################################################################################\n");
75 | System.out.println("Please input transfer value(Wei), and confirm you have the enough Rinkeby Testnet ETH(Wei) to transfer: (For example: 10000)");
76 | System.out.println("\n##########################################################################################################################\n");
77 | String inputValue = sc.nextLine();
78 |
79 | byte[] value;
80 | if(!inputValue.equals("")) {
81 | value = ByteUtil.longToBytesNoLeadZeroes(Long.parseLong(inputValue));
82 | }else {
83 | value = ByteUtil.longToBytesNoLeadZeroes(Long.parseLong("10000"));
84 | }
85 |
86 | //New DCRM test transaction
87 | byte[] gasPrice = ByteUtil.longToBytesNoLeadZeroes(1_000_000_000_000L);
88 | byte[] gasLimit = ByteUtil.longToBytesNoLeadZeroes(21000);
89 | Transaction tx = new Transaction(ByteUtil.longToBytesNoLeadZeroes(0L),
90 | gasPrice,
91 | gasLimit,
92 | toAddress,
93 | value,
94 | null,
95 | 4);
96 |
97 | //Generate the TX Hash for sign function
98 | byte[] txRawHashByte = tx.getRawHash();
99 | String txRawHashHex = Hex.toHexString(txRawHashByte);
100 | String msgHash = txRawHashHex;
101 |
102 | //Generate DCRM signature
103 | ECDSASignature signature = FusionDCRM.sign(userList, encX, msgHash, tokenType);
104 | FusionDCRM.verify(signature, msgHash, pk);
105 |
106 |
107 | //calculate the recId
108 | int recId = -1;
109 | for (int i = 0; i < 4; i++) {
110 | byte[] k = ETHECKeyUtil.recoverPubBytesFromSignature(i, signature.getR(), signature.getS(), txRawHashByte);
111 | if (k != null && Arrays.equals(k, xyPkByte)) {
112 | recId = i;
113 | break;
114 | }
115 | }
116 | signature.setRecoveryParam(recId);
117 |
118 |
119 | //Generate the signed transaction
120 | int v = recId + 27;
121 | tx = new Transaction(ByteUtil.longToBytesNoLeadZeroes(0L),
122 | gasPrice,
123 | gasLimit,
124 | toAddress,
125 | value,
126 | null,
127 | ByteUtil.bigIntegerToBytes(signature.getR()),
128 | ByteUtil.bigIntegerToBytes(signature.getS()),
129 | (byte)v,
130 | 4);
131 |
132 | byte[] txByteArray = tx.getEncoded();
133 | String txHex = Hex.toHexString(txByteArray);
134 |
135 | //Send the signed tranaction to ethereum Rinkeby testnet
136 | System.out.println("\n##########################################################################################################################\n");
137 | System.out.println("Successfully generate the FUSION DCRM signed transaction: 0x"+ txHex);
138 | System.out.println("\nPlease paste the FUSION DCRM signed transaction to the Step 3 (https://www.myetherwallet.com/#offline-transaction) and press the \"SEND TRANSACTION\" button.");
139 | System.out.println("\n##########################################################################################################################\n");
140 |
141 |
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/util/BTCAPIUtil.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.util;
2 |
3 | import org.toilelibre.libe.curl.Curl;
4 |
5 | import net.sf.json.JSONArray;
6 | import net.sf.json.JSONObject;
7 |
8 | public class BTCAPIUtil {
9 |
10 | public static String[] getUtxoByAddress(String fromAddress) {
11 |
12 | String rlt = Curl.$("https://api.blockcypher.com/v1/btc/test3/addrs/" + fromAddress);
13 |
14 | JSONObject rltJson =JSONObject.fromObject(rlt);
15 |
16 | if(rltJson.get("address")==null) {
17 | return new String[] {"address_error"};
18 | }else if(rltJson.get("balance").toString().equals("0")) {
19 | if(!rltJson.get("unconfirmed_balance").toString().equals("0")) {
20 | return new String[] {"wait_confirm"};
21 | }
22 | return new String[] {"no_money"};
23 | }
24 |
25 | JSONArray utxos = rltJson.getJSONArray("txrefs");
26 |
27 | JSONObject item = null;
28 |
29 | for(int i=0; i 0) return 1;
158 | if(key.compareTo(uns) < 0) return 2;
159 | return 0;
160 | }
161 |
162 |
163 |
164 | public static boolean ist_PrivateKey_Base58_Valid(String str)
165 | {
166 | if(str.equals("") || str.length() != 51) return false;
167 | String roh = Base58Util.Base58ToHexString(str,74);
168 | String a = roh.substring(0,66);
169 | String b = roh.substring(66,74).toUpperCase();
170 | String h = null;
171 | h = getHashSHA256_from_HexString(a);
172 | h = getHashSHA256_from_HexString(h);
173 | h=h.substring(0,8);
174 | if(b.equals(h)) return true;
175 | return false;
176 | }
177 |
178 |
179 |
180 | public static boolean ist_PrivateKey_Base58compressed_Valid(String str)
181 | {
182 | if(str.equals("") || str.length() != 52) return false;
183 | String roh = Base58Util.Base58ToHexString(str,76);
184 | String a = roh.substring(0,68);
185 | String b = roh.substring(68,76).toUpperCase();
186 | String h = null;
187 | h = getHashSHA256_from_HexString(a);
188 | h = getHashSHA256_from_HexString(h);
189 | h=h.substring(0,8);
190 | if(b.equals(h)) return true;
191 | return false;
192 | }
193 |
194 |
195 |
196 | public static boolean ist_PrivateKey_Base64_Valid(String str)
197 | {
198 | if(str.length()==44 && str.matches("[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=]+") && str.charAt(43)=='=') return true;
199 | return false;
200 | }
201 |
202 | }
--------------------------------------------------------------------------------
/src/org/fsn_cfc/util/Base58Util.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.util;
2 |
3 |
4 | import java.math.BigInteger;
5 | import java.util.Base64;
6 |
7 |
8 |
9 | public class Base58Util
10 | {
11 |
12 |
13 |
14 | public static byte[] hexStringToByteArray(String hex)
15 | {
16 | if((hex.length()%2)==1)
17 | {
18 | char c = '1';
19 | hex += c;
20 | }
21 | int l = hex.length();
22 | byte[] data = new byte[l/2];
23 | for (int i = 0; i < l; i += 2)
24 | {
25 | data[i/2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4) + Character.digit(hex.charAt(i+1), 16));
26 | }
27 | return data;
28 | }
29 |
30 |
31 |
32 | public static String byteArrayToHexString(byte[] a)
33 | {
34 | StringBuilder sb = new StringBuilder(a.length * 2);
35 | for(byte b: a)
36 | sb.append(String.format("%02X", b));
37 | return sb.toString();
38 | }
39 |
40 |
41 |
42 | public static String hexStringToBase58(String str)
43 | {
44 | byte[] b = hexStringToByteArray(str);
45 | char[] c = toBase58(b);
46 | return String.valueOf(c);
47 | }
48 |
49 |
50 |
51 | private static char[] toBase58(byte[] k)
52 | {
53 | char[] ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".toCharArray();
54 | BigInteger z = new BigInteger(1,k);
55 | BigInteger z1;
56 | BigInteger rest = new BigInteger("0");
57 | BigInteger base = new BigInteger("58");
58 | int laenge=0;
59 | z1=z;
60 | for(double i=1; i>0;)
61 | {
62 | z1 = z1.divide(base);
63 | i = z1.doubleValue();
64 | laenge++;
65 | }
66 | char[] Key = new char[laenge];
67 | for(int i=laenge; i>0; i--)
68 | {
69 | rest = z.mod(base);
70 | Key[i-1] = ALPHABET[rest.intValue()];
71 | z = z.divide(base);
72 | }
73 | int nullLaenge = 0;
74 | for(int i=0; k[i]==0 && i= message.length * 8) {
36 | return new BigInteger(1, message);
37 | } else {
38 | int messageBitLength = message.length * 8;
39 | BigInteger trunc = new BigInteger(1, message);
40 |
41 | if (messageBitLength - n.bitLength() > 0) {
42 | trunc = trunc.shiftRight(messageBitLength - n.bitLength());
43 | }
44 | return trunc;
45 | }
46 | }
47 |
48 |
49 |
50 |
51 | public static byte[] sha256Hash(byte[]... inputs) {
52 | try {
53 | MessageDigest md = MessageDigest.getInstance("SHA-256");
54 | for (byte[] input : inputs) {
55 | md.update(input);
56 | }
57 | return md.digest();
58 |
59 | } catch (NoSuchAlgorithmException ex) {
60 | throw new AssertionError();
61 | }
62 | }
63 |
64 |
65 |
66 | public static String convertBytesToHexString(byte[] data) {
67 |
68 | return ByteArrayHexString.bytesToHexString(data);
69 |
70 | }
71 |
72 |
73 | public static byte[] convertHexStringToBytes(String hexStr) {
74 |
75 | return ByteArrayHexString.toBytes(hexStr);
76 |
77 | }
78 |
79 |
80 |
81 |
82 | public static byte[] getBytes(ECPoint e) {
83 | byte[] x = e.getX().toBigInteger().toByteArray();
84 | byte[] y = e.getY().toBigInteger().toByteArray();
85 | byte[] output = new byte[x.length + y.length];
86 | System.arraycopy(x, 0, output, 0, x.length);
87 | System.arraycopy(y, 0, output, x.length, y.length);
88 | return output;
89 | }
90 |
91 |
92 |
93 |
94 | public static PublicParameters generatePublicParams(ECDomainParameters CURVE, int primeCertainty, int kPrime, SecureRandom rand, PaPublicKey paillierPubKey) {
95 |
96 | BigInteger p;
97 | BigInteger q;
98 | BigInteger pPrime;
99 | BigInteger qPrime;
100 | BigInteger pPrimeqPrime;
101 | BigInteger nHat;
102 |
103 | do {
104 | p = new BigInteger(kPrime / 2, primeCertainty, rand);
105 | } while (!p.subtract(BigInteger.ONE).divide(BigInteger.valueOf(2))
106 | .isProbablePrime(primeCertainty));
107 |
108 | pPrime = p.subtract(BigInteger.ONE).divide(BigInteger.valueOf(2));
109 |
110 | do {
111 | q = new BigInteger(kPrime / 2, primeCertainty, rand);
112 | } while (!q.subtract(BigInteger.ONE).divide(BigInteger.valueOf(2))
113 | .isProbablePrime(primeCertainty));
114 |
115 | qPrime = q.subtract(BigInteger.ONE).divide(BigInteger.valueOf(2));
116 |
117 | nHat = p.multiply(q);
118 |
119 | BigInteger h2 = RandomUtil.randomFromZnStar(nHat, rand);
120 | pPrimeqPrime = pPrime.multiply(qPrime);
121 |
122 | BigInteger x = RandomUtil.randomFromZn(pPrimeqPrime, rand);
123 | BigInteger h1 = h2.modPow(x, nHat);
124 |
125 | return new PublicParameters(CURVE, nHat, kPrime, h1, h2, paillierPubKey);
126 |
127 | }
128 |
129 | public static String subLast64(String str) {
130 | if(str.length()<=64) {
131 | return str;
132 | }
133 | int start = str.length() - 64;
134 | str = str.substring(start);
135 | return str;
136 | }
137 |
138 |
139 | public static String formatString(String str, int len) {
140 | if(str.length() < len) {
141 | int strLen = str.length();
142 | for(int i = 0 ; i < len-strLen ; i++) {
143 | str = "0" + str;
144 | }
145 | }
146 | return str;
147 | }
148 |
149 | }
150 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/util/RandomUtil.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.util;
2 |
3 | import java.math.BigInteger;
4 | import java.security.SecureRandom;
5 |
6 | public class RandomUtil {
7 |
8 |
9 | public static BigInteger randomFromZn(BigInteger n, SecureRandom rnd) {
10 | BigInteger result;
11 | do {
12 | result = new BigInteger(n.bitLength(), rnd);
13 | } while (result.compareTo(n) != -1);
14 |
15 | return result;
16 | }
17 |
18 |
19 | public static BigInteger randomFromZnStar(BigInteger n, SecureRandom rnd) {
20 | BigInteger result;
21 | do {
22 | result = new BigInteger(n.bitLength(), rnd);
23 | } while (result.compareTo(n) != -1 || !result.gcd(n).equals(BigInteger.ONE));
24 |
25 | return result;
26 | }
27 |
28 |
29 |
30 | public static boolean isElementOfZn(BigInteger element, BigInteger n) {
31 | return (element.compareTo(BigInteger.ZERO) != -1) && (element.compareTo(n) == -1);
32 | }
33 |
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/util/User.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.util;
2 |
3 | import java.math.BigInteger;
4 |
5 | import org.bouncycastle.math.ec.ECPoint;
6 | import org.fsn_cfc.cmt.Commitment;
7 | import org.fsn_cfc.cmt.MTDCommitment;
8 | import org.fsn_cfc.cmt.Open;
9 | import org.fsn_cfc.fusiondcrm.FusionDCRM;
10 | import org.fsn_cfc.zkp.ZkpKG;
11 | import org.fsn_cfc.zkp.ZkpSignOne;
12 | import org.fsn_cfc.zkp.ZkpSignTwo;
13 |
14 | public class User {
15 |
16 |
17 | //kgRoundOne
18 | private BigInteger xShare, xShareRnd, encXShare;
19 | private ECPoint yShare;
20 | private MTDCommitment mpkEncXiYi;
21 | private Open openEncXiYi;
22 | private Commitment cmtEncXiYi;
23 |
24 |
25 | //kgRoundTwo
26 | private ZkpKG zkpKG;
27 |
28 |
29 | //kgRoundThree
30 | BigInteger encX;
31 | String pkStr;
32 | ECPoint pk;
33 |
34 |
35 |
36 |
37 | //Signning round 1
38 | private BigInteger rhoI, rhoIRnd, uI, vI;
39 |
40 | private MTDCommitment mpkUiVi;
41 | private Open openUiVi;
42 | private Commitment cmtUiVi;
43 |
44 |
45 |
46 | //Signning round 2
47 | private ZkpSignOne zkp1;
48 |
49 |
50 |
51 | //Signning round 3
52 | private BigInteger kI, cI, cIRnd;
53 | private ECPoint rI;
54 |
55 | private BigInteger mask, wI;
56 |
57 | private MTDCommitment mpkRiWi;
58 | private Open openRiWi;
59 | private Commitment cmtRiWi;
60 |
61 |
62 |
63 | //Signning round 4
64 | private ZkpSignTwo zkp_i2;
65 |
66 |
67 |
68 |
69 | public BigInteger getxShare() {
70 | return xShare;
71 | }
72 | public void setxShare(BigInteger xShare) {
73 | this.xShare = xShare;
74 | }
75 | public BigInteger getxShareRnd() {
76 | return xShareRnd;
77 | }
78 | public void setxShareRnd(BigInteger xShareRnd) {
79 | this.xShareRnd = xShareRnd;
80 | }
81 | public BigInteger getRhoI() {
82 | return rhoI;
83 | }
84 | public void setRhoI(BigInteger rhoI) {
85 | this.rhoI = rhoI;
86 | }
87 | public BigInteger getRhoIRnd() {
88 | return rhoIRnd;
89 | }
90 | public void setRhoIRnd(BigInteger rhoIRnd) {
91 | this.rhoIRnd = rhoIRnd;
92 | }
93 | public Open getOpenUiVi() {
94 | return openUiVi;
95 | }
96 | public void setOpenUiVi(Open openUiVi) {
97 | this.openUiVi = openUiVi;
98 | }
99 | public Open getOpenRiWi() {
100 | return openRiWi;
101 | }
102 | public void setOpenRiWi(Open openRiWi) {
103 | this.openRiWi = openRiWi;
104 | }
105 | public BigInteger getkI() {
106 | return kI;
107 | }
108 | public void setkI(BigInteger kI) {
109 | this.kI = kI;
110 | }
111 | public BigInteger getcI() {
112 | return cI;
113 | }
114 | public void setcI(BigInteger cI) {
115 | this.cI = cI;
116 | }
117 | public BigInteger getcIRnd() {
118 | return cIRnd;
119 | }
120 | public void setcIRnd(BigInteger cIRnd) {
121 | this.cIRnd = cIRnd;
122 | }
123 | public BigInteger getuI() {
124 | return uI;
125 | }
126 | public void setuI(BigInteger uI) {
127 | this.uI = uI;
128 | }
129 | public BigInteger getvI() {
130 | return vI;
131 | }
132 | public void setvI(BigInteger vI) {
133 | this.vI = vI;
134 | }
135 | public BigInteger getwI() {
136 | return wI;
137 | }
138 | public void setwI(BigInteger wI) {
139 | this.wI = wI;
140 | }
141 | public BigInteger getEncXShare() {
142 | return encXShare;
143 | }
144 | public void setEncXShare(BigInteger encXShare) {
145 | this.encXShare = encXShare;
146 | }
147 | public ECPoint getyShare() {
148 | return yShare;
149 | }
150 | public void setyShare(ECPoint yShare) {
151 | this.yShare = yShare;
152 | }
153 | public MTDCommitment getMpkUiVi() {
154 | return mpkUiVi;
155 | }
156 | public void setMpkUiVi(MTDCommitment mpkUiVi) {
157 | this.mpkUiVi = mpkUiVi;
158 | }
159 | public Commitment getCmtUiVi() {
160 | return cmtUiVi;
161 | }
162 | public void setCmtUiVi(Commitment cmtUiVi) {
163 | this.cmtUiVi = cmtUiVi;
164 | }
165 | public ZkpSignOne getZkp1() {
166 | return zkp1;
167 | }
168 | public void setZkp1(ZkpSignOne zkp1) {
169 | this.zkp1 = zkp1;
170 | }
171 | public ECPoint getrI() {
172 | return rI;
173 | }
174 | public void setrI(ECPoint rI) {
175 | this.rI = rI;
176 | }
177 | public BigInteger getMask() {
178 | return mask;
179 | }
180 | public void setMask(BigInteger mask) {
181 | this.mask = mask;
182 | }
183 | public MTDCommitment getMpkRiWi() {
184 | return mpkRiWi;
185 | }
186 | public void setMpkRiWi(MTDCommitment mpkRiWi) {
187 | this.mpkRiWi = mpkRiWi;
188 | }
189 | public Commitment getCmtRiWi() {
190 | return cmtRiWi;
191 | }
192 | public void setCmtRiWi(Commitment cmtRiWi) {
193 | this.cmtRiWi = cmtRiWi;
194 | }
195 | public ZkpSignTwo getZkp_i2() {
196 | return zkp_i2;
197 | }
198 | public void setZkp_i2(ZkpSignTwo zkp_i2) {
199 | this.zkp_i2 = zkp_i2;
200 | }
201 | public MTDCommitment getMpkEncXiYi() {
202 | return mpkEncXiYi;
203 | }
204 | public void setMpkEncXiYi(MTDCommitment mpkEncXiYi) {
205 | this.mpkEncXiYi = mpkEncXiYi;
206 | }
207 | public Open getOpenEncXiYi() {
208 | return openEncXiYi;
209 | }
210 | public void setOpenEncXiYi(Open openEncXiYi) {
211 | this.openEncXiYi = openEncXiYi;
212 | }
213 | public Commitment getCmtEncXiYi() {
214 | return cmtEncXiYi;
215 | }
216 | public void setCmtEncXiYi(Commitment cmtEncXiYi) {
217 | this.cmtEncXiYi = cmtEncXiYi;
218 | }
219 | public ZkpKG getZkpKG() {
220 | return zkpKG;
221 | }
222 | public void setZkpKG(ZkpKG zkpKG) {
223 | this.zkpKG = zkpKG;
224 | }
225 | public BigInteger getEncX() {
226 | return encX;
227 | }
228 | public void setEncX(BigInteger encX) {
229 | this.encX = encX;
230 | }
231 | public String getPkStr() {
232 | return pkStr;
233 | }
234 | public void setPkStr(String pkStr) {
235 | this.pkStr = pkStr;
236 | }
237 | public void setPk(ECPoint pk) {
238 | this.pk = pk;
239 | }
240 | public ECPoint getPk() {
241 | return pk;
242 | }
243 |
244 | }
245 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/zkp/PublicParameters.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.zkp;
2 |
3 | import java.math.BigInteger;
4 |
5 | import org.bouncycastle.crypto.params.ECDomainParameters;
6 | import org.bouncycastle.math.ec.ECPoint;
7 | import org.fsn_cfc.paillier.PaPublicKey;
8 |
9 | public class PublicParameters{
10 |
11 | public final byte[] gRaw;
12 | public final BigInteger h1;
13 | public final BigInteger h2;
14 | public final BigInteger nTilde;
15 | public final PaPublicKey paillierPubKey;
16 |
17 | public PublicParameters(ECDomainParameters CURVE, BigInteger nTilde, int kPrime, BigInteger h1, BigInteger h2, PaPublicKey paillierPubKey)
18 | {
19 | gRaw = CURVE.getG().getEncoded();
20 | this.nTilde = nTilde;
21 | this.h1 = h1;
22 | this.h2 = h2;
23 | this.paillierPubKey = paillierPubKey;
24 | }
25 |
26 | public ECPoint getG(ECDomainParameters curve) {
27 | return curve.getCurve().decodePoint(gRaw);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/zkp/ZkpKG.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.zkp;
2 |
3 | import static org.fsn_cfc.util.OtherUtil.getBytes;
4 | import static org.fsn_cfc.util.OtherUtil.sha256Hash;
5 |
6 | import java.math.BigInteger;
7 | import java.security.SecureRandom;
8 | import java.util.ArrayList;
9 | import java.util.List;
10 | import java.util.concurrent.Callable;
11 | import java.util.concurrent.ExecutionException;
12 | import java.util.concurrent.ExecutorService;
13 | import java.util.concurrent.Executors;
14 | import java.util.concurrent.Future;
15 |
16 | import org.bouncycastle.crypto.params.ECDomainParameters;
17 | import org.bouncycastle.math.ec.ECPoint;
18 | import org.fsn_cfc.util.BitcoinParams;
19 | import org.fsn_cfc.util.RandomUtil;
20 | import org.squareup.jnagmp.Gmp;
21 |
22 |
23 |
24 |
25 |
26 | public class ZkpKG {
27 |
28 | private BigInteger z;
29 | private ECPoint u1;
30 | private BigInteger u2;
31 | private BigInteger u3;
32 | private BigInteger e;
33 | private BigInteger s1;
34 | private BigInteger s2;
35 | private BigInteger s3;
36 |
37 | public ZkpKG(PublicParameters params, BigInteger eta, SecureRandom rand, ECPoint c, BigInteger w, BigInteger r) {
38 |
39 | BigInteger N = params.paillierPubKey.getN();
40 | BigInteger q = BitcoinParams.q;
41 | BigInteger nSquared = N.multiply(N);
42 | BigInteger nTilde = params.nTilde;
43 | BigInteger h1 = params.h1;
44 | BigInteger h2 = params.h2;
45 | BigInteger g = N.add(BigInteger.ONE);
46 |
47 |
48 | BigInteger alpha = RandomUtil.randomFromZn(q.pow(3), rand);
49 | BigInteger rho = RandomUtil.randomFromZn(q.multiply(nTilde), rand);
50 | BigInteger beta = RandomUtil.randomFromZnStar(N, rand);
51 | BigInteger gamma = RandomUtil.randomFromZn(q.pow(3).multiply(nTilde), rand);
52 |
53 |
54 | z = Gmp.modPowSecure(h1,eta, nTilde).multiply(Gmp.modPowSecure(h2,rho, nTilde)).mod(nTilde);
55 | u1 = c.multiply(alpha);
56 | u2 = Gmp.modPowSecure(g,alpha, nSquared).multiply(Gmp.modPowSecure(beta,N, nSquared)).mod(nSquared);
57 | u3 = Gmp.modPowSecure(h1,alpha, nTilde).multiply(Gmp.modPowSecure(h2,gamma, nTilde)).mod(nTilde);
58 |
59 |
60 |
61 | byte[] digest = sha256Hash(getBytes(c), w.toByteArray(), z.toByteArray(), getBytes(u1), u2.toByteArray(), u3.toByteArray());
62 |
63 |
64 | if (digest == null) {
65 | throw new AssertionError();
66 | }
67 |
68 | e = new BigInteger(1, digest);
69 |
70 | s1 = e.multiply(eta).add(alpha);
71 | s2 = r.modPow(e, N).multiply(beta).mod(N);
72 | s3 = e.multiply(rho).add(gamma);
73 |
74 | }
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 | public boolean verify(PublicParameters params, ECDomainParameters CURVE, final ECPoint r, final BigInteger w) {
84 |
85 | final ECPoint c = params.getG(CURVE);
86 |
87 | final BigInteger h1 = params.h1;
88 | final BigInteger h2 = params.h2;
89 | final BigInteger N = params.paillierPubKey.getN();
90 | final BigInteger nTilde = params.nTilde;
91 | final BigInteger nSquared = N.pow(2);
92 | final BigInteger g = N.add(BigInteger.ONE);
93 |
94 | ExecutorService executor = Executors.newCachedThreadPool();
95 |
96 | int numTests = 4;
97 | List> tests = new ArrayList>(
98 | numTests);
99 |
100 | tests.add(new Callable() {
101 | @Override
102 | public Boolean call() {
103 | return u1.equals(c.multiply(s1).add(r.multiply(e.negate())));
104 | }
105 | });
106 |
107 | tests.add(new Callable() {
108 | @Override
109 | public Boolean call() {
110 | return u2.equals(Gmp.modPowSecure(g,s1, nSquared).multiply(Gmp.modPowSecure(s2,N, nSquared))
111 | .multiply(Gmp.modPowSecure(w, e.negate(), nSquared)).mod(nSquared));
112 | }
113 | });
114 |
115 | tests.add(new Callable() {
116 | @Override
117 | public Boolean call() {
118 | return u3.equals(Gmp.modPowSecure(h1,s1, nTilde).multiply(Gmp.modPowSecure(h2,s3, nTilde))
119 | .multiply(z.modPow(e.negate(), nTilde)).mod(nTilde));
120 | }
121 | });
122 |
123 | tests.add(new Callable() {
124 | @Override
125 | public Boolean call() {
126 | byte[] digestRecovered = sha256Hash(getBytes(c), w.toByteArray(), z.toByteArray(), getBytes(u1), u2.toByteArray(), u3.toByteArray());
127 |
128 | if (digestRecovered == null) {
129 | return false;
130 | }
131 |
132 | BigInteger eRecovered = new BigInteger(1, digestRecovered);
133 |
134 | return eRecovered.equals(e);
135 | }
136 | });
137 |
138 |
139 | List> futures = new ArrayList>(numTests);
140 |
141 | for(Callable test: tests) {
142 | futures.add(executor.submit(test));
143 | }
144 |
145 | for(Future future: futures) {
146 | try {
147 | if(!future.get().booleanValue()) {
148 | return false;
149 | }
150 | } catch (InterruptedException e) {
151 | e.printStackTrace();
152 | return false;
153 | } catch (ExecutionException e) {
154 | e.printStackTrace();
155 | return false;
156 | }
157 | }
158 |
159 | executor.shutdown();
160 | return true;
161 |
162 | }
163 |
164 |
165 |
166 |
167 | }
168 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/zkp/ZkpSignOne.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.zkp;
2 |
3 | import static org.fsn_cfc.util.OtherUtil.sha256Hash;
4 |
5 | import java.math.BigInteger;
6 | import java.security.SecureRandom;
7 | import java.util.ArrayList;
8 | import java.util.List;
9 | import java.util.concurrent.Callable;
10 | import java.util.concurrent.ExecutionException;
11 | import java.util.concurrent.ExecutorService;
12 | import java.util.concurrent.Executors;
13 | import java.util.concurrent.Future;
14 |
15 | import org.bouncycastle.crypto.params.ECDomainParameters;
16 | import org.fsn_cfc.util.BitcoinParams;
17 | import org.fsn_cfc.util.RandomUtil;
18 | import org.squareup.jnagmp.Gmp;
19 |
20 |
21 |
22 |
23 |
24 | public class ZkpSignOne {
25 |
26 | private BigInteger z;
27 | private BigInteger u1;
28 | private BigInteger u2;
29 | private BigInteger s1;
30 | private BigInteger s2;
31 | private BigInteger s3;
32 | private BigInteger e;
33 | private BigInteger v;
34 |
35 | public ZkpSignOne(PublicParameters params, BigInteger eta, SecureRandom rand, BigInteger r, BigInteger c1, BigInteger c2, BigInteger c3) {
36 |
37 | BigInteger N = params.paillierPubKey.getN();
38 | BigInteger q = BitcoinParams.q;
39 | BigInteger nSquared = N.multiply(N);
40 | BigInteger nTilde = params.nTilde;
41 | BigInteger h1 = params.h1;
42 | BigInteger h2 = params.h2;
43 | BigInteger g = N.add(BigInteger.ONE);
44 |
45 | BigInteger alpha = RandomUtil.randomFromZn(q.pow(3), rand);
46 | BigInteger beta = RandomUtil.randomFromZnStar(N, rand);
47 | BigInteger gamma = RandomUtil.randomFromZn(q.pow(3).multiply(nTilde), rand);
48 | BigInteger rho = RandomUtil.randomFromZn(q.multiply(nTilde), rand);
49 |
50 |
51 |
52 | z = Gmp.modPowSecure(h1,eta, nTilde).multiply(Gmp.modPowSecure(h2,rho, nTilde)).mod(nTilde);
53 | u1 = Gmp.modPowSecure(g,alpha, nSquared).multiply(Gmp.modPowSecure(beta,N, nSquared)).mod(nSquared);
54 | u2 = Gmp.modPowSecure(h1,alpha, nTilde).multiply(Gmp.modPowSecure(h2,gamma, nTilde)).mod(nTilde);
55 | v = Gmp.modPowSecure(c2,alpha, nSquared);
56 |
57 |
58 |
59 | byte[] digest = sha256Hash(c1.toByteArray(), c2.toByteArray(), c3.toByteArray(), z.toByteArray(), u1.toByteArray(), u2.toByteArray(), v.toByteArray());
60 |
61 | if (digest == null) {
62 | throw new AssertionError();
63 |
64 | }
65 |
66 | e = new BigInteger(1, digest);
67 |
68 | s1 = e.multiply(eta).add(alpha);
69 | s2 = r.modPow(e, N).multiply(beta).mod(N);
70 | s3 = e.multiply(rho).add(gamma);
71 |
72 | }
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 | public boolean verify(PublicParameters params, ECDomainParameters CURVE, final BigInteger c1, final BigInteger c2, final BigInteger c3) {
82 |
83 | final BigInteger h1 = params.h1;
84 | final BigInteger h2 = params.h2;
85 | final BigInteger N = params.paillierPubKey.getN();
86 | final BigInteger nTilde = params.nTilde;
87 | final BigInteger nSquared = N.pow(2);
88 | final BigInteger g = N.add(BigInteger.ONE);
89 |
90 | ExecutorService executor = Executors.newCachedThreadPool();
91 |
92 | int numTests = 4;
93 | List> tests = new ArrayList>(
94 | numTests);
95 |
96 | tests.add(new Callable() {
97 | @Override
98 | public Boolean call() {
99 | return u1.equals(Gmp.modPowSecure(g,s1, nSquared).multiply(Gmp.modPowSecure(s2,N, nSquared))
100 | .multiply(Gmp.modPowSecure(c3, e.negate(), nSquared)).mod(nSquared));
101 | }
102 | });
103 |
104 | tests.add(new Callable() {
105 | @Override
106 | public Boolean call() {
107 | return u2.equals(Gmp.modPowSecure(h1,s1, nTilde).multiply(Gmp.modPowSecure(h2,s3, nTilde))
108 | .multiply(z.modPow(e.negate(), nTilde)).mod(nTilde));
109 | }
110 | });
111 |
112 | tests.add(new Callable() {
113 | @Override
114 | public Boolean call() {
115 | return v.equals(Gmp.modPowSecure(c2,s1, nSquared)
116 | .multiply(Gmp.modPowSecure(c1, e.negate(), nSquared)).mod(nSquared));
117 | }
118 | });
119 |
120 | tests.add(new Callable() {
121 | @Override
122 | public Boolean call() {
123 | byte[] digestRecovered = sha256Hash(c1.toByteArray(), c2.toByteArray(), c3.toByteArray(), z.toByteArray(), u1.toByteArray(), u2.toByteArray(), v.toByteArray());
124 |
125 | if (digestRecovered == null) {
126 | return false;
127 | }
128 |
129 | BigInteger eRecovered = new BigInteger(1, digestRecovered);
130 |
131 | return eRecovered.equals(e);
132 | }
133 | });
134 |
135 |
136 | List> futures = new ArrayList>(numTests);
137 |
138 | for(Callable test: tests) {
139 | futures.add(executor.submit(test));
140 | }
141 |
142 | for(Future future: futures) {
143 | try {
144 | if(!future.get().booleanValue()) {
145 | return false;
146 | }
147 | } catch (InterruptedException e) {
148 | e.printStackTrace();
149 | return false;
150 | } catch (ExecutionException e) {
151 | e.printStackTrace();
152 | return false;
153 | }
154 | }
155 |
156 | executor.shutdown();
157 | return true;
158 |
159 | }
160 |
161 |
162 |
163 |
164 | }
165 |
--------------------------------------------------------------------------------
/src/org/fsn_cfc/zkp/ZkpSignTwo.java:
--------------------------------------------------------------------------------
1 | package org.fsn_cfc.zkp;
2 |
3 | import static org.fsn_cfc.util.OtherUtil.getBytes;
4 | import static org.fsn_cfc.util.OtherUtil.sha256Hash;
5 |
6 | import java.math.BigInteger;
7 | import java.security.SecureRandom;
8 | import java.util.ArrayList;
9 | import java.util.List;
10 | import java.util.concurrent.Callable;
11 | import java.util.concurrent.ExecutionException;
12 | import java.util.concurrent.ExecutorService;
13 | import java.util.concurrent.Executors;
14 | import java.util.concurrent.Future;
15 |
16 | import org.bouncycastle.crypto.params.ECDomainParameters;
17 | import org.bouncycastle.math.ec.ECPoint;
18 | import org.fsn_cfc.util.BitcoinParams;
19 | import org.fsn_cfc.util.RandomUtil;
20 | import org.squareup.jnagmp.Gmp;
21 |
22 |
23 |
24 |
25 | public class ZkpSignTwo {
26 |
27 | private ECPoint u1;
28 | private BigInteger u2;
29 | private BigInteger u3;
30 | private BigInteger z1;
31 | private BigInteger z2;
32 | private BigInteger s1;
33 | private BigInteger s2;
34 | private BigInteger t1;
35 | private BigInteger t2;
36 | private BigInteger t3;
37 | private BigInteger e;
38 | private BigInteger v1;
39 | private BigInteger v3;
40 |
41 | public ZkpSignTwo(PublicParameters params, BigInteger eta1, BigInteger eta2, SecureRandom rand, ECPoint c, BigInteger w, BigInteger u, BigInteger randomness) {
42 |
43 | BigInteger N = params.paillierPubKey.getN();
44 | BigInteger q = BitcoinParams.q;
45 | BigInteger nSquared = N.multiply(N);
46 | BigInteger nTilde = params.nTilde;
47 | BigInteger h1 = params.h1;
48 | BigInteger h2 = params.h2;
49 | BigInteger g = N.add(BigInteger.ONE);
50 |
51 | BigInteger alpha = RandomUtil.randomFromZn(q.pow(3), rand);
52 | BigInteger beta = RandomUtil.randomFromZnStar(N, rand);
53 | BigInteger gamma = RandomUtil.randomFromZn(q.pow(3).multiply(nTilde), rand);
54 | BigInteger mu = RandomUtil.randomFromZnStar(N, rand);
55 | BigInteger theta = RandomUtil.randomFromZn(q.pow(8), rand);
56 | BigInteger tau = RandomUtil.randomFromZn(q.pow(8).multiply(nTilde), rand);
57 |
58 | BigInteger rho1 = RandomUtil.randomFromZn(q.multiply(nTilde), rand);
59 | BigInteger rho2 = RandomUtil.randomFromZn(q.pow(6).multiply(nTilde), rand);
60 |
61 | z1 = Gmp.modPowSecure(h1,eta1, nTilde).multiply(Gmp.modPowSecure(h2,rho1, nTilde))
62 | .mod(nTilde);
63 | z2 = Gmp.modPowSecure(h1,eta2, nTilde).multiply(Gmp.modPowSecure(h2,rho2, nTilde))
64 | .mod(nTilde);
65 | u1 = c.multiply(alpha);
66 | u2 = Gmp.modPowSecure(g,alpha, nSquared).multiply(Gmp.modPowSecure(beta,N, nSquared))
67 | .mod(nSquared);
68 | u3 = Gmp.modPowSecure(h1,alpha, nTilde).multiply(Gmp.modPowSecure(h2,gamma, nTilde))
69 | .mod(nTilde);
70 | v1 = Gmp.modPowSecure(u,alpha, nSquared)
71 | .multiply(Gmp.modPowSecure(g,q.multiply(theta), nSquared))
72 | .multiply(Gmp.modPowSecure(mu,N, nSquared)).mod(nSquared);
73 | v3 = Gmp.modPowSecure(h1,theta, nTilde).multiply(Gmp.modPowSecure(h2,tau, nTilde))
74 | .mod(nTilde);
75 |
76 | byte[] digest = sha256Hash(getBytes(c), w.toByteArray(), u.toByteArray(), z1.toByteArray(), z2.toByteArray(), getBytes(u1),
77 | u2.toByteArray(), u3.toByteArray(), v1.toByteArray(), v3.toByteArray());
78 |
79 | if (digest == null) {
80 | throw new AssertionError();
81 |
82 | }
83 |
84 | e = new BigInteger(1, digest);
85 |
86 | s1 = e.multiply(eta1).add(alpha);
87 | s2 = e.multiply(rho1).add(gamma);
88 | t1 = Gmp.modPowSecure(randomness,e, N).multiply(mu).mod(N);
89 | t2 = e.multiply(eta2).add(theta);
90 | t3 = e.multiply(rho2).add(tau);
91 | }
92 |
93 | public boolean verify(PublicParameters params, ECDomainParameters CURVE, final ECPoint r, final BigInteger u, final BigInteger w) {
94 |
95 | final ECPoint c = params.getG(CURVE);
96 |
97 | final BigInteger h1 = params.h1;
98 | final BigInteger h2 = params.h2;
99 | final BigInteger N = params.paillierPubKey.getN();
100 | final BigInteger nTilde = params.nTilde;
101 | final BigInteger nSquared = N.multiply(N);
102 | final BigInteger g = N.add(BigInteger.ONE);
103 | final BigInteger q = BitcoinParams.q;
104 |
105 |
106 | ExecutorService executor = Executors.newCachedThreadPool();
107 |
108 | int numTests = 5;
109 | List> tests = new ArrayList>(
110 | numTests);
111 |
112 | tests.add(new Callable() {
113 | @Override
114 | public Boolean call() {
115 | return u1.equals(c.multiply(s1).add(r.multiply(e.negate())));
116 | }
117 | });
118 |
119 | tests.add(new Callable() {
120 | @Override
121 | public Boolean call() {
122 | return u3.equals(Gmp.modPowSecure(h1,s1, nTilde).multiply(Gmp.modPowSecure(h2,s2, nTilde))
123 | .multiply(z1.modPow(e.negate(), nTilde)).mod(nTilde));
124 | }
125 | });
126 |
127 | tests.add(new Callable() {
128 | @Override
129 | public Boolean call() {
130 | return v1.equals(Gmp.modPowSecure(u,s1, nSquared)
131 | .multiply(Gmp.modPowSecure(g,q.multiply(t2), nSquared))
132 | .multiply(Gmp.modPowSecure(t1,N, nSquared))
133 | .multiply(w.modPow(e.negate(), nSquared)).mod(nSquared));
134 | }
135 | });
136 |
137 | tests.add(new Callable() {
138 | @Override
139 | public Boolean call() {
140 | return v3.equals(Gmp.modPowSecure(h1,t2, nTilde).multiply(Gmp.modPowSecure(h2,t3, nTilde))
141 | .multiply(z2.modPow(e.negate(), nTilde)).mod(nTilde));
142 | }
143 | });
144 |
145 | tests.add(new Callable() {
146 | @Override
147 | public Boolean call() {
148 | byte[] digestRecovered = sha256Hash(getBytes(c), w.toByteArray(), u.toByteArray(), z1.toByteArray(), z2.toByteArray(), getBytes(u1),
149 | u2.toByteArray(), u3.toByteArray(), v1.toByteArray(), v3.toByteArray());
150 |
151 | if (digestRecovered == null) {
152 | return false;
153 | }
154 |
155 | BigInteger eRecovered = new BigInteger(1, digestRecovered);
156 |
157 | return eRecovered.equals(e);
158 | }
159 | });
160 |
161 | List> futures = new ArrayList>(numTests);
162 |
163 | for(Callable test: tests) {
164 | futures.add(executor.submit(test));
165 | }
166 |
167 | for(Future future: futures) {
168 | try {
169 | if(!future.get().booleanValue()) {
170 | return false;
171 | }
172 | } catch (InterruptedException e) {
173 | e.printStackTrace();
174 | return false;
175 | } catch (ExecutionException e) {
176 | e.printStackTrace();
177 | return false;
178 | }
179 | }
180 |
181 | executor.shutdown();
182 | return true;
183 |
184 | }
185 |
186 | }
187 |
--------------------------------------------------------------------------------
/src/org/squareup/jnagmp/Gmp.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Square Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.squareup.jnagmp;
17 |
18 | import com.sun.jna.Memory;
19 | import com.sun.jna.Native;
20 | import com.sun.jna.NativeLong;
21 | import com.sun.jna.Pointer;
22 | import java.math.BigInteger;
23 |
24 | import org.squareup.jnagmp.LibGmp.mpz_t;
25 |
26 | import static java.lang.Math.max;
27 | import static java.lang.Math.min;
28 | import static org.squareup.jnagmp.LibGmp.__gmpz_clear;
29 | import static org.squareup.jnagmp.LibGmp.__gmpz_cmp_si;
30 | import static org.squareup.jnagmp.LibGmp.__gmpz_divexact;
31 | import static org.squareup.jnagmp.LibGmp.__gmpz_export;
32 | import static org.squareup.jnagmp.LibGmp.__gmpz_gcd;
33 | import static org.squareup.jnagmp.LibGmp.__gmpz_import;
34 | import static org.squareup.jnagmp.LibGmp.__gmpz_init;
35 | import static org.squareup.jnagmp.LibGmp.__gmpz_invert;
36 | import static org.squareup.jnagmp.LibGmp.__gmpz_jacobi;
37 | import static org.squareup.jnagmp.LibGmp.__gmpz_neg;
38 | import static org.squareup.jnagmp.LibGmp.__gmpz_powm;
39 | import static org.squareup.jnagmp.LibGmp.__gmpz_powm_sec;
40 | import static org.squareup.jnagmp.LibGmp.readSizeT;
41 |
42 | public final class Gmp {
43 |
44 | private static final UnsatisfiedLinkError LOAD_ERROR;
45 |
46 | static {
47 | UnsatisfiedLinkError localLoadError = null;
48 | try {
49 | LibGmp.init();
50 | } catch (UnsatisfiedLinkError e) {
51 | localLoadError = e;
52 | }
53 | LOAD_ERROR = localLoadError;
54 | }
55 |
56 | public static void checkLoaded() {
57 | if (LOAD_ERROR != null) {
58 | throw LOAD_ERROR;
59 | }
60 | BigInteger two = BigInteger.valueOf(2);
61 | BigInteger three = BigInteger.valueOf(3);
62 | BigInteger four = BigInteger.valueOf(4);
63 | BigInteger five = BigInteger.valueOf(5);
64 | BigInteger answer;
65 |
66 | answer = modPowInsecure(two, three, five);
67 | if (!three.equals(answer)) {
68 | throw new AssertionError("libgmp is loaded but modPowInsecure returned the wrong answer");
69 | }
70 |
71 | answer = modPowSecure(two, three, five);
72 | if (!three.equals(answer)) {
73 | throw new AssertionError("libgmp is loaded but modPowSecure returned the wrong answer");
74 | }
75 |
76 | int answr = kronecker(four, five);
77 | if (answr != 1) {
78 | throw new AssertionError("libgmp is loaded but kronecker returned the wrong answer");
79 | }
80 | }
81 |
82 | public static int kronecker(BigInteger a, BigInteger p) {
83 | return INSTANCE.get().kroneckerImpl(a, p);
84 | }
85 |
86 | public static BigInteger modPowInsecure(BigInteger base, BigInteger exponent,
87 | BigInteger modulus) {
88 | if (modulus.signum() <= 0) {
89 | throw new ArithmeticException("modulus must be positive");
90 | }
91 | return INSTANCE.get().modPowInsecureImpl(base, exponent, modulus);
92 | }
93 |
94 | public static BigInteger modPowSecure(BigInteger base, BigInteger exponent, BigInteger modulus) {
95 | if (modulus.signum() <= 0) {
96 | throw new ArithmeticException("modulus must be positive");
97 | }
98 | if (!modulus.testBit(0)) {
99 | throw new IllegalArgumentException("modulus must be odd");
100 | }
101 | return INSTANCE.get().modPowSecureImpl(base, exponent, modulus);
102 | }
103 |
104 | public static BigInteger modInverse(BigInteger val, BigInteger modulus) {
105 | if (modulus.signum() <= 0) {
106 | throw new ArithmeticException("modulus must be positive");
107 | }
108 | return INSTANCE.get().modInverseImpl(val, modulus);
109 | }
110 |
111 | public static BigInteger exactDivide(BigInteger dividend, BigInteger divisor) {
112 | if (divisor.signum() == 0) {
113 | throw new ArithmeticException("BigInteger divide by zero");
114 | }
115 | return INSTANCE.get().exactDivImpl(dividend, divisor);
116 | }
117 |
118 | public static BigInteger gcd(BigInteger value1, BigInteger value2) {
119 | return INSTANCE.get().gcdImpl(value1, value2);
120 | }
121 |
122 | static final ThreadLocal INSTANCE = new ThreadLocal() {
123 | @Override protected Gmp initialValue() {
124 | return new Gmp();
125 | }
126 | };
127 |
128 | private static final int INITIAL_BUF_BITS = 2048;
129 | private static final int INITIAL_BUF_SIZE = INITIAL_BUF_BITS / 8;
130 |
131 | private static final int MAX_OPERANDS = 4;
132 |
133 | private static final int SHARED_MEM_SIZE = mpz_t.SIZE * MAX_OPERANDS + Native.SIZE_T_SIZE;
134 |
135 | private final mpz_t[] sharedOperands = new mpz_t[MAX_OPERANDS];
136 |
137 | private final Pointer countPtr;
138 |
139 | /** A fixed, shared, reusable memory buffer. */
140 | private final Memory sharedMem = new Memory(SHARED_MEM_SIZE) {
141 | @Override protected void finalize() {
142 | for (mpz_t sharedOperand : sharedOperands) {
143 | if (sharedOperand != null) {
144 | __gmpz_clear(sharedOperand);
145 | }
146 | }
147 | super.finalize();
148 | }
149 | };
150 |
151 | /** Reusable scratch buffer for moving data between byte[] and mpz_t. */
152 | private Memory scratchBuf = new Memory(INITIAL_BUF_SIZE);
153 |
154 | private Gmp() {
155 | int offset = 0;
156 | for (int i = 0; i < MAX_OPERANDS; ++i) {
157 | this.sharedOperands[i] = new mpz_t(sharedMem.share(offset, mpz_t.SIZE));
158 | __gmpz_init(sharedOperands[i]);
159 | offset += mpz_t.SIZE;
160 | }
161 | this.countPtr = sharedMem.share(offset, Native.SIZE_T_SIZE);
162 | offset += Native.SIZE_T_SIZE;
163 | assert offset == SHARED_MEM_SIZE;
164 | }
165 |
166 | private int kroneckerImpl(BigInteger a, BigInteger p) {
167 | mpz_t aPeer = getPeer(a, sharedOperands[0]);
168 | mpz_t pPeer = getPeer(p, sharedOperands[1]);
169 |
170 | return __gmpz_jacobi(aPeer, pPeer);
171 | }
172 |
173 | private BigInteger modPowInsecureImpl(BigInteger base, BigInteger exp, BigInteger mod) {
174 | boolean invert = exp.signum() < 0;
175 | if (invert) {
176 | exp = exp.negate();
177 | }
178 |
179 | mpz_t basePeer = getPeer(base, sharedOperands[0]);
180 | mpz_t expPeer = getPeer(exp, sharedOperands[1]);
181 | mpz_t modPeer = getPeer(mod, sharedOperands[2]);
182 |
183 | if (invert) {
184 | int res = __gmpz_invert(basePeer, basePeer, modPeer);
185 | if (res == 0) {
186 | throw new ArithmeticException("val not invertible");
187 | }
188 | }
189 |
190 | __gmpz_powm(sharedOperands[3], basePeer, expPeer, modPeer);
191 |
192 | // The result size should be <= modulus size, but round up to the nearest byte.
193 | int requiredSize = (mod.bitLength() + 7) / 8;
194 | return new BigInteger(mpzSgn(sharedOperands[3]), mpzExport(sharedOperands[3], requiredSize));
195 | }
196 |
197 | private BigInteger modPowSecureImpl(BigInteger base, BigInteger exp, BigInteger mod) {
198 | boolean invert = exp.signum() < 0;
199 | if (invert) {
200 | exp = exp.negate();
201 | }
202 |
203 | mpz_t basePeer = getPeer(base, sharedOperands[0]);
204 | mpz_t expPeer = getPeer(exp, sharedOperands[1]);
205 | mpz_t modPeer = getPeer(mod, sharedOperands[2]);
206 |
207 | if (invert) {
208 | int res = __gmpz_invert(basePeer, basePeer, modPeer);
209 | if (res == 0) {
210 | throw new ArithmeticException("val not invertible");
211 | }
212 | }
213 |
214 | __gmpz_powm_sec(sharedOperands[3], basePeer, expPeer, modPeer);
215 |
216 | // The result size should be <= modulus size, but round up to the nearest byte.
217 | int requiredSize = (mod.bitLength() + 7) / 8;
218 | return new BigInteger(mpzSgn(sharedOperands[3]), mpzExport(sharedOperands[3], requiredSize));
219 | }
220 |
221 | private BigInteger modInverseImpl(BigInteger val, BigInteger mod) {
222 | mpz_t valPeer = getPeer(val, sharedOperands[0]);
223 | mpz_t modPeer = getPeer(mod, sharedOperands[1]);
224 |
225 | int res = __gmpz_invert(sharedOperands[2], valPeer, modPeer);
226 | if (res == 0) {
227 | throw new ArithmeticException("val not invertible");
228 | }
229 |
230 | // The result size should be <= modulus size, but round up to the nearest byte.
231 | int requiredSize = (mod.bitLength() + 7) / 8;
232 | return new BigInteger(mpzSgn(sharedOperands[2]), mpzExport(sharedOperands[2], requiredSize));
233 | }
234 |
235 | private BigInteger exactDivImpl(BigInteger dividend, BigInteger divisor) {
236 | mpz_t dividendPeer = getPeer(dividend, sharedOperands[0]);
237 | mpz_t divisorPeer = getPeer(divisor, sharedOperands[1]);
238 |
239 | __gmpz_divexact(sharedOperands[2], dividendPeer, divisorPeer);
240 |
241 | // The result size is never larger than the bit length of the dividend minus that of the divisor
242 | // plus 1 (but is at least 1 bit long to hold the case that the two values are exactly equal)
243 | int requiredSize = max(dividend.bitLength() - divisor.bitLength() + 1, 1);
244 | return new BigInteger(mpzSgn(sharedOperands[2]), mpzExport(sharedOperands[2], requiredSize));
245 | }
246 |
247 | private BigInteger gcdImpl(BigInteger value1, BigInteger value2) {
248 | mpz_t value1Peer = getPeer(value1, sharedOperands[0]);
249 | mpz_t value2Peer = getPeer(value2, sharedOperands[1]);
250 |
251 | __gmpz_gcd(sharedOperands[2], value1Peer, value2Peer);
252 |
253 | // The result size will be no larger than the smaller of the inputs
254 | int requiredSize = min(value1.bitLength(), value2.bitLength());
255 | return new BigInteger(mpzSgn(sharedOperands[2]), mpzExport(sharedOperands[2], requiredSize));
256 | }
257 |
258 | private mpz_t getPeer(BigInteger value, mpz_t sharedPeer) {
259 | if (value instanceof GmpInteger) {
260 | return ((GmpInteger) value).getPeer();
261 | }
262 | mpzImport(sharedPeer, value.signum(), value.abs().toByteArray());
263 | return sharedPeer;
264 | }
265 |
266 | void mpzImport(mpz_t ptr, int signum, byte[] bytes) {
267 | int expectedLength = bytes.length;
268 | ensureBufferSize(expectedLength);
269 | scratchBuf.write(0, bytes, 0, bytes.length);
270 | __gmpz_import(ptr, bytes.length, 1, 1, 1, 0, scratchBuf);
271 | if (signum < 0) {
272 | __gmpz_neg(ptr, ptr);
273 | }
274 | }
275 |
276 | private byte[] mpzExport(mpz_t ptr, int requiredSize) {
277 | ensureBufferSize(requiredSize);
278 | __gmpz_export(scratchBuf, countPtr, 1, 1, 1, 0, ptr);
279 |
280 | int count = readSizeT(countPtr);
281 | byte[] result = new byte[count];
282 | scratchBuf.read(0, result, 0, count);
283 | return result;
284 | }
285 |
286 | private static final NativeLong ZERO = new NativeLong();
287 |
288 | int mpzSgn(mpz_t ptr) {
289 | int result = __gmpz_cmp_si(ptr, ZERO);
290 | if (result < 0) {
291 | return -1;
292 | } else if (result > 0) {
293 | return 1;
294 | }
295 | return 0;
296 | }
297 |
298 | private void ensureBufferSize(int size) {
299 | if (scratchBuf.size() < size) {
300 | long newSize = scratchBuf.size();
301 | while (newSize < size) {
302 | newSize <<= 1;
303 | }
304 | scratchBuf = new Memory(newSize);
305 | }
306 | }
307 | }
308 |
--------------------------------------------------------------------------------
/src/org/squareup/jnagmp/GmpInteger.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Square Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.squareup.jnagmp;
17 |
18 | import com.sun.jna.Memory;
19 | import java.math.BigInteger;
20 | import java.util.Random;
21 |
22 | import org.squareup.jnagmp.LibGmp.mpz_t;
23 |
24 | public class GmpInteger extends BigInteger {
25 |
26 | private static class MpzMemory extends Memory {
27 | public final mpz_t peer;
28 |
29 | MpzMemory() {
30 | super(mpz_t.SIZE);
31 | peer = new mpz_t(this);
32 | LibGmp.__gmpz_init(peer);
33 | }
34 |
35 | @Override protected void finalize() {
36 | LibGmp.__gmpz_clear(peer);
37 | super.finalize();
38 | }
39 | }
40 |
41 | private final MpzMemory mpzMemory = new MpzMemory();
42 |
43 | {
44 | Gmp.INSTANCE.get().mpzImport(mpzMemory.peer, super.signum(), super.abs().toByteArray());
45 | }
46 |
47 | mpz_t getPeer() {
48 | return mpzMemory.peer;
49 | }
50 |
51 | /** Constructs a GmpInteger from a BigInteger. */
52 | public GmpInteger(BigInteger other) {
53 | super(other.toByteArray());
54 | }
55 |
56 | /** @see BigInteger#BigInteger(byte[]) */
57 | public GmpInteger(byte[] val) {
58 | super(val);
59 | }
60 |
61 | /** @see BigInteger#BigInteger(int, byte[]) */
62 | public GmpInteger(int signum, byte[] magnitude) {
63 | super(signum, magnitude);
64 | }
65 |
66 | /** @see BigInteger#BigInteger(String, int) ) */
67 | public GmpInteger(String val, int radix) {
68 | super(val, radix);
69 | }
70 |
71 | /** @see BigInteger#BigInteger(String) */
72 | public GmpInteger(String val) {
73 | super(val);
74 | }
75 |
76 | /** @see BigInteger#BigInteger(int, Random) */
77 | public GmpInteger(int numBits, Random rnd) {
78 | super(numBits, rnd);
79 | }
80 |
81 | /** @see BigInteger#BigInteger(int, int, Random) */
82 | public GmpInteger(int bitLength, int certainty, Random rnd) {
83 | super(bitLength, certainty, rnd);
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/org/squareup/jnagmp/LibGmp.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Square Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /*
17 | * GMP function documentation licensed under GNU Free Documentation License.
18 | * http://gmplib.org/manual/GNU-Free-Documentation-License.html
19 | *
20 | * Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
21 | * 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
22 | */
23 | package org.squareup.jnagmp;
24 |
25 | import com.sun.jna.Native;
26 | import com.sun.jna.NativeLibrary;
27 | import com.sun.jna.NativeLong;
28 | import com.sun.jna.Pointer;
29 | import java.io.File;
30 |
31 | public final class LibGmp {
32 |
33 | private static final Class SIZE_T_CLASS;
34 |
35 | static {
36 | if (Native.SIZE_T_SIZE == 4) {
37 | SIZE_T_CLASS = SizeT4.class;
38 | } else if (Native.SIZE_T_SIZE == 8) {
39 | SIZE_T_CLASS = SizeT8.class;
40 | } else {
41 | throw new AssertionError("Unexpected Native.SIZE_T_SIZE: " + Native.SIZE_T_SIZE);
42 | }
43 | }
44 |
45 | static {
46 | loadLibGmp();
47 | }
48 |
49 | public static void loadLibGmp() {
50 | try {
51 | // Explicitly try to load the embedded version first.
52 | File file = Native.extractFromResourcePath("gmp", LibGmp.class.getClassLoader());
53 | load(file.getAbsolutePath());
54 | return;
55 | } catch (Exception ignored) {
56 | } catch (UnsatisfiedLinkError ignored) {
57 | }
58 | // Fall back to system-wide search.
59 | load("gmp");
60 | }
61 |
62 | public static void load(String name) {
63 | NativeLibrary library = NativeLibrary.getInstance(name, LibGmp.class.getClassLoader());
64 | Native.register(LibGmp.class, library);
65 | Native.register(SIZE_T_CLASS, library);
66 | }
67 |
68 | public static final String __gmp_version;
69 | // CHECKSTYLE.ON: ConstantName
70 |
71 | static {
72 | __gmp_version = NativeLibrary.getProcess() // library is already loaded and linked.
73 | .getGlobalVariableAddress("__gmp_version") // &(const char* __gmp_version)
74 | .getPointer(0) // const char* __gmp_version
75 | .getString(0);
76 | }
77 |
78 | /** Dummy method to force class initialization. */
79 | public static void init() {
80 | }
81 |
82 | /** Helper method to read the value of a (size_t*), depends on {@code sizeof(size_t)}. */
83 | public static int readSizeT(Pointer ptr) {
84 | // TODO(scottb): make not public.
85 | if (SIZE_T_CLASS == SizeT4.class) {
86 | int result;
87 | result = ptr.getInt(0);
88 | assert result >= 0;
89 | return result;
90 | } else {
91 | long result = ptr.getLong(0);
92 | assert result >= 0;
93 | assert result < Integer.MAX_VALUE;
94 | return (int) result;
95 | }
96 | }
97 |
98 | public static class mpz_t extends Pointer {
99 | /** The size, in bytes, of the native structure. */
100 | public static final int SIZE = 16;
101 |
102 | /**
103 | * Constructs an mpz_t from a native address.
104 | *
105 | * @param peer the address of a block of native memory at least {@link #SIZE} bytes large
106 | */
107 | public mpz_t(long peer) {
108 | super(peer);
109 | }
110 |
111 | /**
112 | * Constructs an mpz_t from a Pointer.
113 | *
114 | * @param from an block of native memory at least {@link #SIZE} bytes large
115 | */
116 | public mpz_t(Pointer from) {
117 | this(Pointer.nativeValue(from));
118 | }
119 | }
120 | /** Used on systems with 4-byte size_t. */
121 | static class SizeT4 {
122 | static native void __gmpz_import(mpz_t rop, int count, int order, int size, int endian,
123 | int nails, Pointer buffer);
124 |
125 | static native Pointer __gmpz_export(Pointer rop, Pointer countp, int order, int size,
126 | int endian, int nails, mpz_t op);
127 | }
128 |
129 | /** Used on systems with 8-byte size_t. */
130 | static class SizeT8 {
131 | static native void __gmpz_import(mpz_t rop, long count, int order, int size, int endian,
132 | long nails, Pointer buffer);
133 |
134 | static native Pointer __gmpz_export(Pointer rop, Pointer countp, int order, long size,
135 | int endian, long nails, mpz_t op);
136 | }
137 |
138 | public static void __gmpz_import(mpz_t rop, int count, int order, int size, int endian, int nails,
139 | Pointer buffer) {
140 | if (SIZE_T_CLASS == SizeT4.class) {
141 | SizeT4.__gmpz_import(rop, count, order, size, endian, nails, buffer);
142 | } else {
143 | SizeT8.__gmpz_import(rop, count, order, size, endian, nails, buffer);
144 | }
145 | }
146 |
147 | public static void __gmpz_export(Pointer rop, Pointer countp, int order, int size, int endian,
148 | int nails, mpz_t op) {
149 | if (SIZE_T_CLASS == SizeT4.class) {
150 | SizeT4.__gmpz_export(rop, countp, order, size, endian, nails, op);
151 | } else {
152 | SizeT8.__gmpz_export(rop, countp, order, size, endian, nails, op);
153 | }
154 | }
155 |
156 | public static native void __gmpz_init(mpz_t integer);
157 |
158 | public static native void __gmpz_init2(mpz_t x, NativeLong n);
159 |
160 | public static native void __gmpz_clear(mpz_t x);
161 |
162 | public static native void __gmpz_neg(mpz_t rop, mpz_t op);
163 |
164 | public static native void __gmpz_powm(mpz_t rop, mpz_t base, mpz_t exp, mpz_t mod);
165 |
166 | public static native int __gmpz_cmp_si(mpz_t op1, NativeLong op2);
167 |
168 | public static native void __gmpz_powm_sec(mpz_t rop, mpz_t base, mpz_t exp, mpz_t mod);
169 |
170 | public static native int __gmpz_invert(mpz_t rop, mpz_t op1, mpz_t op2);
171 |
172 | public static native int __gmpz_jacobi(mpz_t a, mpz_t p);
173 |
174 | public static native void __gmpz_mul(mpz_t rop, mpz_t op1, mpz_t op2);
175 |
176 | public static native void __gmpz_mod(mpz_t r, mpz_t n, mpz_t d);
177 |
178 | public static native void __gmpz_divexact(mpz_t q, mpz_t n, mpz_t d);
179 |
180 | public static native void __gmpz_gcd(mpz_t rop, mpz_t op1, mpz_t op2);
181 |
182 | private LibGmp() {
183 | }
184 | }
185 |
--------------------------------------------------------------------------------